From 44d602ca7dbe42be49bfd508fd3c18616261f26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 18 Aug 2023 12:48:57 +0200 Subject: [PATCH] Move InitSysDirectories to where it belongs and rename it. Plus warning fixes. --- Common/GPU/thin3d.cpp | 18 +++++----- Core/RetroAchievements.cpp | 2 +- Core/System.cpp | 68 -------------------------------------- Core/System.h | 4 --- GPU/GPUCommon.h | 2 -- Windows/main.cpp | 61 +++++++++++++++++++++++++++++++++- headless/Headless.cpp | 11 +++--- 7 files changed, 74 insertions(+), 92 deletions(-) diff --git a/Common/GPU/thin3d.cpp b/Common/GPU/thin3d.cpp index 6408a5f327..85b910aeff 100644 --- a/Common/GPU/thin3d.cpp +++ b/Common/GPU/thin3d.cpp @@ -770,15 +770,15 @@ const char *Bugs::GetBugName(uint32_t bug) { const char *PresentModeToString(PresentMode presentMode) { // All 8 possible cases, with three flags, for simplicity. - switch (presentMode) { - case (PresentMode)0: return "NONE"; - case PresentMode::FIFO: return "FIFO"; - case PresentMode::IMMEDIATE: return "IMMEDIATE"; - case PresentMode::MAILBOX: return "MAILBOX"; - case (PresentMode)((int)PresentMode::FIFO | (int)PresentMode::MAILBOX) : return "FIFO|MAILBOX"; - case (PresentMode)((int)PresentMode::FIFO | (int)PresentMode::IMMEDIATE) : return "FIFO|IMMEDIATE"; - case (PresentMode)((int)PresentMode::MAILBOX | (int)PresentMode::IMMEDIATE) : return "MAILBOX|IMMEDIATE"; // Not gonna happen - case (PresentMode)((int)PresentMode::FIFO | (int)PresentMode::MAILBOX | (int)PresentMode::IMMEDIATE) : return "FIFO|MAILBOX|IMMEDIATE"; + switch ((int)presentMode) { + case 0: return "NONE"; + case (int)PresentMode::FIFO: return "FIFO"; + case (int)PresentMode::IMMEDIATE: return "IMMEDIATE"; + case (int)PresentMode::MAILBOX: return "MAILBOX"; + case ((int)PresentMode::FIFO | (int)PresentMode::MAILBOX) : return "FIFO|MAILBOX"; + case ((int)PresentMode::FIFO | (int)PresentMode::IMMEDIATE) : return "FIFO|IMMEDIATE"; + case ((int)PresentMode::MAILBOX | (int)PresentMode::IMMEDIATE) : return "MAILBOX|IMMEDIATE"; // Not gonna happen + case ((int)PresentMode::FIFO | (int)PresentMode::MAILBOX | (int)PresentMode::IMMEDIATE) : return "FIFO|MAILBOX|IMMEDIATE"; default: return "INVALID"; } diff --git a/Core/RetroAchievements.cpp b/Core/RetroAchievements.cpp index 15740d6ce7..77f7008875 100644 --- a/Core/RetroAchievements.cpp +++ b/Core/RetroAchievements.cpp @@ -656,7 +656,7 @@ void identify_and_load_callback(int result, const char *error_message, rc_client char temp[512]; if (RC_OK == rc_client_game_get_image_url(gameInfo, temp, sizeof(temp))) { - Achievements::DownloadImageIfMissing(cacheId, std::move(std::string(temp))); + Achievements::DownloadImageIfMissing(cacheId, std::string(temp)); } g_OSD.Show(OSDType::MESSAGE_INFO, std::string(gameInfo->title), GetGameAchievementSummary(), cacheId, 5.0f); break; diff --git a/Core/System.cpp b/Core/System.cpp index bc8964e689..f1e4163974 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -707,74 +707,6 @@ Path GetSysDirectory(PSPDirectories directoryType) { } } -#if PPSSPP_PLATFORM(WINDOWS) -// Run this at startup time. Please use GetSysDirectory if you need to query where folders are. -void InitSysDirectories() { - if (!g_Config.memStickDirectory.empty() && !g_Config.flash0Directory.empty()) - return; - - const Path &exePath = File::GetExeDirectory(); - // Mount a filesystem - g_Config.flash0Directory = exePath / "assets/flash0"; - - // Detect the "My Documents"(XP) or "Documents"(on Vista/7/8) folder. -#if PPSSPP_PLATFORM(UWP) - // We set g_Config.memStickDirectory outside. - -#else - // Caller sets this to the Documents folder. - const Path rootMyDocsPath = g_Config.internalDataDirectory; - const Path myDocsPath = rootMyDocsPath / "PPSSPP"; - const Path installedFile = exePath / "installed.txt"; - const bool installed = File::Exists(installedFile); - - // If installed.txt exists(and we can determine the Documents directory) - if (installed && !rootMyDocsPath.empty()) { - FILE *fp = File::OpenCFile(installedFile, "rt"); - if (fp) { - char temp[2048]; - char *tempStr = fgets(temp, sizeof(temp), fp); - // Skip UTF-8 encoding bytes if there are any. There are 3 of them. - if (tempStr && strncmp(tempStr, "\xEF\xBB\xBF", 3) == 0) { - tempStr += 3; - } - std::string tempString = tempStr ? tempStr : ""; - if (!tempString.empty() && tempString.back() == '\n') - tempString.resize(tempString.size() - 1); - - g_Config.memStickDirectory = Path(tempString); - fclose(fp); - } - - // Check if the file is empty first, before appending the slash. - if (g_Config.memStickDirectory.empty()) - g_Config.memStickDirectory = myDocsPath; - } else { - g_Config.memStickDirectory = exePath / "memstick"; - } - - // Create the memstickpath before trying to write to it, and fall back on Documents yet again - // if we can't make it. - if (!File::Exists(g_Config.memStickDirectory)) { - if (!File::CreateDir(g_Config.memStickDirectory)) - g_Config.memStickDirectory = myDocsPath; - INFO_LOG(COMMON, "Memstick directory not present, creating at '%s'", g_Config.memStickDirectory.c_str()); - } - - Path testFile = g_Config.memStickDirectory / "_writable_test.$$$"; - - // If any directory is read-only, fall back to the Documents directory. - // We're screwed anyway if we can't write to Documents, or can't detect it. - if (!File::CreateEmptyFile(testFile)) - g_Config.memStickDirectory = myDocsPath; - - // Clean up our mess. - if (File::Exists(testFile)) - File::Delete(testFile); -#endif -} -#endif - void CreateSysDirectories() { // 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. diff --git a/Core/System.h b/Core/System.h index 8daad23755..e10a4f74ec 100644 --- a/Core/System.h +++ b/Core/System.h @@ -106,10 +106,6 @@ void UpdateLoadedFile(FileLoader *fileLoader); // they are not stored anywhere. Path GetSysDirectory(PSPDirectories directoryType); -#ifdef _WIN32 -void InitSysDirectories(); -#endif - void CreateSysDirectories(); // RUNNING must be at 0, NEXTFRAME must be at 1. diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 401572d380..ef7d9187ad 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -351,6 +351,4 @@ private: // Debug stats. double timeSteppingStarted_; double timeSpentStepping_; - - int lastVsync_ = -1; }; diff --git a/Windows/main.cpp b/Windows/main.cpp index 963deff0a0..efb5049490 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -738,6 +738,65 @@ std::vector GetWideCmdLine() { return wideArgs; } +static void InitMemstickDirectory() { + if (!g_Config.memStickDirectory.empty() && !g_Config.flash0Directory.empty()) + return; + + const Path &exePath = File::GetExeDirectory(); + // Mount a filesystem + g_Config.flash0Directory = exePath / "assets/flash0"; + + // Caller sets this to the Documents folder. + const Path rootMyDocsPath = g_Config.internalDataDirectory; + const Path myDocsPath = rootMyDocsPath / "PPSSPP"; + const Path installedFile = exePath / "installed.txt"; + const bool installed = File::Exists(installedFile); + + // If installed.txt exists(and we can determine the Documents directory) + if (installed && !rootMyDocsPath.empty()) { + FILE *fp = File::OpenCFile(installedFile, "rt"); + if (fp) { + char temp[2048]; + char *tempStr = fgets(temp, sizeof(temp), fp); + // Skip UTF-8 encoding bytes if there are any. There are 3 of them. + if (tempStr && strncmp(tempStr, "\xEF\xBB\xBF", 3) == 0) { + tempStr += 3; + } + std::string tempString = tempStr ? tempStr : ""; + if (!tempString.empty() && tempString.back() == '\n') + tempString.resize(tempString.size() - 1); + + g_Config.memStickDirectory = Path(tempString); + fclose(fp); + } + + // Check if the file is empty first, before appending the slash. + if (g_Config.memStickDirectory.empty()) + g_Config.memStickDirectory = myDocsPath; + } else { + g_Config.memStickDirectory = exePath / "memstick"; + } + + // Create the memstickpath before trying to write to it, and fall back on Documents yet again + // if we can't make it. + if (!File::Exists(g_Config.memStickDirectory)) { + if (!File::CreateDir(g_Config.memStickDirectory)) + g_Config.memStickDirectory = myDocsPath; + INFO_LOG(COMMON, "Memstick directory not present, creating at '%s'", g_Config.memStickDirectory.c_str()); + } + + Path testFile = g_Config.memStickDirectory / "_writable_test.$$$"; + + // If any directory is read-only, fall back to the Documents directory. + // We're screwed anyway if we can't write to Documents, or can't detect it. + if (!File::CreateEmptyFile(testFile)) + g_Config.memStickDirectory = myDocsPath; + + // Clean up our mess. + if (File::Exists(testFile)) + File::Delete(testFile); +} + static void WinMainInit() { CoInitializeEx(NULL, COINIT_MULTITHREADED); net::Init(); // This needs to happen before we load the config. So on Windows we also run it in Main. It's fine to call multiple times. @@ -821,7 +880,7 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin // On Win32 it makes more sense to initialize the system directories here // because the next place it was called was in the EmuThread, and it's too late by then. g_Config.internalDataDirectory = Path(W32Util::UserDocumentsPath()); - InitSysDirectories(); + InitMemstickDirectory(); CreateSysDirectories(); // Check for the Vulkan workaround before any serious init. diff --git a/headless/Headless.cpp b/headless/Headless.cpp index 24c98e0201..79aeed0eb5 100644 --- a/headless/Headless.cpp +++ b/headless/Headless.cpp @@ -496,21 +496,18 @@ int main(int argc, const char* argv[]) g_Config.iPSPModel = PSP_MODEL_SLIM; g_Config.iGlobalVolume = VOLUME_FULL; g_Config.iReverbVolume = VOLUME_FULL; - -#if PPSSPP_PLATFORM(WINDOWS) g_Config.internalDataDirectory.clear(); Path exePath = File::GetExeDirectory(); - // Mount a filesystem g_Config.flash0Directory = exePath / "assets/flash0"; + +#if PPSSPP_PLATFORM(WINDOWS) + // Mount a filesystem g_Config.memStickDirectory = exePath / "memstick"; File::CreateDir(g_Config.memStickDirectory); CreateSysDirectories(); -#endif - -#if !PPSSPP_PLATFORM(ANDROID) && !PPSSPP_PLATFORM(WINDOWS) +#elif !PPSSPP_PLATFORM(ANDROID) g_Config.memStickDirectory = Path(std::string(getenv("HOME"))) / ".ppsspp"; - g_Config.flash0Directory = executablePath / "assets/flash0"; #endif // Try to find the flash0 directory. Often this is from a subdirectory.