From e7cfb5234fa06d692947babbfbee63cac4575d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 3 May 2024 16:49:28 +0200 Subject: [PATCH 1/3] Improve checks for JIT ability Prep for iOS --- Core/Config.cpp | 7 +++++++ UI/GameSettingsScreen.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 395e2651ee..3730d51599 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1227,6 +1227,13 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { ResetControlLayout(); } + // Force JIT setting to a valid value for the current system configuration. + if (!System_GetPropertyBool(SYSPROP_CAN_JIT)) { + if (g_Config.iCpuCore == (int)CPUCore::JIT || g_Config.iCpuCore == (int)CPUCore::JIT_IR) { + g_Config.iCpuCore = (int)CPUCore::IR_INTERPRETER; + } + } + const char *gitVer = PPSSPP_GIT_VERSION; Version installed(gitVer); Version upgrade(upgradeVersion); diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index a854b14298..7c8af35a3f 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1755,7 +1755,7 @@ void DeveloperToolsScreen::CreateViews() { list->Add(new ItemHeader(sy->T("General"))); - bool canUseJit = true; + bool canUseJit = System_GetPropertyBool(SYSPROP_CAN_JIT); // iOS can now use JIT on all modes, apparently. // The bool may come in handy for future non-jit platforms though (UWP XB1?) From 0ae0c9bbe9efcf88e099d3c1d98a2068563623c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 3 May 2024 17:00:36 +0200 Subject: [PATCH 2/3] Minor cleanup in main.cpp --- Windows/main.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/Windows/main.cpp b/Windows/main.cpp index 87b99608d0..48ca4c1d73 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -269,23 +269,23 @@ extern WindowsAudioBackend *winAudioBackend; #ifdef _WIN32 #if PPSSPP_PLATFORM(UWP) -static int ScreenDPI() { - return 96; // TODO UWP +static float ScreenDPI() { + return 96.0f; // TODO UWP } #else -static int ScreenDPI() { +static float ScreenDPI() { HDC screenDC = GetDC(nullptr); int dotsPerInch = GetDeviceCaps(screenDC, LOGPIXELSY); ReleaseDC(nullptr, screenDC); - return dotsPerInch ? dotsPerInch : 96; + return dotsPerInch ? (float)dotsPerInch : 96.0f; } #endif #endif -static int ScreenRefreshRateHz() { - static int rate = 0; +static float ScreenRefreshRateHz() { + static float rate = 0.0f; static double lastCheck = 0.0; - double now = time_now_d(); + const double now = time_now_d(); if (!rate || lastCheck < now - 10.0) { lastCheck = now; DEVMODE lpDevMode{}; @@ -295,12 +295,12 @@ static int ScreenRefreshRateHz() { // TODO: Use QueryDisplayConfig instead (Win7+) so we can get fractional refresh rates correctly. if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &lpDevMode) == 0) { - rate = 60; // default value + rate = 60.0f; // default value } else { if (lpDevMode.dmFields & DM_DISPLAYFREQUENCY) { - rate = lpDevMode.dmDisplayFrequency > 60 ? lpDevMode.dmDisplayFrequency : 60; + rate = (float)(lpDevMode.dmDisplayFrequency > 60 ? lpDevMode.dmDisplayFrequency : 60); } else { - rate = 60; + rate = 60.0f; } } } @@ -340,9 +340,9 @@ int64_t System_GetPropertyInt(SystemProperty prop) { float System_GetPropertyFloat(SystemProperty prop) { switch (prop) { case SYSPROP_DISPLAY_REFRESH_RATE: - return (float)ScreenRefreshRateHz(); + return ScreenRefreshRateHz(); case SYSPROP_DISPLAY_DPI: - return (float)ScreenDPI(); + return ScreenDPI(); case SYSPROP_DISPLAY_SAFE_INSET_LEFT: case SYSPROP_DISPLAY_SAFE_INSET_RIGHT: case SYSPROP_DISPLAY_SAFE_INSET_TOP: @@ -480,7 +480,7 @@ void System_Notify(SystemNotification notification) { } } -std::wstring MakeFilter(std::wstring filter) { +static std::wstring MakeFilter(std::wstring filter) { for (size_t i = 0; i < filter.length(); i++) { if (filter[i] == '|') filter[i] = '\0'; @@ -651,7 +651,8 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string void System_AskForPermission(SystemPermission permission) {} PermissionStatus System_GetPermissionStatus(SystemPermission permission) { return PERMISSION_STATUS_GRANTED; } -void EnableCrashingOnCrashes() { +// Don't swallow exceptions. +static void EnableCrashingOnCrashes() { typedef BOOL (WINAPI *tGetPolicy)(LPDWORD lpFlags); typedef BOOL (WINAPI *tSetPolicy)(DWORD dwFlags); const DWORD EXCEPTION_SWALLOWING = 0x1; From ae1ee41eb05273f3d30d5eea8ef05e11f33100db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 3 May 2024 17:54:57 +0200 Subject: [PATCH 3/3] Add functionality to limit a pathbrowser to a specific root --- Common/File/Path.cpp | 3 +++ Common/File/PathBrowser.cpp | 20 +++++++++++++++++++- Common/File/PathBrowser.h | 12 ++++++------ Common/System/System.h | 4 ++++ Core/KeyMapDefaults.cpp | 2 +- UI/MainScreen.cpp | 8 ++++++-- UI/RemoteISOScreen.cpp | 5 +++-- ios/main.mm | 2 ++ 8 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Common/File/Path.cpp b/Common/File/Path.cpp index c9302437eb..4448dffe92 100644 --- a/Common/File/Path.cpp +++ b/Common/File/Path.cpp @@ -240,6 +240,9 @@ bool Path::FilePathContainsNoCase(std::string_view needle) const { } bool Path::StartsWith(const Path &other) const { + if (other.empty()) { + return true; + } if (type_ != other.type_) { // Bad return false; diff --git a/Common/File/PathBrowser.cpp b/Common/File/PathBrowser.cpp index 40689c0c9f..16e83a39bc 100644 --- a/Common/File/PathBrowser.cpp +++ b/Common/File/PathBrowser.cpp @@ -124,9 +124,15 @@ PathBrowser::~PathBrowser() { void PathBrowser::SetPath(const Path &path) { path_ = path; + ApplyRestriction(); HandlePath(); } +void PathBrowser::RestrictToRoot(const Path &root) { + INFO_LOG(SYSTEM, "Restricting to root: %s", root.c_str()); + restrictedRoot_ = root; +} + void PathBrowser::HandlePath() { if (!path_.empty() && path_.ToString()[0] == '!') { if (pendingActive_) @@ -203,7 +209,7 @@ bool PathBrowser::IsListingReady() { std::string PathBrowser::GetFriendlyPath() const { std::string str = GetPath().ToVisualString(); // Show relative to memstick root if there. - if (startsWith(str, aliasMatch_)) { + if (path_.StartsWith(aliasMatch_)) { return aliasDisplay_ + str.substr(aliasMatch_.size()); } @@ -229,12 +235,24 @@ bool PathBrowser::GetListing(std::vector &fileInfo, const char * return true; } +void PathBrowser::ApplyRestriction() { + if (!path_.StartsWith(restrictedRoot_) && !startsWith(path_.ToString(), "!")) { + WARN_LOG(SYSTEM, "Applying path restriction: %s (%s didn't match)", restrictedRoot_.c_str(), path_.c_str()); + path_ = restrictedRoot_; + } +} + bool PathBrowser::CanNavigateUp() { + if (path_ == restrictedRoot_) { + return false; + } return path_.CanNavigateUp(); } void PathBrowser::NavigateUp() { + _dbg_assert_(CanNavigateUp()); path_ = path_.NavigateUp(); + ApplyRestriction(); } // TODO: Support paths like "../../hello" diff --git a/Common/File/PathBrowser.h b/Common/File/PathBrowser.h index f6a8e782df..9e6435b59f 100644 --- a/Common/File/PathBrowser.h +++ b/Common/File/PathBrowser.h @@ -8,7 +8,6 @@ #include #include - #include "Common/File/DirListing.h" #include "Common/File/Path.h" @@ -18,7 +17,6 @@ class PathBrowser { public: PathBrowser() {} - PathBrowser(const Path &path) { SetPath(path); } ~PathBrowser(); void SetPath(const Path &path); @@ -41,11 +39,11 @@ public: void SetUserAgent(const std::string &s) { userAgent_ = s; } - void SetRootAlias(const std::string &alias, const std::string &longValue) { + void SetRootAlias(const std::string &alias, const Path &rootPath) { aliasDisplay_ = alias; - aliasMatch_ = longValue; + aliasMatch_ = rootPath; } - + void RestrictToRoot(const Path &root); bool empty() const { return path_.empty(); } @@ -53,12 +51,14 @@ public: private: void HandlePath(); void ResetPending(); + void ApplyRestriction(); Path path_; Path pendingPath_; + Path restrictedRoot_; std::string userAgent_; std::string aliasDisplay_; - std::string aliasMatch_; + Path aliasMatch_; std::vector pendingFiles_; std::condition_variable pendingCond_; std::mutex pendingLock_; diff --git a/Common/System/System.h b/Common/System/System.h index 763c31f517..96f6bed953 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -193,6 +193,10 @@ enum SystemProperty { SYSPROP_USER_DOCUMENTS_DIR, + // iOS app store limitation: The documents directory should be the only browsable directory. + // We'll not return true for this in non-app-store builds. + SYSPROP_LIMITED_FILE_BROWSING, + SYSPROP_OK_BUTTON_LEFT, SYSPROP_MAIN_WINDOW_HANDLE, diff --git a/Core/KeyMapDefaults.cpp b/Core/KeyMapDefaults.cpp index 3c08f2c94c..b0493a1c2b 100644 --- a/Core/KeyMapDefaults.cpp +++ b/Core/KeyMapDefaults.cpp @@ -352,7 +352,7 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) { switch (dmap) { case DEFAULT_MAPPING_KEYBOARD: { - int keyboardLayout = System_GetPropertyInt(SYSPROP_KEYBOARD_LAYOUT); + int keyboardLayout = (int)System_GetPropertyInt(SYSPROP_KEYBOARD_LAYOUT); switch (keyboardLayout) { case KEYBOARD_LAYOUT_QWERTZ: SetDefaultKeyMap(DEVICE_ID_KEYBOARD, defaultQwertzKeyboardKeyMap, ARRAY_SIZE(defaultQwertzKeyboardKeyMap), replace); diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index f0e2005bfe..751cf8cd5a 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -510,10 +510,14 @@ void DirButton::Draw(UIContext &dc) { } GameBrowser::GameBrowser(int token, const Path &path, BrowseFlags browseFlags, bool *gridStyle, ScreenManager *screenManager, std::string_view lastText, std::string_view lastLink, UI::LayoutParams *layoutParams) - : LinearLayout(UI::ORIENT_VERTICAL, layoutParams), path_(path), gridStyle_(gridStyle), browseFlags_(browseFlags), lastText_(lastText), lastLink_(lastLink), screenManager_(screenManager), token_(token) { + : LinearLayout(UI::ORIENT_VERTICAL, layoutParams), gridStyle_(gridStyle), browseFlags_(browseFlags), lastText_(lastText), lastLink_(lastLink), screenManager_(screenManager), token_(token) { using namespace UI; path_.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION)); - path_.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT).ToVisualString() + "/"); + path_.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT)); + if (System_GetPropertyBool(SYSPROP_LIMITED_FILE_BROWSING)) { + path_.RestrictToRoot(GetSysDirectory(DIRECTORY_MEMSTICK_ROOT)); + } + path_.SetPath(path); Refresh(); } diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index ccfb4e6d83..2d9b436100 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -253,10 +253,11 @@ bool RemoteISOConnectScreen::FindServer(std::string &resultHost, int &resultPort } static bool LoadGameList(const Path &url, std::vector &games) { - PathBrowser browser(url); + PathBrowser browser; + browser.SetPath(url); std::vector files; browser.SetUserAgent(StringFromFormat("PPSSPP/%s", PPSSPP_GIT_VERSION)); - browser.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT).ToVisualString() + "/"); + browser.SetRootAlias("ms:", GetSysDirectory(DIRECTORY_MEMSTICK_ROOT)); browser.GetListing(files, "iso:cso:chd:pbp:elf:prx:ppdmp:", &scanCancelled); if (scanCancelled) { return false; diff --git a/ios/main.mm b/ios/main.mm index 5be93aae33..0389d3452e 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -349,6 +349,8 @@ bool System_GetPropertyBool(SystemProperty prop) { #endif case SYSPROP_CAN_JIT: return g_jitAvailable; + case SYSPROP_LIMITED_FILE_BROWSING: + return false; // But will return true in app store builds. #ifndef HTTPS_NOT_AVAILABLE case SYSPROP_SUPPORTS_HTTPS: return true;