diff --git a/src/DesktopMagic/CalendarManagment.cs b/src/DesktopMagic/CalendarManagment.cs index 96f0f6b..0fff91f 100644 --- a/src/DesktopMagic/CalendarManagment.cs +++ b/src/DesktopMagic/CalendarManagment.cs @@ -17,6 +17,7 @@ namespace DesktopMagic private static string ApplicationName = "Google Calendar API .NET " + MainWindow.AppName; + [Obsolete] public (List, List) GetEvents() { List upcomingEventNames = new List(); diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index 52ea309..ff11bcd 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -11,6 +11,7 @@ using System.Windows.Media; using System.Text.Json; using Stone_Red_Utilities.Logging; using System.Diagnostics; +using System.Reflection; namespace DesktopMagic { @@ -78,7 +79,7 @@ namespace DesktopMagic InitializeComponent(); SetLanguageDictionary(); - this.Title = AppName; + this.Title = $"{AppName} - {Assembly.GetExecutingAssembly().GetName().Version}"; } catch (Exception ex) { @@ -974,7 +975,7 @@ namespace DesktopMagic private void OpenPluginsFolderButton_Click(object sender, RoutedEventArgs e) { - _ = System.Diagnostics.Process.Start("explorer.exe", applicationDataPath + "\\Plugins"); + _ = Process.Start("explorer.exe", applicationDataPath + "\\Plugins"); } private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) diff --git a/src/DesktopMagic/Plugin/PluginData.cs b/src/DesktopMagic/Plugin/PluginData.cs index f301d7f..d812d8f 100644 --- a/src/DesktopMagic/Plugin/PluginData.cs +++ b/src/DesktopMagic/Plugin/PluginData.cs @@ -20,6 +20,10 @@ namespace DesktopMagic public Point WindowPosition => new Point((int)window.Left, (int)window.Top); + public string PluginName => window.PluginName; + + public string PluginPath => window.PluginFolderPath; + public void UpdateWindow() => window.UpdatePluginWindow(); } } \ No newline at end of file diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index 434d7ee..07d0330 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -29,8 +29,8 @@ namespace DesktopMagic private System.Timers.Timer valueTimer; private Plugin pluginClassInstance; - private readonly string pluginName = ""; - private string pluginFolderPath = ""; + public string PluginName { get; private set; } + public string PluginFolderPath { get; private set; } private bool stop = false; public event Action PluginLoaded; @@ -60,7 +60,7 @@ namespace DesktopMagic t.Elapsed += Elapsed; t.Start(); - this.pluginName = pluginName; + this.PluginName = pluginName; key = Registry.CurrentUser.CreateSubKey(@"Software\" + MainWindow.AppName); this.Top = double.Parse(key.GetValue(pluginName + "WindowTop", 100).ToString()); @@ -117,9 +117,9 @@ namespace DesktopMagic private void LoadPlugin() { - pluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{pluginName}"; + PluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{PluginName}"; - if (!File.Exists($"{pluginFolderPath}\\{pluginName}.dll")) + if (!File.Exists($"{PluginFolderPath}\\{PluginName}.dll")) { _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); @@ -142,7 +142,7 @@ namespace DesktopMagic private void ExecuteSource() { - byte[] assemblyBytes = File.ReadAllBytes($"{pluginFolderPath}\\{pluginName}.dll"); + byte[] assemblyBytes = File.ReadAllBytes($"{PluginFolderPath}\\{PluginName}.dll"); Assembly dll = Assembly.Load(assemblyBytes); Type instanceType = dll.GetTypes().FirstOrDefault(type => type.GetTypeInfo().BaseType == typeof(Plugin)); @@ -190,34 +190,45 @@ namespace DesktopMagic private void LoadOptions(object instance) { - Debug.WriteLine(instance.GetType().FullName); - FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField); - - List settingElements = new List(); - foreach (FieldInfo prop in props) + try { - if (prop.GetValue(instance) is Element element) + Debug.WriteLine(instance.GetType().FullName); + FieldInfo[] props = instance.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.GetField); + + List settingElements = new List(); + foreach (FieldInfo prop in props) { - object[] attrs = prop.GetCustomAttributes(true); - foreach (object attr in attrs) + if (prop.GetValue(instance) is Element element) { - if (attr is ElementAttribute elementAttribute) + object[] attrs = prop.GetCustomAttributes(true); + foreach (object attr in attrs) { - settingElements.Add(new SettingElement(element, elementAttribute.Name, elementAttribute.OrderIndex)); - break; + if (attr is ElementAttribute elementAttribute) + { + settingElements.Add(new SettingElement(element, elementAttribute.Name, elementAttribute.OrderIndex)); + break; + } } } } - } - settingElements = settingElements.OrderBy(x => x.OrderIndex).ToList(); - if (MainWindow.PluginsSettings.ContainsKey(pluginName)) - { - MainWindow.PluginsSettings[pluginName] = settingElements; + settingElements = settingElements.OrderBy(x => x.OrderIndex).ToList(); + if (MainWindow.PluginsSettings.ContainsKey(PluginName)) + { + MainWindow.PluginsSettings[PluginName] = settingElements; + } + else + { + MainWindow.PluginsSettings.Add(PluginName, settingElements); + } } - else + catch (Exception ex) { - MainWindow.PluginsSettings.Add(pluginName, settingElements); + stop = true; + MainWindow.Logger.Log(ex.ToString(), "Plugin"); + _ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + Exit(); + return; } } @@ -289,14 +300,14 @@ namespace DesktopMagic private void Window_LocationChanged(object sender, EventArgs e) { - key.SetValue(pluginName + "WindowTop", this.Top); - key.SetValue(pluginName + "WindowLeft", this.Left); + key.SetValue(PluginName + "WindowTop", this.Top); + key.SetValue(PluginName + "WindowLeft", this.Left); } private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { - key.SetValue(pluginName + "WindowHeight", this.Height); - key.SetValue(pluginName + "WindowWidth", this.Width); + key.SetValue(PluginName + "WindowHeight", this.Height); + key.SetValue(PluginName + "WindowWidth", this.Width); tileBar.CaptionHeight = this.ActualHeight - 10; } diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md index 90b9321..7840ec4 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.md @@ -26,6 +26,8 @@ - [IPluginData](#T-DesktopMagicPluginAPI-IPluginData 'DesktopMagicPluginAPI.IPluginData') - [Color](#P-DesktopMagicPluginAPI-IPluginData-Color 'DesktopMagicPluginAPI.IPluginData.Color') - [Font](#P-DesktopMagicPluginAPI-IPluginData-Font 'DesktopMagicPluginAPI.IPluginData.Font') + - [PluginName](#P-DesktopMagicPluginAPI-IPluginData-PluginName 'DesktopMagicPluginAPI.IPluginData.PluginName') + - [PluginPath](#P-DesktopMagicPluginAPI-IPluginData-PluginPath 'DesktopMagicPluginAPI.IPluginData.PluginPath') - [WindowPosition](#P-DesktopMagicPluginAPI-IPluginData-WindowPosition 'DesktopMagicPluginAPI.IPluginData.WindowPosition') - [WindowSize](#P-DesktopMagicPluginAPI-IPluginData-WindowSize 'DesktopMagicPluginAPI.IPluginData.WindowSize') - [UpdateWindow()](#M-DesktopMagicPluginAPI-IPluginData-UpdateWindow 'DesktopMagicPluginAPI.IPluginData.UpdateWindow') @@ -325,6 +327,20 @@ Gets the color of the main application. Gets the font of the main application. + +### PluginName `property` + +##### Summary + +Gets the name of the plugin. + + +### PluginPath `property` + +##### Summary + +Gets the path of the parent directory of the plugin. + ### WindowPosition `property` diff --git a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml index a02771b..a485ff1 100644 --- a/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml +++ b/src/DesktopMagicPluginAPI/DesktopMagicPluginAPI.xml @@ -281,6 +281,16 @@ Gets the window position of the plugin window. + + + Gets the name of the plugin. + + + + + Gets the path of the parent directory of the plugin. + + Updates the plugin window. diff --git a/src/DesktopMagicPluginAPI/IPluginData.cs b/src/DesktopMagicPluginAPI/IPluginData.cs index 9eeef60..a7c0c1e 100644 --- a/src/DesktopMagicPluginAPI/IPluginData.cs +++ b/src/DesktopMagicPluginAPI/IPluginData.cs @@ -27,6 +27,16 @@ namespace DesktopMagicPluginAPI /// Point WindowPosition { get; } + /// + /// Gets the name of the plugin. + /// + string PluginName { get; } + + /// + /// Gets the path of the parent directory of the plugin. + /// + string PluginPath { get; } + /// /// Updates the plugin window. ///