added a debug parameter and a bunch of logging when it's used #13

Merged
waffle.lord merged 3 commits from debug-param into main 2023-11-15 14:34:39 -05:00
9 changed files with 125 additions and 12 deletions
Showing only changes of commit b5a8c8ba1c - Show all commits

13
Patcher/.idea/.idea.Patcher/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/.idea.Patcher.iml
/modules.xml
/projectSettingsUpdater.xml
/contentModel.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -6,6 +6,7 @@ using PatchClient.Views;
using ReactiveUI; using ReactiveUI;
using System.Reactive; using System.Reactive;
using System; using System;
using System.Linq;
using PatcherUtils.Model; using PatcherUtils.Model;
namespace PatchClient namespace PatchClient
@ -27,13 +28,27 @@ namespace PatchClient
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{ {
bool autoClose = false; bool autoClose = false;
bool debugOutput = false;
if(desktop.Args != null && desktop.Args.Length >= 1 && desktop.Args[0]?.ToLower() == "autoclose") if (desktop.Args != null && desktop.Args.Length >= 1)
autoClose = true; {
autoClose = desktop.Args.Any(x => x.ToLower() == "autoclose");
debugOutput = desktop.Args.Any(x => x.ToLower() == "debug");
}
if (debugOutput)
{
PatchLogger.LogInfo("Running in debug mode");
}
if (autoClose)
{
PatchLogger.LogInfo("Running with autoclose");
}
desktop.MainWindow = new MainWindow desktop.MainWindow = new MainWindow
{ {
DataContext = new MainWindowViewModel(autoClose), DataContext = new MainWindowViewModel(autoClose, debugOutput),
}; };
} }

View File

@ -18,11 +18,11 @@ namespace PatchClient.ViewModels
} }
}); });
public MainWindowViewModel(bool autoClose) public MainWindowViewModel(bool autoClose, bool debugOutput)
{ {
this.WhenActivated((CompositeDisposable disposable) => this.WhenActivated((CompositeDisposable disposable) =>
{ {
Router.Navigate.Execute(new PatcherViewModel(this, autoClose)); Router.Navigate.Execute(new PatcherViewModel(this, autoClose, debugOutput));
}); });
} }
} }

View File

