From 6185f458157ebca874de0cf1f902ceedec93d2a7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 9 Mar 2015 15:17:50 +0100 Subject: [PATCH] Hopefully fix all problems with non-ASCII paths on Windows --- Build.PL | 1 - lib/Slic3r.pm | 14 ++++++++------ lib/Slic3r/GUI.pm | 2 +- lib/Slic3r/GUI/BedShapeDialog.pm | 2 +- lib/Slic3r/GUI/MainFrame.pm | 16 ++++++++-------- lib/Slic3r/GUI/Plater.pm | 7 ++++--- slic3r.pl | 3 ++- 7 files changed, 24 insertions(+), 21 deletions(-) diff --git a/Build.PL b/Build.PL index 69d1af618..0c208813b 100644 --- a/Build.PL +++ b/Build.PL @@ -7,7 +7,6 @@ use Config; use File::Spec; my %prereqs = qw( - Encode::Locale 0 ExtUtils::MakeMaker 6.80 ExtUtils::ParseXS 3.22 File::Basename 0 diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index c4466b9bb..c3c21e782 100644 --- a/lib/Slic3r.pm +++ b/lib/Slic3r.pm @@ -32,8 +32,6 @@ warn "Running Slic3r under Perl 5.16 is not supported nor recommended\n" use FindBin; our $var = "$FindBin::Bin/var"; -use Encode; -use Encode::Locale; use Moo 1.003001; use Slic3r::XS; # import all symbols (constants etc.) before they get parsed @@ -261,13 +259,17 @@ sub resume_all_threads { } sub encode_path { - my ($filename) = @_; - return encode('locale_fs', $filename); + my ($path) = @_; + + utf8::downgrade($path) if $^O eq 'MSWin32'; + return $path; } sub decode_path { - my ($filename) = @_; - return decode('locale_fs', $filename); + my ($path) = @_; + + utf8::upgrade($path) if $^O eq 'MSWin32'; + return $path; } sub open { diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 528c55a3f..e968e9410 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -294,7 +294,7 @@ sub open_model { $dialog->Destroy; return; } - my @input_files = $dialog->GetPaths; + my @input_files = map Slic3r::decode_path($_), $dialog->GetPaths; $dialog->Destroy; return @input_files; diff --git a/lib/Slic3r/GUI/BedShapeDialog.pm b/lib/Slic3r/GUI/BedShapeDialog.pm index 7b5c3ca92..fa6429023 100644 --- a/lib/Slic3r/GUI/BedShapeDialog.pm +++ b/lib/Slic3r/GUI/BedShapeDialog.pm @@ -386,7 +386,7 @@ sub _load_stl { $dialog->Destroy; return; } - my $input_file = $dialog->GetPaths; + my $input_file = Slic3r::decode_path($dialog->GetPaths); $dialog->Destroy; my $model = Slic3r::Model->read_from_file($input_file); diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index f3bc6a238..6e3256694 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -305,7 +305,7 @@ sub quick_slice { $dialog->Destroy; return; } - $input_file = $dialog->GetPaths; + $input_file = Slic3r::decode_path($dialog->GetPaths); $dialog->Destroy; $last_input_file = $input_file unless $params{export_svg}; } else { @@ -365,7 +365,7 @@ sub quick_slice { $dlg->Destroy; return; } - $output_file = $dlg->GetPath; + $output_file = Slic3r::decode_path($dlg->GetPath); $last_output_file = $output_file unless $params{export_svg}; $Slic3r::GUI::Settings->{_}{last_output_path} = dirname($output_file); wxTheApp->save_settings; @@ -412,7 +412,7 @@ sub repair_stl { $dialog->Destroy; return; } - $input_file = $dialog->GetPaths; + $input_file = Slic3r::decode_path($dialog->GetPaths); $dialog->Destroy; } @@ -425,7 +425,7 @@ sub repair_stl { $dlg->Destroy; return undef; } - $output_file = $dlg->GetPath; + $output_file = Slic3r::decode_path($dlg->GetPath); $dlg->Destroy; } @@ -462,7 +462,7 @@ sub export_config { my $dlg = Wx::FileDialog->new($self, 'Save configuration as:', $dir, $filename, &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if ($dlg->ShowModal == wxID_OK) { - my $file = $dlg->GetPath; + my $file = Slic3r::decode_path($dlg->GetPath); $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); wxTheApp->save_settings; $last_config = $file; @@ -481,7 +481,7 @@ sub load_config_file { my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini", &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST); return unless $dlg->ShowModal == wxID_OK; - ($file) = $dlg->GetPaths; + $file = Slic3r::decode_path($dlg->GetPaths); $dlg->Destroy; } $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); @@ -506,7 +506,7 @@ sub export_configbundle { my $dlg = Wx::FileDialog->new($self, 'Save presets bundle as:', $dir, $filename, &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); if ($dlg->ShowModal == wxID_OK) { - my $file = $dlg->GetPath; + my $file = Slic3r::decode_path($dlg->GetPath); $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); wxTheApp->save_settings; @@ -539,7 +539,7 @@ sub load_configbundle { my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini", &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST); return unless $dlg->ShowModal == wxID_OK; - my ($file) = $dlg->GetPaths; + my $file = Slic3r::decode_path($dlg->GetPaths); $dlg->Destroy; $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 78fa517e8..7bd8b882a 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1046,9 +1046,10 @@ sub export_gcode { $dlg->Destroy; return; } - $Slic3r::GUI::Settings->{_}{last_output_path} = dirname($dlg->GetPath); + my $path = Slic3r::decode_path($dlg->GetPath); + $Slic3r::GUI::Settings->{_}{last_output_path} = dirname($path); wxTheApp->save_settings; - $self->{export_gcode_output_file} = $Slic3r::GUI::MainFrame::last_output_file = $dlg->GetPath; + $self->{export_gcode_output_file} = $Slic3r::GUI::MainFrame::last_output_file = $path; $dlg->Destroy; } @@ -1244,7 +1245,7 @@ sub _get_export_file { $dlg->Destroy; return undef; } - $output_file = $Slic3r::GUI::MainFrame::last_output_file = $dlg->GetPath; + $output_file = $Slic3r::GUI::MainFrame::last_output_file = Slic3r::decode_path($dlg->GetPath); $dlg->Destroy; } return $output_file; diff --git a/slic3r.pl b/slic3r.pl index 11c0e2bca..a43f9329c 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -94,7 +94,7 @@ my $gui; if ((!@ARGV || $opt{gui}) && !$opt{save} && eval "require Slic3r::GUI; 1") { { no warnings 'once'; - $Slic3r::GUI::datadir = Slic3r::decode_path($opt{datadir}); + $Slic3r::GUI::datadir = Slic3r::decode_path($opt{datadir} // ''); $Slic3r::GUI::no_plater = $opt{no_plater}; $Slic3r::GUI::mode = $opt{gui_mode}; $Slic3r::GUI::autosave = $opt{autosave}; @@ -104,6 +104,7 @@ if ((!@ARGV || $opt{gui}) && !$opt{save} && eval "require Slic3r::GUI; 1") { $gui->{mainframe}->load_config_file($_) for @{$opt{load}}; $gui->{mainframe}->load_config($cli_config); foreach my $input_file (@ARGV) { + $input_file = Slic3r::decode_path($input_file); $gui->{mainframe}{plater}->load_file($input_file) unless $opt{no_plater}; } $gui->MainLoop;