From 7a4efb1a0aa293e8b38e823585d471bc3362807e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 18 Aug 2023 12:56:38 +0200 Subject: [PATCH 1/4] Call CreateSysDirectories on all platforms. --- Core/System.cpp | 44 +++++++++++++++++++++++++++++++---------- Core/System.h | 2 +- UI/NativeApp.cpp | 51 ++++++------------------------------------------ 3 files changed, 41 insertions(+), 56 deletions(-) diff --git a/Core/System.cpp b/Core/System.cpp index f1e4163974..bb06f06c92 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -707,18 +707,42 @@ Path GetSysDirectory(PSPDirectories directoryType) { } } -void CreateSysDirectories() { +bool CreateSysDirectories() { +#if PPSSPP_PLATFORM(ANDROID) + const bool createNoMedia = true; +#else + const bool createNoMedia = false; +#endif + + Path pspDir = GetSysDirectory(DIRECTORY_PSP); + INFO_LOG(IO, "Creating '%s' and subdirs:", pspDir.c_str()); + File::CreateDir(pspDir); + if (!File::Exists(pspDir)) { + INFO_LOG(IO, "Not a workable memstick directory. Giving up"); + return false; + } + // Create the default directories that a real PSP creates. Good for homebrew so they can // expect a standard environment. Skipping THEME though, that's pointless. - File::CreateDir(GetSysDirectory(DIRECTORY_PSP)); - File::CreateDir(GetSysDirectory(DIRECTORY_PSP) / "COMMON"); - File::CreateDir(GetSysDirectory(DIRECTORY_GAME)); - File::CreateDir(GetSysDirectory(DIRECTORY_SAVEDATA)); - File::CreateDir(GetSysDirectory(DIRECTORY_SAVESTATE)); - File::CreateDir(GetSysDirectory(DIRECTORY_SYSTEM)); - File::CreateDir(GetSysDirectory(DIRECTORY_TEXTURES)); + static const PSPDirectories sysDirs[] = { + DIRECTORY_CHEATS, + DIRECTORY_SAVEDATA, + DIRECTORY_SAVESTATE, + DIRECTORY_GAME, + DIRECTORY_SYSTEM, + DIRECTORY_TEXTURES, + DIRECTORY_PLUGINS, + DIRECTORY_CACHE, + }; - if (g_Config.currentDirectory.empty()) { - g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME); + for (auto dir : sysDirs) { + Path path = GetSysDirectory(dir); + File::CreateFullPath(path); + if (createNoMedia) { + // Create a nomedia file in each specified subdirectory. + File::CreateEmptyFile(path / ".nomedia"); + } } + + return true; } diff --git a/Core/System.h b/Core/System.h index e10a4f74ec..c6bc27ffc1 100644 --- a/Core/System.h +++ b/Core/System.h @@ -106,7 +106,7 @@ void UpdateLoadedFile(FileLoader *fileLoader); // they are not stored anywhere. Path GetSysDirectory(PSPDirectories directoryType); -void CreateSysDirectories(); +bool CreateSysDirectories(); // RUNNING must be at 0, NEXTFRAME must be at 1. enum CoreState { diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index db9b8a5518..90c15b49b0 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -290,14 +290,15 @@ static bool CheckFontIsUsable(const wchar_t *fontFace) { } #endif -bool CreateDirectoriesAndroid(); - void PostLoadConfig() { - // On Windows, we deal with currentDirectory in InitSysDirectories(). #if !PPSSPP_PLATFORM(WINDOWS) if (g_Config.currentDirectory.empty()) { g_Config.currentDirectory = g_Config.defaultCurrentDirectory; } +#else + if (g_Config.currentDirectory.empty()) { + g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME); + } #endif // Allow the lang directory to be overridden for testing purposes (e.g. Android, where it's hard to @@ -310,51 +311,11 @@ void PostLoadConfig() { else g_i18nrepo.LoadIni(g_Config.sLanguageIni, langOverridePath); -#if PPSSPP_PLATFORM(ANDROID) - CreateDirectoriesAndroid(); +#if !PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP) + CreateSysDirectories(); #endif } -bool CreateDirectoriesAndroid() { - // TODO: We should probably simply use this as the shared function to create memstick directories. -#if PPSSPP_PLATFORM(ANDROID) - const bool createNoMedia = true; -#else - const bool createNoMedia = false; -#endif - - Path pspDir = GetSysDirectory(DIRECTORY_PSP); - - INFO_LOG(IO, "Creating '%s' and subdirs:", pspDir.c_str()); - File::CreateFullPath(pspDir); - if (!File::Exists(pspDir)) { - INFO_LOG(IO, "Not a workable memstick directory. Giving up"); - return false; - } - - static const PSPDirectories sysDirs[] = { - DIRECTORY_CHEATS, - DIRECTORY_SAVEDATA, - DIRECTORY_SAVESTATE, - DIRECTORY_GAME, - DIRECTORY_SYSTEM, - DIRECTORY_TEXTURES, - DIRECTORY_PLUGINS, - DIRECTORY_CACHE, - }; - - for (auto dir : sysDirs) { - Path path = GetSysDirectory(dir); - File::CreateFullPath(path); - if (createNoMedia) { - // Create a nomedia file in each specified subdirectory. - File::CreateEmptyFile(path / ".nomedia"); - } - } - - return true; -} - static void CheckFailedGPUBackends() { #ifdef _DEBUG // If you're in debug mode, you probably don't want a fallback. If you're in release mode, use IGNORE below. From e3b243f9d243e0fbe69d5be797005c65c521b6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 18 Aug 2023 14:02:59 +0200 Subject: [PATCH 2/4] Simplify current directory initialization, fix defaulting to home --- UI/NativeApp.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 90c15b49b0..db5e44fb03 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -291,15 +291,9 @@ static bool CheckFontIsUsable(const wchar_t *fontFace) { #endif void PostLoadConfig() { -#if !PPSSPP_PLATFORM(WINDOWS) if (g_Config.currentDirectory.empty()) { g_Config.currentDirectory = g_Config.defaultCurrentDirectory; } -#else - if (g_Config.currentDirectory.empty()) { - g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME); - } -#endif // Allow the lang directory to be overridden for testing purposes (e.g. Android, where it's hard to // test new languages without recompiling the entire app, which is a hassle). @@ -437,7 +431,12 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch #endif g_VFS.Register("", new DirectoryReader(Path(savegame_dir))); +#if !PPSSPP_PLATFORM(WINDOWS) g_Config.defaultCurrentDirectory = Path("/"); +#else + g_Config.defaultCurrentDirectory = GetSysDirectory(DIRECTORY_GAME); +#endif + #if !PPSSPP_PLATFORM(UWP) g_Config.internalDataDirectory = Path(savegame_dir); #endif @@ -537,11 +536,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch } #endif -#if (PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)) || PPSSPP_PLATFORM(MAC) if (g_Config.currentDirectory.empty()) { - g_Config.currentDirectory = Path("/"); + g_Config.currentDirectory = g_Config.defaultCurrentDirectory; } -#endif if (cache_dir && strlen(cache_dir)) { g_Config.appCacheDirectory = Path(cache_dir); From 5b76615463ea2dda1a67481338327bc5e224f141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 18 Aug 2023 15:04:20 +0200 Subject: [PATCH 3/4] Cleanup and more sensible defaults for current directory --- Common/System/System.h | 2 ++ Core/Config.cpp | 3 ++- SDL/SDLMain.cpp | 5 +++++ UI/NativeApp.cpp | 18 ++++++++---------- Windows/main.cpp | 2 ++ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Common/System/System.h b/Common/System/System.h index 9652c0d32a..1032411069 100644 --- a/Common/System/System.h +++ b/Common/System/System.h @@ -182,6 +182,8 @@ enum SystemProperty { SYSPROP_KEYBOARD_LAYOUT, SYSPROP_SKIP_UI, + + SYSPROP_USER_DOCUMENTS_DIR, }; enum class SystemNotification { diff --git a/Core/Config.cpp b/Core/Config.cpp index 2bffb81763..8494abb539 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -149,6 +149,7 @@ static bool DefaultCodeGen() { static bool DefaultVSync() { #if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(UWP) + ERROR_LOG(SYSTEM, "Default vsync true"); // Previously we didn't allow turning off vsync/FIFO on Android. Let's set the default accordingly. return true; #else @@ -1225,7 +1226,7 @@ bool Config::Save(const char *saveReason) { CleanRecent(); IniFile iniFile; if (!iniFile.Load(iniFilename_)) { - ERROR_LOG(LOADER, "Error saving config - can't read ini '%s'", iniFilename_.c_str()); + WARN_LOG(LOADER, "Likely saving config for first time - couldn't read ini '%s'", iniFilename_.c_str()); } // Need to do this somewhere... diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 86bd191316..3bc1bb9692 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -465,6 +465,11 @@ std::string System_GetProperty(SystemProperty prop) { } case SYSPROP_BUILD_VERSION: return PPSSPP_GIT_VERSION; + case SYSPROP_USER_DOCUMENTS_DIR: + { + const char *home = getenv("HOME"); + return home ? std::string(home) : "/"; + } default: return ""; } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index db5e44fb03..29a1c392c1 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -431,10 +431,10 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch #endif g_VFS.Register("", new DirectoryReader(Path(savegame_dir))); -#if !PPSSPP_PLATFORM(WINDOWS) - g_Config.defaultCurrentDirectory = Path("/"); +#if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(MAC) + g_Config.defaultCurrentDirectory = Path(System_GetProperty(SYSPROP_USER_DOCUMENTS_DIR)); #else - g_Config.defaultCurrentDirectory = GetSysDirectory(DIRECTORY_GAME); + g_Config.defaultCurrentDirectory = Path("/"); #endif #if !PPSSPP_PLATFORM(UWP) @@ -482,7 +482,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch // Attempt to create directories after reading the path. if (!System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) { - CreateDirectoriesAndroid(); + CreateSysDirectories(); } #elif PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) Path memstickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt"; @@ -510,7 +510,6 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse(); g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0"; #elif PPSSPP_PLATFORM(MAC) - g_Config.defaultCurrentDirectory = Path(getenv("HOME")); g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse(); g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0"; #elif PPSSPP_PLATFORM(SWITCH) @@ -805,6 +804,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch std::string sysName = System_GetProperty(SYSPROP_NAME); isOuya = KeyMap::IsOuya(sysName); + ERROR_LOG(G3D, "Backend: %d", g_Config.iGPUBackend); + // We do this here, instead of in NativeInitGraphics, because the display may be reset. // When it's reset we don't want to forget all our managed things. CheckFailedGPUBackends(); @@ -1213,15 +1214,12 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) { Core_SetPowerSaving(value != "false"); } else if (msg == "permission_granted" && value == "storage") { -#if PPSSPP_PLATFORM(ANDROID) - CreateDirectoriesAndroid(); -#endif + CreateSysDirectories(); // We must have failed to load the config before, so load it now to avoid overwriting the old config // with a freshly generated one. // NOTE: If graphics backend isn't what's in the config (due to error fallback, or not matching the default // and then getting permission), it will get out of sync. So we save and restore g_Config.iGPUBackend. - // Ideally we should simply reinitialize graphics to the mode from the config, but there are potential issues - // and I can't risk it before 1.9.0. + // Ideally we should simply reinitialize graphics to the mode from the config, but there are potential issues. int gpuBackend = g_Config.iGPUBackend; INFO_LOG(IO, "Reloading config after storage permission grant."); g_Config.Reload(); diff --git a/Windows/main.cpp b/Windows/main.cpp index 930fa40e6b..45007fa1f9 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -243,6 +243,8 @@ std::string System_GetProperty(SystemProperty prop) { return gpuDriverVersion; case SYSPROP_BUILD_VERSION: return PPSSPP_GIT_VERSION; + case SYSPROP_USER_DOCUMENTS_DIR: + return Path(W32Util::UserDocumentsPath()).ToString(); // this'll reverse the slashes. default: return ""; } From f3b2cb6fca80643a076b6e37a7653b0e338eb340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 18 Aug 2023 15:04:44 +0200 Subject: [PATCH 4/4] Remove outdated hack for vsync parameter on Android. --- Core/Config.cpp | 6 ------ UI/NativeApp.cpp | 4 +--- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 8494abb539..5f3742a8c7 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -149,7 +149,6 @@ static bool DefaultCodeGen() { static bool DefaultVSync() { #if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(UWP) - ERROR_LOG(SYSTEM, "Default vsync true"); // Previously we didn't allow turning off vsync/FIFO on Android. Let's set the default accordingly. return true; #else @@ -1198,11 +1197,6 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { CleanRecent(); -#if PPSSPP_PLATFORM(ANDROID) - // The on path here is untested, since we don't expose it. - g_Config.bVSync = false; -#endif - PostLoadCleanup(false); INFO_LOG(LOADER, "Config loaded: '%s'", iniFilename_.c_str()); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 29a1c392c1..7f544bdd1b 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -804,12 +804,10 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch std::string sysName = System_GetProperty(SYSPROP_NAME); isOuya = KeyMap::IsOuya(sysName); - ERROR_LOG(G3D, "Backend: %d", g_Config.iGPUBackend); - // We do this here, instead of in NativeInitGraphics, because the display may be reset. // When it's reset we don't want to forget all our managed things. CheckFailedGPUBackends(); - SetGPUBackend((GPUBackend) g_Config.iGPUBackend); + SetGPUBackend((GPUBackend)g_Config.iGPUBackend); renderCounter = 0; // Initialize retro achievements runtime.