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 SourceFolderPath { get; private set; } = "";
public string TargetFolderPath { get; private set; } = "";
public bool AutoClose { get; private set; } = false;
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;
this.SourceFolderPath = SourceFolderPath;
this.TargetFolderPath = TargetFolderPath;
this.AutoZip = AutoZip;
OutputFolderName = outputFolderName;
SourceFolderPath = sourceFolderPath;
TargetFolderPath = targetFolderPath;
AutoZip = autoZip;
AutoClose = autoClose;
}
public static GenStartupArgs Parse(string[] Args)
@ -23,6 +25,7 @@
string sourceFolderPath = "";
string targetFolderPath = "";
bool autoZip = true;
bool autoClose = false;
foreach (string arg in Args)
{
@ -52,10 +55,15 @@
autoZip = bool.Parse(argSplit[1]);
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;
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.PatchName = genArgs.OutputFolderName;
genInfo.AutoZip = genArgs.AutoZip;
genInfo.AutoClose = genArgs.AutoClose;
Router.Navigate.Execute(new PatchGenerationViewModel(this, genInfo));
return;

View File

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

View File

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