- Remove unnecessary code

- Improve startup performance
This commit is contained in:
Stone-Red-Code
2021-09-12 13:24:46 +02:00
parent f94f24297e
commit d70e6229cc
4 changed files with 11 additions and 31 deletions
+3 -4
View File
@@ -636,10 +636,9 @@ namespace DesktopMagic
foreach (char c in chars) foreach (char c in chars)
{ {
textBlock.Text = ""; textBlock.Text = "";
for (int i = 0; i < 100; i++)
{ textBlock.Text += c.ToString();
textBlock.Text += c.ToString();
}
textBlock.UpdateLayout(); textBlock.UpdateLayout();
if (charWidth != textBlock.ActualWidth && charWidth != -1) if (charWidth != textBlock.ActualWidth && charWidth != -1)
+7 -25
View File
@@ -117,7 +117,6 @@ namespace DesktopMagic
private void LoadPlugin() private void LoadPlugin()
{ {
string sourceText;
string PluginPath; string PluginPath;
pluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{pluginName}"; pluginFolderPath = $"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\{MainWindow.AppName}\\Plugins\\{pluginName}";
@@ -128,38 +127,26 @@ namespace DesktopMagic
} }
else else
{ {
MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); _ = MessageBox.Show("File does not exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Exit(); Exit();
return; return;
} }
try try
{ {
sourceText = File.ReadAllText(PluginPath); ExecuteSource();
} }
catch (Exception ex) catch (Exception ex)
{ {
MainWindow.Logger.Log(ex.ToString(), "Plugin"); MainWindow.Logger.Log(ex.ToString(), "Plugin");
MessageBox.Show("File could not be read:\n" + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); _ = MessageBox.Show("File execution error:\n" + ex, "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);
Exit(); Exit();
return; return;
} }
PluginLoaded?.Invoke(); PluginLoaded?.Invoke();
} }
private void ExecuteSource(string sourceText) private void ExecuteSource()
{ {
byte[] assemblyBytes = File.ReadAllBytes($"{pluginFolderPath}\\{pluginName}.dll"); byte[] assemblyBytes = File.ReadAllBytes($"{pluginFolderPath}\\{pluginName}.dll");
Assembly dll = Assembly.Load(assemblyBytes); Assembly dll = Assembly.Load(assemblyBytes);
@@ -173,7 +160,7 @@ namespace DesktopMagic
if (instanceType is null) 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(); Exit();
return; return;
} }
@@ -186,7 +173,7 @@ namespace DesktopMagic
} }
else 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(); Exit();
return; return;
} }
@@ -242,11 +229,6 @@ namespace DesktopMagic
private void ValueTimer_Elapsed(object sender, ElapsedEventArgs e) 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 try
{ {
Bitmap result = pluginClassInstance.Main(); Bitmap result = pluginClassInstance.Main();
@@ -269,7 +251,7 @@ namespace DesktopMagic
catch (Exception ex) catch (Exception ex)
{ {
MainWindow.Logger.Log(ex.ToString(), "Plugin"); 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(); Exit();
return; return;
} }
@@ -5,7 +5,6 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.2.1" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" /> <PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup> </ItemGroup>
+1 -1
View File
@@ -21,7 +21,7 @@ namespace DesktopMagicPlugin.Test
{ {
Bitmap bmp = new Bitmap(100, 100); Bitmap bmp = new Bitmap(100, 100);
using Graphics graphics = Graphics.FromImage(bmp); using Graphics graphics = Graphics.FromImage(bmp);
graphics.Clear(Color.Red); graphics.Clear(Application.Color);
return bmp; return bmp;
} }
} }