Don't log warnings on missing RA login secret. Also don't even check unless a username has been set.

This commit is contained in:
Henrik Rydgård 2023-09-06 10:34:32 +02:00
parent 828328b50d
commit cd79d120d8
3 changed files with 10 additions and 5 deletions

View File

@ -80,5 +80,7 @@ void NativeShutdown();
void PostLoadConfig();
void NativeSaveSecret(const char *nameOfSecret, const std::string &data);
// Returns false on failure. Shouldn't really happen, though.
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);

View File

@ -536,8 +536,8 @@ void Idle() {
if (g_rcClient && IsLoggedIn()) {
return; // All good.
}
if (!HasToken() || g_isLoggingIn) {
// Didn't login yet or is in the process of logging in. Also OK.
if (g_Config.sAchievementsUserName.empty() || g_isLoggingIn || !HasToken()) {
// Didn't try to login yet or is in the process of logging in. Also OK.
return;
}

View File

@ -1465,18 +1465,21 @@ static Path GetSecretPath(const char *nameOfSecret) {
}
// name should be simple alphanumerics to avoid problems on Windows.
void NativeSaveSecret(const char *nameOfSecret, const std::string &data) {
bool NativeSaveSecret(const char *nameOfSecret, const std::string &data) {
Path path = GetSecretPath(nameOfSecret);
if (!File::WriteDataToFile(false, data.data(), (unsigned int)data.size(), path)) {
WARN_LOG(SYSTEM, "Failed to write secret '%s' to path '%s'", nameOfSecret, path.c_str());
return false;
}
return true;
}
// On failure, returns an empty string. Good enough since any real secret is non-empty.
std::string NativeLoadSecret(const char *nameOfSecret) {
Path path = GetSecretPath(nameOfSecret);
std::string data;
if (!File::ReadFileToString(false, path, data)) {
WARN_LOG(SYSTEM, "Failed to read secret '%s' from path '%s'", nameOfSecret, path.c_str());
data.clear(); // just to be sure.
}
return data;
}