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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
using System;
using System.IO;
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 PSProfileFolder[] PrusaSlicerProfiles { get; } = {
new (PSProfileFolder.FolderType.Print),
new (PSProfileFolder.FolderType.Printer),
};
public PSProfileFolder[] SuperSlicerProfiles { get; } = {
new (PSProfileFolder.FolderType.Print, true),
new (PSProfileFolder.FolderType.Printer, true),
};
public bool HavePrusaSlicer
{
get
{
var PSFolder = App.GetPrusaSlicerDirectory();
return !string.IsNullOrEmpty(PSFolder) && Directory.Exists(PSFolder);
}
}
public bool HaveSuperSlicer
{
get
{
var SSFolder = App.GetPrusaSlicerDirectory(true);
return !string.IsNullOrEmpty(SSFolder) && Directory.Exists(SSFolder);
}
}
public int TabSlicerSelectedIndex { get; set; }
public PrusaSlicerManagerWindow()
{
InitializeComponent();
DataContext = this;
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
public void RefreshProfiles()
{
foreach (var profile in PrusaSlicerProfiles)
{
profile.Reset();
}
foreach (var profile in SuperSlicerProfiles)
{
profile.Reset();
}
}
public async void InstallProfiles()
{
bool isSuperSlicer = TabSlicerSelectedIndex == 1;
var printProfiles = isSuperSlicer ? SuperSlicerProfiles[0].SelectedFiles : PrusaSlicerProfiles[0].SelectedFiles;
var printerProfiles = isSuperSlicer ? SuperSlicerProfiles[1].SelectedFiles : PrusaSlicerProfiles[1].SelectedFiles;
var slicerName = isSuperSlicer ? "SuperSlicer" : "PrusaSlicer";
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 {slicerName}:\n" +
"---------- PRINT PROFILES ----------\n" +
printProfiles +
"--------- PRINTER PROFILES ---------\n" +
printerProfiles +
"---------------\n" +
"Click 'Yes' to continue\n" +
"Click 'No' to cancel this operation",
$"Install printers into {slicerName}") != ButtonResult.Yes) return;
ushort count = 0;
try
{
foreach (var profile in isSuperSlicer ? SuperSlicerProfiles : PrusaSlicerProfiles)
{
foreach (var item in profile.Items)
{
if (!item.IsChecked.HasValue || !item.IsChecked.Value) continue;
var fi = item.Tag as FileInfo;
if (fi is null) continue;
fi.CopyTo(Path.Combine(profile.TargetPath, fi.Name), true);
count++;
}
}
}
catch (Exception exception)
{
await this.MessageBoxError(exception.Message, "Unable to install the profiles");
return;
}
await this.MessageBoxInfo(
$"{count} profiles were installed.\nRestart {slicerName} and check if profiles are present.",
"Operation completed");
RefreshProfiles();
}
}
}
|