Skip to content

Commit

Permalink
Merge pull request #4 from Stone-Red-Code/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Stone-Red-Code authored May 1, 2024
2 parents d4cd384 + f7f75a4 commit 242f6a8
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 156 deletions.
Binary file modified installer/DesktopMagic-Installer.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion installer/Installer.iss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#expr Exec('cmd.exe /C ', 'dotnet build -o "' + SourcePath + '\publish" -c Release ' + SourcePath + '..\src\DesktopMagic\')

#define MyAppName "DesktopMagic"
#define MyAppVersion GetVersionNumbersString("/publish/DesktopMagic.exe")
#define MyAppVersion GetStringFileInfo("/publish/DesktopMagic.exe","ProductVersion")
#define MyAppPublisher "Stone_Red"
#define MyAppExeName "DesktopMagic.exe"

Expand Down
4 changes: 3 additions & 1 deletion src/DesktopMagic/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources\Strings\StringResources.en.xaml" />
<materialDesign:BundledTheme BaseTheme="Light" PrimaryColor="Grey" SecondaryColor="LightBlue" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesign3.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/BusyIndicator;component/Theme/Default.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ObsoleteBrushes.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ObsoleteStyles.xaml" />
<ResourceDictionary Source="Resources\Images\ImageResources.xaml" />
</ResourceDictionary.MergedDictionaries>
<Thickness x:Key="DefaultMargin" Top="6" Left="6" Right="6" Bottom ="6"></Thickness>
Expand Down
98 changes: 48 additions & 50 deletions src/DesktopMagic/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
global using Stone_Red_Utilities.Logging;

using Stone_Red_C_Sharp_Utilities.Logging;
using CuteUtils.Logging;

using System;
using System.IO;
Expand All @@ -17,28 +15,65 @@ public partial class App : Application
public const string AppGuid = "{{61FE5CE9-47C3-4255-A1F4-5BCF4ACA0879}";

public const string AppName = "Desktop Magic";
private readonly string logFilePath;

private static readonly string logFilePath = Path.Combine(ApplicationDataPath, $"{AppName}.log");

private readonly Thread? eventThread;

private readonly EventWaitHandle eventWaitHandle;

