From 552430db679cbceebe5b7db761c5624fd53eead7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 13 Jun 2015 11:41:55 +0200 Subject: [PATCH] More fixes for Unicode path handling (thanks @josefprusa for Czech test VM) --- Build.PL | 2 ++ lib/Slic3r.pm | 18 +++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Build.PL b/Build.PL index ff86430bb..e637ebf31 100644 --- a/Build.PL +++ b/Build.PL @@ -7,6 +7,8 @@ use Config; use File::Spec; my %prereqs = qw( + Encode 0 + Encode::Locale 1.05 ExtUtils::MakeMaker 6.80 ExtUtils::ParseXS 3.22 File::Basename 0 diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index 0e8038119..154af904b 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -30,7 +30,7 @@ warn "Running Slic3r under Perl 5.16 is not supported nor recommended\n" if $^V == v5.16; use FindBin; -our $var = "$FindBin::Bin/var"; +our $var = decode_path($FindBin::Bin) . "/var"; use Moo 1.003001; @@ -71,6 +71,8 @@ use Slic3r::Print::SupportMaterial; use Slic3r::Surface; our $build = eval "use Slic3r::Build; 1"; use Thread::Semaphore; +use Encode::Locale 1.05; +use Encode; use Unicode::Normalize; use constant SCALING_FACTOR => 0.000001; @@ -263,11 +265,7 @@ sub encode_path { my ($path) = @_; $path = Unicode::Normalize::NFC($path); - if ($^O eq 'MSWin32') { - utf8::downgrade($path); - } else { - utf8::encode($path); - } + $path = Encode::encode(locale_fs => $path); return $path; } @@ -275,17 +273,15 @@ sub encode_path { sub decode_path { my ($path) = @_; - if ($^O eq 'MSWin32') { - utf8::upgrade($path); - } else { - utf8::decode($path); - } + $path = Encode::decode(locale_fs => $path) + unless utf8::is_utf8($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; }