mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
attempt to fix desktop icon creation
This commit is contained in:
@@ -5,5 +5,5 @@ namespace Snap.Hutao.Core.Shell;
|
||||
|
||||
internal interface IShellLinkInterop
|
||||
{
|
||||
bool TryCreateDesktopShoutcutForElevatedLaunch();
|
||||
ValueTask<bool> TryCreateDesktopShoutcutForElevatedLaunchAsync();
|
||||
}
|
||||
@@ -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<bool> 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
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user