diff --git a/RevokeMsgPatcher/FormMain.Designer.cs b/RevokeMsgPatcher/FormMain.Designer.cs index b638844..66d009e 100644 --- a/RevokeMsgPatcher/FormMain.Designer.cs +++ b/RevokeMsgPatcher/FormMain.Designer.cs @@ -78,7 +78,7 @@ this.btnPatch.Name = "btnPatch"; this.btnPatch.Size = new System.Drawing.Size(98, 23); this.btnPatch.TabIndex = 3; - this.btnPatch.Text = "安装补丁"; + this.btnPatch.Text = "安装补丁!"; this.btnPatch.UseVisualStyleBackColor = true; this.btnPatch.Click += new System.EventHandler(this.btnPatch_Click); // diff --git a/RevokeMsgPatcher/Matcher/ModifyFinder.cs b/RevokeMsgPatcher/Matcher/ModifyFinder.cs index dc4d8fc..4bb75cd 100644 --- a/RevokeMsgPatcher/Matcher/ModifyFinder.cs +++ b/RevokeMsgPatcher/Matcher/ModifyFinder.cs @@ -1,4 +1,5 @@ using RevokeMsgPatcher.Model; +using System; using System.Collections.Generic; using System.IO; @@ -6,15 +7,16 @@ namespace RevokeMsgPatcher.Matcher { public class ModifyFinder { + // TODO 该逻辑需要优化! public static List FindChanges(string path, List replacePatterns) { // 读取整个文件(dll) byte[] fileByteArray = File.ReadAllBytes(path); - List changes = new List(); + List changes = new List(); // 匹配且需要替换的地方 // 查找所有替换点 - int matchNum = 0; + int matchNum = 0; // 匹配数量 foreach (ReplacePattern pattern in replacePatterns) { // 所有的匹配点位 @@ -33,13 +35,24 @@ namespace RevokeMsgPatcher.Matcher // 匹配数和期望的匹配数不一致时报错(当前一个特征只会出现一次) if (matchNum != replacePatterns.Count) { - if (IsAllReplaced(fileByteArray, replacePatterns)) + Tuple> res = IsAllReplaced(fileByteArray, replacePatterns); + if (res.Item1) { throw new BusinessException("match_already_replace", "特征比对:当前应用已经安装了对应功能的补丁!"); } else { - throw new BusinessException("match_inconformity", $"特征比对:当前特征码匹配数[{matchNum}]和期望的匹配数[{replacePatterns.Count}]不一致,如果当前版本为新版本,特征码可能出现变化,请联系作者处理!"); + if (res.Item2.Count > 0) + { + throw new BusinessException("match_inconformity", $"特征比对:以下功能补丁已经安装,请取消勾选!\n已安装功能:【{string.Join("、", res.Item2)}】"); + } + else + { + throw new BusinessException("match_inconformity", $"特征比对:当前特征码匹配数[{matchNum}]和期望的匹配数[{replacePatterns.Count}]不一致。\n" + + $"出现此种情况的一般有如下可能:\n" + + $"1. 你可能已经安装了某个功能的补丁,请选择未安装功能进行安装。\n" + + $"2. 如果当前版本为最新版本,特征码可能出现变化(可能性比较低),请联系作者处理。"); + } } } else @@ -50,11 +63,11 @@ namespace RevokeMsgPatcher.Matcher // 此逻辑在当前特征配置下不会进入,因为查找串和替换串当前全部都是不相同的 if (changes.Count == 0) { - throw new BusinessException("match_already_replace", "特征比对:当前应用已经安装了防撤回补丁!"); + throw new BusinessException("match_already_replace", "特征比对:当前应用已经安装了所选功能补丁!"); } else { - throw new BusinessException("match_part_replace", "特征比对:部分特征已经被替换,请确认是否有使用过其他防撤回补丁!"); + throw new BusinessException("match_part_replace", "特征比对:部分特征已经被替换,请确认是否有使用过其他防撤回/多开补丁!"); } } @@ -66,9 +79,10 @@ namespace RevokeMsgPatcher.Matcher } } - private static bool IsAllReplaced(byte[] fileByteArray, List replacePatterns) + private static Tuple> IsAllReplaced(byte[] fileByteArray, List replacePatterns) { int matchNum = 0; + SortedSet alreadyReplaced = new SortedSet(); // 已经被替换特征的功能 foreach (ReplacePattern pattern in replacePatterns) { // 所有的匹配点位 @@ -76,16 +90,10 @@ namespace RevokeMsgPatcher.Matcher if (matchIndexs.Length == 1) { matchNum++; + alreadyReplaced.Add(pattern.Category); } } - if (matchNum == replacePatterns.Count) - { - return true; - } - else - { - return false; - } + return new Tuple>(matchNum == replacePatterns.Count, alreadyReplaced); } } } diff --git a/RevokeMsgPatcher/Modifier/AppModifier.cs b/RevokeMsgPatcher/Modifier/AppModifier.cs index 1b6c06f..699bf0f 100644 --- a/RevokeMsgPatcher/Modifier/AppModifier.cs +++ b/RevokeMsgPatcher/Modifier/AppModifier.cs @@ -345,6 +345,7 @@ namespace RevokeMsgPatcher.Modifier bool success = editor.Patch(); if (!success) { + // 此处还原逻辑不可能进入 editor.Restore(); } else @@ -369,7 +370,7 @@ namespace RevokeMsgPatcher.Modifier { foreach (FileHexEditor editor in editors) { - if (!File.Exists(editor.FileBakPath)) + if (!File.Exists(editor.FileBakPath) || editor.FileVersion != editor.BackupFileVersion) { return false; } diff --git a/RevokeMsgPatcher/Modifier/FileHexEditor.cs b/RevokeMsgPatcher/Modifier/FileHexEditor.cs index 40be54c..6dbea11 100644 --- a/RevokeMsgPatcher/Modifier/FileHexEditor.cs +++ b/RevokeMsgPatcher/Modifier/FileHexEditor.cs @@ -80,7 +80,19 @@ namespace RevokeMsgPatcher.Modifier /// public void Backup() { - File.Copy(FilePath, FileBakPath, true); + // 不覆盖同版本的备份文件 + if (File.Exists(FileBakPath)) + { + if (FileVersion != BackupFileVersion) + { + File.Copy(FilePath, FileBakPath, true); + } + } + else + { + File.Copy(FilePath, FileBakPath, true); + } + } ///