From 49efa4499e459d971ab2a1a1d6c0a23a4ff877aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 22 Mar 2023 16:20:30 +0100 Subject: [PATCH] Blind convert iOS to the new folder picking path --- UI/DarwinFileSystemServices.h | 2 +- UI/DarwinFileSystemServices.mm | 11 ++++++++--- ios/main.mm | 24 +++++++++++++++++------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/UI/DarwinFileSystemServices.h b/UI/DarwinFileSystemServices.h index f49d053d42..85a61a80c3 100644 --- a/UI/DarwinFileSystemServices.h +++ b/UI/DarwinFileSystemServices.h @@ -12,7 +12,7 @@ #define PreferredMemoryStickUserDefaultsKey "UserPreferredMemoryStickDirectoryPath" -typedef std::function DarwinDirectoryPanelCallback; +typedef std::function DarwinDirectoryPanelCallback; /// A Class providing help functions to work with the FileSystem /// on Darwin platforms. diff --git a/UI/DarwinFileSystemServices.mm b/UI/DarwinFileSystemServices.mm index 50d9f94ec6..c89d039c15 100644 --- a/UI/DarwinFileSystemServices.mm +++ b/UI/DarwinFileSystemServices.mm @@ -33,7 +33,9 @@ - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray *)urls { if (urls.count >= 1) - self.callback(Path(urls[0].path.UTF8String)); + self.callback(true, Path(urls[0].path.UTF8String)); + else + self.callback)false, Path()); } @end @@ -55,8 +57,11 @@ void DarwinFileSystemServices::presentDirectoryPanel(DarwinDirectoryPanelCallbac // panel.allowedFileTypes = @[(__bridge NSString *)kUTTypeFolder]; NSModalResponse modalResponse = [panel runModal]; - if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) - callback(Path(panel.URLs.firstObject.path.UTF8String)); + if (modalResponse == NSModalResponseOK && panel.URLs.firstObject) { + callback(true, Path(panel.URLs.firstObject.path.UTF8String)); + } else if (modalResponse == NSModalReponseCancel) { + callback(false, Path()); + } #elif PPSSPP_PLATFORM(IOS) UIViewController *rootViewController = UIApplication.sharedApplication .keyWindow diff --git a/ios/main.mm b/ios/main.mm index ca0684c074..a96ed3f49a 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -18,6 +18,7 @@ #include "Common/MemoryUtil.h" #include "Common/System/NativeApp.h" #include "Common/System/System.h" +#include "Common/System/Request.h" #include "Common/StringUtils.h" #include "Common/Profiler/Profiler.h" #include "UI/DarwinFileSystemServices.h" @@ -209,17 +210,26 @@ void System_SendMessage(const char *command, const char *parameter) { g_safeInsetTop = top; g_safeInsetBottom = bottom; } - } else if (!strcmp(command, "browse_folder")) { - DarwinDirectoryPanelCallback callback = [] (Path thePathChosen) { - NativeMessageReceived("browse_folderSelect", thePathChosen.c_str()); - }; - - DarwinFileSystemServices services; - services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectorites = */ true); } } bool System_MakeRequest(SystemRequestType type, int requestId, const std::string ¶m1, const std::string ¶m2, int param3) { + switch (type) { + case SystemRequestType::BROWSE_FOR_FOLDER: + { + DarwinDirectoryPanelCallback callback = [] (bool success, Path thePathChosen) { + if (success) { + g_requestManager.PostSystemSuccess(requestId, thePathChosen.c_str()); + } else { + g_requestManager.PostSystemFailure(requestId); + } + }; + DarwinFileSystemServices services; + services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectories = */ true); + } + break; + } + } return false; }