mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
iOS: Try to avoid leaking file bookmarks. Don't try to install zips into iCloud folder.
This commit is contained in:
@@ -1495,6 +1495,12 @@ bool IsProbablyInDownloadsFolder(const Path &filename) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#if PPSSPP_PLATFORM(IOS)
|
||||
if (filename.FilePathContainsNoCase("com~apple~CloudDocs")) {
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return filename.FilePathContainsNoCase("download");
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "Common/Log.h"
|
||||
#include "Common/File/FileUtil.h"
|
||||
#include "Common/File/DirListing.h"
|
||||
#include "Core/Util/DarwinFileSystemServices.h"
|
||||
#include "Core/FileLoaders/LocalFileLoader.h"
|
||||
|
||||
#if PPSSPP_PLATFORM(ANDROID)
|
||||
@@ -77,23 +78,37 @@ LocalFileLoader::LocalFileLoader(const Path &filename)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_LIBRETRO_VFS)
|
||||
file_ = File::OpenCFile(filename, "rb");
|
||||
if (!file_) {
|
||||
ERROR_LOG(Log::FileSystem, "LocalFileLoader: failed to open file: '%s'", filename.c_str());
|
||||
return;
|
||||
}
|
||||
filesize_ = File::GetFileSize(file_);
|
||||
#elif PPSSPP_PLATFORM(IOS)
|
||||
if (!File::Exists(filename)) {
|
||||
// Try to "unlock" the path before the file loader hits it
|
||||
Path newFilename = DarwinFileSystemServices::reauthorizeBookmarkByPath(filename);
|
||||
if (!newFilename.empty()) {
|
||||
filename_ = newFilename;
|
||||
}
|
||||
}
|
||||
fd_ = open(filename_.c_str(), O_RDONLY | O_CLOEXEC);
|
||||
if (fd_ == -1) {
|
||||
ERROR_LOG(Log::FileSystem, "LocalFileLoader: failed to open file: '%s'", filename_.c_str());
|
||||
return;
|
||||
}
|
||||
DetectSizeFd();
|
||||
#elif !defined(_WIN32)
|
||||
|
||||
fd_ = open(filename.c_str(), O_RDONLY | O_CLOEXEC);
|
||||
if (fd_ == -1) {
|
||||
ERROR_LOG(Log::FileSystem, "LocalFileLoader: failed to open file: '%s'", filename.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
DetectSizeFd();
|
||||
|
||||
#else // _WIN32
|
||||
|
||||
const DWORD access = GENERIC_READ, share = FILE_SHARE_READ, mode = OPEN_EXISTING, flags = FILE_ATTRIBUTE_NORMAL;
|
||||
#if PPSSPP_PLATFORM(UWP)
|
||||
handle_ = CreateFile2FromAppW(filename.ToWString().c_str(), access, share, mode, nullptr);
|
||||
@@ -121,6 +136,9 @@ LocalFileLoader::~LocalFileLoader() {
|
||||
if (file_ != nullptr) {
|
||||
fclose(file_);
|
||||
}
|
||||
#elif PPSSPP_PLATFORM(IOS)
|
||||
close(fd_);
|
||||
DarwinFileSystemServices::stopAccessingPath(filename_);
|
||||
#elif !defined(_WIN32)
|
||||
if (fd_ != -1) {
|
||||
close(fd_);
|
||||
|
||||
+1
-9
@@ -58,15 +58,7 @@ FileLoader *ConstructFileLoader(const Path &filename) {
|
||||
}
|
||||
return new CachingFileLoader(baseLoader);
|
||||
}
|
||||
#if PPSSPP_PLATFORM(IOS)
|
||||
if (!File::Exists(filename)) {
|
||||
// Try to "unlock" the path before the file loader hits it
|
||||
Path newFilename = DarwinFileSystemServices::reauthorizeBookmarkByPath(filename);
|
||||
if (!newFilename.empty()) {
|
||||
return new LocalFileLoader(newFilename);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return new LocalFileLoader(filename);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,8 @@ static void addBookmark(NSURL *url);
|
||||
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.
|
||||
// You should call stopAccessingSecurityScopedResource
|
||||
// when the file 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);
|
||||
@@ -139,6 +139,7 @@ static void addBookmark(NSURL *url) {
|
||||
if (accessStarted) [url stopAccessingSecurityScopedResource];
|
||||
}
|
||||
}
|
||||
|
||||
Path DarwinFileSystemServices::reauthorizeBookmarkByPath(const Path &pathStr) {
|
||||
INFO_LOG(Log::System, "Darwin: Reauthorizing [%s]", pathStr.c_str());
|
||||
|
||||
@@ -207,7 +208,7 @@ void DarwinFileSystemServices::stopAccessingPath(const Path &pathStr) {
|
||||
[url stopAccessingSecurityScopedResource];
|
||||
|
||||
activeAccessTokens.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DarwinFileSystemServices::terminate() {
|
||||
|
||||
Reference in New Issue
Block a user