diff --git a/Core/Util/PathUtil.cpp b/Core/Util/PathUtil.cpp index a82bc95fe6..a4e790a599 100644 --- a/Core/Util/PathUtil.cpp +++ b/Core/Util/PathUtil.cpp @@ -155,6 +155,10 @@ bool TryUpdateSavedPath(Path *path) { #if PPSSPP_PLATFORM(IOS) // DEBUG_LOG(Log::Loader, "Original path: %s", path->c_str()); std::string pathStr = path->ToString(); + if (startsWith(pathStr, "/private/var/mobile/Containers/Data/Application/")) { + // For in-application files only, strip off the /private prefix if present - it's sometimes there, sometimes not. + pathStr = pathStr.substr(8); + } const std::string_view applicationRoot = "/var/mobile/Containers/Data/Application/"; if (startsWith(pathStr, applicationRoot)) { diff --git a/UI/DarwinFileSystemServices.mm b/UI/DarwinFileSystemServices.mm index 3e844a10e3..28fbd393b0 100644 --- a/UI/DarwinFileSystemServices.mm +++ b/UI/DarwinFileSystemServices.mm @@ -54,16 +54,23 @@ void DarwinFileSystemServices::ClearDelegate() { } - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray *)urls { - std::string pathStr = urls[0].path.UTF8String; - // Strip /private prefix if present. - if (startsWith(pathStr, "/private/var/mobile/Containers/Data/Application/")) { - pathStr = pathStr.substr(8); + NSURL *url = urls.firstObject; + if (!url) { + self.panelCallback(false, Path()); + return; } - if (urls.count >= 1) - self.panelCallback(true, Path(pathStr)); - else + // 1. Start accessing the resource + BOOL success = [url startAccessingSecurityScopedResource]; + if (success) { + // 2. Pass the path to PPSSPP + // Note: In a real app, you'd want to call stopAccessingSecurityScopedResource + // when the game is closed, otherwise you "leak" kernel permissions. + self.panelCallback(true, Path(url.path.UTF8String)); + } else { + ERROR_LOG(Log::System, "Failed to start accessing security scoped resource for: %s", url.path.UTF8String); self.panelCallback(false, Path()); + } INFO_LOG(Log::System, "Callback processed, pre-emptively hide keyboard"); [sharedViewController hideKeyboard];