diff --git a/src/Snap.Hutao/Snap.Hutao.Win32/NativeMethods.txt b/src/Snap.Hutao/Snap.Hutao.Win32/NativeMethods.txt index 13d7ac22..5fca356a 100644 --- a/src/Snap.Hutao/Snap.Hutao.Win32/NativeMethods.txt +++ b/src/Snap.Hutao/Snap.Hutao.Win32/NativeMethods.txt @@ -61,6 +61,7 @@ FileSaveDialog IFileOpenDialog IFileSaveDialog IPersistFile +IShellLinkDataList IShellLinkW ShellLink SHELL_LINK_DATA_FLAGS diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs b/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs index dec8fbeb..87e7cc3b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Shell/ShellLinkInterop.cs @@ -1,7 +1,6 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. -using Snap.Hutao.Service; using System.IO; using System.Runtime.InteropServices; using Windows.Storage; @@ -19,7 +18,6 @@ namespace Snap.Hutao.Core.Shell; internal sealed partial class ShellLinkInterop : IShellLinkInterop { private readonly RuntimeOptions runtimeOptions; - private readonly AppOptions appOptions; public async ValueTask TryCreateDesktopShoutcutForElevatedLaunchAsync() { @@ -45,12 +43,15 @@ internal sealed partial class ShellLinkInterop : IShellLinkInterop HRESULT result = CoCreateInstance(null, CLSCTX.CLSCTX_INPROC_SERVER, out IShellLinkW shellLink); Marshal.ThrowExceptionForHR(result); - shellLink.SetPath(appOptions.PowerShellPath); - shellLink.SetArguments($""" - -Command "Start-Process shell:AppsFolder\{runtimeOptions.FamilyName}!App -verb runas" - """); - shellLink.SetShowCmd(SHOW_WINDOW_CMD.SW_SHOWMINNOACTIVE); + shellLink.SetPath($"shell:AppsFolder\\{runtimeOptions.FamilyName}!App"); + shellLink.SetShowCmd(SHOW_WINDOW_CMD.SW_NORMAL); shellLink.SetIconLocation(targetLogoPath, 0); + + IShellLinkDataList shellLinkDataList = (IShellLinkDataList)shellLink; + shellLinkDataList.GetFlags(out uint flags); + flags |= (uint)SHELL_LINK_DATA_FLAGS.SLDF_RUNAS_USER; + shellLinkDataList.SetFlags(flags); + string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string target = Path.Combine(desktop, $"{SH.FormatAppNameAndVersion(runtimeOptions.Version)}.lnk"); diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/SettingEntry.Constant.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/SettingEntry.Constant.cs index 37cbdbb3..dfe1ccc6 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/SettingEntry.Constant.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/SettingEntry.Constant.cs @@ -15,6 +15,7 @@ internal sealed partial class SettingEntry public const string GamePathEntries = "GamePathEntries"; + [Obsolete("不再使用 PowerShell")] public const string PowerShellPath = "PowerShellPath"; /// diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx index 1b8cf38a..2564a4b8 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx @@ -186,9 +186,6 @@ 导入 - - 选择 PowerShell - 欢迎使用胡桃 @@ -932,9 +929,6 @@ 未开启长路径功能,无法设置注册表键值 - - 找不到 PowerShell 的安装目录 - 无法读取游戏配置文件 {0},可能是文件不存在 @@ -2435,12 +2429,6 @@ 设置游戏路径时,请选择游戏本体(YuanShen.exe 或 GenshinImpact.exe)而不是启动器(launcher.exe) - - 在创建的快捷方式中启动胡桃需要使用 PowerShell - - - PowerShell 路径 - Shell 体验 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs index 97bef4f0..90d795bb 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs @@ -16,42 +16,12 @@ namespace Snap.Hutao.Service; [Injection(InjectAs.Singleton)] internal sealed partial class AppOptions : DbStoreOptions { - private string? powerShellPath; private bool? isEmptyHistoryWishVisible; private BackdropType? backdropType; private CultureInfo? currentCulture; private Region? region; private string? geetestCustomCompositeUrl; - public string PowerShellPath - { - get - { - return GetOption(ref powerShellPath, SettingEntry.PowerShellPath, GetDefaultPowerShellLocationOrEmpty); - - static string GetDefaultPowerShellLocationOrEmpty() - { - string? paths = Environment.GetEnvironmentVariable("Path"); - if (!string.IsNullOrEmpty(paths)) - { - foreach (StringSegment path in new StringTokenizer(paths, [';'])) - { - if (path is { HasValue: true, Length: > 0 }) - { - if (path.Value.Contains("WindowsPowerShell", StringComparison.OrdinalIgnoreCase)) - { - return Path.Combine(path.Value, "powershell.exe"); - } - } - } - } - - return string.Empty; - } - } - set => SetOption(ref powerShellPath, SettingEntry.PowerShellPath, value); - } - public bool IsEmptyHistoryWishVisible { get => GetOption(ref isEmptyHistoryWishVisible, SettingEntry.IsEmptyHistoryWishVisible); diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml index c554478c..2b14d50e 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml @@ -189,20 +189,7 @@ Header="{shcm:ResourceString Name=ViewPageSettingCreateDesktopShortcutHeader}" HeaderIcon="{shcm:FontIcon Glyph=}" IsClickEnabled="True"/> - - - - - - - - +