diff --git a/src/sketchup-stl.rb b/src/sketchup-stl.rb index 26e12a3..8cd2744 100644 --- a/src/sketchup-stl.rb +++ b/src/sketchup-stl.rb @@ -11,9 +11,18 @@ module CommunityExtensions module STL - PLUGIN_ROOT_PATH = File.dirname(__FILE__) - PLUGIN_PATH = File.join(PLUGIN_ROOT_PATH, 'sketchup-stl') - PLUGIN_STRINGS_PATH = File.join(PLUGIN_PATH, 'strings') + # In SU2014, with Ruby 2.0 the __FILE__ constant return an UTF-8 string with + # incorrect encoding label which will cause load errors when the file path + # contain multi-byte characters. This happens when the user has non-english + # characters in their username. + current_path = File.dirname(__FILE__) + if current_path.respond_to?(:force_encoding) + current_path.force_encoding("UTF-8") + end + + PLUGIN_ROOT_PATH = current_path.freeze + PLUGIN_PATH = File.join(PLUGIN_ROOT_PATH, 'sketchup-stl').freeze + PLUGIN_STRINGS_PATH = File.join(PLUGIN_PATH, 'strings').freeze Sketchup::require File.join(PLUGIN_PATH, 'translator') options = { @@ -41,7 +50,7 @@ def self.translate(string) 'This is an open source project sponsored by the SketchUp team. More ' << 'info and updates at https://github.com/SketchUp/sketchup-stl' ) - extension.version = '2.1.3' + extension.version = '2.1.4' extension.copyright = '2012-2014 Trimble Navigation, ' << 'released under Apache 2.0' extension.creator = 'J. Foltz, N. Bromham, K. Shroeder, SketchUp Team' diff --git a/src/sketchup-stl/SKUI/core.rb b/src/sketchup-stl/SKUI/core.rb index 2a8eccb..2c42add 100644 --- a/src/sketchup-stl/SKUI/core.rb +++ b/src/sketchup-stl/SKUI/core.rb @@ -1,8 +1,17 @@ # @since 1.0.0 module SKUI + # In SU2014, with Ruby 2.0 the __FILE__ constant return an UTF-8 string with + # incorrect encoding label which will cause load errors when the file path + # contain multi-byte characters. This happens when the user has non-english + # characters in their username. + current_path = File.dirname( __FILE__ ) + if current_path.respond_to?( :force_encoding ) + current_path.force_encoding( "UTF-8" ) + end + # @since 1.0.0 - PATH = File.dirname( __FILE__ ).freeze + PATH = current_path.freeze PATH_JS = File.join( PATH, 'js' ).freeze PATH_CSS = File.join( PATH, 'css' ).freeze PATH_HTML = File.join( PATH, 'html' ).freeze @@ -46,4 +55,4 @@ def self.reload $VERBOSE = original_verbose end -end # module +end # module \ No newline at end of file diff --git a/src/sketchup-stl/SKUI/embed_skui.rb b/src/sketchup-stl/SKUI/embed_skui.rb index 472e2da..805fdd0 100644 --- a/src/sketchup-stl/SKUI/embed_skui.rb +++ b/src/sketchup-stl/SKUI/embed_skui.rb @@ -21,6 +21,11 @@ def self.embed_in( context ) Object.send( :remove_const, :SKUI ) # Load SKUI for this SKUI implementation. path = File.dirname( __FILE__ ) + # In SU2014, with Ruby 2.0 the __FILE__ constant return an UTF-8 string with + # incorrect encoding label which will cause load errors when the file path + # contain multi-byte characters. This happens when the user has non-english + # characters in their username. + path.force_encoding( "UTF-8" ) if path.respond_to?( :force_encoding ) core = File.join( path, 'core.rb' ) loaded = require( core ) # One can only embed SKUI into one context per SKUI installation. This is diff --git a/src/sketchup-stl/exporter.rb b/src/sketchup-stl/exporter.rb index 67ea77a..9633b87 100644 --- a/src/sketchup-stl/exporter.rb +++ b/src/sketchup-stl/exporter.rb @@ -11,7 +11,7 @@ module STL module Exporter # Load SKUI lib - load File.join(File.dirname(__FILE__), 'SKUI', 'embed_skui.rb') + load File.join(PLUGIN_PATH, 'SKUI', 'embed_skui.rb') ::SKUI.embed_in(self) STL_ASCII = 'ASCII'.freeze