Merge pull request 'update logging' (#22) from impl/better-logging into main

Reviewed-on: #22
This commit is contained in:
IsWaffle 2024-07-09 22:27:01 +00:00
commit fc6b574f47
4 changed files with 23 additions and 14 deletions

View File

@ -4,8 +4,8 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyVersion>2.15.3</AssemblyVersion> <AssemblyVersion>2.15.4</AssemblyVersion>
<FileVersion>2.15.3</FileVersion> <FileVersion>2.15.4</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<AvaloniaResource Include="Assets\**" /> <AvaloniaResource Include="Assets\**" />

View File

@ -4,8 +4,8 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyVersion>2.15.3</AssemblyVersion> <AssemblyVersion>2.15.4</AssemblyVersion>
<FileVersion>2.15.3</FileVersion> <FileVersion>2.15.4</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -42,8 +42,6 @@
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="..\..\..\..\..\Downloads\PatchClient.exe"> <EmbeddedResource Include="Resources\PatchClient.exe" />
<Link>Resources\PatchClient.exe</Link>
</EmbeddedResource>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -483,10 +483,10 @@ namespace PatcherUtils
if (sourceFile == null) if (sourceFile == null)
{ {
patchingTokenSource.Cancel();
errorsQueue.Enqueue(new PatchMessage( errorsQueue.Enqueue(new PatchMessage(
$"Failed to find matching source file for '{deltaFile.FullName}'", $"Failed to find matching source file for '{deltaFile.FullName}'",
PatcherExitCode.MissingFile)); PatcherExitCode.MissingFile));
patchingTokenSource.Cancel();
return; return;
} }
@ -495,8 +495,8 @@ namespace PatcherUtils
if (!result.Item1) if (!result.Item1)
{ {
patchingTokenSource.Cancel();
errorsQueue.Enqueue(new PatchMessage(result.Item2, PatcherExitCode.PatchFailed)); errorsQueue.Enqueue(new PatchMessage(result.Item2, PatcherExitCode.PatchFailed));
patchingTokenSource.Cancel();
return; return;
} }
@ -520,9 +520,9 @@ namespace PatcherUtils
} }
catch (Exception ex) catch (Exception ex)
{ {
patchingTokenSource.Cancel();
PatchLogger.LogException(ex); PatchLogger.LogException(ex);
errorsQueue.Enqueue(new PatchMessage(ex.Message, PatcherExitCode.PatchFailed)); errorsQueue.Enqueue(new PatchMessage(ex.Message, PatcherExitCode.PatchFailed));
patchingTokenSource.Cancel();
return; return;
} }
@ -545,9 +545,9 @@ namespace PatcherUtils
} }
catch (Exception ex) catch (Exception ex)
{ {
patchingTokenSource.Cancel();
PatchLogger.LogException(ex); PatchLogger.LogException(ex);
errorsQueue.Enqueue(new PatchMessage(ex.Message, PatcherExitCode.PatchFailed)); errorsQueue.Enqueue(new PatchMessage(ex.Message, PatcherExitCode.PatchFailed));
patchingTokenSource.Cancel();
return; return;
} }
@ -573,12 +573,23 @@ namespace PatcherUtils
if (errorsQueue.Count > 0) if (errorsQueue.Count > 0)
{ {
PatchLogger.LogError($"Error queue entry count: {errorsQueue.Count}"); PatchLogger.LogError($"Error queue entry count: {errorsQueue.Count}");
if (!errorsQueue.TryDequeue(out PatchMessage error)) PatchLogger.LogError("Dequeuing errors");
PatchMessage error = null;
for (int i = 0; i < errorsQueue.Count; i++)
{ {
return new PatchMessage("Errors occurred during patching, but we couldn't dequeue them :(\n\nThere may be more information in the log", PatcherExitCode.PatchFailed); if (!errorsQueue.TryDequeue(out error))
{
return new PatchMessage(
"Errors occurred during patching, but we couldn't dequeue them :(\n\nThere may be more information in the log",
PatcherExitCode.PatchFailed);
}
PatchLogger.LogError(error.Message);
} }
return error; return error ?? new PatchMessage("Something went wrong :(", PatcherExitCode.PatchFailed);
} }
PatchLogger.LogInfo("::: Patching Complete :::"); PatchLogger.LogInfo("::: Patching Complete :::");