blob: 4b30c9c80b07f6677f21cf5873ae5f9cdb5f844e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
using System;
using System.IO;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using MessageBox.Avalonia.Enums;
using UVtools.WPF.Controls;
using UVtools.WPF.Extensions;
using UVtools.WPF.Structures;
namespace UVtools.WPF.Windows
{
public class PrusaSlicerManagerWindow : WindowEx
{
public PEProfileFolder[] Profiles { get;}
public PrusaSlicerManagerWindow()
{
InitializeComponent();
Profiles = new[]
{
new PEProfileFolder(PEProfileFolder.FolderType.Print),
new PEProfileFolder(PEProfileFolder.FolderType.Printer),
};
DataContext = this;
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public void RefreshProfiles()
{
foreach (var profile in Profiles)
{
profile.Reset();
}
}
public async void InstallProfiles()
{
var printProfiles = Profiles[0].SelectedFiles;
var printerProfiles = Profiles[1].SelectedFiles;
if (string.IsNullOrEmpty(printProfiles) && string.IsNullOrEmpty(printerProfiles))
{
await this.MessageBoxError("Select at least one profile to install", "None profile was selected");
return;
}
if (await this.MessageBoxQuestion(
"This action will install and override the following profiles into PrusaSlicer:\n" +
"---------- PRINT PROFILES ----------\n" +
Profiles[0].SelectedFiles +
"--------- PRINTER PROFILES ---------\n" +
Profiles[1].SelectedFiles +
"---------------\n" +
"Click 'Yes' to continue\n" +
"Click 'No' to cancel this operation",
"Install printers into PrusaSlicer") != ButtonResult.Yes) return;
ushort count = 0;
try
{
foreach (var profile in Profiles)
{
foreach (CheckBox item in profile.Items)
{
if (!item.IsChecked.HasValue || !item.IsChecked.Value) continue;
var fi = item.Tag as FileInfo;
fi.CopyTo($"{profile.TargetPath}{Path.DirectorySeparatorChar}{fi.Name}", true);
count++;
}
}
}
catch (Exception exception)
{
await this.MessageBoxError(exception.ToString(), "Unable to install the profiles");
return;
}
await this.MessageBoxInfo(
$"{count} profiles were installed.\nRestart PrusaSlicer and check if profiles are present.",
"Operation completed");
RefreshProfiles();
}
}
}
|