mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 23:23:59 -06:00
New commands for exporting/importing full config bundles. Useful for printer vendors. #1365
This commit is contained in:
parent
c98c992b4d
commit
fed8783e30
4 changed files with 143 additions and 16 deletions
|
@ -77,9 +77,16 @@ sub load {
|
|||
my ($file) = @_;
|
||||
|
||||
my $ini = __PACKAGE__->read_ini($file);
|
||||
return $class->load_ini_hash($ini->{_});
|
||||
}
|
||||
|
||||
sub load_ini_hash {
|
||||
my $class = shift;
|
||||
my ($ini_hash) = @_;
|
||||
|
||||
my $config = $class->new;
|
||||
foreach my $opt_key (keys %{$ini->{_}}) {
|
||||
($opt_key, my $value) = _handle_legacy($opt_key, $ini->{_}{$opt_key});
|
||||
foreach my $opt_key (keys %$ini_hash) {
|
||||
($opt_key, my $value) = _handle_legacy($opt_key, $ini_hash->{$opt_key});
|
||||
next if !defined $opt_key;
|
||||
$config->set_deserialize($opt_key, $value);
|
||||
}
|
||||
|
@ -119,7 +126,7 @@ sub _handle_legacy {
|
|||
if ($opt_key eq 'gcode_flavor' && $value eq 'makerbot') {
|
||||
$value = 'makerware';
|
||||
}
|
||||
if ($opt_key eq 'fill_density' && defined($value) && $value <= 1) {
|
||||
if ($opt_key eq 'fill_density' && defined($value) && $value !~ /%/ && $value <= 1) {
|
||||
# fill_density was turned into a percent value
|
||||
$value *= 100;
|
||||
$value = "$value"; # force update of the PV value, workaround for bug https://rt.cpan.org/Ticket/Display.html?id=94110
|
||||
|
@ -161,16 +168,22 @@ sub set_ifndef {
|
|||
}
|
||||
}
|
||||
|
||||
sub save {
|
||||
my $self = shift;
|
||||
my ($file) = @_;
|
||||
sub as_ini {
|
||||
my ($self) = @_;
|
||||
|
||||
my $ini = { _ => {} };
|
||||
foreach my $opt_key (sort @{$self->get_keys}) {
|
||||
next if $Options->{$opt_key}{shortcut};
|
||||
$ini->{_}{$opt_key} = $self->serialize($opt_key);
|
||||
}
|
||||
__PACKAGE__->write_ini($file, $ini);
|
||||
return $ini;
|
||||
}
|
||||
|
||||
sub save {
|
||||
my $self = shift;
|
||||
my ($file) = @_;
|
||||
|
||||
__PACKAGE__->write_ini($file, $self->as_ini);
|
||||
}
|
||||
|
||||
sub setenv {
|
||||
|
@ -382,7 +395,8 @@ sub write_ini {
|
|||
binmode $fh, ':utf8';
|
||||
my $localtime = localtime;
|
||||
printf $fh "# generated by Slic3r $Slic3r::VERSION on %s\n", "$localtime";
|
||||
foreach my $category (sort keys %$ini) {
|
||||
# make sure the _ category is the first one written
|
||||
foreach my $category (sort { ($a eq '_') ? -1 : ($a cmp $b) } keys %$ini) {
|
||||
printf $fh "\n[%s]\n", $category if $category ne '_';
|
||||
foreach my $key (sort keys %{$ini->{$category}}) {
|
||||
printf $fh "%s = %s\n", $key, $ini->{$category}{$key};
|
||||
|
@ -406,7 +420,7 @@ sub read_ini {
|
|||
next if /^\s+/;
|
||||
next if /^$/;
|
||||
next if /^\s*#/;
|
||||
if (/^\[(\w+)\]$/) {
|
||||
if (/^\[(.+?)\]$/) {
|
||||
$category = $1;
|
||||
next;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue