diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Shell/IShellLinkInterop.cs b/src/Snap.Hutao/Snap.Hutao/Core/Shell/IShellLinkInterop.cs index b0662b90..30242a88 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Shell/IShellLinkInterop.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Shell/IShellLinkInterop.cs @@ -5,5 +5,5 @@ namespace Snap.Hutao.Core.Shell; internal interface IShellLinkInterop { - bool TryCreateDesktopShoutcutForElevatedLaunch(); + ValueTask TryCreateDesktopShoutcutForElevatedLaunchAsync(); } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs b/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs index 146a193d..1cb469bd 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs @@ -2,6 +2,8 @@ // Licensed under the MIT license. using System.IO; +using Windows.Storage; +using Windows.Storage.Streams; using Windows.Win32; using Windows.Win32.System.Com; using Windows.Win32.UI.Shell; @@ -15,15 +17,21 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop { private readonly RuntimeOptions runtimeOptions; - public bool TryCreateDesktopShoutcutForElevatedLaunch() + public async ValueTask TryCreateDesktopShoutcutForElevatedLaunchAsync() { - string sourceLogoPath = Path.Combine(runtimeOptions.InstalledLocation, "Assets/Logo.ico"); + Uri sourceLogoUri = "ms-appx:///Assets/Logo.ico".ToUri(); string targetLogoPath = Path.Combine(runtimeOptions.DataFolder, "ShellLinkLogo.ico"); try { - // System.IO.IOException: 无法加密指定的文件。 - File.Copy(sourceLogoPath, targetLogoPath, true); + StorageFile iconFile = await StorageFile.GetFileFromApplicationUriAsync(sourceLogoUri); + using (Stream inputStream = (await iconFile.OpenReadAsync()).AsStream()) + { + using (FileStream outputStream = File.Create(targetLogoPath)) + { + await inputStream.CopyToAsync(outputStream).ConfigureAwait(false); + } + } } catch { diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/SettingViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/SettingViewModel.cs index 616d848b..e23ea930 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/SettingViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/SettingViewModel.cs @@ -268,9 +268,9 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel } [Command("CreateDesktopShortcutCommand")] - private void CreateDesktopShortcutForElevatedLaunch() + private async Task CreateDesktopShortcutForElevatedLaunch() { - bool created = shellLinkInterop.TryCreateDesktopShoutcutForElevatedLaunch(); + bool created = await shellLinkInterop.TryCreateDesktopShoutcutForElevatedLaunchAsync(); if (created) { infoBarService.Information(SH.ViewModelSettingActionComplete);