From eada184e9e91a57f82b9ac013a989945e7078d8c Mon Sep 17 00:00:00 2001 From: Erich Date: Tue, 27 Aug 2024 21:49:04 +0800 Subject: [PATCH] add a shortcut for 3dGameMode, resolve links in file system --- src/Magpie.App/App.cpp | 2 +- src/Magpie.App/App.idl | 1 + src/Magpie.App/AppSettings.cpp | 51 +++++ src/Magpie.App/AppSettings.h | 1 + src/Magpie.App/HomePage.xaml | 193 ++++++++++--------- src/Magpie.App/Magpie.App.vcxproj | 1 + src/Magpie.App/Magpie.App.vcxproj.filters | 3 + src/Magpie.App/Profile.cpp | 6 + src/Magpie.App/Profile.h | 2 + src/Magpie.App/ProfileService.cpp | 4 +- src/Magpie.App/ProfileViewModel.cpp | 7 + src/Magpie.App/ProfileViewModel.h | 3 + src/Magpie.App/Resources.language-en-US.resw | 3 + src/Magpie.App/ScalingService.cpp | 12 ++ src/Magpie.App/ScalingService.h | 1 + src/Magpie.App/ShortcutHelper.cpp | 4 + src/Magpie.App/ShortcutService.cpp | 1 + src/Magpie.Core/ScalingRuntime.cpp | 11 ++ src/Magpie.Core/ScalingRuntime.h | 2 + src/Magpie.Core/ScalingWindow.cpp | 12 +- src/Magpie.Core/ScalingWindow.h | 2 + 21 files changed, 224 insertions(+), 98 deletions(-) create mode 100644 src/Magpie.App/Profile.cpp diff --git a/src/Magpie.App/App.cpp b/src/Magpie.App/App.cpp index 3c95a78d2..fc9eb3c41 100644 --- a/src/Magpie.App/App.cpp +++ b/src/Magpie.App/App.cpp @@ -30,12 +30,12 @@ #include "EffectsService.h" #include "UpdateService.h" #include "LocalizationService.h" -#include "Logger.h" namespace winrt::Magpie::App::implementation { App::App() { UnhandledException([this](IInspectable const&, UnhandledExceptionEventArgs const& e) { + Logger::Get().Error(to_string(e.Message())); Logger::Get().ComCritical("未处理的异常", e.Exception().value); if (IsDebuggerPresent()) { diff --git a/src/Magpie.App/App.idl b/src/Magpie.App/App.idl index c7058f017..aa6835711 100644 --- a/src/Magpie.App/App.idl +++ b/src/Magpie.App/App.idl @@ -43,6 +43,7 @@ namespace Magpie.App { enum ShortcutAction { Scale, Overlay, + Is3DGameMode, COUNT_OR_NONE }; diff --git a/src/Magpie.App/AppSettings.cpp b/src/Magpie.App/AppSettings.cpp index 8eb94b250..8e9189f8f 100644 --- a/src/Magpie.App/AppSettings.cpp +++ b/src/Magpie.App/AppSettings.cpp @@ -499,6 +499,8 @@ bool AppSettings::_Save(const _AppSettingsData& data) noexcept { writer.Uint(EncodeShortcut(data._shortcuts[(size_t)ShortcutAction::Scale])); writer.Key("overlay"); writer.Uint(EncodeShortcut(data._shortcuts[(size_t)ShortcutAction::Overlay])); + writer.Key("3DGameMode"); + writer.Uint(EncodeShortcut(data._shortcuts[(size_t)ShortcutAction::Is3DGameMode])); writer.EndObject(); writer.Key("autoRestore"); @@ -654,6 +656,11 @@ void AppSettings::_LoadSettings(const rapidjson::GenericObjectvalue.IsUint()) { DecodeShortcut(overlayNode->value.GetUint(), _shortcuts[(size_t)ShortcutAction::Overlay]); } + + auto is3DGameModeNode = shortcutsObj.FindMember("3DGameMode"); + if (is3DGameModeNode != shortcutsObj.MemberEnd() && is3DGameModeNode->value.IsUint()) { + DecodeShortcut(is3DGameModeNode->value.GetUint(), _shortcuts[(size_t)ShortcutAction::Is3DGameMode]); + } } JsonHelper::ReadBool(root, "autoRestore", _isAutoRestore); @@ -771,6 +778,10 @@ bool AppSettings::_LoadProfile( JsonHelper::ReadString(profileObj, "launcherPath", profile.launcherPath); JsonHelper::ReadBool(profileObj, "autoScale", profile.isAutoScale); JsonHelper::ReadString(profileObj, "launchParameters", profile.launchParameters); + + if (!profile.isPackaged) { + _SetTruePath(profile); + } } JsonHelper::ReadInt(profileObj, "scalingMode", profile.scalingMode); @@ -874,6 +885,37 @@ bool AppSettings::_LoadProfile( return true; } +fire_and_forget AppSettings::_SetTruePath(Profile& profile) const { + HANDLE handle = CreateFile( + profile.pathRule.c_str(), + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + NULL, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL + ); + + if (handle == INVALID_HANDLE_VALUE) { + co_return; + } + + TCHAR path[MAX_PATH]; + DWORD length = GetFinalPathNameByHandle( + handle, + path, + MAX_PATH, + 0 + ); + + if (length > 0) { + // Skip `\\?\` prefix + profile.truePath = &path[4]; + } + + CloseHandle(handle); +} + bool AppSettings::_SetDefaultShortcuts() noexcept { bool changed = false; @@ -895,6 +937,15 @@ bool AppSettings::_SetDefaultShortcuts() noexcept { changed = true; } + Shortcut& is3DGameModeShortcut = _shortcuts[(size_t)ShortcutAction::Is3DGameMode]; + if (is3DGameModeShortcut.IsEmpty()) { + is3DGameModeShortcut.win = true; + is3DGameModeShortcut.shift = true; + is3DGameModeShortcut.code = 'E'; + + changed = true; + } + return changed; } diff --git a/src/Magpie.App/AppSettings.h b/src/Magpie.App/AppSettings.h index c05a982f4..3a24fea88 100644 --- a/src/Magpie.App/AppSettings.h +++ b/src/Magpie.App/AppSettings.h @@ -305,6 +305,7 @@ class AppSettings : private _AppSettingsData { Profile& profile, bool isDefault = false ) const noexcept; + fire_and_forget _SetTruePath(Profile& profile) const; bool _SetDefaultShortcuts() noexcept; void _SetDefaultScalingModes() noexcept; diff --git a/src/Magpie.App/HomePage.xaml b/src/Magpie.App/HomePage.xaml index daf54f3a7..13f998073 100644 --- a/src/Magpie.App/HomePage.xaml +++ b/src/Magpie.App/HomePage.xaml @@ -1,45 +1,45 @@ + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:local="using:Magpie.App" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:muxc="using:Microsoft.UI.Xaml.Controls" + mc:Ignorable="d"> + x:Uid="Home_PageFrame"> + HorizontalAlignment="Stretch" + ChildrenTransitions="{StaticResource SettingsCardsAnimations}" + Spacing="{StaticResource SettingsGroupSpacing}"> + Title="{x:Bind ViewModel.UpdateCardTitle, Mode=OneWay}" + x:Load="{x:Bind ViewModel.ShowUpdateCard, Mode=OneWay}" + IsOpen="{x:Bind ViewModel.ShowUpdateCard, Mode=TwoWay}" + Severity="Informational"> + Spacing="8"> + IsChecked="{x:Bind ViewModel.IsAutoCheckForUpdates, Mode=TwoWay}"/> + HorizontalSpacing="8" + Orientation="Horizontal" + VerticalSpacing="6">