Merge pull request #4198 from thedax/sysDirectoriesRevamp

Eliminate GetSysDirectories and instead provide a new function: GetSysDirectory.
This commit is contained in:
Henrik Rydgård 2013-10-15 03:18:45 -07:00
commit f68a672c0b
11 changed files with 78 additions and 71 deletions

View file

@ -29,8 +29,8 @@ static void __CheatStart() {
gameTitle = g_paramSFO.GetValueString("DISC_ID"); gameTitle = g_paramSFO.GetValueString("DISC_ID");
activeCheatFile = g_Config.memCardDirectory + "PSP/Cheats/" + gameTitle + ".ini"; activeCheatFile = GetSysDirectory(DIRECTORY_CHEATS) + gameTitle + ".ini";
File::CreateFullPath(g_Config.memCardDirectory + "PSP/Cheats"); File::CreateFullPath(GetSysDirectory(DIRECTORY_CHEATS));
if (!File::Exists(activeCheatFile)) { if (!File::Exists(activeCheatFile)) {
File::CreateEmptyFile(activeCheatFile); File::CreateEmptyFile(activeCheatFile);

View file

@ -448,15 +448,11 @@ void __IoInit() {
asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify); asyncNotifyEvent = CoreTiming::RegisterEvent("IoAsyncNotify", __IoAsyncNotify);
syncNotifyEvent = CoreTiming::RegisterEvent("IoSyncNotify", __IoSyncNotify); syncNotifyEvent = CoreTiming::RegisterEvent("IoSyncNotify", __IoSyncNotify);
std::string memstickpath; memstickSystem = new DirectoryFileSystem(&pspFileSystem, g_Config.memCardDirectory);
std::string flash0path;
GetSysDirectories(memstickpath, flash0path);
memstickSystem = new DirectoryFileSystem(&pspFileSystem, memstickpath);
#ifdef ANDROID #ifdef ANDROID
flash0System = new VFSFileSystem(&pspFileSystem, "flash0"); flash0System = new VFSFileSystem(&pspFileSystem, "flash0");
#else #else
flash0System = new DirectoryFileSystem(&pspFileSystem, flash0path); flash0System = new DirectoryFileSystem(&pspFileSystem, g_Config.flash0Directory);
#endif #endif
pspFileSystem.Mount("ms0:", memstickSystem); pspFileSystem.Mount("ms0:", memstickSystem);
pspFileSystem.Mount("fatms0:", memstickSystem); pspFileSystem.Mount("fatms0:", memstickSystem);

View file

@ -360,17 +360,42 @@ CoreParameter &PSP_CoreParameter() {
return 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/";
// 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) {
#ifdef _WIN32 #ifdef _WIN32
// 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;
const std::string path = ConvertWStringToUTF8(File::GetExeDirectory()); const std::string path = ConvertWStringToUTF8(File::GetExeDirectory());
// Mount a filesystem // Mount a filesystem
flash0path = path + "/flash0/"; g_Config.flash0Directory = path + "/flash0/";
// Detect the "My Documents"(XP) or "Documents"(on Vista/7/8) folder. // Detect the "My Documents"(XP) or "Documents"(on Vista/7/8) folder.
wchar_t myDocumentsPath[MAX_PATH]; wchar_t myDocumentsPath[MAX_PATH];
const HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, myDocumentsPath); 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 std::string installedFile = path + "/installed.txt";
const bool installed = File::Exists(installedFile); const bool installed = File::Exists(installedFile);
@ -388,41 +413,41 @@ void GetSysDirectories(std::string &memstickpath, std::string &flash0path) {
if (tempString.substr(0, 3) == "\xEF\xBB\xBF") if (tempString.substr(0, 3) == "\xEF\xBB\xBF")
tempString = tempString.substr(3); tempString = tempString.substr(3);
memstickpath = tempString; g_Config.memCardDirectory = tempString;
} }
inputFile.close(); inputFile.close();
// Check if the file is empty first, before appending the slash. // Check if the file is empty first, before appending the slash.
if (memstickpath.empty()) if (g_Config.memCardDirectory.empty())
memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; g_Config.memCardDirectory = myDocsPath;
size_t lastSlash = memstickpath.find_last_of("/"); size_t lastSlash = g_Config.memCardDirectory.find_last_of("/");
if (lastSlash != (memstickpath.length() - 1)) if (lastSlash != (g_Config.memCardDirectory.length() - 1))
memstickpath.append("/"); g_Config.memCardDirectory.append("/");
} else { } 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 // Create the memstickpath before trying to write to it, and fall back on Documents yet again
// if we can't make it. // if we can't make it.
if (!File::Exists(memstickpath)) { if (!File::Exists(g_Config.memCardDirectory)) {
if(!File::CreateDir(memstickpath)) if (!File::CreateDir(g_Config.memCardDirectory))
memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; g_Config.memCardDirectory = myDocsPath;
} }
const std::string testFile = "/_writable_test.$$$"; const std::string testFile = "/_writable_test.$$$";
// If any directory is read-only, fall back to the Documents directory. // 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. // We're screwed anyway if we can't write to Documents, or can't detect it.
if (!File::CreateEmptyFile(memstickpath + testFile)) if (!File::CreateEmptyFile(g_Config.memCardDirectory + testFile))
memstickpath = ConvertWStringToUTF8(myDocumentsPath) + "/PPSSPP/"; g_Config.memCardDirectory = myDocsPath;
// Clean up our mess. // Clean up our mess.
if (File::Exists(memstickpath + testFile)) if (File::Exists(g_Config.memCardDirectory + testFile))
File::Delete(memstickpath + testFile); File::Delete(g_Config.memCardDirectory + testFile);
#else
// TODO if (g_Config.currentDirectory.empty()) {
memstickpath = g_Config.memCardDirectory; g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME);
flash0path = g_Config.flash0Directory; }
#endif
} }
#endif

