From bf3acd9208319ed5431fe80ab63a2ab1be89faf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 11 Jul 2023 10:16:58 +0200 Subject: [PATCH] Fix some minor login issues, center login dialog on Windows. --- Core/RetroAchievements.cpp | 14 +++++++++++--- Windows/InputBox.cpp | 31 ++++++++++++++++--------------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/Core/RetroAchievements.cpp b/Core/RetroAchievements.cpp index 3b080cbfaf..dcfd8fa320 100644 --- a/Core/RetroAchievements.cpp +++ b/Core/RetroAchievements.cpp @@ -355,9 +355,14 @@ void Initialize() { INFO_LOG(ACHIEVEMENTS, "Achievements are disabled, not initializing."); return; } - _assert_msg_(g_Config.bAchievementsEnable, "Achievements are enabled"); + _assert_msg_(!g_rcClient, "Achievements already initialized"); g_rcClient = rc_client_create(read_memory_callback, server_call_callback); + if (!g_rcClient) { + // Shouldn't happen really. + return; + } + // Provide a logging function to simplify debugging rc_client_enable_logging(g_rcClient, RC_CLIENT_LOG_LEVEL_VERBOSE, log_message_callback); @@ -370,6 +375,8 @@ void Initialize() { if (!api_token.empty()) { rc_client_begin_login_with_token(g_rcClient, g_Config.sAchievementsUserName.c_str(), api_token.c_str(), &login_token_callback, nullptr); } + + INFO_LOG(ACHIEVEMENTS, "Achievements initialized."); } static void login_password_callback(int result, const char *error_message, rc_client_t *client, void *userdata) { @@ -416,13 +423,13 @@ void Logout() { } void UpdateSettings() { - if (!g_Config.bAchievementsEnable) { + if (g_rcClient && !g_Config.bAchievementsEnable) { // we're done here Shutdown(); return; } - if (!g_rcClient) { + if (!g_rcClient && g_Config.bAchievementsEnable) { // we just got enabled. Initialize(); } @@ -432,6 +439,7 @@ bool Shutdown() { g_activeChallenges.clear(); rc_client_destroy(g_rcClient); g_rcClient = nullptr; + INFO_LOG(ACHIEVEMENTS, "Achievements shut down."); return true; } diff --git a/Windows/InputBox.cpp b/Windows/InputBox.cpp index 45cee40f77..9db0b10dbd 100644 --- a/Windows/InputBox.cpp +++ b/Windows/InputBox.cpp @@ -2,6 +2,7 @@ #include "Common/CommonWindows.h" #include "Windows/InputBox.h" #include "Windows/resource.h" +#include "Windows/W32Util/Misc.h" #include "Common/Data/Encoding/Utf8.h" static std::wstring textBoxContents; @@ -18,34 +19,31 @@ static INT_PTR CALLBACK InputBoxFunc(HWND hDlg, UINT message, WPARAM wParam, LPA case WM_INITDIALOG: SetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), textBoxContents.c_str()); SetWindowText(hDlg, windowTitle.c_str()); - if (defaultSelected == false) PostMessage(GetDlgItem(hDlg,IDC_INPUTBOX),EM_SETSEL,-1,-1); + if (defaultSelected == false) + PostMessage(GetDlgItem(hDlg,IDC_INPUTBOX),EM_SETSEL,-1,-1); + W32Util::CenterWindow(hDlg); return TRUE; case WM_COMMAND: - switch (wParam) - { + switch (wParam) { case IDOK: { - wchar_t temp[256]; - GetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), temp, 255); + wchar_t temp[512]; + GetWindowText(GetDlgItem(hDlg, IDC_INPUTBOX), temp, ARRAY_SIZE(temp) - 1); out = temp; + EndDialog(hDlg, IDOK); + return TRUE; } - EndDialog(hDlg, IDOK); - return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; + default: + return FALSE; } default: return FALSE; } } -template -void InputBoxFunc() -{ - -} - bool InputBox_GetString(HINSTANCE hInst, HWND hParent, const wchar_t *title, const std::string &defaultValue, std::string &outvalue, bool selected) { defaultSelected = selected; @@ -151,6 +149,7 @@ static INT_PTR CALLBACK UserPasswordBoxFunc(HWND hDlg, UINT message, WPARAM wPar SetWindowText(hDlg, windowTitle.c_str()); PostMessage(GetDlgItem(hDlg, IDC_INPUTBOX), EM_SETSEL, -1, -1); PostMessage(GetDlgItem(hDlg, IDC_PASSWORDBOX), EM_SETSEL, -1, -1); + W32Util::CenterWindow(hDlg); return TRUE; case WM_COMMAND: switch (wParam) @@ -162,12 +161,14 @@ static INT_PTR CALLBACK UserPasswordBoxFunc(HWND hDlg, UINT message, WPARAM wPar g_userName = ConvertWStringToUTF8(temp); GetWindowText(GetDlgItem(hDlg, IDC_PASSWORDBOX), temp, 255); g_passWord = ConvertWStringToUTF8(temp); + EndDialog(hDlg, IDOK); + return TRUE; } - EndDialog(hDlg, IDOK); - return TRUE; case IDCANCEL: EndDialog(hDlg, IDCANCEL); return TRUE; + default: + return FALSE; } default: return FALSE;