Hopefully fix all problems with non-ASCII paths on Windows

This commit is contained in:
Alessandro Ranellucci 2015-03-09 15:17:50 +01:00
parent 66824fd17e
commit 6185f45815
7 changed files with 24 additions and 21 deletions

View File

@ -7,7 +7,6 @@ use Config;
use File::Spec; use File::Spec;
my %prereqs = qw( my %prereqs = qw(
Encode::Locale 0
ExtUtils::MakeMaker 6.80 ExtUtils::MakeMaker 6.80
ExtUtils::ParseXS 3.22 ExtUtils::ParseXS 3.22
File::Basename 0 File::Basename 0

View File

@ -32,8 +32,6 @@ warn "Running Slic3r under Perl 5.16 is not supported nor recommended\n"
use FindBin; use FindBin;
our $var = "$FindBin::Bin/var"; our $var = "$FindBin::Bin/var";
use Encode;
use Encode::Locale;
use Moo 1.003001; use Moo 1.003001;
use Slic3r::XS; # import all symbols (constants etc.) before they get parsed use Slic3r::XS; # import all symbols (constants etc.) before they get parsed
@ -261,13 +259,17 @@ sub resume_all_threads {
} }
sub encode_path { sub encode_path {
my ($filename) = @_; my ($path) = @_;
return encode('locale_fs', $filename);
utf8::downgrade($path) if $^O eq 'MSWin32';
return $path;
} }
sub decode_path { sub decode_path {
my ($filename) = @_; my ($path) = @_;
return decode('locale_fs', $filename);
utf8::upgrade($path) if $^O eq 'MSWin32';
return $path;
} }
sub open { sub open {

View File

@ -294,7 +294,7 @@ sub open_model {
$dialog->Destroy; $dialog->Destroy;
return; return;
} }
my @input_files = $dialog->GetPaths; my @input_files = map Slic3r::decode_path($_), $dialog->GetPaths;
$dialog->Destroy; $dialog->Destroy;
return @input_files; return @input_files;

View File

@ -386,7 +386,7 @@ sub _load_stl {
$dialog->Destroy; $dialog->Destroy;
return; return;
} }
my $input_file = $dialog->GetPaths; my $input_file = Slic3r::decode_path($dialog->GetPaths);
$dialog->Destroy; $dialog->Destroy;
my $model = Slic3r::Model->read_from_file($input_file); my $model = Slic3r::Model->read_from_file($input_file);

View File

@ -305,7 +305,7 @@ sub quick_slice {
$dialog->Destroy; $dialog->Destroy;
return; return;
} }
$input_file = $dialog->GetPaths; $input_file = Slic3r::decode_path($dialog->GetPaths);
$dialog->Destroy; $dialog->Destroy;
$last_input_file = $input_file unless $params{export_svg}; $last_input_file = $input_file unless $params{export_svg};
} else { } else {
@ -365,7 +365,7 @@ sub quick_slice {
$dlg->Destroy; $dlg->Destroy;
return; return;
} }
$output_file = $dlg->GetPath; $output_file = Slic3r::decode_path($dlg->GetPath);
$last_output_file = $output_file unless $params{export_svg}; $last_output_file = $output_file unless $params{export_svg};
$Slic3r::GUI::Settings->{_}{last_output_path} = dirname($output_file); $Slic3r::GUI::Settings->{_}{last_output_path} = dirname($output_file);
wxTheApp->save_settings; wxTheApp->save_settings;
@ -412,7 +412,7 @@ sub repair_stl {
$dialog->Destroy; $dialog->Destroy;
return; return;
} }
$input_file = $dialog->GetPaths; $input_file = Slic3r::decode_path($dialog->GetPaths);
$dialog->Destroy; $dialog->Destroy;
} }
@ -425,7 +425,7 @@ sub repair_stl {
$dlg->Destroy; $dlg->Destroy;
return undef; return undef;
} }
$output_file = $dlg->GetPath; $output_file = Slic3r::decode_path($dlg->GetPath);
$dlg->Destroy; $dlg->Destroy;
} }
@ -462,7 +462,7 @@ sub export_config {
my $dlg = Wx::FileDialog->new($self, 'Save configuration as:', $dir, $filename, my $dlg = Wx::FileDialog->new($self, 'Save configuration as:', $dir, $filename,
&Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if ($dlg->ShowModal == wxID_OK) { if ($dlg->ShowModal == wxID_OK) {
my $file = $dlg->GetPath; my $file = Slic3r::decode_path($dlg->GetPath);
$Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file);
wxTheApp->save_settings; wxTheApp->save_settings;
$last_config = $file; $last_config = $file;
@ -481,7 +481,7 @@ sub load_config_file {
my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini", my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini",
&Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST); &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
return unless $dlg->ShowModal == wxID_OK; return unless $dlg->ShowModal == wxID_OK;
($file) = $dlg->GetPaths; $file = Slic3r::decode_path($dlg->GetPaths);
$dlg->Destroy; $dlg->Destroy;
} }
$Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); $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, my $dlg = Wx::FileDialog->new($self, 'Save presets bundle as:', $dir, $filename,
&Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
if ($dlg->ShowModal == wxID_OK) { if ($dlg->ShowModal == wxID_OK) {
my $file = $dlg->GetPath; my $file = Slic3r::decode_path($dlg->GetPath);
$Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file);
wxTheApp->save_settings; wxTheApp->save_settings;
@ -539,7 +539,7 @@ sub load_configbundle {
my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini", my $dlg = Wx::FileDialog->new($self, 'Select configuration to load:', $dir, "config.ini",
&Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST); &Slic3r::GUI::FILE_WILDCARDS->{ini}, wxFD_OPEN | wxFD_FILE_MUST_EXIST);
return unless $dlg->ShowModal == wxID_OK; return unless $dlg->ShowModal == wxID_OK;
my ($file) = $dlg->GetPaths; my $file = Slic3r::decode_path($dlg->GetPaths);
$dlg->Destroy; $dlg->Destroy;
$Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file); $Slic3r::GUI::Settings->{recent}{config_directory} = dirname($file);

View File

@ -1046,9 +1046,10 @@ sub export_gcode {
$dlg->Destroy; $dlg->Destroy;
return; 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; 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; $dlg->Destroy;
} }
@ -1244,7 +1245,7 @@ sub _get_export_file {
$dlg->Destroy; $dlg->Destroy;
return undef; 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; $dlg->Destroy;
} }
return $output_file; return $output_file;

View File

@ -94,7 +94,7 @@ my $gui;
if ((!@ARGV || $opt{gui}) && !$opt{save} && eval "require Slic3r::GUI; 1") { if ((!@ARGV || $opt{gui}) && !$opt{save} && eval "require Slic3r::GUI; 1") {
{ {
no warnings 'once'; 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::no_plater = $opt{no_plater};
$Slic3r::GUI::mode = $opt{gui_mode}; $Slic3r::GUI::mode = $opt{gui_mode};
$Slic3r::GUI::autosave = $opt{autosave}; $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_file($_) for @{$opt{load}};
$gui->{mainframe}->load_config($cli_config); $gui->{mainframe}->load_config($cli_config);
foreach my $input_file (@ARGV) { foreach my $input_file (@ARGV) {
$input_file = Slic3r::decode_path($input_file);
$gui->{mainframe}{plater}->load_file($input_file) unless $opt{no_plater}; $gui->{mainframe}{plater}->load_file($input_file) unless $opt{no_plater};
} }
$gui->MainLoop; $gui->MainLoop;