修复选择快捷方式作为启动器时丢失参数 (#1162)

* feat: 支持选择 lnk 作为启动器

* chore: 注释
This commit is contained in:
Xu 2025-05-24 17:49:01 +08:00 committed by GitHub
commit fb6ae46734
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 16 additions and 10 deletions

View file

@ -759,7 +759,7 @@ bool AppSettings::_LoadProfile(
JsonHelper::ReadString(profileObj, "launcherPath", profile.launcherPath);
// 将旧版本的相对路径转换为绝对路径
if (PathIsRelative(profile.launcherPath.c_str())) {
if (!profile.launcherPath.empty() && PathIsRelative(profile.launcherPath.c_str())) {
size_t delimPos = profile.pathRule.find_last_of(L'\\');
if (delimPos != std::wstring::npos) {
wil::unique_hlocal_string combinedPath;

View file

@ -11,10 +11,13 @@ using namespace winrt;
namespace Magpie {
// 出错返回空,取消返回空字符串
std::optional<std::wstring> FileDialogHelper::OpenFileDialog(IFileDialog* fileDialog, FILEOPENDIALOGOPTIONS options) noexcept {
FILEOPENDIALOGOPTIONS options1{};
fileDialog->GetOptions(&options1);
fileDialog->SetOptions(options1 | options | FOS_FORCEFILESYSTEM);
std::optional<std::wstring> FileDialogHelper::OpenFileDialog(
IFileDialog* fileDialog,
FILEOPENDIALOGOPTIONS options
) noexcept {
FILEOPENDIALOGOPTIONS oldOptions{};
fileDialog->GetOptions(&oldOptions);
fileDialog->SetOptions(oldOptions | options | FOS_FORCEFILESYSTEM | FOS_OKBUTTONNEEDSINTERACTION);
if (fileDialog->Show(App::Get().MainWindow().Handle()) != S_OK) {
// 被用户取消

View file

@ -48,8 +48,7 @@ struct Profile {
std::wstring pathRule;
std::wstring classNameRule;
// 如果在同一个驱动器上则存储相对路径,否则存储绝对路径
// 若为空使用 pathRule
// 允许 exe 和 lnk
std::wstring launcherPath;
CursorScaling cursorScaling = CursorScaling::NoScaling;

View file

@ -149,12 +149,16 @@ void ProfileViewModel::ChangeExeForLaunching() const noexcept {
fileDialog->SetFolder(shellItem.get());
}
std::optional<std::wstring> exePath = FileDialogHelper::OpenFileDialog(fileDialog.get(), FOS_STRICTFILETYPES);
if (!exePath || exePath->empty() || *exePath == _data->pathRule) {
// GH#1158
// 选择 exe 的快捷方式时 IFileOpenDialog 默认解析它指向的文件路径,导致参数丢失。
// FOS_NODEREFERENCELINKS 可以禁止解析,直接返回 lnk 文件。
std::optional<std::wstring> launcherPath = FileDialogHelper::OpenFileDialog(
fileDialog.get(), FOS_STRICTFILETYPES | FOS_NODEREFERENCELINKS);
if (!launcherPath || launcherPath->empty() || *launcherPath == _data->pathRule) {
return;
}
_data->launcherPath = std::move(*exePath);
_data->launcherPath = std::move(*launcherPath);
AppSettings::Get().SaveAsync();
}