diff --git a/Patcher/PatchClient/PatchClient.csproj b/Patcher/PatchClient/PatchClient.csproj index 8f005df..ed2bdbf 100644 --- a/Patcher/PatchClient/PatchClient.csproj +++ b/Patcher/PatchClient/PatchClient.csproj @@ -4,8 +4,8 @@ net8.0 true enable - 2.11.0 - 2.11.0 + 2.12.0 + 2.12.0 diff --git a/Patcher/PatchGenerator/PatchGenerator.csproj b/Patcher/PatchGenerator/PatchGenerator.csproj index 1349aa8..f70c910 100644 --- a/Patcher/PatchGenerator/PatchGenerator.csproj +++ b/Patcher/PatchGenerator/PatchGenerator.csproj @@ -4,8 +4,8 @@ net8.0 true enable - 2.11.0 - 2.11.0 + 2.12.0 + 2.12.0 @@ -27,7 +27,7 @@ - + diff --git a/Patcher/PatchGenerator/Resources/7za.exe b/Patcher/PatchGenerator/Resources/7za.exe deleted file mode 100644 index 2bdd57d..0000000 Binary files a/Patcher/PatchGenerator/Resources/7za.exe and /dev/null differ diff --git a/Patcher/PatchGenerator/Resources/PatchClient.exe b/Patcher/PatchGenerator/Resources/PatchClient.exe index 33ecaa5..1cb26eb 100644 Binary files a/Patcher/PatchGenerator/Resources/PatchClient.exe and b/Patcher/PatchGenerator/Resources/PatchClient.exe differ diff --git a/Patcher/PatchGenerator/ViewModels/PatchGenerationViewModel.cs b/Patcher/PatchGenerator/ViewModels/PatchGenerationViewModel.cs index be5ce67..1d83b55 100644 --- a/Patcher/PatchGenerator/ViewModels/PatchGenerationViewModel.cs +++ b/Patcher/PatchGenerator/ViewModels/PatchGenerationViewModel.cs @@ -16,6 +16,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Timers; +using PatcherUtils.Model; namespace PatchGenerator.ViewModels { @@ -140,12 +141,19 @@ namespace PatchGenerator.ViewModels System.Threading.Thread.Sleep(2000); - PatchItemCollection.Add(new PatchItem("Kicking off 7zip ...")); - - LazyOperations.StartZipProcess(generationInfo.PatchName.FromCwd(), $"{generationInfo.PatchName}.zip".FromCwd()); + PatchItemCollection.Add(new PatchItem("Zipping patcher ...")); + ProgressMessage = "Zipping patcher"; + IndeterminateProgress = false; + var progress = new Progress(p => + { + PatchPercent = p; + }); + + LazyOperations.CompressDirectory(generationInfo.PatchName.FromCwd(), $"{generationInfo.PatchName}.7z".FromCwd(), progress); + PatchItemCollection.Add(new PatchItem("Done")); } diff --git a/Patcher/PatcherUtils/LazyOperations.cs b/Patcher/PatcherUtils/LazyOperations.cs index 1ff02d6..8c059bf 100644 --- a/Patcher/PatcherUtils/LazyOperations.cs +++ b/Patcher/PatcherUtils/LazyOperations.cs @@ -1,7 +1,9 @@ -using PatcherUtils.Model; -using System.Diagnostics; +using System; +using PatcherUtils.Model; using System.IO; using System.Reflection; +using Aki.Common.Utils; +using SevenZip; namespace PatcherUtils { @@ -18,12 +20,12 @@ namespace PatcherUtils /// public static string PatchFolder = "Aki_Patches"; - private static string SevenZExe = "7za.exe"; + private static string SevenZDll = "7z.dll"; /// /// The path to the 7za.exe file in the /// - public static string SevenZExePath = $"{TempDir}\\{SevenZExe}"; + public static string SevenZDllPath = $"{TempDir}\\{SevenZDll}"; private static string PatcherClient = "PatchClient.exe"; /// @@ -79,9 +81,9 @@ namespace PatcherUtils { switch (resource) { - case string a when a.EndsWith(SevenZExe): + case string a when a.EndsWith(SevenZDll): { - StreamResourceOut(assembly, resource, SevenZExePath); + StreamResourceOut(assembly, resource, SevenZDllPath); break; } case string a when a.EndsWith(PatcherClient): @@ -98,17 +100,34 @@ namespace PatcherUtils } } - public static void StartZipProcess(string SourcePath, string DestinationPath) + public static void CompressDirectory(string SourceDirectoryPath, string DestinationFilePath, IProgress progress) { - ProcessStartInfo procInfo = new ProcessStartInfo() + var outputFile = new FileInfo(DestinationFilePath); + + SevenZipBase.SetLibraryPath(SevenZDllPath); + var compressor = new SevenZipCompressor() { - FileName = SevenZExePath, - Arguments = $"a -mm=LZMA {DestinationPath} {SourcePath}" + ArchiveFormat = OutArchiveFormat.SevenZip, + CompressionMethod = CompressionMethod.Lzma2, + CompressionLevel = CompressionLevel.Normal }; - Process.Start(procInfo); + compressor.Compressing += (_, args) => + { + progress.Report(args.PercentDone); + }; - PatchLogger.LogInfo($"Zip process started"); + using var outputStream = outputFile.OpenWrite(); + + compressor.CompressDirectory(SourceDirectoryPath, outputStream); + + outputFile.Refresh(); + + // failed to compress data + if (!outputFile.Exists || outputFile.Length == 0) + { + Logger.LogError("Failed to compress patcher"); + } } /// diff --git a/Patcher/PatcherUtils/PatcherUtils.csproj b/Patcher/PatcherUtils/PatcherUtils.csproj index 57898b3..55ccfb0 100644 --- a/Patcher/PatcherUtils/PatcherUtils.csproj +++ b/Patcher/PatcherUtils/PatcherUtils.csproj @@ -11,6 +11,7 @@ + @@ -20,4 +21,8 @@ + + + + diff --git a/Patcher/PatcherUtils/Resources/7z.dll b/Patcher/PatcherUtils/Resources/7z.dll new file mode 100644 index 0000000..2ba9f27 Binary files /dev/null and b/Patcher/PatcherUtils/Resources/7z.dll differ