impr/parallel-patching #17

Merged
waffle.lord merged 2 commits from impr/parallel-patching into main 2024-05-04 10:57:31 -04:00
6 changed files with 48 additions and 48 deletions
Showing only changes of commit 24fe16177a - Show all commits

View File

@ -23,7 +23,6 @@ namespace PatchGenerator.ViewModels
{ {
this.WhenActivated((CompositeDisposable disposables) => this.WhenActivated((CompositeDisposable disposables) =>
{ {
if (genArgs != null && genArgs.ReadyToRun) if (genArgs != null && genArgs.ReadyToRun)
{ {
PatchGenInfo genInfo = new PatchGenInfo(); PatchGenInfo genInfo = new PatchGenInfo();
@ -31,7 +30,8 @@ namespace PatchGenerator.ViewModels
genInfo.TargetFolderPath = genArgs.TargetFolderPath; genInfo.TargetFolderPath = genArgs.TargetFolderPath;
genInfo.SourceFolderPath = genArgs.SourceFolderPath; genInfo.SourceFolderPath = genArgs.SourceFolderPath;
genInfo.PatchName = genArgs.OutputFolderName; genInfo.PatchName = genArgs.OutputFolderName;
genInfo.AutoZip = genArgs.AutoZip; // issues with auto zip, but it's not really used anymore so just disabling for now
genInfo.AutoZip = false;
genInfo.AutoClose = genArgs.AutoClose; genInfo.AutoClose = genArgs.AutoClose;
Router.Navigate.Execute(new PatchGenerationViewModel(this, genInfo)); Router.Navigate.Execute(new PatchGenerationViewModel(this, genInfo));

View File

@ -14,9 +14,11 @@ using System.IO;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers; using System.Timers;
using PatcherUtils.Model; using PatcherUtils.Model;
using Timer = System.Timers.Timer;
namespace PatchGenerator.ViewModels namespace PatchGenerator.ViewModels
{ {
@ -137,31 +139,30 @@ namespace PatchGenerator.ViewModels
PatchLogger.LogInfo("Copied patcher.exe to output folder"); PatchLogger.LogInfo("Copied patcher.exe to output folder");
if (generationInfo.AutoZip) // if (generationInfo.AutoZip)
{ // {
PatchLogger.LogInfo("AutoZipping"); // PatchLogger.LogInfo("AutoZipping");
IndeterminateProgress = true; // IndeterminateProgress = true;
//
PatchItemCollection.Add(new PatchItem("Allowing Time for files to unlock ...")); // PatchItemCollection.Add(new PatchItem("Allowing Time for files to unlock ..."));
//
System.Threading.Thread.Sleep(2000); // Thread.Sleep(2000);
//
PatchItemCollection.Add(new PatchItem("Zipping patcher ...")); // PatchItemCollection.Add(new PatchItem("Zipping patcher ..."));
//
ProgressMessage = "Zipping patcher"; // ProgressMessage = "Zipping patcher";
//
IndeterminateProgress = false; // IndeterminateProgress = false;
//
var progress = new Progress<int>(p => // var progress = new Progress<int>(p =>
{ // {
PatchLogger.LogInfo($"compressing directory @ {p}%"); // PatchPercent = p;
PatchPercent = p; // });
}); //
// LazyOperations.CompressDirectory(generationInfo.PatchName.FromCwd(), $"{generationInfo.PatchName}.7z".FromCwd(), progress);
LazyOperations.CompressDirectory(generationInfo.PatchName.FromCwd(), $"{generationInfo.PatchName}.7z".FromCwd(), progress); //
// PatchItemCollection.Add(new PatchItem("Done"));
PatchItemCollection.Add(new PatchItem("Done")); // }
}
if (generationInfo.AutoClose) if (generationInfo.AutoClose)
{ {

View File

@ -16,8 +16,9 @@
Watermark="Output Folder Name" Watermark="Output Folder Name"
/> />
<CheckBox Content="Zip Generated Files" Grid.Row="4" <!-- UNRESOLVED ISSUES: disabling for now -->
IsChecked="{Binding GenerationInfo.AutoZip}"/> <!-- <CheckBox Content="Zip Generated Files" Grid.Row="4" -->
<!-- IsChecked="{Binding GenerationInfo.AutoZip}"/> -->
<Button Content="Generate Patches" Grid.ColumnSpan="3" Grid.Row="4" <Button Content="Generate Patches" Grid.ColumnSpan="3" Grid.Row="4"
HorizontalAlignment="Right" HorizontalAlignment="Right"

View File

@ -2,7 +2,6 @@
using PatcherUtils.Model; using PatcherUtils.Model;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using Aki.Common.Utils;
using SevenZip; using SevenZip;
namespace PatcherUtils namespace PatcherUtils
@ -115,7 +114,8 @@ namespace PatcherUtils
{ {
ArchiveFormat = OutArchiveFormat.SevenZip, ArchiveFormat = OutArchiveFormat.SevenZip,
CompressionMethod = CompressionMethod.Lzma2, CompressionMethod = CompressionMethod.Lzma2,
CompressionLevel = CompressionLevel.Normal CompressionLevel = CompressionLevel.Normal,
PreserveDirectoryRoot = true
}; };
compressor.Compressing += (_, args) => { progress.Report(args.PercentDone); }; compressor.Compressing += (_, args) => { progress.Report(args.PercentDone); };

View File

@ -280,10 +280,11 @@ namespace PatcherUtils
LazyOperations.ExtractResourcesToTempDir(); LazyOperations.ExtractResourcesToTempDir();
List<FileInfo> SourceFiles = sourceDir.GetFiles("*", SearchOption.AllDirectories).ToList(); List<FileInfo> sourceFiles = sourceDir.GetFiles("*", SearchOption.AllDirectories).ToList();
var targetFiles = targetDir.GetFiles("*", SearchOption.AllDirectories).ToList();
ConcurrentQueue<FileInfo> foundFilesQueue = new ConcurrentQueue<FileInfo>(); ConcurrentQueue<FileInfo> foundFilesQueue = new ConcurrentQueue<FileInfo>();
fileCountTotal = SourceFiles.Count; fileCountTotal = targetFiles.Count;
PatchLogger.LogInfo($"Total source files: {fileCountTotal}"); PatchLogger.LogInfo($"Total source files: {fileCountTotal}");
@ -297,14 +298,11 @@ namespace PatcherUtils
RaiseProgressChanged(0, fileCountTotal, "Generating deltas..."); RaiseProgressChanged(0, fileCountTotal, "Generating deltas...");
// use 5 threads to process source files / create deltas Parallel.ForEach(targetFiles,
Parallel.ForEach(targetDir.GetFiles("*", SearchOption.AllDirectories), new ParallelOptions() { MaxDegreeOfParallelism = 5 }, targetFile =>
new ParallelOptions() { MaxDegreeOfParallelism = 5 },
targetFile =>
{ {
//find a matching source file based on the relative path of the file //find a matching source file based on the relative path of the file
FileInfo sourceFile = sourceFiles.Find(f =>
FileInfo sourceFile = SourceFiles.Find(f =>
f.FullName.Replace(sourceDir.FullName, "") == f.FullName.Replace(sourceDir.FullName, "") ==
targetFile.FullName.Replace(targetDir.FullName, "")); targetFile.FullName.Replace(targetDir.FullName, ""));
@ -363,7 +361,7 @@ namespace PatcherUtils
{ {
RaiseProgressChanged(processedQueueCount, queueTotal, $"Queued file removed: {queuedFile.Name}", RaiseProgressChanged(processedQueueCount, queueTotal, $"Queued file removed: {queuedFile.Name}",
AdditionalInfo.ToArray()); AdditionalInfo.ToArray());
SourceFiles.Remove(queuedFile); sourceFiles.Remove(queuedFile);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -374,18 +372,18 @@ 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) if (sourceFiles.Count == 0)
{ {
PatchLogger.LogInfo("::: Patch Generation Complete :::"); PatchLogger.LogInfo("::: Patch Generation Complete :::");
return new PatchMessage("Generation Done", PatcherExitCode.Success); 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;
fileCountTotal = SourceFiles.Count; fileCountTotal = sourceFiles.Count;
foreach (FileInfo delFile in SourceFiles) foreach (FileInfo delFile in sourceFiles)
{ {
PatchLogger.LogInfo("::: Creating .del file :::"); PatchLogger.LogInfo("::: Creating .del file :::");
CreateDelFile(delFile.FullName); CreateDelFile(delFile.FullName);

View File

@ -22,7 +22,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.1.23" /> <PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.2.24" />
</ItemGroup> </ItemGroup>
</Project> </Project>