Move InitSysDirectories to where it belongs and rename it. Plus warning fixes.

This commit is contained in:
Henrik Rydgård 2023-08-18 12:48:57 +02:00
parent 6f6ea4595a
commit 44d602ca7d
7 changed files with 74 additions and 92 deletions

View File

@ -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";
}

View File

@ -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;

View File

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

View File

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

View File

@ -351,6 +351,4 @@ private:
// Debug stats.
double timeSteppingStarted_;
double timeSpentStepping_;
int lastVsync_ = -1;
};

View File

@ -738,6 +738,65 @@ std::vector<std::wstring> 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.

View File

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