French OS Compatibility Issue

I have a customer who has installed my plugins on a French Canadian Windows 10 OS and is getting the following error in both the French and English versions of SketchUp Make 2017:

I’ve never seen this error before and it appears to be related to the French OS.

Has anyone ever seen this sort of thing before? Solution?

Could it be due to having binaries installed/located on both the C: and D: drives?

The user’s name contains an accented character - “benoît”

In the past this was the kiss-of-death to Ruby on PCs, however changes to Ruby have covered a lot [if not all] such cases…
The clue is also in the start of the error-message - “…mismatch… UTF-8 regexp with Windows-1252 string…
Without seeing your code it has to be a guess, but I suspect that you are somehow passing a string-path to part of your code which is NOT forced its encoding into UTF-8

Whenever you get a string reference to a path - especially in the user’s AppData tree - it’s vital to immediately force its encoding correctly…
e.g.

ME = __FILE__.force_encoding("UTF-8")

which returns a loaded script’s full-path into a Constant ME - e.g. the file in its main folder
From that you can parse out its folder-path, or create a reference to nested folder with it etc… e.g.

MY_DIR = File.dirname(ME)
MY_MATS = File.join(MY_DIR, "Materials")
1 Like

Same error from another user in Russia, his username is: peter novák

Looks like I need to figure this one out and fully address it.

The chunk of code were I probably need to address this is here:

############
# Initialization Check for Wall Plugin Parameters

WIN_OS = ( Sketchup.platform == :platform_win rescue RUBY_PLATFORM !~ /(darwin)/i )
if WIN_OS
          appdata = ENV['AppData'].gsub(/(\\\\|\\)/,'/')
else
          appdata = File.expand_path('~/Library/Application Support')
end

su_version = Sketchup.version.to_i + 2000
    		
APPDATA_MEDEEK_WALL = File.join(appdata,"Medeek/#{su_version}/medeek_wall_ext")

I’m doing something similar here already with this chunk of code:

this_dir = File.dirname(__FILE__)
	# Fix for ruby 2.0
	if this_dir.respond_to?(:force_encoding)
		THIS_DIR = this_dir.dup.force_encoding("UTF-8")
	else
		THIS_DIR = this_dir
	end

So my first chunk of code should be updated to?

############
# Initialization Check for Wall Plugin Parameters

WIN_OS = ( Sketchup.platform == :platform_win rescue RUBY_PLATFORM !~ /(darwin)/i )
if WIN_OS
      	appdata = ENV['AppData'].gsub(/(\\\\|\\)/,'/')
else
      	appdata = File.expand_path('~/Library/Application Support')
end

if appdata.respond_to?(:force_encoding)
	APPDATA = appdata.dup.force_encoding("UTF-8")
else
	APPDATA = appdata
end

su_version = Sketchup.version.to_i + 2000
		
APPDATA_MEDEEK_WALL = File.join(APPDATA,"Medeek/#{su_version}/medeek_wall_ext")

I guess I’m still not clear on what is going on here. With this particular line of code why the need for “dup” method?

I think it came from someone’s attempt to not modify the strings in the ENV hash.

But in your case String#gsub creates a new String anyway.
And I think the same for File::expand_path method.

The encoding output by these methods may be dependent upon what you use for a script encoding.
This is why it is strongly suggested you use a “magic comment” at the tippy top of every file. IE …

# encoding: UTF-8

Suggested reading is the preamble to the Encoding class.

1 Like

Looks like I am still having problems with users have strange characters in their usernames.

I’m going to try the magic comment at the top of the file as Dan suggested, hopefully this resolves the issue.

Even with the magic comment at the top of the file it still seems to be a problem, any suggestions?

I’m getting this error:

“Unable to find AppData directory”

I think the code is breaking on this line:

appdata = ENV['AppData'].gsub(/(\\\\|\\)/,'/')

Does the AppData folder not exist in French Windows 10?

The AppData path is a user path, so if they have unicode characters within their username, then it will be part of the AppData path.

1 Like

Yes, but why would I get the error above, I’ve never seen that before. Could the AppData sub-folder name be spelled differently? Never seen this error before, I don’t think it is a UTF-8 error because my previous fix seemed to resolve all of the issue people were having prior and no new reports of it being an issue. This particular users computer (Windows 10 French) seems to actually be missing the AppData subfolder or at least it is not coming up as an environment variable, strange.

Adding the magic comment to the top of the Ruby file did not change the error or behavior so that solidifies in my mind that this is not a UTF-8 issue.

I think the magic comment affects how the text of the Ruby script is handled. It does not change handling of data read from the environment or from other files.

Something like:

### Check for OS - PC v MAC
### Its actual ENV 'key' is in uppercase - although it should still work as you've typed it...
### And the user might have messed with his ENV settings & removed its entry...
appdata = ENV["APPDATA"] ### the default value
unless appdata
  appdata = File.dirname(File.dirname(Sketchup.temp_dir))
  ### Sketchup's temp folder is in the AppData tree on PC - 
  ### of course if it relies on a good ENV set up it'll also fail !
end
###
if appdata.respond_to?(:force_encoding)
  APPDATA = appdata.dup.tr("\\", "/").force_encoding("UTF-8")
else
  APPDATA = appdata
end

??