处理文件不存在但是希望打补丁的情况

This commit is contained in:
辉鸭蛋 2024-06-15 00:37:39 +08:00
parent 8b63257bb4
commit 344f2f7e75

View File

@ -106,7 +106,14 @@ namespace RevokeMsgPatcher.Modifier
string content = File.ReadAllText(indexPath);
// 正则 require\(String.raw`.*`\);
string pattern = @"require\(String.raw`.*`\);";
string replacement = $"require(String.raw`{GetLiteLoaderPath()}`);";
string liteLoaderPath = GetLiteLoaderPath();
if (!File.Exists(liteLoaderPath))
{
MessageBox.Show("LiteLoaderQQNT文件夹不存在仅安装QQNT去验证补丁", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string replacement = $"require(String.raw`{liteLoaderPath}`);";
if (Regex.IsMatch(content, pattern))
{
content = Regex.Replace(content, pattern, replacement);