Add game executable hash check

This commit is contained in:
HolographicHat
2022-10-03 16:33:58 +08:00
parent 204f211249
commit 1207dd70b3
4 changed files with 26 additions and 0 deletions

9
res/App.Designer.cs generated
View File

@@ -219,6 +219,15 @@ namespace YaeAchievement.res {
}
}
/// <summary>
/// Looks up a localized string similar to Please update genshin and retry..
/// </summary>
internal static string GenshinHashError {
get {
return ResourceManager.GetString("GenshinHashError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Please close game before run this application. ({0}).
/// </summary>

View File

@@ -126,4 +126,7 @@ Input a number (0-5): </value>
<data name="Updater" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Updater.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="GenshinHashError" xml:space="preserve">
<value>Please update genshin and retry.</value>
</data>
</root>

View File

@@ -116,4 +116,7 @@
<data name="ExceptionNetwork" xml:space="preserve">
<value>网络错误,请检查网络后重试 ({0}: {1})</value>
</data>
<data name="GenshinHashError" xml:space="preserve">
<value>请将原神更新至最新版本后重试</value>
</data>
</root>

View File

@@ -8,6 +8,7 @@ using System.Runtime.InteropServices;
using Microsoft.Win32;
using YaeAchievement.AppCenterSDK;
using YaeAchievement.res;
using YaeAchievement.res;
using YaeAchievement.Win32;
namespace YaeAchievement;
@@ -198,9 +199,19 @@ public static class Utils {
Environment.Exit(-1);
};
}
private static bool CheckGenshinIsLatestVersion(string path) {
return File.Exists(path) && File.ReadAllBytes(path).MD5Hash()
is "b162c802d986d8b76e12a68d204d79a3"
or "dd07216f0c5aae8dfd388dbb61dd16a7";
}
// ReSharper disable once UnusedMethodReturnValue.Global
public static Thread StartAndWaitResult(string exePath, Func<string, bool> onReceive) {
if (!CheckGenshinIsLatestVersion(exePath)) {
Console.WriteLine(App.GenshinHashError);
Environment.Exit(0);
}
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
try {
File.Delete(GlobalVars.LibFilePath);