finish adding parallel processing
This commit is contained in:
parent
5e8293fcbc
commit
24fe16177a
@ -23,7 +23,6 @@ namespace PatchGenerator.ViewModels
|
||||
{
|
||||
this.WhenActivated((CompositeDisposable disposables) =>
|
||||
{
|
||||
|
||||
if (genArgs != null && genArgs.ReadyToRun)
|
||||
{
|
||||
PatchGenInfo genInfo = new PatchGenInfo();
|
||||
@ -31,7 +30,8 @@ namespace PatchGenerator.ViewModels
|
||||
genInfo.TargetFolderPath = genArgs.TargetFolderPath;
|
||||
genInfo.SourceFolderPath = genArgs.SourceFolderPath;
|
||||
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;
|
||||
|
||||
Router.Navigate.Execute(new PatchGenerationViewModel(this, genInfo));
|
||||
|
@ -14,9 +14,11 @@ using System.IO;
|
||||
using System.Reactive.Disposables;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using PatcherUtils.Model;
|
||||
using Timer = System.Timers.Timer;
|
||||
|
||||
namespace PatchGenerator.ViewModels
|
||||
{
|
||||
@ -137,31 +139,30 @@ namespace PatchGenerator.ViewModels
|
||||
|
||||
PatchLogger.LogInfo("Copied patcher.exe to output folder");
|
||||
|
||||
if (generationInfo.AutoZip)
|
||||
{
|
||||
PatchLogger.LogInfo("AutoZipping");
|
||||
IndeterminateProgress = true;
|
||||
|
||||
PatchItemCollection.Add(new PatchItem("Allowing Time for files to unlock ..."));
|
||||
|
||||
System.Threading.Thread.Sleep(2000);
|
||||
|
||||
PatchItemCollection.Add(new PatchItem("Zipping patcher ..."));
|
||||
|
||||
ProgressMessage = "Zipping patcher";
|
||||
|
||||
IndeterminateProgress = false;
|
||||
|
||||
var progress = new Progress<int>(p =>
|
||||
{
|
||||
PatchLogger.LogInfo($"compressing directory @ {p}%");
|
||||
PatchPercent = p;
|
||||
});
|
||||
|
||||
LazyOperations.CompressDirectory(generationInfo.PatchName.FromCwd(), $"{generationInfo.PatchName}.7z".FromCwd(), progress);
|
||||
|
||||
PatchItemCollection.Add(new PatchItem("Done"));
|
||||
}
|
||||
// if (generationInfo.AutoZip)
|
||||
// {
|
||||
// PatchLogger.LogInfo("AutoZipping");
|
||||
// IndeterminateProgress = true;
|
||||
//
|
||||
// PatchItemCollection.Add(new PatchItem("Allowing Time for files to unlock ..."));
|
||||
//
|
||||
// Thread.Sleep(2000);
|
||||
//
|
||||
// PatchItemCollection.Add(new PatchItem("Zipping patcher ..."));
|
||||
//
|
||||
// ProgressMessage = "Zipping patcher";
|
||||
//
|
||||
// IndeterminateProgress = false;
|
||||
//
|
||||
// var progress = new Progress<int>(p =>
|
||||
// {
|
||||
// PatchPercent = p;
|
||||
// });
|
||||
//
|
||||
// LazyOperations.CompressDirectory(generationInfo.PatchName.FromCwd(), $"{generationInfo.PatchName}.7z".FromCwd(), progress);
|
||||
//
|
||||
// PatchItemCollection.Add(new PatchItem("Done"));
|
||||
// }
|
||||
|
||||
if (generationInfo.AutoClose)
|
||||
{
|
||||
|
@ -15,9 +15,10 @@
|
||||
Grid.Row="2" Grid.ColumnSpan="3"
|
||||
Watermark="Output Folder Name"
|
||||
/>
|
||||
|
||||
<CheckBox Content="Zip Generated Files" Grid.Row="4"
|
||||
IsChecked="{Binding GenerationInfo.AutoZip}"/>
|
||||
|
||||
<!-- UNRESOLVED ISSUES: disabling for now -->
|
||||
<!-- <CheckBox Content="Zip Generated Files" Grid.Row="4" -->
|
||||
<!-- IsChecked="{Binding GenerationInfo.AutoZip}"/> -->
|
||||
|
||||
<Button Content="Generate Patches" Grid.ColumnSpan="3" Grid.Row="4"
|
||||
HorizontalAlignment="Right"
|
||||
|
@ -2,7 +2,6 @@
|
||||
using PatcherUtils.Model;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Aki.Common.Utils;
|
||||
using SevenZip;
|
||||
|
||||
namespace PatcherUtils
|
||||
@ -115,7 +114,8 @@ namespace PatcherUtils
|
||||
{
|
||||
ArchiveFormat = OutArchiveFormat.SevenZip,
|
||||
CompressionMethod = CompressionMethod.Lzma2,
|
||||
CompressionLevel = CompressionLevel.Normal
|
||||
CompressionLevel = CompressionLevel.Normal,
|
||||
PreserveDirectoryRoot = true
|
||||
};
|
||||
|
||||
compressor.Compressing += (_, args) => { progress.Report(args.PercentDone); };
|
||||
|
@ -280,10 +280,11 @@ namespace PatcherUtils
|
||||
|
||||
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>();
|
||||
|
||||
fileCountTotal = SourceFiles.Count;
|
||||
fileCountTotal = targetFiles.Count;
|
||||
|
||||
PatchLogger.LogInfo($"Total source files: {fileCountTotal}");
|
||||
|
||||
@ -296,15 +297,12 @@ namespace PatcherUtils
|
||||
filesProcessed = 0;
|
||||
|
||||
RaiseProgressChanged(0, fileCountTotal, "Generating deltas...");
|
||||
|
||||
// use 5 threads to process source files / create deltas
|
||||
Parallel.ForEach(targetDir.GetFiles("*", SearchOption.AllDirectories),
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = 5 },
|
||||
targetFile =>
|
||||
|
||||
Parallel.ForEach(targetFiles,
|
||||
new ParallelOptions() { MaxDegreeOfParallelism = 5 }, targetFile =>
|
||||
{
|
||||
//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, "") ==
|
||||
targetFile.FullName.Replace(targetDir.FullName, ""));
|
||||
|
||||
@ -349,7 +347,7 @@ namespace PatcherUtils
|
||||
AdditionalInfo[3].ItemValue = existCount;
|
||||
|
||||
RaiseProgressChanged(filesProcessed, fileCountTotal,
|
||||
$"{targetFile.FullName.Replace(TargetFolder, "...")}{extension}", AdditionalInfo.ToArray());
|
||||
$"{targetFile.FullName.Replace(TargetFolder, "...")}{extension}", AdditionalInfo.ToArray());
|
||||
});
|
||||
|
||||
// remove all queued files that were found in the source files list
|
||||
@ -363,7 +361,7 @@ namespace PatcherUtils
|
||||
{
|
||||
RaiseProgressChanged(processedQueueCount, queueTotal, $"Queued file removed: {queuedFile.Name}",
|
||||
AdditionalInfo.ToArray());
|
||||
SourceFiles.Remove(queuedFile);
|
||||
sourceFiles.Remove(queuedFile);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -374,18 +372,18 @@ namespace PatcherUtils
|
||||
//Any remaining source files do not exist in the target folder and can be removed.
|
||||
//reset progress info
|
||||
|
||||
if (SourceFiles.Count == 0)
|
||||
if (sourceFiles.Count == 0)
|
||||
{
|
||||
PatchLogger.LogInfo("::: Patch Generation Complete :::");
|
||||
|
||||
return new PatchMessage("Generation Done", PatcherExitCode.Success);
|
||||
}
|
||||
|
||||
RaiseProgressChanged(0, SourceFiles.Count, "Processing .del files...");
|
||||
RaiseProgressChanged(0, sourceFiles.Count, "Processing .del files...");
|
||||
filesProcessed = 0;
|
||||
fileCountTotal = SourceFiles.Count;
|
||||
fileCountTotal = sourceFiles.Count;
|
||||
|
||||
foreach (FileInfo delFile in SourceFiles)
|
||||
foreach (FileInfo delFile in sourceFiles)
|
||||
{
|
||||
PatchLogger.LogInfo("::: Creating .del file :::");
|
||||
CreateDelFile(delFile.FullName);
|
||||
|
@ -22,7 +22,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.1.23" />
|
||||
<PackageReference Include="Squid-Box.SevenZipSharp" Version="1.6.2.24" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user