From c38fdf30d0d70979e7c250fc649b5f21d9fef9d1 Mon Sep 17 00:00:00 2001 From: fanbook-wangdage <124357765+fanbook-wangdage@users.noreply.github.com> Date: Fri, 26 Dec 2025 18:33:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A5=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=91=98=E6=9D=83=E9=99=90=E9=87=8D=E5=90=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Factory/Process/ProcessFactory.cs | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Factory/Process/ProcessFactory.cs b/src/Snap.Hutao/Snap.Hutao/Factory/Process/ProcessFactory.cs index 990ea08..95a0064 100644 --- a/src/Snap.Hutao/Snap.Hutao/Factory/Process/ProcessFactory.cs +++ b/src/Snap.Hutao/Snap.Hutao/Factory/Process/ProcessFactory.cs @@ -193,11 +193,39 @@ internal sealed class ProcessFactory public static void StartUsingShellExecuteRunAs(string fileName) { - global::System.Diagnostics.Process.Start(new global::System.Diagnostics.ProcessStartInfo + // 尝试从app包中启动 + try { - FileName = fileName, - UseShellExecute = true, - Verb = "runas", - }); + global::System.Diagnostics.Process.Start(new global::System.Diagnostics.ProcessStartInfo + { + FileName = fileName, + UseShellExecute = true, + Verb = "runas", + }); + }catch + { + // 如果失败且filename含有Snap.Hutao.Unpackaged,就直接用Snap.Hutao.exe重启 + if (fileName.Contains("Snap.Hutao.Unpackaged")) + { + string currentDirectory = Directory.GetCurrentDirectory(); + string unpackagedPath = Path.Combine(currentDirectory, "Snap.Hutao.exe"); + if (File.Exists(unpackagedPath)) + { + fileName = unpackagedPath; + } + // 否则抛出异常 + else + { + throw; + } + // 重新尝试启动 + global::System.Diagnostics.Process.Start(new global::System.Diagnostics.ProcessStartInfo + { + FileName = fileName, + UseShellExecute = true, + Verb = "runas", + }); + } + } } } \ No newline at end of file