Core: More consistently use directory constants.

This commit is contained in:
Unknown W. Brackets 2018-09-02 10:27:11 -07:00
parent d1c5668612
commit d715ed8fba
5 changed files with 27 additions and 28 deletions

View File

@ -269,9 +269,11 @@ bool Delete(const std::string &filename) {
// Returns true if successful, or path already exists.
bool CreateDir(const std::string &path)
{
DEBUG_LOG(COMMON, "CreateDir('%s')", path.c_str());
std::string fn = path;
StripTailDirSlashes(fn);
DEBUG_LOG(COMMON, "CreateDir('%s')", fn.c_str());
#ifdef _WIN32
if (::CreateDirectory(ConvertUTF8ToWString(path).c_str(), NULL))
if (::CreateDirectory(ConvertUTF8ToWString(fn).c_str(), NULL))
return true;
DWORD error = GetLastError();
if (error == ERROR_ALREADY_EXISTS)
@ -282,25 +284,27 @@ bool CreateDir(const std::string &path)
ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %i", path.c_str(), error);
return false;
#else
if (mkdir(path.c_str(), 0755) == 0)
if (mkdir(fn.c_str(), 0755) == 0)
return true;
int err = errno;
if (err == EEXIST)
{
WARN_LOG(COMMON, "CreateDir: mkdir failed on %s: already exists", path.c_str());
WARN_LOG(COMMON, "CreateDir: mkdir failed on %s: already exists", fn.c_str());
return true;
}
ERROR_LOG(COMMON, "CreateDir: mkdir failed on %s: %s", path.c_str(), strerror(err));
ERROR_LOG(COMMON, "CreateDir: mkdir failed on %s: %s", fn.c_str(), strerror(err));
return false;
#endif
}
// Creates the full path of fullPath returns true on success
bool CreateFullPath(const std::string &fullPath)
bool CreateFullPath(const std::string &path)
{
std::string fullPath = path;
StripTailDirSlashes(fullPath);
int panicCounter = 100;
VERBOSE_LOG(COMMON, "CreateFullPath: path %s", fullPath.c_str());

View File

@ -410,13 +410,8 @@ namespace SaveState
}
fullDiscId = StringFromFormat("%s_%s", discId.c_str(), discVer.c_str());
std::string temp = StringFromFormat("ms0:/PSP/PPSSPP_STATE/%s_%d.%s", fullDiscId.c_str(), slot, extension);
std::string hostPath;
if (pspFileSystem.GetHostPath(temp, hostPath)) {
return hostPath;
} else {
return "";
}
std::string filename = StringFromFormat("%s_%d.%s", fullDiscId.c_str(), slot, extension);
return GetSysDirectory(DIRECTORY_SAVESTATE) + filename;
}
int GetCurrentSlot()
@ -878,7 +873,7 @@ namespace SaveState
void Init()
{
// Make sure there's a directory for save slots
pspFileSystem.MkDir("ms0:/PSP/PPSSPP_STATE");
File::CreateFullPath(GetSysDirectory(DIRECTORY_SAVESTATE));
std::lock_guard<std::mutex> guard(mutex);
rewindStates.Clear();

View File

@ -596,9 +596,9 @@ void InitSysDirectories() {
// expect a standard environment. Skipping THEME though, that's pointless.
File::CreateDir(g_Config.memStickDirectory + "PSP");
File::CreateDir(g_Config.memStickDirectory + "PSP/COMMON");
File::CreateDir(g_Config.memStickDirectory + "PSP/GAME");
File::CreateDir(g_Config.memStickDirectory + "PSP/SAVEDATA");
File::CreateDir(g_Config.memStickDirectory + "PSP/PPSSPP_STATE");
File::CreateDir(GetSysDirectory(DIRECTORY_GAME));
File::CreateDir(GetSysDirectory(DIRECTORY_SAVEDATA));
File::CreateDir(GetSysDirectory(DIRECTORY_SAVESTATE));
if (g_Config.currentDirectory.empty()) {
g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME);

View File

@ -398,7 +398,7 @@ void NewLanguageScreen::OnCompleted(DialogResult result) {
bool iniLoadedSuccessfully = false;
// Allow the lang directory to be overridden for testing purposes (e.g. Android, where it's hard to
// test new languages without recompiling the entire app, which is a hassle).
const std::string langOverridePath = g_Config.memStickDirectory + "PSP/SYSTEM/lang/";
const std::string langOverridePath = GetSysDirectory(DIRECTORY_SYSTEM) + "lang/";
// If we run into the unlikely case that "lang" is actually a file, just use the built-in translations.
if (!File::Exists(langOverridePath) || !File::IsDirectory(langOverridePath))

View File

@ -323,7 +323,7 @@ static void PostLoadConfig() {
// Allow the lang directory to be overridden for testing purposes (e.g. Android, where it's hard to
// test new languages without recompiling the entire app, which is a hassle).
const std::string langOverridePath = g_Config.memStickDirectory + "PSP/SYSTEM/lang/";
const std::string langOverridePath = GetSysDirectory(DIRECTORY_SYSTEM) + "lang/";
// If we run into the unlikely case that "lang" is actually a file, just use the built-in translations.
if (!File::Exists(langOverridePath) || !File::IsDirectory(langOverridePath))
@ -336,15 +336,15 @@ void CreateDirectoriesAndroid() {
// On Android, create a PSP directory tree in the external_dir,
// to hopefully reduce confusion a bit.
ILOG("Creating %s", (g_Config.memStickDirectory + "PSP").c_str());
File::CreateDir(g_Config.memStickDirectory + "PSP");
File::CreateDir(g_Config.memStickDirectory + "PSP/SAVEDATA");
File::CreateDir(g_Config.memStickDirectory + "PSP/PPSSPP_STATE");
File::CreateDir(g_Config.memStickDirectory + "PSP/GAME");
File::CreateDir(g_Config.memStickDirectory + "PSP/SYSTEM");
File::CreateFullPath(g_Config.memStickDirectory + "PSP");
File::CreateFullPath(GetSysDirectory(DIRECTORY_SAVEDATA));
File::CreateFullPath(GetSysDirectory(DIRECTORY_SAVESTATE));
File::CreateFullPath(GetSysDirectory(DIRECTORY_GAME));
File::CreateFullPath(GetSysDirectory(DIRECTORY_SYSTEM));
// Avoid media scanners in PPSSPP_STATE and SAVEDATA directories
File::CreateEmptyFile(g_Config.memStickDirectory + "PSP/PPSSPP_STATE/.nomedia");
File::CreateEmptyFile(g_Config.memStickDirectory + "PSP/SAVEDATA/.nomedia");
File::CreateEmptyFile(GetSysDirectory(DIRECTORY_SAVESTATE) + ".nomedia");
File::CreateEmptyFile(GetSysDirectory(DIRECTORY_SAVEDATA) + ".nomedia");
File::CreateEmptyFile(GetSysDirectory(DIRECTORY_SYSTEM) + ".nomedia");
}
@ -421,8 +421,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
#ifndef _WIN32
g_Config.AddSearchPath(user_data_path);
g_Config.AddSearchPath(g_Config.memStickDirectory + "PSP/SYSTEM/");
g_Config.SetDefaultPath(g_Config.memStickDirectory + "PSP/SYSTEM/");
g_Config.AddSearchPath(GetSysDirectory(DIRECTORY_SYSTEM));
g_Config.SetDefaultPath(GetSysDirectory(DIRECTORY_SYSTEM));
// Note that if we don't have storage permission here, loading the config will
// fail and it will be set to the default. Later, we load again when we get permission.