From 8d23df07878a888c831f9c7198f088cccbc834a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tiago=20Concei=C3=A7=C3=A3o?= Date: Wed, 7 Oct 2020 05:02:33 +0100 Subject: [PATCH] WPF progress --- UVtools.WPF/App.axaml.cs | 21 +++++++ UVtools.WPF/MainWindow.axaml.cs | 11 ++++ UVtools.WPF/Structures/PEProfileFolder.cs | 27 ++++++--- UVtools.WPF/Windows/PrusaSlicerManager.axaml | 16 +++-- .../Windows/PrusaSlicerManager.axaml.cs | 58 ++++++++++++++++++- 5 files changed, 118 insertions(+), 15 deletions(-) diff --git a/UVtools.WPF/App.axaml.cs b/UVtools.WPF/App.axaml.cs index 1919abd..7a819ce 100644 --- a/UVtools.WPF/App.axaml.cs +++ b/UVtools.WPF/App.axaml.cs @@ -167,6 +167,27 @@ namespace UVtools.WPF return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); } + public static string GetPrusaSlicerDirectory() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}{Path.DirectorySeparatorChar}PrusaSlicer"; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return $"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)}{Path.DirectorySeparatorChar}.PrusaSlicer"; + } + + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + return string.Format("{0}{1}Library{1}Application Support{1}PrusaSlicer", + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), Path.DirectorySeparatorChar); + } + + return null; + } + #endregion } } diff --git a/UVtools.WPF/MainWindow.axaml.cs b/UVtools.WPF/MainWindow.axaml.cs index feb9ade..7a36ce8 100644 --- a/UVtools.WPF/MainWindow.axaml.cs +++ b/UVtools.WPF/MainWindow.axaml.cs @@ -586,6 +586,17 @@ namespace UVtools.WPF public async void MenuHelpInstallProfilesClicked() { + var PEFolder = App.GetPrusaSlicerDirectory(); + if (string.IsNullOrEmpty(PEFolder) || !Directory.Exists(PEFolder)) + { + if(await this.MessageBoxQuestion( + "Unable to detect PrusaSlicer on your system, please ensure you have latest version installed.\n" + + $"Was looking on: {PEFolder}\n\n" + + "Click 'Yes' to open the PrusaSlicer webpage for download\n" + + "Click 'No' to dismiss", + "Unable to detect PrusaSlicer") == ButtonResult.Yes) App.OpenBrowser("https://www.prusa3d.com/prusaslicer/"); + return; + } await new PrusaSlicerManager().ShowDialog(this); } diff --git a/UVtools.WPF/Structures/PEProfileFolder.cs b/UVtools.WPF/Structures/PEProfileFolder.cs index 1d83a5c..b949e6d 100644 --- a/UVtools.WPF/Structures/PEProfileFolder.cs +++ b/UVtools.WPF/Structures/PEProfileFolder.cs @@ -45,6 +45,21 @@ namespace UVtools.WPF.Structures set => RaiseAndSetIfChanged(ref _updates, value); } + public string SelectedFiles + { + get + { + StringBuilder sb = new StringBuilder(); + foreach (CheckBox item in Items) + { + if (!item.IsChecked.HasValue || !item.IsChecked.Value) continue; + sb.AppendLine(item.Content.ToString()); + } + + return sb.ToString(); + } + } + public PEProfileFolder(FolderType type) { Type = type; @@ -54,16 +69,12 @@ namespace UVtools.WPF.Structures case FolderType.Print: SourcePath = string.Format("{0}{1}Assets{1}PrusaSlicer{1}sla_print", App.GetApplicationPath(), Path.DirectorySeparatorChar); - TargetPath = string.Format("{0}{1}PrusaSlicer{1}sla_print", - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - Path.DirectorySeparatorChar); + TargetPath = $"{App.GetPrusaSlicerDirectory()}{Path.DirectorySeparatorChar}sla_print"; break; case FolderType.Printer: SourcePath = string.Format("{0}{1}Assets{1}PrusaSlicer{1}printer", App.GetApplicationPath(), Path.DirectorySeparatorChar); - TargetPath = string.Format("{0}{1}PrusaSlicer{1}printer", - Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), - Path.DirectorySeparatorChar); + TargetPath = $"{App.GetPrusaSlicerDirectory()}{Path.DirectorySeparatorChar}printer"; break; } @@ -86,8 +97,8 @@ namespace UVtools.WPF.Structures { Items.Add(new CheckBox { - Content = files[i].Name, - Tag = files + Content = Path.GetFileNameWithoutExtension(files[i].Name), + Tag = files[i] }); if (folderExists) diff --git a/UVtools.WPF/Windows/PrusaSlicerManager.axaml b/UVtools.WPF/Windows/PrusaSlicerManager.axaml index 393256e..fdda65a 100644 --- a/UVtools.WPF/Windows/PrusaSlicerManager.axaml +++ b/UVtools.WPF/Windows/PrusaSlicerManager.axaml @@ -28,7 +28,7 @@ Width="18" Height="18" BorderBrush="Black" BorderThickness="2" - Background="Green"> + Background="Green"/> + Background="Red"/> + Background="Black"/> - @@ -146,7 +148,7 @@ - + @@ -285,6 +288,7 @@ diff --git a/UVtools.WPF/Windows/PrusaSlicerManager.axaml.cs b/UVtools.WPF/Windows/PrusaSlicerManager.axaml.cs index d7f81b7..ae24b3c 100644 --- a/UVtools.WPF/Windows/PrusaSlicerManager.axaml.cs +++ b/UVtools.WPF/Windows/PrusaSlicerManager.axaml.cs @@ -1,7 +1,11 @@ -using Avalonia; +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 @@ -34,5 +38,57 @@ namespace UVtools.WPF.Windows 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(); + + } } }