diff --git a/lib/Slic3r.pm b/lib/Slic3r.pm index a0a95b68e..129f8376a 100644 --- a/lib/Slic3r.pm +++ b/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 diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 263eb2630..7f2a6ed0e 100644 --- a/lib/Slic3r/Config.pm +++ b/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; diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index 011ed972f..ccf0e9c9b 100644 --- a/lib/Slic3r/GUI.pm +++ b/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$//; diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index a5867d0ff..74ae10749 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/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) { diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index f0ae7ee8b..5d6f8d23a 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/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); } diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 26a8a4522..dbaacf6c8 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/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."); diff --git a/lib/Slic3r/Model.pm b/lib/Slic3r/Model.pm index 7c0a035b8..5b0992b46 100644 --- a/lib/Slic3r/Model.pm +++ b/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" diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index c35d10572..4999ce3f6 100644 --- a/lib/Slic3r/Print.pm +++ b/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}; } diff --git a/slic3r.pl b/slic3r.pl index 29e760b91..26a7f51d3 100755 --- a/slic3r.pl +++ b/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; diff --git a/utils/amf-to-stl.pl b/utils/amf-to-stl.pl index 64910dc31..f49af94eb 100755 --- a/utils/amf-to-stl.pl +++ b/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}); diff --git a/utils/pdf-slices.pl b/utils/pdf-slices.pl index fa7612bb1..670a17171 100755 --- a/utils/pdf-slices.pl +++ b/utils/pdf-slices.pl @@ -82,7 +82,7 @@ my %opt = (); my $output_file = $opt{output_file}; if (!defined $output_file) { $output_file = $input_file; - $output_file =~ s/\.(?:stl)$/.pdf/i; + $output_file =~ s/\.(?:[sS][tT][lL])$/.pdf/; } $pdf->saveas($output_file); printf "PDF file written to %s\n", $output_file; diff --git a/utils/split_stl.pl b/utils/split_stl.pl index 1c46e9729..ac890fc3e 100755 --- a/utils/split_stl.pl +++ b/utils/split_stl.pl @@ -27,7 +27,7 @@ my %opt = (); { my $model = Slic3r::Model->load_stl(Slic3r::encode_path($ARGV[0]), basename($ARGV[0])); my $basename = $ARGV[0]; - $basename =~ s/\.stl$//i; + $basename =~ s/\.[sS][tT][lL]$//; my $part_count = 0; my $mesh = $model->objects->[0]->volumes->[0]->mesh; diff --git a/utils/stl-to-amf.pl b/utils/stl-to-amf.pl index 072fe96fc..d32e799aa 100755 --- a/utils/stl-to-amf.pl +++ b/utils/stl-to-amf.pl @@ -27,7 +27,7 @@ my %opt = (); { my @models = map Slic3r::Model->load_stl(Slic3r::encode_path($_), basename($_)), @ARGV; my $output_file = $ARGV[0]; - $output_file =~ s/\.stl$/.amf.xml/i; + $output_file =~ s/\.[sS][tT][lL]$/.amf.xml/; my $new_model = Slic3r::Model->new;