From d296ac3805ba466a142347868c3f5b2d724f86b2 Mon Sep 17 00:00:00 2001 From: thomthom Date: Fri, 28 Mar 2014 10:51:19 +0100 Subject: [PATCH 1/2] Fixing load errors on systems where multi-byte characters are present in the load path. Fixes #134. --- src/sketchup-stl.rb | 15 ++++++++++++--- src/sketchup-stl/SKUI/core.rb | 13 +++++++++++-- src/sketchup-stl/SKUI/embed_skui.rb | 5 +++++ src/sketchup-stl/exporter.rb | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/sketchup-stl.rb b/src/sketchup-stl.rb index 26e12a3..fe46b04 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 = { 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 From 945c197dfcfb7512cb2882081f0e7f9e1cef1079 Mon Sep 17 00:00:00 2001 From: thomthom Date: Fri, 28 Mar 2014 11:00:44 +0100 Subject: [PATCH 2/2] Bumping version number to 2.1.4 for release. --- src/sketchup-stl.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sketchup-stl.rb b/src/sketchup-stl.rb index fe46b04..8cd2744 100644 --- a/src/sketchup-stl.rb +++ b/src/sketchup-stl.rb @@ -50,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'