Browse Source

Fix of
"Unicode char like for example "ł" crush app when used in profile name"
https://github.com/prusa3d/Slic3r/issues/388

The Prusa3D binary builds are missing the UTF8 libraries.
To avoid having to bundle them, the case sensitive regexes testing
file suffixes were replaced with explicit enumeration of lower / upper
case letters. While crude, it avoids triggering the UTF8 library.

bubnikv 7 years ago
parent
commit
6f28818f87

+ 2 - 2
lib/Slic3r.pm

@@ -234,8 +234,8 @@ sub decode_path {
     my ($path) = @_;
     
     $path = Encode::decode(locale_fs => $path)
-        unless utf8::is_utf8($path);
-    
+        unless Encode::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 

+ 3 - 1
lib/Slic3r/Config.pm

@@ -101,7 +101,9 @@ sub load {
     my $class = shift;
     my ($file) = @_;
 
-    if ($file =~ /\.gcode$/i || $file =~ /\.g$/i) {
+    # Instead of using the /i modifier for case-insensitive matching, the case insensitivity is expressed
+    # explicitely to avoid having to bundle the UTF8 Perl library.
+    if ($file =~ /\.[gG][cC][oO][dD][eE]/ || $file =~ /\.[gG]/) {
         my $config = $class->new;        
         $config->_load_from_gcode($file);
         return $config;

+ 3 - 1
lib/Slic3r/GUI.pm

@@ -313,7 +313,9 @@ sub presets {
     my %presets = ();
     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) {
+    # Instead of using the /i modifier for case-insensitive matching, the case insensitivity is expressed
+    # explicitely to avoid having to bundle the UTF8 Perl library.
+    foreach my $file (grep /\.[iI][nN][iI]$/, readdir $dh) {
         $file = Slic3r::decode_path($file);
         my $name = basename($file);
         $name =~ s/\.ini$//;

+ 2 - 2
lib/Slic3r/GUI/MainFrame.pm

@@ -417,7 +417,7 @@ sub quick_slice {
             $output_file = $qs_last_output_file if defined $qs_last_output_file;
         } elsif ($params{save_as}) {
             $output_file = $sprint->output_filepath;
-            $output_file =~ s/\.gcode$/.svg/i if $params{export_svg};
+            $output_file =~ s/\.[gG][cC][oO][dD][eE]$/.svg/ if $params{export_svg};
             my $dlg = Wx::FileDialog->new($self, 'Save ' . ($params{export_svg} ? 'SVG' : 'G-code') . ' file as:',
                 wxTheApp->output_path(dirname($output_file)),
                 basename($output_file), $params{export_svg} ? &Slic3r::GUI::FILE_WILDCARDS->{svg} : &Slic3r::GUI::FILE_WILDCARDS->{gcode}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
@@ -485,7 +485,7 @@ sub repair_stl {
     
     my $output_file = $input_file;
     {
-        $output_file =~ s/\.stl$/_fixed.obj/i;
+        $output_file =~ s/\.[sS][tT][lL]$/_fixed.obj/;
         my $dlg = Wx::FileDialog->new($self, "Save OBJ file (less prone to coordinate errors than STL) as:", dirname($output_file),
             basename($output_file), &Slic3r::GUI::FILE_WILDCARDS->{obj}, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
         if ($dlg->ShowModal != wxID_OK) {

+ 3 - 3
lib/Slic3r/GUI/Plater.pm

@@ -703,7 +703,7 @@ sub load_files {
     # One of the files is potentionally a bundle of files. Don't bundle them, but load them one by one.
     # Only bundle .stls or .objs if the printer has multiple extruders.
     my $one_by_one = (@$nozzle_dmrs <= 1) || (@$input_files == 1) || 
-        defined(first { $_ =~ /.amf$/i || $_ =~ /.3mf$/i || $_ =~ /.prusa$/i } @$input_files);
+        defined(first { $_ =~ /.[aA][mM][fF]$/ || $_ =~ /.3[mM][fF]$/ || $_ =~ /.[pP][rR][uI][sS][aA]$/ } @$input_files);
         
     my $process_dialog = Wx::ProgressDialog->new('Loading…', "Processing input file\n" . basename($input_files->[0]), 100, $self, 0);
     $process_dialog->Pulse;
@@ -1660,7 +1660,7 @@ sub _get_export_file {
     my $output_file = $main::opt{output};
     {
         $output_file = $self->{print}->output_filepath($output_file);
-        $output_file =~ s/\.gcode$/$suffix/i;
+        $output_file =~ s/\.[gG][cC][oO][dD][eE]$/$suffix/;
         my $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file),
             basename($output_file), &Slic3r::GUI::MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
         if ($dlg->ShowModal != wxID_OK) {
@@ -2194,7 +2194,7 @@ sub OnDropFiles {
     @_ = ();
     
     # only accept STL, OBJ and AMF files
-    return 0 if grep !/\.(?:stl|obj|amf(?:\.xml)?|prusa)$/i, @$filenames;
+    return 0 if grep !/\.(?:[sS][tT][lL]|[oO][bB][jJ]|[aA][mM][fF](?:\.[xX][mM][lL])?|[pP][rR][uU][sS][aA])$/, @$filenames;
     
     $self->{window}->load_files($filenames);
 }

+ 2 - 2
lib/Slic3r/GUI/Tab.pm

@@ -178,7 +178,7 @@ sub save_preset {
     if (!defined $name) {
         my $preset = $self->get_current_preset;
         my $default_name = $preset->default ? 'Untitled' : $preset->name;
-        $default_name =~ s/\.ini$//i;
+        $default_name =~ s/\.[iI][nN][iI]$//;
     
         my $dlg = Slic3r::GUI::SavePresetWindow->new($self,
             title   => lc($self->title),
@@ -1830,7 +1830,7 @@ sub accept {
     my ($self, $event) = @_;
 
     if (($self->{chosen_name} = $self->{combo}->GetValue)) {
-        if ($self->{chosen_name} !~ /^[^<>:\/\\|?*\"]+$/i) {
+        if ($self->{chosen_name} !~ /^[^<>:\/\\|?*\"]+$/) {
             Slic3r::GUI::show_error($self, "The supplied name is not valid; the following characters are not allowed: <>:/\|?*\"");
         } elsif ($self->{chosen_name} eq '- default -') {
             Slic3r::GUI::show_error($self, "The supplied name is not available.");

+ 4 - 4
lib/Slic3r/Model.pm

@@ -9,10 +9,10 @@ sub read_from_file {
     my ($class, $input_file, $add_default_instances) = @_;
     $add_default_instances //= 1;
     
-    my $model = $input_file =~ /\.stl$/i            ? Slic3r::Model->load_stl(Slic3r::encode_path($input_file), basename($input_file))
-              : $input_file =~ /\.obj$/i            ? Slic3r::Model->load_obj(Slic3r::encode_path($input_file), basename($input_file))
-              : $input_file =~ /\.amf(\.xml)?$/i    ? Slic3r::Model->load_amf(Slic3r::encode_path($input_file))
-              : $input_file =~ /\.prusa$/i          ? Slic3r::Model->load_prus(Slic3r::encode_path($input_file))
+    my $model = $input_file =~ /\.[sS][tT][lL]$/                    ? Slic3r::Model->load_stl(Slic3r::encode_path($input_file), basename($input_file))
+              : $input_file =~ /\.[oO][bB][jJ]$/                    ? Slic3r::Model->load_obj(Slic3r::encode_path($input_file), basename($input_file))
+              : $input_file =~ /\.[aA][mM][fF](\.[xX][mM][lL])?$/   ? Slic3r::Model->load_amf(Slic3r::encode_path($input_file))
+              : $input_file =~ /\.[pP][rR][uU][sS][aA]$/            ? Slic3r::Model->load_prus(Slic3r::encode_path($input_file))
               : die "Input file must have .stl, .obj or .amf(.xml) extension\n";
     
     die "The supplied file couldn't be read because it's empty.\n"

+ 1 - 1
lib/Slic3r/Print.pm

@@ -115,7 +115,7 @@ sub export_svg {
     my $fh = $params{output_fh};
     if (!$fh) {
         my $output_file = $self->output_filepath($params{output_file});
-        $output_file =~ s/\.gcode$/.svg/i;
+        $output_file =~ s/\.[gG][cC][oO][dD][eE]$/.svg/;
         Slic3r::open(\$fh, ">", $output_file) or die "Failed to open $output_file for writing\n";
         print "Exporting to $output_file..." unless $params{quiet};
     }

+ 2 - 2
slic3r.pl

@@ -125,10 +125,10 @@ if (@ARGV) {  # slicing from command line
         foreach my $file (@ARGV) {
             $file = Slic3r::decode_path($file);
             die "Repair is currently supported only on STL files\n"
-                if $file !~ /\.stl$/i;
+                if $file !~ /\.[sS][tT][lL]$/;
             
             my $output_file = $file;
-            $output_file =~ s/\.(stl)$/_fixed.obj/i;
+            $output_file =~ s/\.([sS][tT][lL])$/_fixed.obj/;
             my $tmesh = Slic3r::TriangleMesh->new;
             $tmesh->ReadSTLFile($file);
             $tmesh->repair;

+ 1 - 1
utils/amf-to-stl.pl

@@ -27,7 +27,7 @@ my %opt = ();
 {
     my $model = Slic3r::Model->load_amf(Slic3r::encode_path($ARGV[0]));
     my $output_file = $ARGV[0];
-    $output_file =~ s/\.amf(?:\.xml)?$/\.stl/i;
+    $output_file =~ s/\.[aA][mM][fF](?:\.[xX][mM][lL])?$/\.stl/;
     
     printf "Writing to %s\n", basename($output_file);
     $model->store_stl(Slic3r::encode_path($output_file), binary => !$opt{ascii});

Some files were not shown because too many files changed in this diff