View file

@ -36,6 +36,15 @@ enum GlobalUIState {
UISTATE_EXIT, UISTATE_EXIT,
}; };
// Use these in conjunction with GetSysDirectory.
enum PSPDirectories {
DIRECTORY_CHEATS,
DIRECTORY_SCREENSHOT,
DIRECTORY_SYSTEM,
DIRECTORY_GAME,
DIRECTORY_SAVEDATA,
DIRECTORY_PAUTH,
};
extern GlobalUIState globalUIState; extern GlobalUIState globalUIState;
@ -58,7 +67,10 @@ void Audio_Init();
bool IsOnSeparateCPUThread(); bool IsOnSeparateCPUThread();
bool IsAudioInitialised(); bool IsAudioInitialised();
void GetSysDirectories(std::string &memstickpath, std::string &flash0path); std::string GetSysDirectory(PSPDirectories directoryType);
#ifdef _WIN32
void InitSysDirectories();
#endif
// RUNNING must be at 0, NEXTFRAME must be at 1. // RUNNING must be at 0, NEXTFRAME must be at 1.
enum CoreState enum CoreState

View file

@ -153,12 +153,10 @@ UI::EventReturn CwCheatScreen::OnImportCheat(UI::EventParams &params)
std::vector<std::string> title; std::vector<std::string> title;
bool finished = false, skip = false; bool finished = false, skip = false;
std::vector<std::string> newList; std::vector<std::string> newList;
#if defined(ANDROID) || defined(__SYMBIAN32__) || defined(BLACKBERRY) || defined(_WIN32)
std::string cheatDir = g_Config.memCardDirectory + "PSP/Cheats/cheat.db"; std::string cheatDir = GetSysDirectory(DIRECTORY_CHEATS) + "cheat.db";
is.open(cheatDir.c_str()); is.open(cheatDir.c_str());
#else
is.open("cheats/cheat.db");
#endif
while (is.good()) while (is.good())
{ {
getline(is, line); // get line from file getline(is, line); // get line from file

View file

@ -71,11 +71,10 @@ u64 GameInfo::GetGameSizeInBytes() {
} }
std::vector<std::string> GameInfo::GetSaveDataDirectories() { std::vector<std::string> GameInfo::GetSaveDataDirectories() {
std::string memc, flash; std::string memc = GetSysDirectory(DIRECTORY_SAVEDATA);
GetSysDirectories(memc, flash);
std::vector<FileInfo> dirs; std::vector<FileInfo> dirs;
getFilesInDir((memc + "PSP/SAVEDATA/").c_str(), &dirs); getFilesInDir(memc.c_str(), &dirs);
std::vector<std::string> directories; std::vector<std::string> directories;
for (size_t i = 0; i < dirs.size(); i++) { for (size_t i = 0; i < dirs.size(); i++) {

View file

@ -301,12 +301,6 @@ void PathBrowser::Navigate(const std::string &path) {
} }
} }
static std::string GetMemCardDirectory() {
std::string memCardDirectory, ignore;
GetSysDirectories(memCardDirectory, ignore);
return memCardDirectory;
}
class GameBrowser : public UI::LinearLayout { class GameBrowser : public UI::LinearLayout {
public: public:
GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle_, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = 0); GameBrowser(std::string path, bool allowBrowsing, bool *gridStyle_, std::string lastText, std::string lastLink, UI::LayoutParams *layoutParams = 0);
@ -350,7 +344,7 @@ UI::EventReturn GameBrowser::LastClick(UI::EventParams &e) {
} }
UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) { UI::EventReturn GameBrowser::HomeClick(UI::EventParams &e) {
path_.SetPath(GetMemCardDirectory()); path_.SetPath(g_Config.memCardDirectory);
g_Config.currentDirectory = path_.GetPath(); g_Config.currentDirectory = path_.GetPath();
Refresh(); Refresh();
return UI::EVENT_DONE; return UI::EVENT_DONE;
@ -497,7 +491,7 @@ void MainScreen::CreateViews() {
GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, true, &g_Config.bGridView2, GameBrowser *tabAllGames = new GameBrowser(g_Config.currentDirectory, true, &g_Config.bGridView2,
m->T("How to get games"), "http://www.ppsspp.org/getgames.html", m->T("How to get games"), "http://www.ppsspp.org/getgames.html",
new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); new LinearLayoutParams(FILL_PARENT, FILL_PARENT));
GameBrowser *tabHomebrew = new GameBrowser(GetMemCardDirectory() + "PSP/GAME/", false, &g_Config.bGridView3, GameBrowser *tabHomebrew = new GameBrowser(GetSysDirectory(DIRECTORY_GAME), false, &g_Config.bGridView3,
m->T("How to get homebrew & demos"), "http://www.ppsspp.org/gethomebrew.html", m->T("How to get homebrew & demos"), "http://www.ppsspp.org/gethomebrew.html",
new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); new LinearLayoutParams(FILL_PARENT, FILL_PARENT));

View file

@ -367,12 +367,6 @@ void NativeInit(int argc, const char *argv[],
if (!gfxLog) if (!gfxLog)
logman->SetLogLevel(LogTypes::G3D, LogTypes::LERROR); logman->SetLogLevel(LogTypes::G3D, LogTypes::LERROR);
INFO_LOG(BOOT, "Logger inited."); INFO_LOG(BOOT, "Logger inited.");
#else
if (g_Config.currentDirectory.empty()) {
g_Config.currentDirectory = ConvertWStringToUTF8(File::GetExeDirectory());
}
// TODO: Is this even needed, when PPSSPP uses GetSysDirectories in multiple other places?
g_Config.memCardDirectory = "memstick/";
#endif #endif
i18nrepo.LoadIni(g_Config.sLanguageIni); i18nrepo.LoadIni(g_Config.sLanguageIni);

View file

@ -86,15 +86,12 @@ unsigned int WINAPI TheThread(void *)
setCurrentThreadName("EmuThread"); setCurrentThreadName("EmuThread");
std::string memstick, flash0;
GetSysDirectories(memstick, flash0);
// Native overwrites host. Can't allow that. // Native overwrites host. Can't allow that.
Host *oldHost = host; Host *oldHost = host;
UpdateScreenScale(); UpdateScreenScale();
NativeInit(__argc, (const char **)__argv, memstick.c_str(), memstick.c_str(), "1234"); NativeInit(__argc, (const char **)__argv, "1234", "1234", "1234");
Host *nativeHost = host; Host *nativeHost = host;
host = oldHost; host = oldHost;

View file

@ -1127,20 +1127,11 @@ namespace MainWindow
break; break;
case ID_FILE_LOAD_MEMSTICK: case ID_FILE_LOAD_MEMSTICK:
{ BrowseAndBoot(GetSysDirectory(DIRECTORY_GAME));
std::string memStickDir, flash0dir;
GetSysDirectories(memStickDir, flash0dir);
memStickDir += "PSP\\GAME\\";
BrowseAndBoot(memStickDir);
}
break; break;
case ID_FILE_MEMSTICK: case ID_FILE_MEMSTICK:
{ ShellExecute(NULL, L"open", ConvertUTF8ToWString(g_Config.memCardDirectory).c_str(), 0, 0, SW_SHOW);
std::string memStickDir, flash0dir;
GetSysDirectories(memStickDir, flash0dir);
ShellExecuteA(NULL, "open", memStickDir.c_str(), 0, 0, SW_SHOW);
}
break; break;
case ID_TOGGLE_PAUSE: case ID_TOGGLE_PAUSE:

View file

@ -217,14 +217,15 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin
} }
} }
std::string memstickpath, flash0path; // On Win32 it makes more sense to initialize the system directories here
GetSysDirectories(memstickpath, flash0path); // because the next place it was called was in the EmuThread, and it's too late by then.
InitSysDirectories();
// Load config up here, because those changes below would be overwritten // Load config up here, because those changes below would be overwritten
// if it's not loaded here first. // if it's not loaded here first.
g_Config.AddSearchPath(""); g_Config.AddSearchPath("");
g_Config.AddSearchPath(memstickpath + "PSP/SYSTEM/"); g_Config.AddSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
g_Config.SetDefaultPath(memstickpath + "PSP/SYSTEM/"); g_Config.SetDefaultPath(GetSysDirectory(DIRECTORY_SYSTEM));
g_Config.Load(configFilename, controlsConfigFilename); g_Config.Load(configFilename, controlsConfigFilename);
// The rest is handled in NativeInit(). // The rest is handled in NativeInit().