Cleanup and more sensible defaults for current directory

This commit is contained in:
Henrik Rydgård 2023-08-18 15:04:20 +02:00
parent e3b243f9d2
commit 5b76615463
5 changed files with 19 additions and 11 deletions

View File

@ -182,6 +182,8 @@ enum SystemProperty {
SYSPROP_KEYBOARD_LAYOUT, SYSPROP_KEYBOARD_LAYOUT,
SYSPROP_SKIP_UI, SYSPROP_SKIP_UI,
SYSPROP_USER_DOCUMENTS_DIR,
}; };
enum class SystemNotification { enum class SystemNotification {

View File

@ -149,6 +149,7 @@ static bool DefaultCodeGen() {
static bool DefaultVSync() { static bool DefaultVSync() {
#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(UWP) #if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(UWP)
ERROR_LOG(SYSTEM, "Default vsync true");
// Previously we didn't allow turning off vsync/FIFO on Android. Let's set the default accordingly. // Previously we didn't allow turning off vsync/FIFO on Android. Let's set the default accordingly.
return true; return true;
#else #else
@ -1225,7 +1226,7 @@ bool Config::Save(const char *saveReason) {
CleanRecent(); CleanRecent();
IniFile iniFile; IniFile iniFile;
if (!iniFile.Load(iniFilename_)) { 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... // Need to do this somewhere...

View File

@ -465,6 +465,11 @@ std::string System_GetProperty(SystemProperty prop) {
} }
case SYSPROP_BUILD_VERSION: case SYSPROP_BUILD_VERSION:
return PPSSPP_GIT_VERSION; return PPSSPP_GIT_VERSION;
case SYSPROP_USER_DOCUMENTS_DIR:
{
const char *home = getenv("HOME");
return home ? std::string(home) : "/";
}
default: default:
return ""; return "";
} }

View File

@ -431,10 +431,10 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
#endif #endif
g_VFS.Register("", new DirectoryReader(Path(savegame_dir))); g_VFS.Register("", new DirectoryReader(Path(savegame_dir)));
#if !PPSSPP_PLATFORM(WINDOWS) #if PPSSPP_PLATFORM(WINDOWS) || PPSSPP_PLATFORM(MAC)
g_Config.defaultCurrentDirectory = Path("/"); g_Config.defaultCurrentDirectory = Path(System_GetProperty(SYSPROP_USER_DOCUMENTS_DIR));
#else #else
g_Config.defaultCurrentDirectory = GetSysDirectory(DIRECTORY_GAME); g_Config.defaultCurrentDirectory = Path("/");
#endif #endif
#if !PPSSPP_PLATFORM(UWP) #if !PPSSPP_PLATFORM(UWP)
@ -482,7 +482,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
// Attempt to create directories after reading the path. // Attempt to create directories after reading the path.
if (!System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) { if (!System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
CreateDirectoriesAndroid(); CreateSysDirectories();
} }
#elif PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__) #elif PPSSPP_PLATFORM(UWP) && !defined(__LIBRETRO__)
Path memstickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt"; Path memstickDirFile = g_Config.internalDataDirectory / "memstick_dir.txt";
@ -510,7 +510,6 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse(); g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse();
g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0"; g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0";
#elif PPSSPP_PLATFORM(MAC) #elif PPSSPP_PLATFORM(MAC)
g_Config.defaultCurrentDirectory = Path(getenv("HOME"));
g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse(); g_Config.memStickDirectory = DarwinFileSystemServices::appropriateMemoryStickDirectoryToUse();
g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0"; g_Config.flash0Directory = Path(std::string(external_dir)) / "flash0";
#elif PPSSPP_PLATFORM(SWITCH) #elif PPSSPP_PLATFORM(SWITCH)
@ -805,6 +804,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
std::string sysName = System_GetProperty(SYSPROP_NAME); std::string sysName = System_GetProperty(SYSPROP_NAME);
isOuya = KeyMap::IsOuya(sysName); isOuya = KeyMap::IsOuya(sysName);
ERROR_LOG(G3D, "Backend: %d", g_Config.iGPUBackend);
// We do this here, instead of in NativeInitGraphics, because the display may be reset. // 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. // When it's reset we don't want to forget all our managed things.
CheckFailedGPUBackends(); CheckFailedGPUBackends();
@ -1213,15 +1214,12 @@ void HandleGlobalMessage(const std::string &msg, const std::string &value) {
Core_SetPowerSaving(value != "false"); Core_SetPowerSaving(value != "false");
} }
else if (msg == "permission_granted" && value == "storage") { else if (msg == "permission_granted" && value == "storage") {
#if PPSSPP_PLATFORM(ANDROID) CreateSysDirectories();
CreateDirectoriesAndroid();
#endif
// We must have failed to load the config before, so load it now to avoid overwriting the old config // We must have failed to load the config before, so load it now to avoid overwriting the old config
// with a freshly generated one. // 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 // 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. // 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 // 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.
int gpuBackend = g_Config.iGPUBackend; int gpuBackend = g_Config.iGPUBackend;
INFO_LOG(IO, "Reloading config after storage permission grant."); INFO_LOG(IO, "Reloading config after storage permission grant.");
g_Config.Reload(); g_Config.Reload();

View File

@ -243,6 +243,8 @@ std::string System_GetProperty(SystemProperty prop) {
return gpuDriverVersion; return gpuDriverVersion;
case SYSPROP_BUILD_VERSION: case SYSPROP_BUILD_VERSION:
return PPSSPP_GIT_VERSION; return PPSSPP_GIT_VERSION;
case SYSPROP_USER_DOCUMENTS_DIR:
return Path(W32Util::UserDocumentsPath()).ToString(); // this'll reverse the slashes.
default: default:
return ""; return "";
} }