add autoclose parameter to patch generator with exit codes

This commit is contained in:
IsWaffle 2022-05-16 17:33:37 -04:00
parent 37f3be1a7b
commit a7345f533c
5 changed files with 39 additions and 11 deletions

View File

@ -6,13 +6,15 @@
public string OutputFolderName { get; private set; } = ""; public string OutputFolderName { get; private set; } = "";
public string SourceFolderPath { get; private set; } = ""; public string SourceFolderPath { get; private set; } = "";
public string TargetFolderPath { get; private set; } = ""; public string TargetFolderPath { get; private set; } = "";
public bool AutoClose { get; private set; } = false;
public bool AutoZip { get; private set; } = true; public bool AutoZip { get; private set; } = true;
protected GenStartupArgs(string OutputFolderName, string SourceFolderPath, string TargetFolderPath, bool AutoZip) protected GenStartupArgs(string outputFolderName, string sourceFolderPath, string targetFolderPath, bool autoZip, bool autoClose)
{ {
this.OutputFolderName = OutputFolderName; OutputFolderName = outputFolderName;
this.SourceFolderPath = SourceFolderPath; SourceFolderPath = sourceFolderPath;
this.TargetFolderPath = TargetFolderPath; TargetFolderPath = targetFolderPath;
this.AutoZip = AutoZip; AutoZip = autoZip;
AutoClose = autoClose;
} }
public static GenStartupArgs Parse(string[] Args) public static GenStartupArgs Parse(string[] Args)
@ -23,6 +25,7 @@
string sourceFolderPath = ""; string sourceFolderPath = "";
string targetFolderPath = ""; string targetFolderPath = "";
bool autoZip = true; bool autoZip = true;
bool autoClose = false;
foreach (string arg in Args) foreach (string arg in Args)
{ {
@ -52,10 +55,15 @@
autoZip = bool.Parse(argSplit[1]); autoZip = bool.Parse(argSplit[1]);
break; break;
} }
case "AutoClose":
{
autoClose = bool.Parse(argSplit[1]);
break;
}
} }
} }
return new GenStartupArgs(outputFolderPath, sourceFolderPath, targetFolderPath, autoZip); return new GenStartupArgs(outputFolderPath, sourceFolderPath, targetFolderPath, autoZip, autoClose);
} }
} }
} }

View File

@ -62,5 +62,12 @@ namespace PatchGenerator.Models
get => _ReadyToRun; get => _ReadyToRun;
set => this.RaiseAndSetIfChanged(ref _ReadyToRun, value); set => this.RaiseAndSetIfChanged(ref _ReadyToRun, value);
} }
private bool _AutoClose = false;
public bool AutoClose
{
get => _AutoClose;
set => this.RaiseAndSetIfChanged(ref _AutoClose, value);
}
} }
} }

View File

@ -32,6 +32,7 @@ namespace PatchGenerator.ViewModels
genInfo.SourceFolderPath = genArgs.SourceFolderPath; genInfo.SourceFolderPath = genArgs.SourceFolderPath;
genInfo.PatchName = genArgs.OutputFolderName; genInfo.PatchName = genArgs.OutputFolderName;
genInfo.AutoZip = genArgs.AutoZip; genInfo.AutoZip = genArgs.AutoZip;
genInfo.AutoClose = genArgs.AutoClose;
Router.Navigate.Execute(new PatchGenerationViewModel(this, genInfo)); Router.Navigate.Execute(new PatchGenerationViewModel(this, genInfo));
return; return;

View File

@ -1,10 +1,12 @@
using Avalonia; using Avalonia;
using Avalonia.Media; using Avalonia.Media;
using Avalonia.Threading; using Avalonia.Threading;
using PatchClient.Models;
using PatcherUtils; using PatcherUtils;
using PatchGenerator.Helpers; using PatchGenerator.Helpers;
using PatchGenerator.Models; using PatchGenerator.Models;
using ReactiveUI; using ReactiveUI;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics; using System.Diagnostics;
@ -87,7 +89,12 @@ namespace PatchGenerator.ViewModels
patchGenStopwatch.Start(); patchGenStopwatch.Start();
patcher.GeneratePatches(); var message = patcher.GeneratePatches();
if(message.ExitCode != PatcherExitCode.Success && generationInfo.AutoClose)
{
Environment.Exit((int)message.ExitCode);
}
patchGenStopwatch.Stop(); patchGenStopwatch.Stop();
@ -119,6 +126,11 @@ namespace PatchGenerator.ViewModels
PatchItemCollection.Add(new PatchItem("Done")); PatchItemCollection.Add(new PatchItem("Done"));
} }
if (generationInfo.AutoClose)
{
Environment.Exit((int)PatcherExitCode.Success);
}
}); });
} }

View File

@ -168,7 +168,7 @@ namespace PatcherUtils
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
/// <remarks>Patches are created in the delta folder specified during contruction</remarks> /// <remarks>Patches are created in the delta folder specified during contruction</remarks>
public bool GeneratePatches() public PatchMessage GeneratePatches()
{ {
//get all directory information needed //get all directory information needed
DirectoryInfo sourceDir = new DirectoryInfo(SourceFolder); DirectoryInfo sourceDir = new DirectoryInfo(SourceFolder);
@ -179,7 +179,7 @@ namespace PatcherUtils
if (!sourceDir.Exists || !targetDir.Exists || !deltaDir.Exists) if (!sourceDir.Exists || !targetDir.Exists || !deltaDir.Exists)
{ {
//One of the directories doesn't exist //One of the directories doesn't exist
return false; return new PatchMessage("Could not find a directory", PatcherExitCode.MissingDir);
} }
LazyOperations.ExtractResourcesToTempDir(); LazyOperations.ExtractResourcesToTempDir();
@ -244,7 +244,7 @@ namespace PatcherUtils
//Any remaining source files do not exist in the target folder and can be removed. //Any remaining source files do not exist in the target folder and can be removed.
//reset progress info //reset progress info
if (SourceFiles.Count == 0) return true; if (SourceFiles.Count == 0) return new PatchMessage("Generation Done", PatcherExitCode.Success);
RaiseProgressChanged(0, SourceFiles.Count, "Processing .del files..."); RaiseProgressChanged(0, SourceFiles.Count, "Processing .del files...");
filesProcessed = 0; filesProcessed = 0;
@ -262,7 +262,7 @@ namespace PatcherUtils
RaiseProgressChanged(filesProcessed, fileCountTotal, $"{delFile.FullName.Replace(SourceFolder, "...")}.del", AdditionalInfo.ToArray()); RaiseProgressChanged(filesProcessed, fileCountTotal, $"{delFile.FullName.Replace(SourceFolder, "...")}.del", AdditionalInfo.ToArray());
} }
return true; return new PatchMessage("Generation Done", PatcherExitCode.Success);
} }
/// <summary> /// <summary>