From 2056fa8f4d1e79578ede1016fd780bf8a9a31c0d Mon Sep 17 00:00:00 2001 From: qhy040404 Date: Sat, 20 Apr 2024 15:28:07 +0800 Subject: [PATCH] extract launcher --- .../Snap.Hutao/Core/Shell/ShellLinkInterop.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs b/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs index 7b3e7690..eb0edf3a 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs @@ -20,9 +20,18 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop public async ValueTask TryCreateDesktopShoutcutForElevatedLaunchAsync() { - Uri elevatedLauncherUri = "ms-appx:///Snap.Hutao.Elevated.Launcher.exe".ToUri(); - StorageFile launcherFile = await StorageFile.GetFileFromApplicationUriAsync(elevatedLauncherUri); - string elevatedLauncherPath = launcherFile.Path; + string elevatedLauncherPath = Path.Combine(runtimeOptions.DataFolder, "Snap.Hutao.Elevated.Launcher.exe"); + + try + { + Uri elevatedLauncherUri = "ms-appx:///Snap.Hutao.Elevated.Launcher.exe".ToUri(); + StorageFile launcherFile = await StorageFile.GetFileFromApplicationUriAsync(elevatedLauncherUri); + await launcherFile.OverwriteCopyAsync(elevatedLauncherPath).ConfigureAwait(false); + } + catch + { + return false; + } return UnsafeTryCreateDesktopShoutcutForElevatedLaunch(elevatedLauncherPath); }