From 56b993bb89f0d2f27ff4a2198e510125ed8ed90d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 2 Jun 2015 16:10:15 +0200 Subject: [PATCH] More fixes for Unicode filenames support on Windows and OS X --- Build.PL | 1 + lib/Slic3r.pm | 15 ++++++++++++++- lib/Slic3r/GUI/Tab.pm | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Build.PL b/Build.PL index 0c208813b..ff86430bb 100644 --- a/Build.PL +++ b/Build.PL @@ -22,6 +22,7 @@ my %prereqs = qw( IO::Scalar 0 threads 1.96 Time::HiRes 0 + Unicode::Normalize 0 ); my %recommends = qw( Class::XSAccessor 0 diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 9fc1df029..0e8038119 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -71,6 +71,7 @@ use Slic3r::Print::SupportMaterial; use Slic3r::Surface; our $build = eval "use Slic3r::Build; 1"; use Thread::Semaphore; +use Unicode::Normalize; use constant SCALING_FACTOR => 0.000001; use constant RESOLUTION => 0.0125; @@ -261,7 +262,13 @@ sub resume_all_threads { sub encode_path { my ($path) = @_; - utf8::downgrade($path) if $^O eq 'MSWin32'; + $path = Unicode::Normalize::NFC($path); + if ($^O eq 'MSWin32') { + utf8::downgrade($path); + } else { + utf8::encode($path); + } + return $path; } @@ -273,6 +280,12 @@ sub decode_path { } else { utf8::decode($path); } + + # The filesystem might force a normalization form (like HFS+ does) so + # if we rely on the filename being comparable after the open() + readdir() + # roundtrip (like when creating and then selecting a preset), we need to + # restore our normalization form. + $path = Unicode::Normalize::NFC($path); return $path; } diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 88d7db8ba..d6b84d5cd 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -204,6 +204,8 @@ sub select_preset { sub select_preset_by_name { my ($self, $name) = @_; + + $name = Unicode::Normalize::NFC($name); $self->select_preset(first { $self->{presets}[$_]->name eq $name } 0 .. $#{$self->{presets}}); } @@ -1462,7 +1464,7 @@ sub config { if ($self->default) { return Slic3r::Config->new_from_defaults(@$keys); } else { - if (!-e $self->file) { + if (!-e Slic3r::encode_path($self->file)) { Slic3r::GUI::show_error(undef, "The selected preset does not exist anymore (" . $self->file . ")."); return undef; }