Bugfix: crash when reading/writing files to paths containing non-ASCII characters on Windows. #651 #865
This commit is contained in:
parent
73aae07e74
commit
ad9be0e4d7
1
Build.PL
1
Build.PL
@ -8,6 +8,7 @@ my $build = Module::Build->new(
|
|||||||
license => 'perl',
|
license => 'perl',
|
||||||
requires => {
|
requires => {
|
||||||
'Boost::Geometry::Utils' => '0',
|
'Boost::Geometry::Utils' => '0',
|
||||||
|
'Encode::Locale' => '0',
|
||||||
'File::Basename' => '0',
|
'File::Basename' => '0',
|
||||||
'File::Spec' => '0',
|
'File::Spec' => '0',
|
||||||
'Getopt::Long' => '0',
|
'Getopt::Long' => '0',
|
||||||
|
@ -27,7 +27,10 @@ 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 0.091009;
|
use Moo 0.091009;
|
||||||
|
|
||||||
use Slic3r::Config;
|
use Slic3r::Config;
|
||||||
use Slic3r::ExPolygon;
|
use Slic3r::ExPolygon;
|
||||||
use Slic3r::Extruder;
|
use Slic3r::Extruder;
|
||||||
@ -88,4 +91,9 @@ sub parallelize {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub open {
|
||||||
|
my ($fh, $mode, $filename) = @_;
|
||||||
|
return CORE::open $$fh, $mode, encode('locale_fs', $filename);
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -946,7 +946,7 @@ sub new_from_cli {
|
|||||||
if ($args{$opt_key}) {
|
if ($args{$opt_key}) {
|
||||||
die "Invalid value for --${_}-gcode: file does not exist\n"
|
die "Invalid value for --${_}-gcode: file does not exist\n"
|
||||||
if !-e $args{$opt_key};
|
if !-e $args{$opt_key};
|
||||||
open my $fh, "<", $args{$opt_key}
|
Slic3r::open(\my $fh, "<", $args{$opt_key})
|
||||||
or die "Failed to open $args{$opt_key}\n";
|
or die "Failed to open $args{$opt_key}\n";
|
||||||
binmode $fh, ':utf8';
|
binmode $fh, ':utf8';
|
||||||
$args{$opt_key} = do { local $/; <$fh> };
|
$args{$opt_key} = do { local $/; <$fh> };
|
||||||
@ -1251,7 +1251,7 @@ sub write_ini {
|
|||||||
my $class = shift;
|
my $class = shift;
|
||||||
my ($file, $ini) = @_;
|
my ($file, $ini) = @_;
|
||||||
|
|
||||||
open my $fh, '>', $file;
|
Slic3r::open(\my $fh, '>', $file);
|
||||||
binmode $fh, ':utf8';
|
binmode $fh, ':utf8';
|
||||||
my $localtime = localtime;
|
my $localtime = localtime;
|
||||||
printf $fh "# generated by Slic3r $Slic3r::VERSION on %s\n", "$localtime";
|
printf $fh "# generated by Slic3r $Slic3r::VERSION on %s\n", "$localtime";
|
||||||
@ -1269,7 +1269,7 @@ sub read_ini {
|
|||||||
my ($file) = @_;
|
my ($file) = @_;
|
||||||
|
|
||||||
local $/ = "\n";
|
local $/ = "\n";
|
||||||
open my $fh, '<', $file;
|
Slic3r::open(\my $fh, '<', $file);
|
||||||
binmode $fh, ':utf8';
|
binmode $fh, ':utf8';
|
||||||
|
|
||||||
my $ini = { _ => {} };
|
my $ini = { _ => {} };
|
||||||
|
@ -13,7 +13,7 @@ sub read_file {
|
|||||||
1;
|
1;
|
||||||
} or die "AMF parsing requires XML::SAX\n";
|
} or die "AMF parsing requires XML::SAX\n";
|
||||||
|
|
||||||
open my $fh, '<', $file or die "Failed to open $file\n";
|
Slic3r::open(\my $fh, '<', $file) or die "Failed to open $file\n";
|
||||||
|
|
||||||
my $model = Slic3r::Model->new;
|
my $model = Slic3r::Model->new;
|
||||||
XML::SAX::ParserFactory
|
XML::SAX::ParserFactory
|
||||||
@ -30,7 +30,7 @@ sub write_file {
|
|||||||
|
|
||||||
my %vertices_offset = ();
|
my %vertices_offset = ();
|
||||||
|
|
||||||
open my $fh, '>', $file;
|
Slic3r::open(\my $fh, '>', $file);
|
||||||
binmode $fh, ':utf8';
|
binmode $fh, ':utf8';
|
||||||
printf $fh qq{<?xml version="1.0" encoding="UTF-8"?>\n};
|
printf $fh qq{<?xml version="1.0" encoding="UTF-8"?>\n};
|
||||||
printf $fh qq{<amf unit="millimeter">\n};
|
printf $fh qq{<amf unit="millimeter">\n};
|
||||||
|
@ -5,7 +5,7 @@ sub read_file {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($file) = @_;
|
my ($file) = @_;
|
||||||
|
|
||||||
open my $fh, '<', $file or die "Failed to open $file\n";
|
Slic3r::open(\my $fh, '<', $file) or die "Failed to open $file\n";
|
||||||
my $vertices = [];
|
my $vertices = [];
|
||||||
my $facets = [];
|
my $facets = [];
|
||||||
while (my $_ = <$fh>) {
|
while (my $_ = <$fh>) {
|
||||||
|
@ -7,7 +7,7 @@ sub read_file {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($file) = @_;
|
my ($file) = @_;
|
||||||
|
|
||||||
open my $fh, '<', $file or die "Failed to open $file\n";
|
Slic3r::open(\my $fh, '<', $file) or die "Failed to open $file\n";
|
||||||
|
|
||||||
# let's detect whether file is ASCII or binary
|
# let's detect whether file is ASCII or binary
|
||||||
my $mode;
|
my $mode;
|
||||||
@ -103,7 +103,7 @@ sub write_file {
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($file, $model, %params) = @_;
|
my ($file, $model, %params) = @_;
|
||||||
|
|
||||||
open my $fh, '>', $file;
|
Slic3r::open(\my $fh, '>', $file);
|
||||||
|
|
||||||
$params{binary}
|
$params{binary}
|
||||||
? _write_binary($fh, $model->mesh)
|
? _write_binary($fh, $model->mesh)
|
||||||
|
@ -472,7 +472,7 @@ sub export_svg {
|
|||||||
my $output_file = $self->expanded_output_filepath($params{output_file});
|
my $output_file = $self->expanded_output_filepath($params{output_file});
|
||||||
$output_file =~ s/\.gcode$/.svg/i;
|
$output_file =~ s/\.gcode$/.svg/i;
|
||||||
|
|
||||||
open my $fh, ">", $output_file or die "Failed to open $output_file for writing\n";
|
Slic3r::open(\my $fh, ">", $output_file) or die "Failed to open $output_file for writing\n";
|
||||||
print "Exporting to $output_file...";
|
print "Exporting to $output_file...";
|
||||||
my $print_size = $self->size;
|
my $print_size = $self->size;
|
||||||
print $fh sprintf <<"EOF", unscale($print_size->[X]), unscale($print_size->[Y]);
|
print $fh sprintf <<"EOF", unscale($print_size->[X]), unscale($print_size->[Y]);
|
||||||
@ -647,7 +647,7 @@ sub write_gcode {
|
|||||||
if (ref $file eq 'IO::Scalar') {
|
if (ref $file eq 'IO::Scalar') {
|
||||||
$fh = $file;
|
$fh = $file;
|
||||||
} else {
|
} else {
|
||||||
open $fh, ">", $file
|
Slic3r::open(\$fh, ">", $file)
|
||||||
or die "Failed to open $file for writing\n";
|
or die "Failed to open $file for writing\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ sub output_lines {
|
|||||||
sub write_svg {
|
sub write_svg {
|
||||||
my ($svg, $filename) = @_;
|
my ($svg, $filename) = @_;
|
||||||
|
|
||||||
open my $fh, '>', $filename;
|
Slic3r::open(\my $fh, '>', $filename);
|
||||||
print $fh $svg->xmlify;
|
print $fh $svg->xmlify;
|
||||||
close $fh;
|
close $fh;
|
||||||
printf "SVG written to %s\n", $filename;
|
printf "SVG written to %s\n", $filename;
|
||||||
|
Loading…
Reference in New Issue
Block a user