diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 339d79b532..d9ba778f1b 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -131,6 +131,34 @@ EmuScreen::EmuScreen(const std::string &filename) OnDevMenu.Handle(this, &EmuScreen::OnDevTools); } +bool EmuScreen::bootAllowStorage(const std::string &filename) { + // No permissions needed. The easy life. + if (filename.find("http://") == 0 || filename.find("https://") == 0) + return true; + if (!System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) + return true; + + PermissionStatus status = System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE); + switch (status) { + case PERMISSION_STATUS_UNKNOWN: + System_AskForPermission(SYSTEM_PERMISSION_STORAGE); + return false; + + case PERMISSION_STATUS_DENIED: + stopRender_ = true; + screenManager()->switchScreen(new MainScreen()); + System_SendMessage("event", "failstartgame"); + return false; + + case PERMISSION_STATUS_PENDING: + // Keep waiting. + return false; + + case PERMISSION_STATUS_GRANTED: + return true; + } +} + void EmuScreen::bootGame(const std::string &filename) { if (PSP_IsIniting()) { std::string error_string; @@ -150,6 +178,10 @@ void EmuScreen::bootGame(const std::string &filename) { SetBackgroundAudioGame(""); + // Check permission status first, in case we came from a shortcut. + if (!bootAllowStorage(filename)) + return; + //pre-emptive loading of game specific config if possible, to get all the settings std::shared_ptr info = g_gameInfoCache->GetInfo(nullptr, filename, 0); if (info && !info->id.empty()) { diff --git a/UI/EmuScreen.h b/UI/EmuScreen.h index c5f95d515b..dd1fd0ee5c 100644 --- a/UI/EmuScreen.h +++ b/UI/EmuScreen.h @@ -54,6 +54,7 @@ protected: private: void bootGame(const std::string &filename); + bool bootAllowStorage(const std::string &filename); void bootComplete(); void renderUI(); void processAxis(const AxisInput &axis, int direction); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 8308e6fb00..7b7fc40e4d 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -444,11 +444,16 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch ILOG("Boot filename found in args: '%s'", argv[i]); bool okToLoad = true; + bool okToCheck = true; if (System_GetPropertyBool(SYSPROP_SUPPORTS_PERMISSIONS)) { PermissionStatus status = System_GetPermissionStatus(SYSTEM_PERMISSION_STORAGE); - if (status != PERMISSION_STATUS_GRANTED) { - ELOG("Storage permission not granted. Launching without argument."); + if (status == PERMISSION_STATUS_DENIED) { + ELOG("Storage permission denied. Launching without argument."); okToLoad = false; + okToCheck = false; + } else if (status != PERMISSION_STATUS_GRANTED) { + ELOG("Storage permission not granted. Launching without argument check."); + okToCheck = false; } else { ILOG("Storage permission granted."); } @@ -459,7 +464,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch boot_filename = ReplaceAll(boot_filename, "\\", "/"); #endif skipLogo = true; - + } + if (okToLoad && okToCheck) { std::unique_ptr fileLoader(ConstructFileLoader(boot_filename)); if (!fileLoader->Exists()) { fprintf(stderr, "File not found: %s\n", boot_filename.c_str());