Blind convert iOS to the new folder picking path

This commit is contained in:
Henrik Rydgård 2023-03-22 16:20:30 +01:00
parent 9508ef467e
commit 49efa4499e
3 changed files with 26 additions and 11 deletions

View File

@ -12,7 +12,7 @@
#define PreferredMemoryStickUserDefaultsKey "UserPreferredMemoryStickDirectoryPath"
typedef std::function<void (Path)> DarwinDirectoryPanelCallback;
typedef std::function<void (bool, Path)> DarwinDirectoryPanelCallback;
/// A Class providing help functions to work with the FileSystem
/// on Darwin platforms.

View File

@ -33,7 +33,9 @@
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)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

View File

@ -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 &param1, const std::string &param2, 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;
}