mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
RetroAchievements: Cleanup better on login failure
This commit is contained in:
@@ -78,6 +78,9 @@ void NativeShutdown();
|
||||
void PostLoadConfig();
|
||||
|
||||
// Returns false on failure. Shouldn't really happen, though.
|
||||
bool NativeSaveSecret(const char *nameOfSecret, const std::string &data);
|
||||
bool NativeSaveSecret(std::string_view nameOfSecret, std::string_view data);
|
||||
inline bool NativeClearSecret(std::string_view nameOfSecret) {
|
||||
return NativeSaveSecret(nameOfSecret, "");
|
||||
}
|
||||
// On failure, returns an empty string. Good enough since any real secret is non-empty.
|
||||
std::string NativeLoadSecret(const char *nameOfSecret);
|
||||
std::string NativeLoadSecret(std::string_view nameOfSecret);
|
||||
|
||||
@@ -503,8 +503,19 @@ static void login_token_callback(int result, const char *error_message, rc_clien
|
||||
auto ac = GetI18NCategory(I18NCat::ACHIEVEMENTS);
|
||||
g_OSD.Show(OSDType::MESSAGE_WARNING, ac->T("Failed logging in to RetroAchievements"), "", g_RAImageID);
|
||||
}
|
||||
|
||||
// Clear the token.
|
||||
if (result == RC_INVALID_CREDENTIALS || result == RC_EXPIRED_TOKEN) {
|
||||
g_Config.sAchievementsUserName.clear();
|
||||
NativeClearSecret(RA_TOKEN_SECRET_NAME);
|
||||
g_loginResult = RC_OK;
|
||||
} else {
|
||||
g_loginResult = result;
|
||||
}
|
||||
|
||||
OnAchievementsLoginStateChange();
|
||||
break;
|
||||
g_isLoggingIn = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
g_loginResult = result;
|
||||
@@ -718,7 +729,7 @@ void Logout() {
|
||||
rc_client_logout(g_rcClient);
|
||||
// remove from config
|
||||
g_Config.sAchievementsUserName.clear();
|
||||
NativeSaveSecret(RA_TOKEN_SECRET_NAME, "");
|
||||
NativeClearSecret(RA_TOKEN_SECRET_NAME);
|
||||
g_Config.Save("Achievements logout");
|
||||
g_activeChallenges.clear();
|
||||
g_loginResult = RC_OK; // Allow trying again
|
||||
|
||||
+6
-4
@@ -1536,14 +1536,16 @@ void NativeShutdown() {
|
||||
// In the future, we might make this more sophisticated, such as storing in the app private directory on Android.
|
||||
// Right now we just store secrets in separate files next to ppsspp.ini. The important thing is keeping them out of it
|
||||
// since we often ask people to post or send the ini for debugging.
|
||||
static Path GetSecretPath(const char *nameOfSecret) {
|
||||
static Path GetSecretPath(std::string_view nameOfSecret) {
|
||||
return GetSysDirectory(DIRECTORY_SYSTEM) / ("ppsspp_" + std::string(nameOfSecret) + ".dat");
|
||||
}
|
||||
|
||||
// name should be simple alphanumerics to avoid problems on Windows.
|
||||
bool NativeSaveSecret(const char *nameOfSecret, const std::string &data) {
|
||||
bool NativeSaveSecret(std::string_view nameOfSecret, std::string_view data) {
|
||||
Path path = GetSecretPath(nameOfSecret);
|
||||
if (!File::WriteDataToFile(false, data.data(), data.size(), path)) {
|
||||
if (data.empty() && File::Exists(path)) {
|
||||
return File::Delete(path);
|
||||
} else if (!File::WriteDataToFile(false, data.data(), data.size(), path)) {
|
||||
WARN_LOG(Log::System, "Failed to write secret '%s' to path '%s'", nameOfSecret, path.c_str());
|
||||
return false;
|
||||
}
|
||||
@@ -1551,7 +1553,7 @@ bool NativeSaveSecret(const char *nameOfSecret, const std::string &data) {
|
||||
}
|
||||
|
||||
// On failure, returns an empty string. Good enough since any real secret is non-empty.
|
||||
std::string NativeLoadSecret(const char *nameOfSecret) {
|
||||
std::string NativeLoadSecret(std::string_view nameOfSecret) {
|
||||
Path path = GetSecretPath(nameOfSecret);
|
||||
std::string data;
|
||||
if (!File::ReadBinaryFileToString(path, &data)) {
|
||||
|
||||
@@ -348,6 +348,7 @@ void CGEDebugger::UpdatePrimPreview(u32 op, int which) {
|
||||
u16 minIndex = 0;
|
||||
u16 maxIndex = count - 1;
|
||||
if (!indices.empty()) {
|
||||
_dbg_assert_(count <= indices.size());
|
||||
minIndex = 0xFFFF;
|
||||
maxIndex = 0;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
|
||||
@@ -142,8 +142,8 @@ void System_AudioClear() {}
|
||||
void System_AudioPushSamples(const s32 *audio, int numSamples) {}
|
||||
|
||||
// TODO: To avoid having to define these here, these should probably be turned into system "requests".
|
||||
bool NativeSaveSecret(const char *nameOfSecret, const std::string &data) { return false; }
|
||||
std::string NativeLoadSecret(const char *nameOfSecret) {
|
||||
bool NativeSaveSecret(std::string_view nameOfSecret, std::string_view data) { return false; }
|
||||
std::string NativeLoadSecret(std::string_view nameOfSecret) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@@ -1962,7 +1962,7 @@ bool System_AudioRecordingState() { return false; }
|
||||
#endif
|
||||
|
||||
// TODO: To avoid having to define these here, these should probably be turned into system "requests".
|
||||
bool NativeSaveSecret(const char *nameOfSecret, const std::string &data) { return false; }
|
||||
std::string NativeLoadSecret(const char *nameOfSecret) {
|
||||
bool NativeSaveSecret(std::string_view nameOfSecret, std::string_view data) { return false; }
|
||||
std::string NativeLoadSecret(std::string_view nameOfSecret) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -108,8 +108,9 @@ void System_AudioClear() {}
|
||||
void System_AudioPushSamples(const s32 *audio, int numSamples) {}
|
||||
|
||||
// TODO: To avoid having to define these here, these should probably be turned into system "requests".
|
||||
bool NativeSaveSecret(const char *nameOfSecret, const std::string &data) { return false; }
|
||||
std::string NativeLoadSecret(const char *nameOfSecret) {
|
||||
// To clear the secret entirely, just save an empty string.
|
||||
bool NativeSaveSecret(std::string_view nameOfSecret, std::string_view data) { return false; }
|
||||
std::string NativeLoadSecret(std::string_view nameOfSecret) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user