Skip to content

Commit

Permalink
More fixes for Unicode filenames support on Windows and OS X
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Jun 2, 2015
1 parent 7b65a35 commit 56b993b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions Build.PL
Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion lib/Slic3r.pm
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Slic3r/GUI/Tab.pm
Expand Up @@ -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}});
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 56b993b

Please sign in to comment.