diff options
Diffstat (limited to 'UVtools.WPF/Windows/PrusaSlicerManagerWindow.axaml.cs')
-rw-r--r-- | UVtools.WPF/Windows/PrusaSlicerManagerWindow.axaml.cs | 68 |
1 files changed, 48 insertions, 20 deletions
diff --git a/UVtools.WPF/Windows/PrusaSlicerManagerWindow.axaml.cs b/UVtools.WPF/Windows/PrusaSlicerManagerWindow.axaml.cs index 4b30c9c..29e09ac 100644 --- a/UVtools.WPF/Windows/PrusaSlicerManagerWindow.axaml.cs +++ b/UVtools.WPF/Windows/PrusaSlicerManagerWindow.axaml.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using Avalonia; using Avalonia.Controls; using Avalonia.Markup.Xaml; using MessageBox.Avalonia.Enums; @@ -12,17 +11,38 @@ namespace UVtools.WPF.Windows { public class PrusaSlicerManagerWindow : WindowEx { - public PEProfileFolder[] Profiles { get;} + 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(); - Profiles = new[] - { - new PEProfileFolder(PEProfileFolder.FolderType.Print), - new PEProfileFolder(PEProfileFolder.FolderType.Printer), - }; - DataContext = this; } @@ -33,7 +53,12 @@ namespace UVtools.WPF.Windows public void RefreshProfiles() { - foreach (var profile in Profiles) + foreach (var profile in PrusaSlicerProfiles) + { + profile.Reset(); + } + + foreach (var profile in SuperSlicerProfiles) { profile.Reset(); } @@ -41,8 +66,10 @@ namespace UVtools.WPF.Windows public async void InstallProfiles() { - var printProfiles = Profiles[0].SelectedFiles; - var printerProfiles = Profiles[1].SelectedFiles; + 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)) { @@ -51,40 +78,41 @@ namespace UVtools.WPF.Windows } if (await this.MessageBoxQuestion( - "This action will install and override the following profiles into PrusaSlicer:\n" + + $"This action will install and override the following profiles into {slicerName}:\n" + "---------- PRINT PROFILES ----------\n" + - Profiles[0].SelectedFiles + + printProfiles + "--------- PRINTER PROFILES ---------\n" + - Profiles[1].SelectedFiles + + printerProfiles + "---------------\n" + "Click 'Yes' to continue\n" + "Click 'No' to cancel this operation", - "Install printers into PrusaSlicer") != ButtonResult.Yes) return; + $"Install printers into {slicerName}") != ButtonResult.Yes) return; ushort count = 0; try { - foreach (var profile in Profiles) + foreach (var profile in isSuperSlicer ? SuperSlicerProfiles : PrusaSlicerProfiles) { - foreach (CheckBox item in profile.Items) + foreach (var 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); + if (fi is null) continue; + fi.CopyTo(Path.Combine(profile.TargetPath, fi.Name), true); count++; } } } catch (Exception exception) { - await this.MessageBoxError(exception.ToString(), "Unable to install the profiles"); + await this.MessageBoxError(exception.Message, "Unable to install the profiles"); return; } await this.MessageBoxInfo( - $"{count} profiles were installed.\nRestart PrusaSlicer and check if profiles are present.", + $"{count} profiles were installed.\nRestart {slicerName} and check if profiles are present.", "Operation completed"); RefreshProfiles(); |