Fix dialog

This commit is contained in:
HolographicHat
2022-06-21 11:05:53 +08:00
parent 0ace6b951f
commit 468b4b91ea
3 changed files with 45 additions and 4 deletions

View File

@@ -1,16 +1,18 @@
using YaeAchievement;
using static YaeAchievement.Utils;
InstallExitHook();
TryDisableQuickEdit();
InstallExceptionHook();
CheckGenshinIsRunning();
Console.WriteLine("----------------------------------------------------");
Console.WriteLine($"YaeAchievement - 原神成就导出工具 ({GlobalVars.AppVersionName})");
Console.WriteLine("https://github.com/HolographicHat/YaeAchievement");
Console.WriteLine("----------------------------------------------------");
InstallExitHook();
InstallExceptionHook();
CheckGenshinIsRunning();
LoadConfig();
CheckUpdate();
TryDisableQuickEdit();
StartAndWaitResult(GlobalVars.GamePath, str => {
GlobalVars.UnexpectedExit = false;
var list = AchievementAllDataNotify.Parser.ParseFrom(Convert.FromBase64String(str));

View File

@@ -149,6 +149,7 @@ public static class Utils {
private static string SelectGameExecutable() {
var fnPtr = Marshal.AllocHGlobal(32768);
Native.RtlZeroMemory(fnPtr, 32768);
var ofn = new OpenFileName {
file = fnPtr,
size = Marshal.SizeOf<OpenFileName>(),
@@ -158,6 +159,19 @@ public static class Utils {
filter = "国服/国际服主程序 (YuanShen/GenshinImpact.exe)\0YuanShen.exe;GenshinImpact.exe\0",
maxFile = 32768
};
new Thread(() => {
var handle = Native.FindWindow("#32770", "选择主程序");
while (handle == IntPtr.Zero) {
handle = Native.FindWindow("#32770", "选择主程序");
Thread.Sleep(1);
}
var currentThreadId = Native.GetCurrentThreadId();
var foregroundThreadId = Native.GetWindowThreadProcessId(Native.GetForegroundWindow(), out _);
Native.AttachThreadInput(currentThreadId, foregroundThreadId, true);
Native.SetWindowPos(handle, new IntPtr(-1), 0, 0, 0, 0, 1 | 2);
Native.SetForegroundWindow(handle);
Native.AttachThreadInput(currentThreadId, foregroundThreadId, false);
}).Start();
if(!Native.GetOpenFileName(ofn)) {
var err = Native.CommDlgExtendedError();
if (err != 0) {

View File

@@ -113,4 +113,29 @@ public static class Native {
[DllImport("user32.dll")]
public static extern bool EmptyClipboard();
[DllImport("kernel32.dll")]
public static extern void RtlZeroMemory(IntPtr dst, ulong length);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
[DllImport("user32.dll", SetLastError = true)]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint pid);
[DllImport("kernel32.dll")]
public static extern uint GetCurrentThreadId();
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", SetLastError = true)]
public static extern bool AttachThreadInput(uint idAttach, uint idAttachTo, bool fAttach);
}