From d70e6229cc2ca79b471488251a48d1be4d0b17bb Mon Sep 17 00:00:00 2001 From: Stone-Red-Code <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sun, 12 Sep 2021 13:24:46 +0200 Subject: [PATCH] - Remove unnecessary code - Improve startup performance --- src/DesktopMagic/MainWindow.xaml.cs | 7 ++-- src/DesktopMagic/Plugin/PluginWindow.xaml.cs | 32 ++++--------------- .../DesktopMagicPlugin.Test.csproj | 1 - src/DesktopMagicPlugin.Test/PluginScript.cs | 2 +- 4 files changed, 11 insertions(+), 31 deletions(-) diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index da90875..d4e7457 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -636,10 +636,9 @@ namespace DesktopMagic foreach (char c in chars) { textBlock.Text = ""; - for (int i = 0; i < 100; i++) - { - textBlock.Text += c.ToString(); - } + + textBlock.Text += c.ToString(); + textBlock.UpdateLayout(); if (charWidth != textBlock.ActualWidth && charWidth != -1) diff --git a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs index 26eb572..25abc25 100644 --- a/src/DesktopMagic/Plugin/PluginWindow.xaml.cs +++ b/src/DesktopMagic/Plugin/PluginWindow.xaml.cs @@ -117,7 +117,6 @@ namespace DesktopMagic private void LoadPlugin() { - string sourceText; string PluginPath; pluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{pluginName}"; @@ -128,38 +127,26 @@ namespace DesktopMagic } else { - MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } try { - sourceText = File.ReadAllText(PluginPath); + ExecuteSource(); } catch (Exception ex) { MainWindow.Logger.Log(ex.ToString(), "Plugin"); - MessageBox.Show("File could not be read:\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); - Exit(); - return; - } - - try - { - ExecuteSource(sourceText); - } - catch (Exception ex) - { - MainWindow.Logger.Log(ex.ToString(), "Plugin"); - MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } PluginLoaded?.Invoke(); } - private void ExecuteSource(string sourceText) + private void ExecuteSource() { byte[] assemblyBytes = File.ReadAllBytes($"{pluginFolderPath}\\{pluginName}.dll"); Assembly dll = Assembly.Load(assemblyBytes); @@ -173,7 +160,7 @@ namespace DesktopMagic if (instanceType is null) { - MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } @@ -186,7 +173,7 @@ namespace DesktopMagic } else { - MessageBox.Show($"The \"Plugin\" class has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show($"The \"Plugin\" class has to inherit from \"{typeof(Plugin).FullName}\"", "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } @@ -242,11 +229,6 @@ namespace DesktopMagic private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e) { - //Set Arguments - SolidBrush newBrush = (SolidBrush)MainWindow.GlobalSystemColor; - System.Drawing.Color color = newBrush.Color; - string font = MainWindow.GlobalFont; - try { Bitmap result = pluginClassInstance.Main(); @@ -269,7 +251,7 @@ namespace DesktopMagic catch (Exception ex) { MainWindow.Logger.Log(ex.ToString(), "Plugin"); - MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); + _ = MessageBox.Show("File execution error:\n" + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error); Exit(); return; } diff --git a/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj b/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj index 19fb9b6..d2240e9 100644 --- a/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj +++ b/src/DesktopMagicPlugin.Test/DesktopMagicPlugin.Test.csproj @@ -5,7 +5,6 @@ - diff --git a/src/DesktopMagicPlugin.Test/PluginScript.cs b/src/DesktopMagicPlugin.Test/PluginScript.cs index 67a7c0d..175a2db 100644 --- a/src/DesktopMagicPlugin.Test/PluginScript.cs +++ b/src/DesktopMagicPlugin.Test/PluginScript.cs @@ -21,7 +21,7 @@ namespace DesktopMagicPlugin.Test { Bitmap bmp = new Bitmap(100, 100); using Graphics graphics = Graphics.FromImage(bmp); - graphics.Clear(Color.Red); + graphics.Clear(Application.Color); return bmp; } }