mirror of
https://github.com/Stone-Red-Code/DesktopMagic.git
synced 2026-09-04 08:56:15 +02:00
- Fix logging issues
This commit is contained in:
@@ -19,7 +19,7 @@ public partial class App : Application
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json");
|
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/develop/update/updateInfo.json");
|
||||||
#else
|
#else
|
||||||
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json");
|
private readonly Updater updater = new Updater(TimeSpan.FromDays(1), "https://raw.githubusercontent.com/Stone-Red-Code/DesktopMagic/main/update/updateInfo.json");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public const string AppName = "Desktop Magic";
|
public const string AppName = "Desktop Magic";
|
||||||
@@ -30,19 +30,21 @@ public partial class App : Application
|
|||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
logFilePath = ApplicationDataPath + "\\Log.log";
|
logFilePath = ApplicationDataPath + "\\Log.log";
|
||||||
Setup();
|
|
||||||
// Try to grab mutex
|
// Try to grab mutex
|
||||||
_mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew);
|
_mutex = new Mutex(true, $"Stone_Red{AppName}", out bool createdNew);
|
||||||
|
|
||||||
//check if creating new was successful
|
//check if creating new was successful
|
||||||
if (!createdNew)
|
if (!createdNew)
|
||||||
{
|
{
|
||||||
|
Setup(false);
|
||||||
Logger.Log("Shutting down because other instance already running.", "Setup");
|
Logger.Log("Shutting down because other instance already running.", "Setup");
|
||||||
//Shutdown Application
|
//Shutdown Application
|
||||||
Current.Shutdown();
|
Current.Shutdown();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Setup(true);
|
||||||
Exit += CloseMutexHandler;
|
Exit += CloseMutexHandler;
|
||||||
|
|
||||||
updater.ProgressChanged += Updater_ProgressChanged;
|
updater.ProgressChanged += Updater_ProgressChanged;
|
||||||
@@ -60,7 +62,7 @@ public partial class App : Application
|
|||||||
|
|
||||||
private void Updater_NoUpdateAvailible()
|
private void Updater_NoUpdateAvailible()
|
||||||
{
|
{
|
||||||
Logger.Log("No update available.", "Updater");
|
Logger.Log("No update available", "Updater");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Updater_OnException(Exception exception)
|
private void Updater_OnException(Exception exception)
|
||||||
@@ -70,7 +72,7 @@ public partial class App : Application
|
|||||||
|
|
||||||
private void Updater_ProgressChanged(long? totalFileSize, long totalBytesDownloaded, double? progressPercentage)
|
private void Updater_ProgressChanged(long? totalFileSize, long totalBytesDownloaded, double? progressPercentage)
|
||||||
{
|
{
|
||||||
Logger.Log($"{progressPercentage}% {totalBytesDownloaded}/{totalFileSize}", "Updater");
|
Logger.Log($"Downloading: {progressPercentage}% {totalBytesDownloaded}/{totalFileSize}", "Updater");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void CloseMutexHandler(object sender, EventArgs e)
|
protected void CloseMutexHandler(object sender, EventArgs e)
|
||||||
@@ -78,7 +80,7 @@ public partial class App : Application
|
|||||||
_mutex?.Close();
|
_mutex?.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Setup()
|
private void Setup(bool clearLogFile)
|
||||||
{
|
{
|
||||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||||
|
|
||||||
@@ -129,12 +131,16 @@ public partial class App : Application
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Log(ex.Message, "Setup", LogSeverity.Error);
|
|
||||||
_ = MessageBox.Show(ex.ToString());
|
_ = MessageBox.Show(ex.ToString());
|
||||||
|
Logger.Log(ex.Message, "Setup", LogSeverity.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.ClearLogFile(LogSeverity.Info);
|
if (clearLogFile)
|
||||||
Logger.Log("Log setup complete.", "Setup");
|
{
|
||||||
|
Logger.ClearLogFile(LogSeverity.Info);
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Log("Log setup complete", "Setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||||
|
|||||||
@@ -7,11 +7,11 @@
|
|||||||
<ApplicationIcon>icon.ico</ApplicationIcon>
|
<ApplicationIcon>icon.ico</ApplicationIcon>
|
||||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||||
<Authors>Stone_Red</Authors>
|
<Authors>Stone_Red</Authors>
|
||||||
<Version>0.0.3.1</Version>
|
<Version>0.0.3.2</Version>
|
||||||
<PackageProjectUrl>https://github.com/Stone-Red-Code/DesktopMagic</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/Stone-Red-Code/DesktopMagic</PackageProjectUrl>
|
||||||
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
|
<RepositoryUrl>https://github.com/Stone-Red-Code/DesktopMagic</RepositoryUrl>
|
||||||
<AssemblyVersion>0.0.3.1</AssemblyVersion>
|
<AssemblyVersion>0.0.3.2</AssemblyVersion>
|
||||||
<FileVersion>0.0.3.1</FileVersion>
|
<FileVersion>0.0.3.2</FileVersion>
|
||||||
<TargetFramework>net6.0-windows</TargetFramework>
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user