Skip to content

Commit e5662f6

Browse files
authored
Merge pull request #19213 from hrydgard/fix-recents-ios
iOS: Prevent the Recents list from disappearing a lot
2 parents a851e82 + 8691390 commit e5662f6

File tree

5 files changed

+59
-6
lines changed

5 files changed

+59
-6
lines changed

Common/File/FileUtil.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,9 @@ std::string ResolvePath(const std::string &path) {
340340
delete [] buf;
341341
return output;
342342

343+
#elif PPSSPP_PLATFORM(IOS)
344+
// Resolving has wacky effects on documents paths.
345+
return path;
343346
#else
344347
std::unique_ptr<char[]> buf(new char[PATH_MAX + 32768]);
345348
if (realpath(path.c_str(), buf.get()) == nullptr)
@@ -404,8 +407,8 @@ bool Exists(const Path &path) {
404407
SetErrorMode(OldMode);
405408
#endif
406409
return true;
407-
#else
408-
struct stat file_info;
410+
#else // !WIN32
411+
struct stat file_info{};
409412
return stat(path.c_str(), &file_info) == 0;
410413
#endif
411414
}

Common/GPU/Vulkan/VulkanLoader.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ void VulkanSetAvailable(bool available) {
381381
bool VulkanMayBeAvailable() {
382382
#if PPSSPP_PLATFORM(IOS)
383383
g_vulkanAvailabilityChecked = true;
384+
// MoltenVK does no longer seem to support iOS <= 12, despite what the docs say.
384385
g_vulkanMayBeAvailable = System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= 13;
385-
INFO_LOG(SYSTEM, "VulkanMayBeAvailable: Detected version: %d", (int)System_GetPropertyInt(SYSPROP_SYSTEMVERSION));
386386
return g_vulkanMayBeAvailable;
387387
#else
388388
// Unsupported in VR at the moment

Core/Config.cpp

+49-3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ static const char * const logSectionName = "LogDebug";
8181
static const char * const logSectionName = "Log";
8282
#endif
8383

84+
static bool TryUpdateSavedPath(Path *path);
85+
8486
std::string GPUBackendToString(GPUBackend backend) {
8587
switch (backend) {
8688
case GPUBackend::OPENGL:
@@ -1147,6 +1149,9 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
11471149

11481150
iRunCount++;
11491151

1152+
// For iOS, issue #19211
1153+
TryUpdateSavedPath(&currentDirectory);
1154+
11501155
// This check is probably not really necessary here anyway, you can always
11511156
// press Home or Browse if you're in a bad directory.
11521157
if (!File::Exists(currentDirectory))
@@ -1367,7 +1372,7 @@ bool Config::Save(const char *saveReason) {
13671372
playTimeTracker_.Save(playTime);
13681373

13691374
if (!iniFile.Save(iniFilename_)) {
1370-
ERROR_LOG(LOADER, "Error saving config (%s)- can't write ini '%s'", saveReason, iniFilename_.c_str());
1375+
ERROR_LOG(LOADER, "Error saving config (%s) - can't write ini '%s'", saveReason, iniFilename_.c_str());
13711376
return false;
13721377
}
13731378
INFO_LOG(LOADER, "Config saved (%s): '%s' (%0.1f ms)", saveReason, iniFilename_.c_str(), (time_now_d() - startTime) * 1000.0);
@@ -1546,6 +1551,34 @@ void Config::RemoveRecent(const std::string &file) {
15461551
recentIsos.erase(iter, recentIsos.end());
15471552
}
15481553

1554+
// On iOS, the path to the app documents directory changes on each launch.
1555+
// Example path:
1556+
// /var/mobile/Containers/Data/Application/0E0E89DE-8D8E-485A-860C-700D8BC87B86/Documents/PSP/GAME/SuicideBarbie
1557+
// The GUID part changes on each launch.
1558+
static bool TryUpdateSavedPath(Path *path) {
1559+
#if PPSSPP_PLATFORM(IOS)
1560+
INFO_LOG(LOADER, "Original path: %s", path->c_str());
1561+
std::string pathStr = path->ToString();
1562+
1563+
const std::string_view applicationRoot = "/var/mobile/Containers/Data/Application/";
1564+
if (startsWith(pathStr, applicationRoot)) {
1565+
size_t documentsPos = pathStr.find("/Documents/");
1566+
if (documentsPos == std::string::npos) {
1567+
return false;
1568+
}
1569+
std::string memstick = g_Config.memStickDirectory.ToString();
1570+
size_t memstickDocumentsPos = memstick.find("/Documents"); // Note: No trailing slash, or we won't find it.
1571+
*path = Path(memstick.substr(0, memstickDocumentsPos) + pathStr.substr(documentsPos));
1572+
return true;
1573+
} else {
1574+
// Path can't be auto-updated.
1575+
return false;
1576+
}
1577+
#else
1578+
return false;
1579+
#endif
1580+
}
1581+
15491582
void Config::CleanRecent() {
15501583
private_->SetRecentIsosThread([this] {
15511584
SetCurrentThreadName("RecentISOs");
@@ -1556,13 +1589,23 @@ void Config::CleanRecent() {
15561589

15571590
std::lock_guard<std::mutex> guard(private_->recentIsosLock);
15581591
std::vector<std::string> cleanedRecent;
1592+
if (recentIsos.empty()) {
1593+
INFO_LOG(LOADER, "No recents list found.");
1594+
}
1595+
15591596
for (size_t i = 0; i < recentIsos.size(); i++) {
15601597
bool exists = false;
15611598
Path path = Path(recentIsos[i]);
15621599
switch (path.Type()) {
15631600
case PathType::CONTENT_URI:
15641601
case PathType::NATIVE:
15651602
exists = File::Exists(path);
1603+
if (!exists) {
1604+
if (TryUpdateSavedPath(&path)) {
1605+
exists = File::Exists(path);
1606+
INFO_LOG(LOADER, "Exists=%d when checking updated path: %s", exists, path.c_str());
1607+
}
1608+
}
15661609
break;
15671610
default:
15681611
FileLoader *loader = ConstructFileLoader(path);
@@ -1572,11 +1615,14 @@ void Config::CleanRecent() {
15721615
}
15731616

15741617
if (exists) {
1618+
std::string pathStr = path.ToString();
15751619
// Make sure we don't have any redundant items.
1576-
auto duplicate = std::find(cleanedRecent.begin(), cleanedRecent.end(), recentIsos[i]);
1620+
auto duplicate = std::find(cleanedRecent.begin(), cleanedRecent.end(), pathStr);
15771621
if (duplicate == cleanedRecent.end()) {
1578-
cleanedRecent.push_back(recentIsos[i]);
1622+
cleanedRecent.push_back(pathStr);
15791623
}
1624+
} else {
1625+
DEBUG_LOG(LOADER, "Removed %s from recent. errno=%d", path.c_str(), errno);
15801626
}
15811627
}
15821628

ios/ViewController.mm

+2
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ - (void)shutdown
292292
{
293293
INFO_LOG(SYSTEM, "shutdown GL");
294294

295+
g_Config.Save("shutdown GL");
296+
295297
_dbg_assert_(graphicsContext);
296298
_dbg_assert_(sharedViewController != nil);
297299
sharedViewController = nil;

ios/ViewControllerMetal.mm

+2
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ - (void)shutdown
353353
{
354354
INFO_LOG(SYSTEM, "shutdown VK");
355355

356+
g_Config.Save("shutdown vk");
357+
356358
_dbg_assert_(sharedViewController != nil);
357359
sharedViewController = nil;
358360

0 commit comments

Comments
 (0)