mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-18 11:54:30 +01:00
Eliminate GetSysDirectories and instead provide a new function: GetSysDirectory.
On Win32, call InitSysDirectories before the emuthread starts just to be safe.
This commit is contained in:
1 parent
533e219862
commit
c7bdeb3084
9 files changed
+77
-57
No files matched your search
+50
-17
@@ -360,17 +360,46 @@ CoreParameter &PSP_CoreParameter() {
|
||||
return coreParameter;
|
||||
}
|
||||
|
||||
std::string GetSysDirectory(PSPDirectories directoryType) {
|
||||
switch (directoryType) {
|
||||
case DIRECTORY_CHEATS:
|
||||
return g_Config.memCardDirectory + "/PSP/Cheats/";
|
||||
case DIRECTORY_GAME:
|
||||
return g_Config.memCardDirectory + "/PSP/GAME/";
|
||||
case DIRECTORY_SAVEDATA:
|
||||
return g_Config.memCardDirectory + "/PSP/SAVEDATA/";
|
||||
case DIRECTORY_SCREENSHOT:
|
||||
return g_Config.memCardDirectory + "/PSP/SCREENSHOT/";
|
||||
case DIRECTORY_SYSTEM:
|
||||
return g_Config.memCardDirectory + "/PSP/SYSTEM/";
|
||||
case DIRECTORY_PAUTH:
|
||||
return g_Config.memCardDirectory + "/PAUTH/";
|
||||
case DIRECTORY_FLASH0:
|
||||
return g_Config.flash0Directory;
|
||||
case DIRECTORY_MEMSTICK:
|
||||
return g_Config.memCardDirectory;
|
||||
// Just return the memory stick root if we run into some sort of problem.
|
||||
default:
|
||||
ERROR_LOG(FILESYS, "Unknown directory type.");
|
||||
return g_Config.memCardDirectory;
|
||||
}
|
||||
}
|
||||
|
||||
void GetSysDirectories(std::string &memstickpath, std::string &flash0path) {
|
||||
// Run this at startup time. Please use GetSysDirectory if you need to query where folders are.
|
||||
void InitSysDirectories() {
|
||||
|
||||
if (!g_Config.memCardDirectory.empty() && !g_Config.flash0Directory.empty())
|
||||
return;
|
||||
#ifdef _WIN32
|
||||
const std::string path = ConvertWStringToUTF8(File::GetExeDirectory());
|
||||
|
||||
// Mount a filesystem
|
||||
flash0path = path + "/flash0/";
|
||||
g_Config.flash0Directory = path + "/flash0/";
|
||||
|
||||
// Detect the "My Documents"(XP) or "Documents"(on Vista/7/8) folder.
|
||||
wchar_t myDocumentsPath[MAX_PATH];
|
||||
const HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocumentsPath);
|
||||
const std::string myDocsPath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/";
|
||||
|
||||
const std::string installedFile = path + "/installed.txt";
|
||||
const bool installed = File::Exists(installedFile);
|
||||
@@ -388,40 +417,44 @@ void GetSysDirectories(std::string &memstickpath, std::string &flash0path) {
|
||||
if (tempString.substr(0, 3) == "\xEF\xBB\xBF")
|
||||
tempString = tempString.substr(3);
|
||||
|
||||
memstickpath = tempString;
|
||||
g_Config.memCardDirectory = tempString;
|
||||
}
|
||||
inputFile.close();
|
||||
|
||||
// Check if the file is empty first, before appending the slash.
|
||||
if (memstickpath.empty())
|
||||
memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/";
|
||||
if (g_Config.memCardDirectory.empty())
|
||||
g_Config.memCardDirectory = myDocsPath;
|
||||
|
||||
size_t lastSlash = memstickpath.find_last_of("/");
|
||||
if (lastSlash != (memstickpath.length() - 1))
|
||||
memstickpath.append("/");
|
||||
size_t lastSlash = g_Config.memCardDirectory.find_last_of("/");
|
||||
if (lastSlash != (g_Config.memCardDirectory.length() - 1))
|
||||
g_Config.memCardDirectory.append("/");
|
||||
} else {
|
||||
memstickpath = path + "/memstick/";
|
||||
g_Config.memCardDirectory = path + "/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(memstickpath)) {
|
||||
if(!File::CreateDir(memstickpath))
|
||||
memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/";
|
||||
if (!File::Exists(g_Config.memCardDirectory)) {
|
||||
if (!File::CreateDir(g_Config.memCardDirectory))
|
||||
g_Config.memCardDirectory = myDocsPath;
|
||||
}
|
||||
|
||||
const std::string testFile = "/_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(memstickpath + testFile))
|
||||
memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/";
|
||||
if (!File::CreateEmptyFile(g_Config.memCardDirectory + testFile))
|
||||
g_Config.memCardDirectory = myDocsPath;
|
||||
|
||||
// Clean up our mess.
|
||||
if (File::Exists(memstickpath + testFile))
|
||||
File::Delete(memstickpath + testFile);
|
||||
if (File::Exists(g_Config.memCardDirectory + testFile))
|
||||
File::Delete(g_Config.memCardDirectory + testFile);
|
||||
|
||||
if (g_Config.currentDirectory.empty()) {
|
||||
g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME);
|
||||
}
|
||||
#else
|
||||
// TODO
|
||||
// TODO: Perhaps move your platforms' directory stuff out of NativeInit and into here.
|
||||
memstickpath = g_Config.memCardDirectory;
|
||||
flash0path = g_Config.flash0Directory;
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user