Fixes to UTF-8 handling in file paths

This commit is contained in:
Alessandro Ranellucci 2014-11-22 21:55:45 +01:00
parent 049859e5b1
commit 989ec5cf4d
5 changed files with 20 additions and 8 deletions

View File

@ -234,6 +234,11 @@ sub encode_path {
return encode('locale_fs', $filename);
}
sub decode_path {
my ($filename) = @_;
return decode('locale_fs', $filename);
}
sub open {
my ($fh, $mode, $filename) = @_;
return CORE::open $$fh, $mode, encode_path($filename);

View File

@ -380,7 +380,8 @@ sub read_ini {
my ($file) = @_;
local $/ = "\n";
Slic3r::open(\my $fh, '<', $file);
Slic3r::open(\my $fh, '<', $file)
or die "Unable to open $file: $!\n";
binmode $fh, ':utf8';
my $ini = { _ => {} };

View File

@ -75,20 +75,20 @@ sub OnInit {
# locate or create data directory
$datadir ||= Wx::StandardPaths::Get->GetUserDataDir;
$datadir = Slic3r::encode_path($datadir);
my $enc_datadir = Slic3r::encode_path($datadir);
Slic3r::debugf "Data directory: %s\n", $datadir;
# just checking for existence of $datadir is not enough: it may be an empty directory
# supplied as argument to --datadir; in that case we should still run the wizard
my $run_wizard = (-d $datadir && -e "$datadir/slic3r.ini") ? 0 : 1;
for ($datadir, "$datadir/print", "$datadir/filament", "$datadir/printer") {
my $run_wizard = (-d $enc_datadir && -e "$enc_datadir/slic3r.ini") ? 0 : 1;
for ($enc_datadir, "$enc_datadir/print", "$enc_datadir/filament", "$enc_datadir/printer") {
mkdir or $self->fatal_error("Slic3r was unable to create its data directory at $_ (errno: $!).")
unless -d $_;
}
# load settings
my $last_version;
if (-f "$datadir/slic3r.ini") {
if (-f "$enc_datadir/slic3r.ini") {
my $ini = eval { Slic3r::Config->read_ini("$datadir/slic3r.ini") };
$Settings = $ini if $ini;
$last_version = $Settings->{_}{version};
@ -212,7 +212,8 @@ sub presets {
my ($self, $section) = @_;
my %presets = ();
opendir my $dh, "$Slic3r::GUI::datadir/$section" or die "Failed to read directory $Slic3r::GUI::datadir/$section (errno: $!)\n";
opendir my $dh, Slic3r::encode_path("$Slic3r::GUI::datadir/$section")
or die "Failed to read directory $Slic3r::GUI::datadir/$section (errno: $!)\n";
foreach my $file (grep /\.ini$/i, readdir $dh) {
my $name = basename($file);
$name =~ s/\.ini$//;

View File

@ -77,7 +77,7 @@ sub _init_tabpanel {
my $simple_config;
if ($self->{mode} eq 'simple') {
$simple_config = Slic3r::Config->load("$Slic3r::GUI::datadir/simple.ini")
if -e "$Slic3r::GUI::datadir/simple.ini";
if -e Slic3r::encode_path("$Slic3r::GUI::datadir/simple.ini");
}
my $class_prefix = $self->{mode} eq 'simple' ? "Slic3r::GUI::SimpleTab::" : "Slic3r::GUI::Tab::";

View File

@ -60,6 +60,7 @@ my %cli_options = ();
my @external_configs = ();
if ($opt{load}) {
foreach my $configfile (@{$opt{load}}) {
$configfile = Slic3r::decode_path($configfile);
if (-e $configfile) {
push @external_configs, Slic3r::Config->load($configfile);
} elsif (-e "$FindBin::Bin/$configfile") {
@ -92,7 +93,7 @@ my $gui;
if (!@ARGV && !$opt{save} && eval "require Slic3r::GUI; 1") {
{
no warnings 'once';
$Slic3r::GUI::datadir = $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};
@ -111,6 +112,7 @@ if (@ARGV) { # slicing from command line
if ($opt{repair}) {
foreach my $file (@ARGV) {
$file = Slic3r::decode_path($file);
die "Repair is currently supported only on STL files\n"
if $file !~ /\.stl$/i;
@ -126,6 +128,7 @@ if (@ARGV) { # slicing from command line
if ($opt{cut}) {
foreach my $file (@ARGV) {
$file = Slic3r::decode_path($file);
my $model = Slic3r::Model->read_from_file($file);
$model->add_default_instances;
my $mesh = $model->mesh;
@ -145,6 +148,7 @@ if (@ARGV) { # slicing from command line
if ($opt{split}) {
foreach my $file (@ARGV) {
$file = Slic3r::decode_path($file);
my $model = Slic3r::Model->read_from_file($file);
$model->add_default_instances;
my $mesh = $model->mesh;
@ -161,6 +165,7 @@ if (@ARGV) { # slicing from command line
}
while (my $input_file = shift @ARGV) {
$input_file = Slic3r::decode_path($input_file);
my $model;
if ($opt{merge}) {
my @models = map Slic3r::Model->read_from_file($_), $input_file, (splice @ARGV, 0);