mirror of
https://github.com/HolographicHat/Yae.git
synced 2025-12-12 01:18:15 +08:00
Fix
This commit is contained in:
9
res/App.Designer.cs
generated
9
res/App.Designer.cs
generated
@@ -246,6 +246,15 @@ namespace YaeAchievement.res {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to No write permission on {0}..
|
||||||
|
/// </summary>
|
||||||
|
internal static string NoWritePermission {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("NoWritePermission", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Press any key to exit..
|
/// Looks up a localized string similar to Press any key to exit..
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -126,4 +126,7 @@ Input a number (0-5): </value>
|
|||||||
<data name="GenshinHashError" xml:space="preserve">
|
<data name="GenshinHashError" xml:space="preserve">
|
||||||
<value>Please update genshin and retry.</value>
|
<value>Please update genshin and retry.</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NoWritePermission" xml:space="preserve">
|
||||||
|
<value>No write permission on {0}.</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -117,4 +117,7 @@
|
|||||||
<data name="GenshinHashError" xml:space="preserve">
|
<data name="GenshinHashError" xml:space="preserve">
|
||||||
<value>请将原神更新至最新版本后重试</value>
|
<value>请将原神更新至最新版本后重试</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="NoWritePermission" xml:space="preserve">
|
||||||
|
<value>无法写入文件,请更换软件所在目录后重试</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -85,8 +85,9 @@ public static class Export {
|
|||||||
// ReSharper disable once InconsistentNaming
|
// ReSharper disable once InconsistentNaming
|
||||||
private static void ToUIAFJson(AchievementAllDataNotify data) {
|
private static void ToUIAFJson(AchievementAllDataNotify data) {
|
||||||
var path = Path.GetFullPath($"uiaf-{DateTime.Now:yyyyMMddHHmmss}.json");
|
var path = Path.GetFullPath($"uiaf-{DateTime.Now:yyyyMMddHHmmss}.json");
|
||||||
File.WriteAllText(path, JsonSerializer.Serialize(ExportToUIAFApp(data)));
|
if (TryWriteToFile(path, JsonSerializer.Serialize(ExportToUIAFApp(data)))) {
|
||||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ToPaimon(AchievementAllDataNotify data) {
|
private static void ToPaimon(AchievementAllDataNotify data) {
|
||||||
@@ -105,8 +106,9 @@ public static class Export {
|
|||||||
["achievement"] = output.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value)
|
["achievement"] = output.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value)
|
||||||
};
|
};
|
||||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-paimon.json");
|
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-paimon.json");
|
||||||
File.WriteAllText(path, JsonSerializer.Serialize(final));
|
if (TryWriteToFile(path, JsonSerializer.Serialize(final))) {
|
||||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ToSeelie(AchievementAllDataNotify data) {
|
private static void ToSeelie(AchievementAllDataNotify data) {
|
||||||
@@ -120,8 +122,9 @@ public static class Export {
|
|||||||
["achievements"] = output.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value)
|
["achievements"] = output.OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value)
|
||||||
};
|
};
|
||||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-seelie.json");
|
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-seelie.json");
|
||||||
File.WriteAllText(path, JsonSerializer.Serialize(final));
|
if (TryWriteToFile(path, JsonSerializer.Serialize(final))) {
|
||||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once InconsistentNaming
|
// ReSharper disable once InconsistentNaming
|
||||||
@@ -151,9 +154,10 @@ public static class Export {
|
|||||||
return item.JoinToString(",");
|
return item.JoinToString(",");
|
||||||
}));
|
}));
|
||||||
var path = Path.GetFullPath($"achievement-{DateTime.Now:yyyyMMddHHmmss}.csv");
|
var path = Path.GetFullPath($"achievement-{DateTime.Now:yyyyMMddHHmmss}.csv");
|
||||||
File.WriteAllText(path, $"\uFEFF{string.Join("\n", output)}");
|
if (TryWriteToFile(path, $"\uFEFF{string.Join("\n", output)}")) {
|
||||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||||
Process.Start("explorer.exe", $"{Path.GetDirectoryName(path)}");
|
Process.Start("explorer.exe", $"{Path.GetDirectoryName(path)}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ToXunkong(AchievementAllDataNotify data) {
|
private static void ToXunkong(AchievementAllDataNotify data) {
|
||||||
@@ -169,10 +173,12 @@ public static class Export {
|
|||||||
|
|
||||||
private static void ToRawJson(AchievementAllDataNotify data) {
|
private static void ToRawJson(AchievementAllDataNotify data) {
|
||||||
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-raw.json");
|
var path = Path.GetFullPath($"export-{DateTime.Now:yyyyMMddHHmmss}-raw.json");
|
||||||
File.WriteAllText(path, JsonSerializer.Serialize(data, new JsonSerializerOptions {
|
var text = JsonSerializer.Serialize(data, new JsonSerializerOptions {
|
||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
}));
|
});
|
||||||
Console.WriteLine(App.ExportToFileSuccess, path);
|
if (TryWriteToFile(path, text)) {
|
||||||
|
Console.WriteLine(App.ExportToFileSuccess, path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once InconsistentNaming
|
// ReSharper disable once InconsistentNaming
|
||||||
@@ -228,4 +234,14 @@ public static class Export {
|
|||||||
AppCenter.TrackCrash(ex, false);
|
AppCenter.TrackCrash(ex, false);
|
||||||
return ex.NativeErrorCode;
|
return ex.NativeErrorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool TryWriteToFile(string path, string contents) {
|
||||||
|
try {
|
||||||
|
File.WriteAllText(path, contents);
|
||||||
|
return true;
|
||||||
|
} catch (UnauthorizedAccessException) {
|
||||||
|
Console.WriteLine(App.NoWritePermission, path);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Windows.Win32.System.Threading;
|
|||||||
namespace YaeAchievement;
|
namespace YaeAchievement;
|
||||||
|
|
||||||
public static class Injector {
|
public static class Injector {
|
||||||
|
|
||||||
public static unsafe bool CreateProcess(string path, out HANDLE hProc, out HANDLE hThread, out uint pid) {
|
public static unsafe bool CreateProcess(string path, out HANDLE hProc, out HANDLE hThread, out uint pid) {
|
||||||
Span<char> cmdLines = stackalloc char[1]; // "\0"
|
Span<char> cmdLines = stackalloc char[1]; // "\0"
|
||||||
var si = new STARTUPINFOW {
|
var si = new STARTUPINFOW {
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ TryDisableQuickEdit();
|
|||||||
InstallExitHook();
|
InstallExitHook();
|
||||||
InstallExceptionHook();
|
InstallExceptionHook();
|
||||||
|
|
||||||
await CheckVcRuntime();
|
|
||||||
CheckSelfIsRunning();
|
CheckSelfIsRunning();
|
||||||
|
await CheckVcRuntime();
|
||||||
CheckGenshinIsRunning();
|
CheckGenshinIsRunning();
|
||||||
|
|
||||||
Console.WriteLine(@"----------------------------------------------------");
|
Console.WriteLine(@"----------------------------------------------------");
|
||||||
|
|||||||
40
src/Utils.cs
40
src/Utils.cs
@@ -50,7 +50,7 @@ public static class Utils {
|
|||||||
cacheFile.Write(responseBytes, etag);
|
cacheFile.Write(responseBytes, etag);
|
||||||
}
|
}
|
||||||
return responseBytes;
|
return responseBytes;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) when(e is SocketException or TaskCanceledException) {
|
||||||
Console.WriteLine(App.NetworkError, e.Message);
|
Console.WriteLine(App.NetworkError, e.Message);
|
||||||
Environment.Exit(-1);
|
Environment.Exit(-1);
|
||||||
return null!;
|
return null!;
|
||||||
@@ -73,8 +73,8 @@ public static class Utils {
|
|||||||
if (Native.OpenClipboard(HWND.Null))
|
if (Native.OpenClipboard(HWND.Null))
|
||||||
{
|
{
|
||||||
Native.EmptyClipboard();
|
Native.EmptyClipboard();
|
||||||
HANDLE hGlobal = (HANDLE)Marshal.AllocHGlobal((text.Length + 1) * 2);
|
var hGlobal = (HANDLE) Marshal.AllocHGlobal((text.Length + 1) * 2);
|
||||||
IntPtr hPtr = (IntPtr)Native.GlobalLock(hGlobal);
|
var hPtr = (nint) Native.GlobalLock(hGlobal);
|
||||||
Marshal.Copy(text.ToCharArray(), 0, hPtr, text.Length);
|
Marshal.Copy(text.ToCharArray(), 0, hPtr, text.Length);
|
||||||
Native.GlobalUnlock(hPtr);
|
Native.GlobalUnlock(hPtr);
|
||||||
Native.SetClipboardData(13, hGlobal);
|
Native.SetClipboardData(13, hGlobal);
|
||||||
@@ -121,15 +121,17 @@ public static class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void CheckSelfIsRunning() {
|
public static void CheckSelfIsRunning() {
|
||||||
Process.EnterDebugMode();
|
try {
|
||||||
var cur = Process.GetCurrentProcess();
|
Process.EnterDebugMode();
|
||||||
foreach (var process in Process.GetProcesses().Where(process => process.Id != cur.Id)) {
|
var cur = Process.GetCurrentProcess();
|
||||||
if (process.ProcessName == cur.ProcessName) {
|
foreach (var process in Process.GetProcesses().Where(process => process.Id != cur.Id)) {
|
||||||
Console.WriteLine(App.AnotherInstance);
|
if (process.ProcessName == cur.ProcessName) {
|
||||||
Environment.Exit(302);
|
Console.WriteLine(App.AnotherInstance);
|
||||||
|
Environment.Exit(302);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Process.LeaveDebugMode();
|
||||||
Process.LeaveDebugMode();
|
} catch (Win32Exception) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once UnusedMethodReturnValue.Global
|
// ReSharper disable once UnusedMethodReturnValue.Global
|
||||||
@@ -162,7 +164,7 @@ public static class Utils {
|
|||||||
foreach (var process in Process.GetProcesses()) {
|
foreach (var process in Process.GetProcesses()) {
|
||||||
if (process.ProcessName is "GenshinImpact" or "YuanShen"
|
if (process.ProcessName is "GenshinImpact" or "YuanShen"
|
||||||
&& !process.HasExited
|
&& !process.HasExited
|
||||||
&& process.MainWindowHandle != IntPtr.Zero
|
&& process.MainWindowHandle != nint.Zero
|
||||||
) {
|
) {
|
||||||
Console.WriteLine(App.GenshinIsRunning, process.Id);
|
Console.WriteLine(App.GenshinIsRunning, process.Id);
|
||||||
Environment.Exit(301);
|
Environment.Exit(301);
|
||||||
@@ -212,8 +214,9 @@ public static class Utils {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
|
if (!File.Exists(path)) return false;
|
||||||
var hash = File.ReadAllBytes(path).MD5Hash();
|
var hash = File.ReadAllBytes(path).MD5Hash();
|
||||||
return File.Exists(path) && (hash == _updateInfo.CurrentCNGameHash || hash == _updateInfo.CurrentOSGameHash);
|
return hash == _updateInfo.CurrentCNGameHash || hash == _updateInfo.CurrentOSGameHash;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,8 +285,6 @@ public static class Utils {
|
|||||||
th.Start();
|
th.Start();
|
||||||
return th;
|
return th;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CA1416
|
|
||||||
|
|
||||||
public static async Task CheckVcRuntime() {
|
public static async Task CheckVcRuntime() {
|
||||||
using var root = Registry.LocalMachine;
|
using var root = Registry.LocalMachine;
|
||||||
@@ -301,7 +302,14 @@ public static class Utils {
|
|||||||
if (!installed) {
|
if (!installed) {
|
||||||
Console.WriteLine(App.VcRuntimeDownload);
|
Console.WriteLine(App.VcRuntimeDownload);
|
||||||
var pkgPath = Path.Combine(GlobalVars.DataPath, "vc_redist.x64.exe");
|
var pkgPath = Path.Combine(GlobalVars.DataPath, "vc_redist.x64.exe");
|
||||||
var bytes = await CHttpClient.GetByteArrayAsync("https://aka.ms/vs/17/release/vc_redist.x64.exe");
|
byte[] bytes;
|
||||||
|
try {
|
||||||
|
bytes = await CHttpClient.GetByteArrayAsync("https://aka.ms/vs/17/release/vc_redist.x64.exe");
|
||||||
|
} catch (Exception e) when(e is SocketException or TaskCanceledException) {
|
||||||
|
Console.WriteLine(App.NetworkError, e.Message);
|
||||||
|
Environment.Exit(-1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
await File.WriteAllBytesAsync(pkgPath, bytes);
|
await File.WriteAllBytesAsync(pkgPath, bytes);
|
||||||
Console.WriteLine(App.VcRuntimeInstalling);
|
Console.WriteLine(App.VcRuntimeInstalling);
|
||||||
using var process = new Process {
|
using var process = new Process {
|
||||||
|
|||||||
Reference in New Issue
Block a user