private readonly Logger logger = new Logger();
public static string ApplicationDataPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", AppName);
public static Logger Logger { get; } = new Logger()
{
Config = new()
{
FatalConfig = new OutputConfig()
{
ConsoleColor = ConsoleColor.DarkRed,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
ErrorConfig = new OutputConfig()
{
ConsoleColor = ConsoleColor.Red,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
WarnConfig = new OutputConfig()
{
ConsoleColor = ConsoleColor.Yellow,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
InfoConfig = new OutputConfig()
{
ConsoleColor = ConsoleColor.White,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
DebugConfig = new OutputConfig()
{
ConsoleColor = ConsoleColor.Gray,
LogTarget = LogTarget.DebugConsole,
},
FormatConfig = new FormatConfig()
{
DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:HH:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\nat {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}"
}
}
};

public static Logger Logger => ((App)Current).logger;
public static string ApplicationDataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", AppName);

public App()
{
logFilePath = ApplicationDataPath + "\\log.log";

// Setup global event handler
eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, AppGuid, out bool createdNew);

//check if creating new was successful
if (!createdNew)
{
Setup(false);
Logger.Log("Shutting down because other instance already running.", "Setup", LogSeverity.Warn);
Logger.LogWarn("Shutting down because other instance already running.", source: "Setup");
//Shutdown Application
_ = eventWaitHandle.Set();
Current.Shutdown();
Expand Down Expand Up @@ -71,50 +106,13 @@ private void Setup(bool clearLogFile)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

Logger.Config = new LogConfig()
{
FatalConfig = new OutputConfig()
{
Color = ConsoleColor.DarkRed,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
ErrorConfig = new OutputConfig()
{
Color = ConsoleColor.Red,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
WarnConfig = new OutputConfig()
{
Color = ConsoleColor.Yellow,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
InfoConfig = new OutputConfig()
{
Color = ConsoleColor.White,
LogTarget = LogTarget.DebugConsole | LogTarget.File,
FilePath = logFilePath
},
DebugConfig = new OutputConfig()
{
Color = ConsoleColor.Gray,
LogTarget = LogTarget.DebugConsole,
},
FormatConfig = new FormatConfig()
{
DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:HH:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\nat {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}"
}
};

try
{
if (!Directory.Exists(ApplicationDataPath))
{
_ = Directory.CreateDirectory(ApplicationDataPath);
}
Logger.Log("Created ApplicationData Folder", "Main");
Logger.LogInfo("Created ApplicationData Folder", source: "Main");
}
catch (Exception ex)
{
Expand All @@ -127,12 +125,12 @@ private void Setup(bool clearLogFile)
Logger.ClearLogFile(LogSeverity.Info);
}

Logger.Log("Log setup complete", "Setup");
Logger.LogInfo("Setup complete", source: "Setup");
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception exception = (Exception)e.ExceptionObject;
Logger.Log(exception + (e.IsTerminating ? "\t Process terminating!" : ""), exception.Source, LogSeverity.Fatal);
Logger.LogFatal(exception + (e.IsTerminating ? "\t Process terminating!" : ""), source: exception.Source ?? "Unknown");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ private void FftCalculated(object? sender, FftEventArgs e)
}
catch (Exception ex)
{
App.Logger.Log(ex.Message, "Music Visualizer", LogSeverity.Error);
App.Logger.LogError(ex.Message, source: "Music Visualizer");
}
}

Expand Down
103 changes: 52 additions & 51 deletions src/DesktopMagic/DesktopMagic.csproj
Original file line number Diff line number Diff line change
@@ -1,60 +1,61 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
<RootNamespace>DesktopMagic</RootNamespace>
<ApplicationIcon>icon.ico</ApplicationIcon>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<Authors>Stone_Red</Authors>
<Version>1.0.1.0</Version>
<PackageProjectUrl>https://github.com/Stone-Red-Code/DesktopMagic</PackageProjectUrl>
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF>
<RootNamespace>DesktopMagic</RootNamespace>
<ApplicationIcon>icon.ico</ApplicationIcon>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<Authors>Stone_Red</Authors>
<Version>1.0.1.240501</Version>
<PackageProjectUrl>https://github.com/Stone-Red-Code/DesktopMagic</PackageProjectUrl>
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
<AssemblyVersion>1.0.1.0501</AssemblyVersion>
<FileVersion>1.0.1.0501</FileVersion>
<TargetFramework>net8.0-windows7.0</TargetFramework>
<Nullable>enable</Nullable>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<None Remove="icon.ico" />
<None Remove="icons8_volunteering_26_85L_icon.ico" />
<None Remove="icon_Dark.ico" />
<None Remove="Resources\Images\modio-cog-blue.png" />
<None Remove="Resources\Images\modio-logo-bluedark.png" />
</ItemGroup>
<ItemGroup>
<None Remove="icon.ico" />
<None Remove="icons8_volunteering_26_85L_icon.ico" />
<None Remove="icon_Dark.ico" />
<None Remove="Resources\Images\modio-cog-blue.png" />
<None Remove="Resources\Images\modio-logo-bluedark.png" />
</ItemGroup>

<ItemGroup>
<Resource Include="Resources\Images\modio-cog-blue.png">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\Images\modio-cog-blue.png">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Resource>
</ItemGroup>

<ItemGroup>
<PackageReference Include="BusyIndicators" Version="2.1.2" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.5.1" />
<PackageReference Include="MaterialDesignThemes" Version="4.9.0" />
<PackageReference Include="Modio.NET" Version="1.1.1" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="Stone_Red-C-Sharp-Utilities" Version="1.0.3.2" />
<PackageReference Include="System.Management" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="BusyIndicators" Version="2.1.2" />
<PackageReference Include="CuteUtils" Version="1.0.0" />
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.6.0" />
<PackageReference Include="MaterialDesignThemes" Version="5.0.0" />
<PackageReference Include="Modio.NET" Version="1.1.1" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="System.Management" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DesktopMagicPluginAPI\DesktopMagic.Api.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DesktopMagicPluginAPI\DesktopMagic.Api.csproj" />
</ItemGroup>

<ItemGroup>
<Resource Include="icon_Dark.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Resources\Images\modio-logo-bluedark.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="icon_Dark.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="icon.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Resource>
<Resource Include="Resources\Images\modio-logo-bluedark.png" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/DesktopMagic/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
[assembly: SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "No need to")]
[assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "<Pending>")]
[assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "<Pending>", Scope = "member", Target = "~P:DesktopMagic.DataContexts.MainWindowDataContext.Settings")]
[assembly: SuppressMessage("Major Code Smell", "S3885:\"Assembly.Load\" should be used", Justification = "Assembly.Load does not load dependencies", Scope = "member", Target = "~M:DesktopMagic.PluginWindow.ExecuteSource")]
2 changes: 1 addition & 1 deletion src/DesktopMagic/Helpers/SettingElementGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void Generate(SettingElement settingElement, DockPanel dockPanel, TextBlo

private void DisplayException(string message)
{
App.Logger.Log(message, "PluginInput");
App.Logger.LogInfo(message, source: "PluginInput");
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
int index = MainWindow.WindowNames.IndexOf(optionsComboBox.SelectedItem.ToString() ?? string.Empty);

Expand Down
27 changes: 14 additions & 13 deletions src/DesktopMagic/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Reflection;
using System.Text.Json;
Expand Down Expand Up @@ -63,9 +64,9 @@ public MainWindow()
SetLanguageDictionary();

#if DEBUG
Title = $"{App.AppName} - Dev {Assembly.GetExecutingAssembly().GetName().Version}";
Title = $"{App.AppName} - Dev {System.Windows.Forms.Application.ProductVersion}";
#else
Title = $"{App.AppName} - {Assembly.GetExecutingAssembly().GetName().Version}";
Title = $"{App.AppName} - {System.Windows.Forms.Application.ProductVersion}";
#endif
}
catch (Exception ex)
Expand All @@ -86,23 +87,23 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
{
_ = Directory.CreateDirectory(App.ApplicationDataPath + "\\Plugins");
}
App.Logger.Log("Created Plugins Folder", "Main");
App.Logger.LogInfo("Created Plugins Folder", source: "Main");

//Write To Log File and Load Elements

App.Logger.Log("Loading Plugin names", "Main");
App.Logger.LogInfo("Loading Plugin names", source: "Main");
LoadPlugins();
App.Logger.Log("Loading Layout names", "Main");
App.Logger.LogInfo("Loading Layout names", source: "Main");
LoadSettings();
App.Logger.Log("Loading Layout", "Main");
App.Logger.LogInfo("Loading Layout", source: "Main");
LoadLayout();

loaded = true;
App.Logger.Log("Window Loaded", "Main");
App.Logger.LogInfo("Window Loaded", source: "Main");
}
catch (Exception ex)
{
App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
App.Logger.LogError(ex.Message, source: "Main");
_ = MessageBox.Show(ex.ToString());
}
}
Expand All @@ -126,27 +127,27 @@ private void LoadPlugins()

if (pluginDllPath is null)
{
App.Logger.Log($"Plugin \"{directory}\" has no \"main.dll\"", "Main", LogSeverity.Error);
App.Logger.LogError($"Plugin \"{directory}\" has no \"main.dll\"", source: "Main");
continue;
}

if (pluginMetadataPath is null)
{
App.Logger.Log($"Plugin \"{directory}\" has no \"metadata.json\"", "Main", LogSeverity.Warn);
App.Logger.LogWarn($"Plugin \"{directory}\" has no \"metadata.json\"", source: "Main");
continue;
}

PluginMetadata? pluginMetadata = JsonSerializer.Deserialize<PluginMetadata>(File.ReadAllText(pluginMetadataPath));

if (pluginMetadata is null)
{
App.Logger.Log($"Plugin \"{directory}\" has no valid \"metadata.json\"", "Main", LogSeverity.Error);
App.Logger.LogError($"Plugin \"{directory}\" has no valid \"metadata.json\"", source: "Main");
continue;
}

if (plugins.ContainsKey(pluginMetadata.Id))
{
App.Logger.Log($"Plugin \"{directory}\" has the same id as another plugin", "Main", LogSeverity.Error);
App.Logger.LogError($"Plugin \"{directory}\" has the same id as another plugin", source: "Main");
continue;
}

Expand Down Expand Up @@ -204,7 +205,7 @@ private void LoadPlugin(uint pluginId)
}
catch (Exception ex)
{
App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
App.Logger.LogError(ex.Message, source: "Main");
}
}
return;
Expand Down
Loading

0 comments on commit 242f6a8

Please sign in to comment.