SDL buildfix, fix file/folder browsers on Darwin

This commit is contained in:
Henrik Rydgård committed 2023-03-22 19:25:35 +01:00
1 parent b7350f3cbf
commit dfa06c4e77
5 files changed
+48 -20

No files matched your search

+1 -1
View File
@@ -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;
+26 -7
View File
@@ -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 &param1, const std::string &param2, 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;
}
+1 -1
View File
@@ -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)
+3 -6
View File
@@ -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
+17 -5
View File
@@ -215,19 +215,31 @@ void System_SendMessage(const char *command, const char *parameter) {
bool System_MakeRequest(SystemRequestType type, int requestId, const std::string &param1, const std::string &param2, 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;