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] 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.