From 482e989cd7134c6cf759e2ef0350941f5ade5dc4 Mon Sep 17 00:00:00 2001 From: Serena Date: Wed, 1 Feb 2023 19:03:12 +0300 Subject: [PATCH] convert to System_SendMessage insanity --- SDL/SDLMain.cpp | 16 +++++++++++++++- UI/DarwinFileSystemServices.h | 5 +---- UI/MainScreen.cpp | 16 ---------------- UI/NativeApp.cpp | 9 +++++++++ ios/main.mm | 8 ++++++++ 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 376bf89427..0a76076e09 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -58,6 +58,9 @@ SDLJoystick *joystick = NULL; #include "SDLGLGraphicsContext.h" #include "SDLVulkanGraphicsContext.h" +#if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) +#include "UI/DarwinFileSystemServices.h" +#endif GlobalUIState lastUIState = UISTATE_MENU; GlobalUIState GetUIState(); @@ -185,7 +188,18 @@ void System_SendMessage(const char *command, const char *parameter) { } else if (!strcmp(command, "audio_resetDevice")) { StopSDLAudioDevice(); InitSDLAudioDevice(); - } + } +#if PPSSPP_PLATFORM(MAC) || PPSSPP_PLATFORM(IOS) + else if (!strcmp(command, "browse_folder")) { + DarwinDirectoryPanelCallback callback = [] (Path thePathChosen) { + NativeMessageReceived("browse_folder", thePathChosen.c_str()); + }; + + DarwinFileSystemServices services; + services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectorites = */ true); + } +#endif + } void System_AskForPermission(SystemPermission permission) {} diff --git a/UI/DarwinFileSystemServices.h b/UI/DarwinFileSystemServices.h index 208d4dcf0a..f49d053d42 100644 --- a/UI/DarwinFileSystemServices.h +++ b/UI/DarwinFileSystemServices.h @@ -5,8 +5,7 @@ // Created by Serena on 20/01/2023. // -#ifndef DarwinFileSystemServices_h -#define DarwinFileSystemServices_h +#pragma once #include "ppsspp_config.h" #include "Common/File/Path.h" @@ -33,5 +32,3 @@ private: void *__pickerDelegate = NULL; #endif // PPSSPP_PLATFORM(IOS) }; - -#endif /* DarwinFileSystemServices_h */ diff --git a/UI/MainScreen.cpp b/UI/MainScreen.cpp index dd19d1b902..ed600b42d3 100644 --- a/UI/MainScreen.cpp +++ b/UI/MainScreen.cpp @@ -538,23 +538,7 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) { } UI::EventReturn GameBrowser::BrowseClick(UI::EventParams &e) { -#if PPSSPP_PLATFORM(IOS) || PPSSPP_PLATFORM(MAC) - DarwinDirectoryPanelCallback callback = [this] (Path thePathChosen) { - File::FileInfo info; - if (!File::GetFileInfo(thePathChosen, &info)) - return; - - if (info.isDirectory) - SetPath(thePathChosen); // user selected a dir, go there - else - LaunchFile(screenManager_, thePathChosen); // it's a file, try open it - }; - - DarwinFileSystemServices services; - services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectorites = */ true); -#else System_SendMessage("browse_folder", ""); -#endif return UI::EVENT_DONE; } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 6baed37ede..2ced18a168 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -1258,6 +1258,15 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) { else if (msg == "app_resumed" || msg == "got_focus") { // Assume that the user may have modified things. MemoryStick_NotifyWrite(); + } else if (msg == "browse_folder") { + Path thePath = Path(value); + File::FileInfo info; + if (!File::GetFileInfo(thePath, &info)) + return; + if (info.isDirectory) + NativeMessageReceived("browse_folderSelect", thePath.c_str()); + else + NativeMessageReceived("browse_fileSelect", thePath.c_str()); } } diff --git a/ios/main.mm b/ios/main.mm index b10db1a79c..49b35c50b0 100644 --- a/ios/main.mm +++ b/ios/main.mm @@ -20,6 +20,7 @@ #include "Common/System/System.h" #include "Common/StringUtils.h" #include "Common/Profiler/Profiler.h" +#include "UI/DarwinFileSystemServices.h" static int (*csops)(pid_t pid, unsigned int ops, void * useraddr, size_t usersize); static boolean_t (*exc_server)(mach_msg_header_t *, mach_msg_header_t *); @@ -201,6 +202,13 @@ 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_folder", thePathChosen.c_str()); + }; + + DarwinFileSystemServices services; + services.presentDirectoryPanel(callback, /* allowFiles = */ true, /* allowDirectorites = */ true); } }