Skip to content

Commit

Permalink
add a shortcut for 3dGameMode, resolve links in file system
Browse files Browse the repository at this point in the history
  • Loading branch information
eriforce committed Aug 27, 2024
1 parent 452ff29 commit eada184
Show file tree
Hide file tree
Showing 21 changed files with 224 additions and 98 deletions.
2 changes: 1 addition & 1 deletion src/Magpie.App/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions src/Magpie.App/App.idl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace Magpie.App {
enum ShortcutAction {
Scale,
Overlay,
Is3DGameMode,
COUNT_OR_NONE
};

Expand Down
51 changes: 51 additions & 0 deletions src/Magpie.App/AppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -654,6 +656,11 @@ void AppSettings::_LoadSettings(const rapidjson::GenericObject<true, rapidjson::
if (overlayNode != shortcutsObj.MemberEnd() && overlayNode->value.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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/Magpie.App/AppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit eada184

Please sign in to comment.