Bugfix: crash when reading/writing files to paths containing non-ASCII characters on Windows. #651 #865

obj-materials
Alessandro Ranellucci 2013-01-13 10:18:34 +01:00
parent 73aae07e74
commit ad9be0e4d7
8 changed files with 20 additions and 11 deletions

View File

@ -8,6 +8,7 @@ my $build = Module::Build->new(
license => 'perl',
requires => {
'Boost::Geometry::Utils' => '0',
'Encode::Locale' => '0',
'File::Basename' => '0',
'File::Spec' => '0',
'Getopt::Long' => '0',

View File

@ -27,7 +27,10 @@ warn "Running Slic3r under Perl >= 5.16 is not supported nor recommended\n"
use FindBin;
our $var = "$FindBin::Bin/var";
use Encode;
use Encode::Locale;
use Moo 0.091009;
use Slic3r::Config;
use Slic3r::ExPolygon;
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;

View File

@ -946,7 +946,7 @@ sub new_from_cli {
if ($args{$opt_key}) {
die "Invalid value for --${_}-gcode: file does not exist\n"
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";
binmode $fh, ':utf8';
$args{$opt_key} = do { local $/; <$fh> };
@ -1251,7 +1251,7 @@ sub write_ini {
my $class = shift;
my ($file, $ini) = @_;
open my $fh, '>', $file;
Slic3r::open(\my $fh, '>', $file);
binmode $fh, ':utf8';
my $localtime = localtime;
printf $fh "# generated by Slic3r $Slic3r::VERSION on %s\n", "$localtime";
@ -1269,7 +1269,7 @@ sub read_ini {
my ($file) = @_;
local $/ = "\n";
open my $fh, '<', $file;
Slic3r::open(\my $fh, '<', $file);
binmode $fh, ':utf8';
my $ini = { _ => {} };

View File

@ -13,7 +13,7 @@ sub read_file {
1;
} 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;
XML::SAX::ParserFactory
@ -30,7 +30,7 @@ sub write_file {
my %vertices_offset = ();
open my $fh, '>', $file;
Slic3r::open(\my $fh, '>', $file);
binmode $fh, ':utf8';
printf $fh qq{<?xml version="1.0" encoding="UTF-8"?>\n};
printf $fh qq{<amf unit="millimeter">\n};

View File

@ -5,7 +5,7 @@ sub read_file {
my $self = shift;
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 $facets = [];
while (my $_ = <$fh>) {

View File

@ -7,7 +7,7 @@ sub read_file {
my $self = shift;
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
my $mode;
@ -103,7 +103,7 @@ sub write_file {
my $self = shift;
my ($file, $model, %params) = @_;
open my $fh, '>', $file;
Slic3r::open(\my $fh, '>', $file);
$params{binary}
? _write_binary($fh, $model->mesh)

View File

@ -472,7 +472,7 @@ sub export_svg {
my $output_file = $self->expanded_output_filepath($params{output_file});
$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...";
my $print_size = $self->size;
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') {
$fh = $file;
} else {
open $fh, ">", $file
Slic3r::open(\$fh, ">", $file)
or die "Failed to open $file for writing\n";
}

View File

@ -130,7 +130,7 @@ sub output_lines {
sub write_svg {
my ($svg, $filename) = @_;
open my $fh, '>', $filename;
Slic3r::open(\my $fh, '>', $filename);
print $fh $svg->xmlify;
close $fh;
printf "SVG written to %s\n", $filename;