-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Catch file reading errors and provide a useful error message #98
Comments
Not sure if this is helpful yet or not... If I know the 20th file name in my tmp folder contains UTF, then I can read the file using (This is reading the face count from a binary .stl.) begin
# file_name = 'C:\Users\Jim\tmp\François.stl'
Dir.chdir('C:/Users/Jim/tmp')
puts "The file name: #{Dir["*"][20].inspect}"
file = File.open(Dir['*'][20], 'rb')
puts file
file.seek(80, IO::SEEK_SET)
face_count = file.read(4).unpack('i')[0]
puts "face_count: #{face_count}"
ensure
file.close
puts 'file closed.'
puts Sketchup.version
end
|
Really? That worked with Ruby 1.8? |
Yes, but only when providing the unicode path string directly. It does not work when using For example, this works in SketchUp 13 (Ruby 1.8.6): puts "SketchUp Version: #{Sketchup.version}"
puts "RUBY_VERSION: #{RUBY_VERSION}"
file_name = 'C:/Users/Jim/tmp/François/François.stl'
str = File.read(file_name)
puts str[0..80].inspect
puts "Done" prints
This is the string returned by So the problem is that Ruby 1.8.6 does not use the Windows Unicode version of file i/o functions. SketchUp Unicode Discussion Perhaps a WebDialog file selector could return a unicode filename, but that doesn't integrate in the Sketchup::Importer api. |
How are you entering `file_name = 'C:/Users/Jim/tmp/François/François.stl'1 into SketchUp, via a file? Is that saved as UTF-8? Or is it saved in ANSI? |
Copy-paste into my editor from Chrome. I think I understand what you mean. So I am using Noel's tunnel from my editor, which uses |
|
I thought I might be able to trick SketchUp 2013 into reading those Unicode file names, but I don't think it's going to work. Not putting any more time in it. |
We should not assume file operations succeed. See confusion in this thread related to user trying to load file from a path with non-ASCII characters.
I also think we should detect Unicode characters and provide an error message especially for this scenario as well.
http://sketchucation.com/forums/viewtopic.php?f=323&t=54409&view=unread#p493547
The text was updated successfully, but these errors were encountered: