Merge pull request #17928 from hrydgard/unify-path-creation

Unify memstick PSP/subdirectory creation
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2023-08-18 15:40:39 +02:00
commit d8f8dcbc17
7 files changed
+57 -75

No files matched your search

+2
View File
@@ -182,6 +182,8 @@ enum SystemProperty {
SYSPROP_KEYBOARD_LAYOUT,
SYSPROP_SKIP_UI,
SYSPROP_USER_DOCUMENTS_DIR,
};
enum class SystemNotification {
+1 -6
View File
@@ -1203,11 +1203,6 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
CleanRecent();
#if PPSSPP_PLATFORM(ANDROID)
// The on path here is untested, since we don't expose it.
g_Config.bVSync = false;
#endif
PostLoadCleanup(false);
INFO_LOG(LOADER, "Config loaded: '%s'", iniFilename_.c_str());
@@ -1231,7 +1226,7 @@ bool Config::Save(const char *saveReason) {
CleanRecent();
IniFile iniFile;
if (!iniFile.Load(iniFilename_)) {
ERROR_LOG(LOADER, "Error saving config - can't read ini '%s'", iniFilename_.c_str());
WARN_LOG(LOADER, "Likely saving config for first time - couldn't read ini '%s'", iniFilename_.c_str());
}
// Need to do this somewhere...
+34 -10
View File
@@ -707,18 +707,42 @@ Path GetSysDirectory(PSPDirectories directoryType) {
}
}
void CreateSysDirectories() {
bool CreateSysDirectories() {
#if PPSSPP_PLATFORM(ANDROID)
const bool createNoMedia = true;
#else
const bool createNoMedia = false;
#endif
Path pspDir = GetSysDirectory(DIRECTORY_PSP);
INFO_LOG(IO, "Creating '%s' and subdirs:", pspDir.c_str());
File::CreateDir(pspDir);
if (!File::Exists(pspDir)) {
INFO_LOG(IO, "Not a workable memstick directory. Giving up");
return false;
}
// 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.
File::CreateDir(GetSysDirectory(DIRECTORY_PSP));
File::CreateDir(GetSysDirectory(DIRECTORY_PSP) / "COMMON");
File::CreateDir(GetSysDirectory(DIRECTORY_GAME));
File::CreateDir(GetSysDirectory(DIRECTORY_SAVEDATA));
File::CreateDir(GetSysDirectory(DIRECTORY_SAVESTATE));
File::CreateDir(GetSysDirectory(DIRECTORY_SYSTEM));
File::CreateDir(GetSysDirectory(DIRECTORY_TEXTURES));
static const PSPDirectories sysDirs[] = {
DIRECTORY_CHEATS,
DIRECTORY_SAVEDATA,
DIRECTORY_SAVESTATE,
DIRECTORY_GAME,
DIRECTORY_SYSTEM,
DIRECTORY_TEXTURES,
DIRECTORY_PLUGINS,
DIRECTORY_CACHE,
};
if (g_Config.currentDirectory.empty()) {
g_Config.currentDirectory = GetSysDirectory(DIRECTORY_GAME);
for (auto dir : sysDirs) {
Path path = GetSysDirectory(dir);
File::CreateFullPath(path);
if (createNoMedia) {
// Create a nomedia file in each specified subdirectory.
File::CreateEmptyFile(path / ".nomedia");
}
}
return true;
}
+1 -1
View File
@@ -106,7 +106,7 @@ void UpdateLoadedFile(FileLoader *fileLoader);
// they are not stored anywhere.
Path GetSysDirectory(PSPDirectories directoryType);
void CreateSysDirectories();
bool CreateSysDirectories();
// RUNNING must be at 0, NEXTFRAME must be at 1.
enum CoreState {
+5
View File
@@ -465,6 +465,11 @@ std::string System_GetProperty(SystemProperty prop) {
}
case SYSPROP_BUILD_VERSION:
return PPSSPP_GIT_VERSION;
case SYSPROP_USER_DOCUMENTS_DIR:
{
const char *home = getenv("HOME");
return home ? std::string(home) : "/";
}
default:
return "";
}
+12 -58
View File
@@ -290,15 +290,10 @@ static bool CheckFontIsUsable(const wchar_t *fontFace) {
}
#endif
bool CreateDirectoriesAndroid();
void PostLoadConfig() {
// On Windows, we deal with currentDirectory in InitSysDirectories().
#if !PPSSPP_PLATFORM(WINDOWS)
if (g_Config.currentDirectory.empty()) {
g_Config.currentDirectory = g_Config.defaultCurrentDirectory;
}
#endif
// 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).
@@ -310,51 +305,11 @@ void PostLoadConfig() {
else
g_i18nrepo.LoadIni(g_Config.sLanguageIni, langOverridePath);
#if PPSSPP_PLATFORM(ANDROID)
CreateDirectoriesAndroid();
#if !PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)
CreateSysDirectories();
#endif
}
bool CreateDirectoriesAndroid() {
// TODO: We should probably simply use this as the shared function to create memstick directories.
#if PPSSPP_PLATFORM(ANDROID)
const bool createNoMedia = true;
#else
const bool createNoMedia = false;
#endif
Path pspDir = GetSysDirectory(DIRECTORY_PSP);
INFO_LOG(IO, "Creating '%s' and subdirs:", pspDir.c_str());
File::CreateFullPath(pspDir);
if (!File::Exists(pspDir)) {
INFO_LOG(IO, "Not a workable memstick directory. Giving up");
return false;
}
static const PSPDirectories sysDirs[] = {
DIRECTORY_CHEATS,
DIRECTORY_SAVEDATA,
DIRECTORY_SAVESTATE,
DIRECTORY_GAME,
DIRECTORY_SYSTEM,
DIRECTORY_TEXTURES,
DIRECTORY_PLUGINS,
DIRECTORY_CACHE,
};
for (auto dir : sysDirs) {
Path path = GetSysDirectory(dir);
File::CreateFullPath(path);
if (createNoMedia) {
// Create a nomedia file in each specified subdirectory.
File::CreateEmptyFile(path / ".nomedia");
}
}
return true;
}
static void CheckFailedGPUBackends() {
#ifdef _DEBUG
// If you're in debug mode, you probably don't want a fallback. If you're in release mode, use IGNORE below.
@@ -476,7 +431,12 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
#endif
g_VFS.Register("", new DirectoryReader(Path(savegame_dir)));
#if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(MAC)
g_Config.defaultCurrentDirectory = Path(System_GetProperty(SYSPROP_USER_DOCUMENTS_DIR));
#else
g_Config.defaultCurrentDirectory = Path("/");
#endif
#if !PPSSPP_PLATFORM(UWP)
g_Config.internalDataDirectory = Path(savegame_dir);
#endif
@@ -522,7 +482,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
// Attempt to create directories after reading the path.
if (!System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
CreateDirectoriesAndroid();
CreateSysDirectories();
}
#elif PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__)
Path memstickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt";
@@ -550,7 +510,6 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse();
g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0";
#elif PPSSPP_PLATFORM(MAC)
g_Config.defaultCurrentDirectory = Path(getenv("HOME"));
g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse();
g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0";
#elif PPSSPP_PLATFORM(SWITCH)
@@ -576,11 +535,9 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
}
#endif
#if (PPSSPP_PLATFORM(WINDOWS) && !PPSSPP_PLATFORM(UWP)) || PPSSPP_PLATFORM(MAC)
if (g_Config.currentDirectory.empty()) {
g_Config.currentDirectory = Path("/");
g_Config.currentDirectory = g_Config.defaultCurrentDirectory;
}
#endif
if (cache_dir && strlen(cache_dir)) {
g_Config.appCacheDirectory = Path(cache_dir);
@@ -850,7 +807,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
// We do this here, instead of in NativeInitGraphics, because the display may be reset.
// When it's reset we don't want to forget all our managed things.
CheckFailedGPUBackends();
SetGPUBackend((GPUBackend) g_Config.iGPUBackend);
SetGPUBackend((GPUBackend)g_Config.iGPUBackend);
renderCounter = 0;
// Initialize retro achievements runtime.
@@ -1255,15 +1212,12 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) {
Core_SetPowerSaving(value != "false");
}
else if (msg == "permission_granted" && value == "storage") {
#if PPSSPP_PLATFORM(ANDROID)
CreateDirectoriesAndroid();
#endif
CreateSysDirectories();
// We must have failed to load the config before, so load it now to avoid overwriting the old config
// with a freshly generated one.
// NOTE: If graphics backend isn't what's in the config (due to error fallback, or not matching the default
// and then getting permission), it will get out of sync. So we save and restore g_Config.iGPUBackend.
// Ideally we should simply reinitialize graphics to the mode from the config, but there are potential issues
// and I can't risk it before 1.9.0.
// Ideally we should simply reinitialize graphics to the mode from the config, but there are potential issues.
int gpuBackend = g_Config.iGPUBackend;
INFO_LOG(IO, "Reloading config after storage permission grant.");
g_Config.Reload();
+2
View File
@@ -243,6 +243,8 @@ std::string System_GetProperty(SystemProperty prop) {
return gpuDriverVersion;
case SYSPROP_BUILD_VERSION:
return PPSSPP_GIT_VERSION;
case SYSPROP_USER_DOCUMENTS_DIR:
return Path(W32Util::UserDocumentsPath()).ToString(); // this'll reverse the slashes.
default:
return "";
}