mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-13 18:08:15 +08:00
Fix
This commit is contained in:
9
res/App.Designer.cs
generated
9
res/App.Designer.cs
generated
@@ -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>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to 按任意键退出.
|
/// Looks up a localized string similar to 按任意键退出.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -124,4 +124,7 @@ Input a number (0-5): </value>
|
|||||||
<data name="RefreshData" xml:space="preserve">
|
<data name="RefreshData" xml:space="preserve">
|
||||||
<value>To fetch new data, Restart the application after delete cache\d1a8ef40a67a5929.miko.</value>
|
<value>To fetch new data, Restart the application after delete cache\d1a8ef40a67a5929.miko.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NetworkError" xml:space="preserve">
|
||||||
|
<value>Network error:</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -132,4 +132,7 @@
|
|||||||
<data name="RefreshData" xml:space="preserve">
|
<data name="RefreshData" xml:space="preserve">
|
||||||
<value>要重新获取数据,手动删除 cache\d1a8ef40a67a5929.miko 后重新启动 YaeAchievement</value>
|
<value>要重新获取数据,手动删除 cache\d1a8ef40a67a5929.miko 后重新启动 YaeAchievement</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NetworkError" xml:space="preserve">
|
||||||
|
<value>网络错误: {0}</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
62
src/Utils.cs
62
src/Utils.cs
@@ -29,25 +29,31 @@ public static class Utils {
|
|||||||
});
|
});
|
||||||
|
|
||||||
public static byte[] GetBucketFileAsByteArray(string path, bool cache = true) {
|
public static byte[] GetBucketFileAsByteArray(string path, bool cache = true) {
|
||||||
using var msg = new HttpRequestMessage {
|
try {
|
||||||
Method = HttpMethod.Get,
|
using var msg = new HttpRequestMessage {
|
||||||
RequestUri = new Uri($"{GlobalVars.BucketHost}/{path}")
|
Method = HttpMethod.Get,
|
||||||
};
|
RequestUri = new Uri($"{GlobalVars.BucketHost}/{path}")
|
||||||
var cacheFile = new CacheFile(path);
|
};
|
||||||
if (cache && cacheFile.Exists()) {
|
var cacheFile = new CacheFile(path);
|
||||||
msg.Headers.TryAddWithoutValidation("If-None-Match", $"{cacheFile.Read().Etag}");
|
if (cache && cacheFile.Exists()) {
|
||||||
|
msg.Headers.TryAddWithoutValidation("If-None-Match", $"{cacheFile.Read().Etag}");
|
||||||
|
}
|
||||||
|
using var response = CHttpClient.Value.Send(msg);
|
||||||
|
if (cache && response.StatusCode == HttpStatusCode.NotModified) {
|
||||||
|
return cacheFile.Read().Content.ToByteArray();
|
||||||
|
}
|
||||||
|
response.EnsureSuccessStatusCode();
|
||||||
|
var responseBytes = response.Content.ReadAsByteArrayAsync().Result;
|
||||||
|
if (cache) {
|
||||||
|
var etag = response.Headers.ETag!.Tag;
|
||||||
|
cacheFile.Write(responseBytes, etag);
|
||||||
|
}
|
||||||
|
return responseBytes;
|
||||||
|
} catch (Exception e) {
|
||||||
|
Console.WriteLine(App.NetworkError, e.Message);
|
||||||
|
Environment.Exit(-1);
|
||||||
|
return null!;
|
||||||
}
|
}
|
||||||
using var response = CHttpClient.Value.Send(msg);
|
|
||||||
if (cache && response.StatusCode == HttpStatusCode.NotModified) {
|
|
||||||
return cacheFile.Read().Content.ToByteArray();
|
|
||||||
}
|
|
||||||
response.EnsureSuccessStatusCode();
|
|
||||||
var responseBytes = response.Content.ReadAsByteArrayAsync().Result;
|
|
||||||
if (cache) {
|
|
||||||
var etag = response.Headers.ETag!.Tag;
|
|
||||||
cacheFile.Write(responseBytes, etag);
|
|
||||||
}
|
|
||||||
return responseBytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CopyToClipboard(string text) {
|
public static void CopyToClipboard(string text) {
|
||||||
@@ -101,12 +107,16 @@ public static class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool ShellOpen(string path) {
|
public static bool ShellOpen(string path) {
|
||||||
return new Process {
|
try {
|
||||||
StartInfo = {
|
return new Process {
|
||||||
FileName = path,
|
StartInfo = {
|
||||||
UseShellExecute = true
|
FileName = path,
|
||||||
}
|
UseShellExecute = true
|
||||||
}.Start();
|
}
|
||||||
|
}.Start();
|
||||||
|
} catch (Exception) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool CheckGamePathValid(string? path) {
|
public static bool CheckGamePathValid(string? path) {
|
||||||
@@ -197,7 +207,9 @@ public static class Utils {
|
|||||||
var lib = Path.Combine(dataDir, "yae.dll");
|
var lib = Path.Combine(dataDir, "yae.dll");
|
||||||
File.Copy(Path.GetFullPath(GlobalVars.LibName), lib, true);
|
File.Copy(Path.GetFullPath(GlobalVars.LibName), lib, true);
|
||||||
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
|
AppDomain.CurrentDomain.ProcessExit += (_, _) => {
|
||||||
File.Delete(lib);
|
try {
|
||||||
|
File.Delete(lib);
|
||||||
|
} catch (Exception) { /* ignored */ }
|
||||||
};
|
};
|
||||||
if (!Injector.CreateProcess(exePath, out var hProcess, out var hThread, out var pid)) {
|
if (!Injector.CreateProcess(exePath, out var hProcess, out var hThread, out var pid)) {
|
||||||
Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("ICreateProcess fail"));
|
Environment.Exit(new Win32Exception().PrintMsgAndReturnErrCode("ICreateProcess fail"));
|
||||||
|
|||||||
Reference in New Issue
Block a user