@ -18,6 +18,7 @@ namespace PatchClient.ViewModels
{ {
private bool _initLineItemProgress = true; private bool _initLineItemProgress = true;
private bool _autoClose = false; private bool _autoClose = false;
private bool _debugOutput = false;
private Stopwatch _patchStopwatch; private Stopwatch _patchStopwatch;
private Timer _udpatePatchElapsedTimer = new Timer(1000); private Timer _udpatePatchElapsedTimer = new Timer(1000);
@ -52,9 +53,10 @@ namespace PatchClient.ViewModels
} }
public PatcherViewModel(IScreen Host, bool autoClose) : base(Host) public PatcherViewModel(IScreen Host, bool autoClose, bool debugOutput) : base(Host)
{ {
_autoClose = autoClose; _autoClose = autoClose;
_debugOutput = debugOutput;
ElapsedPatchTimeDetails = "Starting ..."; ElapsedPatchTimeDetails = "Starting ...";
_udpatePatchElapsedTimer.Elapsed += _udpatePatchElapsedTimer_Elapsed; _udpatePatchElapsedTimer.Elapsed += _udpatePatchElapsedTimer_Elapsed;
@ -104,7 +106,7 @@ namespace PatchClient.ViewModels
{ {
LazyOperations.ExtractResourcesToTempDir(Assembly.GetExecutingAssembly()); LazyOperations.ExtractResourcesToTempDir(Assembly.GetExecutingAssembly());
PatchHelper patcher = new PatchHelper(Environment.CurrentDirectory, null, LazyOperations.PatchFolder); PatchHelper patcher = new PatchHelper(Environment.CurrentDirectory, null, LazyOperations.PatchFolder, _debugOutput);
patcher.ProgressChanged += patcher_ProgressChanged; patcher.ProgressChanged += patcher_ProgressChanged;

View File

@ -42,6 +42,7 @@ namespace PatcherUtils.Model
LogToFile($"{GetTimestamp()}[OS]: {RuntimeInformation.OSDescription}"); LogToFile($"{GetTimestamp()}[OS]: {RuntimeInformation.OSDescription}");
} }
public static void LogDebug(string message) => LogToFile($"{GetTimestamp()}[DEBUG]: {message}");
public static void LogInfo(string message) => LogToFile($"{GetTimestamp()}[INFO]: {message}"); public static void LogInfo(string message) => LogToFile($"{GetTimestamp()}[INFO]: {message}");
public static void LogError(string message) => LogToFile($"{GetTimestamp()}[ERROR]: {message}"); public static void LogError(string message) => LogToFile($"{GetTimestamp()}[ERROR]: {message}");
public static void LogException(Exception ex) => LogToFile($"{GetTimestamp()}[EXCEPTION]: {ex.Message}\n\nStackTrace:\n{ex.StackTrace}"); public static void LogException(Exception ex) => LogToFile($"{GetTimestamp()}[EXCEPTION]: {ex.Message}\n\nStackTrace:\n{ex.StackTrace}");

View File

@ -23,6 +23,8 @@ namespace PatcherUtils
private int delCount; private int delCount;
private int existCount; private int existCount;
private bool debugOutput;
private List<LineItem> AdditionalInfo = new List<LineItem>(); private List<LineItem> AdditionalInfo = new List<LineItem>();
/// <summary> /// <summary>
@ -45,11 +47,12 @@ namespace PatcherUtils
/// <param name="TargetFolder">The directory to compare against during patch creation.</param> /// <param name="TargetFolder">The directory to compare against during patch creation.</param>
/// <param name="DeltaFolder">The directory where the patches are/will be located.</param> /// <param name="DeltaFolder">The directory where the patches are/will be located.</param>
/// <remarks><paramref name="TargetFolder"/> can be null if you only plan to apply patches.</remarks> /// <remarks><paramref name="TargetFolder"/> can be null if you only plan to apply patches.</remarks>
public PatchHelper(string SourceFolder, string TargetFolder, string DeltaFolder) public PatchHelper(string SourceFolder, string TargetFolder, string DeltaFolder, bool debugOutput = false)
{ {
this.SourceFolder = SourceFolder; this.SourceFolder = SourceFolder;
this.TargetFolder = TargetFolder; this.TargetFolder = TargetFolder;
this.DeltaFolder = DeltaFolder; this.DeltaFolder = DeltaFolder;
this.debugOutput = debugOutput;
} }
/// <summary> /// <summary>
@ -99,13 +102,74 @@ namespace PatcherUtils
{ {
string decodedPath = SourceFilePath + ".decoded"; string decodedPath = SourceFilePath + ".decoded";
Process.Start(new ProcessStartInfo var xdeltaArgs = $"-d {(debugOutput ? "-v -v" : "")} -f -s";
if (debugOutput)
{
try
{
var stream = File.Open(SourceFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
stream.Close();
stream.Dispose();
PatchLogger.LogDebug($"File is openable: {SourceFilePath}");
}
catch (Exception ex)
{
PatchLogger.LogException(ex);
}
try
{
var stream = File.Open(SourceFilePath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
stream.Close();
stream.Dispose();
PatchLogger.LogDebug($"File is openable: {DeltaFilePath}");
}
catch (Exception ex)
{
PatchLogger.LogException(ex);
}
}
var proc = Process.Start(new ProcessStartInfo
{ {
FileName = LazyOperations.XDelta3Path, FileName = LazyOperations.XDelta3Path,
Arguments = $"-d -f -s \"{SourceFilePath}\" \"{DeltaFilePath}\" \"{decodedPath}\"", Arguments = $"{xdeltaArgs} \"{SourceFilePath}\" \"{DeltaFilePath}\" \"{decodedPath}\"",
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true CreateNoWindow = true
}) });
.WaitForExit();
if (proc == null)
{
PatchLogger.LogError($"xdelta3 process failed to start: {nameof(proc)} is null");
return (false, "xdelta3 process failed to start");
}
proc.WaitForExit();
if (debugOutput)
{
try
{
PatchLogger.LogDebug($"xdelta exit code :: {proc.ExitCode}");
PatchLogger.LogDebug("___Dumping xdelta stdout___");
while (!proc.StandardOutput.EndOfStream)
{
PatchLogger.LogDebug(proc.StandardOutput.ReadLine());
}
PatchLogger.LogDebug("___Dumping xdelta stderr___");
while (!proc.StandardError.EndOfStream)
{
PatchLogger.LogDebug(proc.StandardError.ReadLine());
}
}
catch (Exception ex)
{
PatchLogger.LogException(ex);
}
}
if (File.Exists(decodedPath)) if (File.Exists(decodedPath))
{ {