diff --git a/Patcher/_port/Patcher/PatcherUtils/PatchHelper.cs b/Patcher/_port/Patcher/PatcherUtils/PatchHelper.cs index a72db81..ac36a71 100644 --- a/Patcher/_port/Patcher/PatcherUtils/PatchHelper.cs +++ b/Patcher/_port/Patcher/PatcherUtils/PatchHelper.cs @@ -22,6 +22,10 @@ namespace PatcherUtils private List AdditionalInfo = new List(); + /// + /// Reports patch creation or application progress + /// + /// Includes an array of with details for each type of patch public event ProgressChangedHandler ProgressChanged; protected virtual void RaiseProgressChanged(int progress, int total, string Message = "", params LineItem[] AdditionalLineItems) @@ -31,6 +35,13 @@ namespace PatcherUtils ProgressChanged?.Invoke(this, progress, total, percent, Message, AdditionalLineItems); } + /// + /// A helper class to create and apply patches to folders + /// + /// The directory that will have patches applied to it. + /// The directory to compare against during patch creation. + /// The directory where the patches are/will be located. + /// can be null if you only plan to apply patches. public PatchHelper(string SourceFolder, string TargetFolder, string DeltaFolder) { this.SourceFolder = SourceFolder; @@ -38,11 +49,24 @@ namespace PatcherUtils this.DeltaFolder = DeltaFolder; } + /// + /// Get the delta folder file path. + /// + /// + /// + /// The extension to append to the file + /// A file path inside the delta folder private string GetDeltaPath(string SourceFilePath, string SourceFolderPath, string FileExtension) { return Path.Join(DeltaFolder, $"{SourceFilePath.Replace(SourceFolderPath, "")}.{FileExtension}"); } + /// + /// Check if two files have the same MD5 hash + /// + /// + /// + /// True if the hashes match private bool CompareFileHashes(string SourceFilePath, string TargetFilePath) { using (MD5 md5Service = MD5.Create()) @@ -56,6 +80,11 @@ namespace PatcherUtils } } + /// + /// Apply a delta to a file using xdelta + /// + /// + /// private void ApplyDelta(string SourceFilePath, string DeltaFilePath) { string decodedPath = SourceFilePath + ".decoded"; @@ -75,6 +104,12 @@ namespace PatcherUtils } } + /// + /// Create a .delta file using xdelta + /// + /// + /// + /// Used to patch an existing file with xdelta private void CreateDelta(string SourceFilePath, string TargetFilePath) { FileInfo sourceFileInfo = new FileInfo(SourceFilePath); @@ -94,6 +129,11 @@ namespace PatcherUtils .WaitForExit(); } + /// + /// Create a .del file + /// + /// + /// Used to mark a file for deletion private void CreateDelFile(string SourceFile) { FileInfo sourceFileInfo = new FileInfo(SourceFile); @@ -105,6 +145,11 @@ namespace PatcherUtils File.Create(deltaPath); } + /// + /// Create a .new file + /// + /// + /// Used to mark a file that needs to be added private void CreateNewFile(string TargetFile) { FileInfo targetSourceInfo = new FileInfo(TargetFile); @@ -116,6 +161,11 @@ namespace PatcherUtils targetSourceInfo.CopyTo(deltaPath, true); } + /// + /// Generate a full set of patches using the source and target folders specified during contruction./> + /// + /// + /// Patches are created in the delta folder specified during contruction public bool GeneratePatches() { //get all directory information needed @@ -162,7 +212,7 @@ namespace PatcherUtils } //if a matching source file was found, check the file hashes and get the delta. - if(CompareFileHashes(sourceFile.FullName, targetFile.FullName)) + if(!CompareFileHashes(sourceFile.FullName, targetFile.FullName)) { CreateDelta(sourceFile.FullName, targetFile.FullName); deltaCount++; @@ -199,6 +249,10 @@ namespace PatcherUtils return true; } + /// + /// Apply a set of patches using the source and delta folders specified during construction. + /// + /// public string ApplyPatches() { //get needed directory information