Skip to content

Commit

Permalink
Merge pull request #135 from thomthom/master
Browse files Browse the repository at this point in the history
Fixing load errors on systems where multi-byte characters are present in the load path.
thomthom committed Mar 28, 2014
2 parents d7054d7 + 945c197 commit 08fe358
Showing 4 changed files with 30 additions and 7 deletions.
17 changes: 13 additions & 4 deletions src/sketchup-stl.rb
Original file line number Diff line number Diff line change
@@ -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'
13 changes: 11 additions & 2 deletions src/sketchup-stl/SKUI/core.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions src/sketchup-stl/SKUI/embed_skui.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/sketchup-stl/exporter.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 08fe358

Please sign in to comment.