From 92c13c5ed08b739d40ea3e45c296881a3d1131f2 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Tue, 3 Dec 2024 00:15:50 +0100 Subject: [PATCH] Change app name from "Desktop Magic" to "DesktopMagic" and some QOL improvments --- src/DesktopMagic/App.xaml.cs | 28 ++++++-- src/DesktopMagic/MainWindow.xaml | 1 - src/DesktopMagic/MainWindow.xaml.cs | 72 +++++++++------------ src/DesktopMagic/Plugins/PluginManager.xaml | 2 +- 4 files changed, 55 insertions(+), 48 deletions(-) diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index e4beedc..d1edcfa 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -14,13 +14,17 @@ public partial class App : Application { public const string AppGuid = "{{61FE5CE9-47C3-4255-A1F4-5BCF4ACA0879}"; - public const string AppName = "Desktop Magic"; + public const string AppName = "DesktopMagic"; + + // This is the previous name of the application, used to migrate the application data folder + private const string PreviousAppName = "Desktop Magic"; private static readonly string logFilePath = Path.Combine(ApplicationDataPath, $"{AppName}.log"); - private readonly Thread? eventThread; - private readonly EventWaitHandle eventWaitHandle; + public static string ApplicationDataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", AppName); + + public static string PluginsPath => Path.Combine(ApplicationDataPath, "Plugins"); public static Logger Logger { get; } = new Logger() { @@ -62,7 +66,7 @@ public partial class App : Application } }; - public static string ApplicationDataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", AppName); + private static string PreviousApplicationDataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", PreviousAppName); public App() { @@ -114,15 +118,27 @@ public partial class App : Application try { + if (Directory.Exists(PreviousApplicationDataPath)) + { + Directory.Move(PreviousApplicationDataPath, ApplicationDataPath); + Logger.LogInfo("Migrated ApplicationData Folder", source: "Setup"); + } + if (!Directory.Exists(ApplicationDataPath)) { _ = Directory.CreateDirectory(ApplicationDataPath); + Logger.LogInfo("Created ApplicationData Folder", source: "Setup"); + } + + if (!Directory.Exists(PluginsPath)) + { + _ = Directory.CreateDirectory(PluginsPath); + Logger.LogInfo("Created Plugins Folder", source: "Setup"); } - Logger.LogInfo("Created ApplicationData Folder", source: "Main"); } catch (Exception ex) { - _ = MessageBox.Show(ex.ToString()); + _ = MessageBox.Show(ex.ToString(), AppName, MessageBoxButton.OK, MessageBoxImage.Error); Logger.Log(ex.Message, "Setup", LogSeverity.Error); } diff --git a/src/DesktopMagic/MainWindow.xaml b/src/DesktopMagic/MainWindow.xaml index 271e2ea..3833e3e 100644 --- a/src/DesktopMagic/MainWindow.xaml +++ b/src/DesktopMagic/MainWindow.xaml @@ -20,7 +20,6 @@ MinHeight="520" MinWidth="570" WindowState="Minimized" - StateChanged="Window_StateChanged" Loaded="Window_Loaded"> diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index e6ff4da..6ec808d 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -9,12 +9,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; -using System.IO.Packaging; using System.Linq; -using System.Reflection; using System.Text.Json; using System.Threading; -using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -65,7 +62,7 @@ namespace DesktopMagic new System.Windows.Forms.ToolStripMenuItem("Toggle Edit Mode", null, (s, e) => { EditCheckBox.IsChecked = !EditCheckBox.IsChecked; EditCheckBox_Click(null, null); }), new System.Windows.Forms.ToolStripMenuItem("Plugin Manager", null, (s, e) => PluginManagerButton_Click(null!, null!)), new System.Windows.Forms.ToolStripMenuItem("GitHub", null, (s, e) => GitHubButton_Click(null!, null!)), - new System.Windows.Forms.ToolStripMenuItem("Exit", null, (s, e) => Close()), + new System.Windows.Forms.ToolStripMenuItem("Quit", null, (s, e) => Quit()), } }; @@ -81,7 +78,7 @@ namespace DesktopMagic } catch (Exception ex) { - _ = MessageBox.Show(ex.ToString()); + _ = MessageBox.Show(ex.ToString(), App.AppName, MessageBoxButton.OK, MessageBoxImage.Error); } } @@ -93,12 +90,6 @@ namespace DesktopMagic { try { - if (!Directory.Exists(App.ApplicationDataPath + "\\Plugins")) - { - _ = Directory.CreateDirectory(App.ApplicationDataPath + "\\Plugins"); - } - App.Logger.LogInfo("Created Plugins Folder", source: "Main"); - //Write To Log File and Load Elements App.Logger.LogInfo("Loading Plugin names", source: "Main"); @@ -114,7 +105,7 @@ namespace DesktopMagic catch (Exception ex) { App.Logger.LogError(ex.Message, source: "Main"); - _ = MessageBox.Show(ex.ToString()); + _ = MessageBox.Show(ex.ToString(), App.AppName, MessageBoxButton.OK, MessageBoxImage.Error); } } @@ -128,9 +119,7 @@ namespace DesktopMagic plugins.Add(buildInPlugin.Id, new(buildInPlugin, string.Empty)); } - string pluginsPath = App.ApplicationDataPath + "\\Plugins"; - - foreach (string directory in Directory.GetDirectories(pluginsPath)) + foreach (string directory in Directory.GetDirectories(App.PluginsPath)) { string? pluginDllPath = Directory.GetFiles(directory, "main.dll").FirstOrDefault(); string? pluginMetadataPath = Directory.GetFiles(directory, "metadata.json").FirstOrDefault(); @@ -289,9 +278,23 @@ namespace DesktopMagic private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { - MessageBoxResult msbRes = MessageBox.Show((string)FindResource("wantToCloseProgram"), App.AppName, MessageBoxButton.YesNo); - e.Cancel = msbRes != MessageBoxResult.Yes; SaveSettings(); + + if (blockWindowsClosing) + { + e.Cancel = true; + + EditCheckBox.IsChecked = false; + EditCheckBox_Click(null, null); + ShowInTaskbar = false; + Visibility = Visibility.Collapsed; + + foreach (Window item in Windows) + { + WindowPos.SendWpfWindowBack(item); + WindowPos.SendWpfWindowBack(item); + } + } } private void Window_Closed(object sender, EventArgs e) @@ -305,22 +308,6 @@ namespace DesktopMagic Environment.Exit(0); } - private void Window_StateChanged(object? sender, EventArgs? e) - { - if (WindowState == WindowState.Minimized) - { - EditCheckBox.IsChecked = false; - EditCheckBox_Click(null, null); - ShowInTaskbar = false; - Visibility = Visibility.Collapsed; - foreach (Window item in Windows) - { - WindowPos.SendWpfWindowBack(item); - WindowPos.SendWpfWindowBack(item); - } - } - } - #endregion Windows #region Options @@ -387,9 +374,15 @@ namespace DesktopMagic } } + private void Quit() + { + blockWindowsClosing = false; + Close(); + } + private void OpenPluginsFolderButton_Click(object sender, RoutedEventArgs e) { - _ = Process.Start("explorer.exe", App.ApplicationDataPath + "\\Plugins"); + _ = Process.Start("explorer.exe", App.PluginsPath); } private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) @@ -507,7 +500,7 @@ namespace DesktopMagic { if (Settings.Layouts.Any(l => l.Name.Trim() == inputDialog.ResponseText.Trim())) { - _ = MessageBox.Show((string)FindResource("layoutAlreadyExists")); + _ = MessageBox.Show((string)FindResource("layoutAlreadyExists"), App.AppName, MessageBoxButton.OK, MessageBoxImage.Warning); return; } @@ -627,14 +620,13 @@ namespace DesktopMagic if (!showWindow && minimize) { - WindowState = WindowState.Minimized; - Window_StateChanged(null, null); + Close(); } else { - WindowState = WindowState.Normal; - Window_StateChanged(null, null); + RestoreWindow(); } + mainWindowDataContext.IsLoading = false; } @@ -670,7 +662,7 @@ namespace DesktopMagic PluginManager pluginManager = new PluginManager(); pluginManager.ShowDialog(); LoadPlugins(); - LoadLayout(false); + LoadLayout(Visibility != Visibility.Visible); } private void SetLanguageDictionary() diff --git a/src/DesktopMagic/Plugins/PluginManager.xaml b/src/DesktopMagic/Plugins/PluginManager.xaml index 49a64dd..f517ded 100644 --- a/src/DesktopMagic/Plugins/PluginManager.xaml +++ b/src/DesktopMagic/Plugins/PluginManager.xaml @@ -9,7 +9,7 @@ xmlns:dataContexts="clr-namespace:DesktopMagic.DataContexts" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=dataContexts:PluginManagerDataContext}" - Title="PluginManager" + Title="Plugin Manager" Height="450" Width="800" MinHeight="520"