From dfa06c4e777b30bd97e09a13c6f2f940e3438d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 22 Mar 2023 17:57:28 +0100 Subject: [PATCH] SDL buildfix, fix file/folder browsers on Darwin --- Common/File/Path.h | 2 +- SDL/SDLMain.cpp | 33 ++++++++++++++++++++++++++------- UI/DarwinFileSystemServices.mm | 2 +- UI/GameSettingsScreen.cpp | 9 +++------ ios/main.mm | 22 +++++++++++++++++----- 5 files changed, 48 insertions(+), 20 deletions(-) diff --git a/Common/File/Path.h b/Common/File/Path.h index aded7b5bde..b66471c53e 100644 --- a/Common/File/Path.h +++ b/Common/File/Path.h @@ -81,9 +81,9 @@ public: Path WithReplacedExtension(const std::string &oldExtension, const std::string &newExtension) const; Path WithReplacedExtension(const std::string &newExtension) const; - // Removes the last component. std::string GetFilename() const; // Really, GetLastComponent. Could be a file or directory. Includes the extension. std::string GetFileExtension() const; // Always lowercase return. Includes the dot. + // Removes the last component. std::string GetDirectory() const; const std::string &ToString() const; diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 7ac7ae1868..ad80509a44 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -24,10 +24,12 @@ SDLJoystick *joystick = NULL; #include "Common/System/Display.h" #include "Common/System/System.h" +#include "Common/System/Request.h" #include "Common/System/NativeApp.h" #include "ext/glslang/glslang/Public/ShaderLang.h" #include "Common/Data/Format/PNGLoad.h" #include "Common/Net/Resolve.h" +#include "Common/File/FileUtil.h" #include "NKCodeFromSDL.h" #include "Common/Math/math_util.h" #include "Common/GPU/OpenGL/GLRenderManager.h" @@ -168,20 +170,33 @@ void System_Vibrate(int length_ms) { bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { switch (type) { - case SystemRequestType::BROWSE_FOR_FOLDER: #if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) - DarwinDirectoryPanelCallback callback = [](bool success, Path thePathChosen) { + case SystemRequestType::BROWSE_FOR_FILE: + { + DarwinDirectoryPanelCallback callback = [requestId] (bool success, Path path) { if (success) { - g_requestManager.PostSystemSuccess(requestId, thePathChosen.c_str()); + g_requestManager.PostSystemSuccess(requestId, path.c_str()); } else { g_requestManager.PostSystemFailure(requestId); } }; DarwinFileSystemServices services; - services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ true); + services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false); return true; -#else - return false; + } + case SystemRequestType::BROWSE_FOR_FOLDER: + { + DarwinDirectoryPanelCallback callback = [requestId] (bool success, Path path) { + if (success) { + g_requestManager.PostSystemSuccess(requestId, path.c_str()); + } else { + g_requestManager.PostSystemFailure(requestId); + } + }; + DarwinFileSystemServices services; + services.presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true); + return true; + } #endif } return false; @@ -440,7 +455,11 @@ bool System_GetPropertyBool(SystemProperty prop) { return true; case SYSPROP_SUPPORTS_OPEN_FILE_IN_EDITOR: return true; // FileUtil.cpp: OpenFileInEditor - +#if PPSSPP_PLATFORM(MAC) + case SYSPROP_HAS_FOLDER_BROWSER: + case SYSPROP_HAS_FILE_BROWSER: + return true; +#endif default: return false; } diff --git a/UI/DarwinFileSystemServices.mm b/UI/DarwinFileSystemServices.mm index c89d039c15..b5006351db 100644 --- a/UI/DarwinFileSystemServices.mm +++ b/UI/DarwinFileSystemServices.mm @@ -59,7 +59,7 @@ void DarwinFileSystemServices::presentDirectoryPanel(DarwinDirectoryPanelCallbac NSModalResponse modalResponse = [panel runModal]; if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) { callback(true, Path(panel.URLs.firstObject.path.UTF8String)); - } else if (modalResponse == NSModalReponseCancel) { + } else if (modalResponse == NSModalResponseCancel) { callback(false, Path()); } #elif PPSSPP_PLATFORM(IOS) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 85cb888bf6..470efbca15 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1233,12 +1233,9 @@ UI::EventReturn GameSettingsScreen::OnJitAffectingSetting(UI::EventParams &e) { UI::EventReturn GameSettingsScreen::OnChangeMemStickDir(UI::EventParams &e) { #if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) - DarwinFileSystemServices memoryStickManager; - DarwinDirectoryPanelCallback callback = [] (Path thePathChosen) { - DarwinFileSystemServices::setUserPreferredMemoryStickDirectory(thePathChosen); - }; - - memoryStickManager.presentDirectoryPanel(callback); + System_BrowseForFolder("", [](const std::string &value, int) { + DarwinFileSystemServices::setUserPreferredMemoryStickDirectory(Path(value)); + }); #else screenManager()->push(new MemStickScreen(false)); #endif diff --git a/ios/main.mm b/ios/main.mm index a96ed3f49a..c879c0793d 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -215,19 +215,31 @@ void System_SendMessage(const char *command, const char *parameter) { bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { switch (type) { - case SystemRequestType::BROWSE_FOR_FOLDER: + case SystemRequestType::BROWSE_FOR_FILE: { - DarwinDirectoryPanelCallback callback = [] (bool success, Path thePathChosen) { + DarwinDirectoryPanelCallback callback = [requestId] (bool success, Path path) { if (success) { - g_requestManager.PostSystemSuccess(requestId, thePathChosen.c_str()); + g_requestManager.PostSystemSuccess(requestId, path.c_str()); } else { g_requestManager.PostSystemFailure(requestId); } }; DarwinFileSystemServices services; - services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ true); + services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ false); + return true; } - break; + case SystemRequestType::BROWSE_FOR_FOLDER: + { + DarwinDirectoryPanelCallback callback = [requestId] (bool success, Path path) { + if (success) { + g_requestManager.PostSystemSuccess(requestId, path.c_str()); + } else { + g_requestManager.PostSystemFailure(requestId); + } + }; + DarwinFileSystemServices services; + services.presentDirectoryPanel(callback, /* allowFiles = */ false, /* allowDirectories = */ true); + return true; } } return false;