This commit is contained in:
HolographicHat
2022-09-02 20:24:05 +08:00
parent 29aa4fea2d
commit 251246fd74
4 changed files with 52 additions and 25 deletions

9
res/App.Designer.cs generated
View File

@@ -229,6 +229,15 @@ namespace YaeAchievement.res {
}
}
/// <summary>
/// Looks up a localized string similar to 网络错误: {0}.
/// </summary>
internal static string NetworkError {
get {
return ResourceManager.GetString("NetworkError", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to 按任意键退出.
/// </summary>

View File

@@ -124,4 +124,7 @@ Input a number (0-5): </value>
<data name="RefreshData" xml:space="preserve">
<value>To fetch new data, Restart the application after delete cache\d1a8ef40a67a5929.miko.</value>
</data>
<data name="NetworkError" xml:space="preserve">
<value>Network error:</value>
</data>
</root>

View File

@@ -132,4 +132,7 @@
<data name="RefreshData" xml:space="preserve">
<value>要重新获取数据,手动删除 cache\d1a8ef40a67a5929.miko 后重新启动 YaeAchievement</value>
</data>
<data name="NetworkError" xml:space="preserve">
<value>网络错误: {0}</value>
</data>
</root>

View File

@@ -29,6 +29,7 @@ public static class Utils {
});
public static byte[] GetBucketFileAsByteArray(string path, bool cache = true) {
try {
using var msg = new HttpRequestMessage {
Method = HttpMethod.Get,
RequestUri = new Uri($"{GlobalVars.BucketHost}/{path}")
@@ -48,6 +49,11 @@ public static class Utils {
cacheFile.Write(responseBytes, etag);
}
return responseBytes;
} catch (Exception e) {
Console.WriteLine(App.NetworkError, e.Message);
Environment.Exit(-1);
return null!;
}
}
public static void CopyToClipboard(string text) {
@@ -101,12 +107,16 @@ public static class Utils {
}
public static bool ShellOpen(string path) {
try {
return new Process {
StartInfo = {
FileName = path,
UseShellExecute = true
}
}.Start();
} catch (Exception) {
return false;
}
}
public static bool CheckGamePathValid(string? path) {
@@ -197,7 +207,9 @@ public static class Utils {
var lib = Path.Combine(dataDir, "yae.dll");
File.Copy(Path.GetFullPath(GlobalVars.LibName), lib, true);
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
try {
File.Delete(lib);
} catch (Exception) { /* ignored */ }
};
if (!Injector.CreateProcess(exePath, out var hProcess, out var hThread, out var pid)) {
Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("ICreateProcess fail"));