From cd437f8e13e4ad1fd8da6e8b74fb5bf76e78dbba Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Sun, 2 Jun 2024 00:04:17 +0300 Subject: [PATCH] * Add a bunch more strings to the resources. This allows easier localization when needed. --- src/discord/Util.cpp | 14 +++++++ src/discord/Util.hpp | 1 + src/resource.h | 60 ++++++++++++++++++++++++++- src/resource.rc | 75 ++++++++++++++++++++++++++++++++++ src/windows/Frontend_Win32.cpp | 36 ++++++---------- src/windows/ImageViewer.cpp | 2 +- src/windows/Main.cpp | 35 ++++------------ src/windows/MessageEditor.cpp | 22 +++++----- src/windows/MessageList.cpp | 45 +++++++++----------- src/windows/OptionsDialog.cpp | 13 +----- src/windows/ProgressDialog.cpp | 14 +++---- src/windows/StatusBar.cpp | 6 +-- src/windows/UploadDialog.cpp | 2 +- src/windows/WinUtils.cpp | 13 +++--- 14 files changed, 224 insertions(+), 114 deletions(-) diff --git a/src/discord/Util.cpp b/src/discord/Util.cpp index 34ed25c..a76a4fb 100644 --- a/src/discord/Util.cpp +++ b/src/discord/Util.cpp @@ -510,6 +510,20 @@ std::string FormatDuration(int seconds) return result; } +std::string Format(const char* fmt, ...) +{ + va_list vl; + va_start(vl, fmt); + + char pos[2048]; + vsnprintf(pos, sizeof pos, fmt, vl); + pos[sizeof pos - 1] = 0; + + va_end(vl); + + return std::string(pos); +} + #ifdef USE_DEBUG_PRINTS void DbgPrintF(const char* fmt, ...) { diff --git a/src/discord/Util.hpp b/src/discord/Util.hpp index 99b3acc..0edf55e 100644 --- a/src/discord/Util.hpp +++ b/src/discord/Util.hpp @@ -47,6 +47,7 @@ float CompareFuzzy(const std::string& item, const char* query); // returns a "cl float GetAppVersion(); std::string GetAppVersionString(); std::string FormatDuration(int durationSec); +std::string Format(const char* fmt, ...); #ifdef USE_DEBUG_PRINTS void DbgPrintF(const char* fmt, ...); diff --git a/src/resource.h b/src/resource.h index 5d4a8e3..afd3056 100644 --- a/src/resource.h +++ b/src/resource.h @@ -93,7 +93,6 @@ #define IDR_AVI_UPLOAD_HC 93 #define IDR_AVI_UPLOAD_LC 94 #define IDI_BOOST 95 -#define IDI_ICON2 96 #define IDI_BOOST_2K 96 #define IDB_TARGET 200 #define IDB_CHANNEL 201 @@ -231,6 +230,63 @@ #define IDS_FAILED_TO_UPLOAD 698 #define IDS_SAVED_UPDATE 699 #define IDS_MAY_CONTAIN_TOKEN 700 +#define IDS_CANT_UPLOAD_SEVERAL 701 +#define IDS_WELCOME_TO_START_1 702 +#define IDS_WELCOME_TO_START_2 703 +#define IDS_PINNED_1 704 +#define IDS_PINNED_2 705 +#define IDS_PINNED_3 706 +#define IDS_BOOSTED_GUILD 707 +#define IDS_BOOSTED_ACHIEVED 708 +#define IDS_BOOSTED_TIER_1 709 +#define IDS_BOOSTED_TIER_2 710 +#define IDS_BOOSTED_TIER_3 711 +#define IDS_STAGE_STARTED 712 +#define IDS_STAGE_ENDED 713 +#define IDS_STAGE_TOPIC 714 +#define IDS_STAGE_SPEAKER 715 +#define IDS_GROUP_JOIN_1 716 +#define IDS_GROUP_JOIN_2 717 +#define IDS_GROUP_REMOVE_1 718 +#define IDS_GROUP_REMOVE_2 719 +#define IDS_CHANNEL_RENAME 720 +#define IDS_GROUP_SELF_REMOVE 721 +#define IDS_EXCITED_YES 722 +#define IDS_CANT_LAUNCH_URL_MEM 723 +#define IDS_CANT_LAUNCH_URL_ERR 724 +#define IDS_SSL_ERROR_1 725 +#define IDS_SSL_ERROR_2 726 +#define IDS_SSL_ERROR_TITLE 727 +#define IDS_UNKNOWN_FILE_NAME 728 +#define IDS_RESTART_CONFIG_CHANGE 729 +#define IDS_NO_APPDATA 730 +#define IDS_NO_CACHE_DIR 731 +#define IDS_NON_CRITICAL_ERROR 732 +#define IDS_ERROR 733 +#define IDS_JSON_EXCEPTION 734 +#define IDS_PROTOBUF_ERROR 735 +#define IDS_CANNOT_CONNECT_WS 736 +#define IDS_SSL_ERROR_WS 737 +#define IDS_SSL_ERROR_3 738 +#define IDS_IS_TYPING 739 +#define IDS_ARE_TYPING 740 +#define IDS_CANNOT_CONNECT_WS_2 741 +#define IDS_AND 742 +#define IDS_LOG_OUT_MESSAGE 743 +#define IDS_CERT_SETTING_CONFIRM 744 +#define IDS_CANCELLING 745 +#define IDS_CALCULATING 746 +#define IDS_ETA_STRING 747 +#define IDS_KB_PER_SEC 748 +#define IDS_FILE_DOWNLOAD 749 +#define IDS_FILE_UPLOAD 750 +#define IDS_DOWNLOADING 751 +#define IDS_UPLOADING 752 +#define IDS_EDITING_MESSAGE 753 +#define IDS_REPLYING_TO_MESSAGE 754 +#define IDS_MENTION 755 +#define IDS_SEND_MESSAGE 756 +#define IDS_CANT_SHOW_BITMAP 757 #define IDC_OPTIONS_TABS 801 #define IDC_MY_ACCOUNT_BOX 802 #define IDC_MY_ACCOUNT_NAME 803 @@ -389,7 +445,7 @@ // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 97 +#define _APS_NEXT_RESOURCE_VALUE 99 #define _APS_NEXT_COMMAND_VALUE 1069 #define _APS_NEXT_CONTROL_VALUE 882 #define _APS_NEXT_SYMED_VALUE 40000 diff --git a/src/resource.rc b/src/resource.rc index 052d7c1..35a4751 100644 --- a/src/resource.rc +++ b/src/resource.rc @@ -1068,6 +1068,81 @@ BEGIN IDS_FAILED_TO_UPLOAD "Error! Can't upload file %s, got error %d." IDS_SAVED_UPDATE "Your downloaded file was saved at the following path: %s." IDS_MAY_CONTAIN_TOKEN "This message may contain a Discord authentication token, which may grant an attacker access to your account. Are you sure you want to send it?" + IDS_CANT_UPLOAD_SEVERAL "Hey! I currently only take one file at a time." + IDS_WELCOME_TO_START_1 "Welcome to the beginning of the " + IDS_WELCOME_TO_START_2 " channel." +END + +STRINGTABLE +BEGIN + IDS_PINNED_1 " pinned " + IDS_PINNED_2 "a message" + IDS_PINNED_3 " to this channel." + IDS_BOOSTED_GUILD " has boosted the server! " + IDS_BOOSTED_ACHIEVED " has achieved " + IDS_BOOSTED_TIER_1 "Level 1" + IDS_BOOSTED_TIER_2 "Level 2" + IDS_BOOSTED_TIER_3 "Level 3" + IDS_STAGE_STARTED " started " + IDS_STAGE_ENDED " ended " + IDS_STAGE_TOPIC " changed the Stage topic: " + IDS_STAGE_SPEAKER " is now a speaker." + IDS_GROUP_JOIN_1 " added " + IDS_GROUP_JOIN_2 " to the group." + IDS_GROUP_REMOVE_1 " removed " + IDS_GROUP_REMOVE_2 " from the group." +END + +STRINGTABLE +BEGIN + IDS_CHANNEL_RENAME " has changed the channel name: " + IDS_GROUP_SELF_REMOVE " left the group." + IDS_EXCITED_YES "Yep!" + IDS_CANT_LAUNCH_URL_MEM "Whoa, like, can't launch the URL %s! Yer' outta memory, duuude!" + IDS_CANT_LAUNCH_URL_ERR "Can't launch URL %s. ShellExecute returned error %d. Look up ""ShellExecute error %d"" if you care." + IDS_SSL_ERROR_1 "WARNING: Your connection may not be private\n\nDiscord Messenger could not verify that it is connecting to the following URL: " + IDS_SSL_ERROR_2 "\n\nThis could be because:\no Your computer does not trust the certificate that the service has declared because it is wrong,\no Your computer does not trust the certificate that the service has declared because it doesn't trust the root certificate,\no Your computer does not trust the certificate that the service has declared because your date and time are incorrect,\no The website reported a protocol which the client is outdated for and cannot handle, or\no SOMEONE IS EAVESDROPPING ON YOU RIGHT NOW! (man-in-the-middle attack)\n\nIt is not recommended to proceed if you see this error. Please ensure you can connect to the URL using a capable device on the same network as this one. If you are able to connect, export the root certificate from that device and import it into Windows, so that you won't get this error again.\n\nYou may also disable SSL server verification, and then restart the application. However, you have to take into account the risks that this entails." + IDS_SSL_ERROR_TITLE "Discord Messenger - SECURITY ALERT" + IDS_UNKNOWN_FILE_NAME "unknown.png" + IDS_RESTART_CONFIG_CHANGE + "Discord Messenger will now restart due to a change in configuration." + IDS_NO_APPDATA "Discord Messenger could not locate your Application Data directory. The application cannot cache images or save your configuration." + IDS_NO_CACHE_DIR "Discord Messenger could not create ""DiscordMessenger\\cache"" in your Application Data directory. The application cannot store caches of images." + IDS_NON_CRITICAL_ERROR "Discord Messenger - Non-critical Error" + IDS_ERROR "Discord Messenger Error" + IDS_JSON_EXCEPTION "A bug has occurred and Discord Messenger failed to parse a piece of JSON received from the server.\n\nMessage:" + IDS_PROTOBUF_ERROR "Cannot load settings information from Discord. Got error code %d from protobuf." +END + +STRINGTABLE +BEGIN + IDS_CANNOT_CONNECT_WS "ERROR: Could not connect to the websocket gateway.\nConnection was closed with code: %d\n\nMessage: %s" + IDS_SSL_ERROR_WS "WARNING: Your connection may not be private\n\nDiscord Messenger could not verify that it is connecting to the WebSocket service required to use Discord Messenger in real time." + IDS_SSL_ERROR_3 "\n\nUse one of the following buttons to determine how to proceed:\no ABORT: Declare this HTTP request a failure.\no RETRY: Retry this HTTP request. Keep in mind that you will need to restart the app if you have installed a new certificate.\no IGNORE: This error and future SSL errors will be ignored. This option is RISKY because it could expose you to man-in-the-middle attacks. If you wish to enable SSL server verification again after clicking Ignore, you can go to the File > Preferences menu, Connection tab, and check the relevant checkbox." + IDS_IS_TYPING " is typing..." + IDS_ARE_TYPING " are typing..." + IDS_CANNOT_CONNECT_WS_2 "\n\nClick Retry to try connecting again, or Cancel to quit." + IDS_AND " and " + IDS_LOG_OUT_MESSAGE "Are you sure you want to log out?\n\nThis won't revoke your token, so you can log in with the same token again." + IDS_CERT_SETTING_CONFIRM + "WARNING:\n\nYou are about to change the TLS certificate verification setting. This may expose you to MITM (man-in-the-middle) attacks. It is recommended you instead import the required certificates into Windows.\n\nAre you sure you want to do this? (you can re-enable it anytime in the preferences menu)" + IDS_CANCELLING "Cancelling..." + IDS_CALCULATING "Calculating..." + IDS_ETA_STRING "%s (%s uploaded)" + IDS_KB_PER_SEC "%zu KB/Sec" + IDS_FILE_DOWNLOAD "File Download" + IDS_FILE_UPLOAD "File Upload" + IDS_DOWNLOADING "Downloading:" +END + +STRINGTABLE +BEGIN + IDS_UPLOADING "Uploading:" + IDS_EDITING_MESSAGE "Editing message" + IDS_REPLYING_TO_MESSAGE "Replying to " + IDS_MENTION "Mention" + IDS_SEND_MESSAGE "Send" + IDS_CANT_SHOW_BITMAP "Can't show bitmap! Windows API mismatch?" END #endif // English (United States) resources diff --git a/src/windows/Frontend_Win32.cpp b/src/windows/Frontend_Win32.cpp index 11ced70..a6b362f 100644 --- a/src/windows/Frontend_Win32.cpp +++ b/src/windows/Frontend_Win32.cpp @@ -72,6 +72,8 @@ extern int g_latestSSLError; // HACK -- defined by the NetworkerThread. Used to void Frontend_Win32::OnGenericError(const std::string& message) { std::string newMsg = message; + + // TODO HACK: remove soon if (g_latestSSLError) { char buff[128]; snprintf(buff, sizeof buff, "\n\nAdditionally, an SSL error code of 0x%x was provided. Consider sending this to iProgramInCpp!", g_latestSSLError); @@ -80,17 +82,17 @@ void Frontend_Win32::OnGenericError(const std::string& message) } LPCTSTR pMsgBoxText = ConvertCppStringToTString(newMsg); - MessageBox(g_Hwnd, pMsgBoxText, TEXT("Discord Messenger Error"), MB_OK | MB_ICONERROR); + MessageBox(g_Hwnd, pMsgBoxText, TmGetTString(IDS_ERROR), MB_OK | MB_ICONERROR); free((void*)pMsgBoxText); pMsgBoxText = NULL; } void Frontend_Win32::OnJsonException(const std::string& message) { - std::string err("Json Exception!\n\nMessage: "); + std::string err(TmGetString(IDS_JSON_EXCEPTION)); err += message; LPCTSTR pMsgBoxText = ConvertCppStringToTString(err); - MessageBox(g_Hwnd, pMsgBoxText, TEXT("Discord Messenger Error"), MB_OK | MB_ICONERROR); + MessageBox(g_Hwnd, pMsgBoxText, TmGetTString(IDS_ERROR), MB_OK | MB_ICONERROR); free((void*)pMsgBoxText); pMsgBoxText = NULL; } @@ -120,8 +122,8 @@ void Frontend_Win32::OnProtobufError(Protobuf::ErrorCode code) { char buff[512]; buff[511] = 0; - snprintf(buff, sizeof buff - 1, "Error while loading settings data, got error code %d from protobuf implementation.", code); - MessageBoxA(g_Hwnd, buff, "Settings error", MB_ICONERROR); + snprintf(buff, sizeof buff - 1, TmGetString(IDS_PROTOBUF_ERROR).c_str(), code); + MessageBoxA(g_Hwnd, buff, TmGetString(IDS_ERROR).c_str(), MB_ICONERROR); } void Frontend_Win32::OnRequestDone(NetRequest* pRequest) @@ -221,6 +223,7 @@ void Frontend_Win32::OnAttachmentDownloaded(bool bIsProfilePicture, const uint8_ FILE* f = fopen(final_path.c_str(), "wb"); if (!f) { DbgPrintW("ERROR: Could not open %s for writing", final_path.c_str()); + // TODO: error message return; } @@ -353,33 +356,20 @@ void Frontend_Win32::OnWebsocketFail(int gatewayID, int errorCode, const std::st WAsnprintf( buffer, _countof(buffer), - TEXT("ERROR: Could not connect to the websocket gateway.\nConnection was closed with code: %d\n\nMessage: %s"), + TmGetTString(IDS_CANNOT_CONNECT_WS), errorCode, msg ); free(msg); if (isTLSError) { - _tcscat( - buffer, - TEXT("\n\nWARNING: Your connection may not be private\n\nDiscord Messenger could not verify that it is connecting to a Websocket service ") - TEXT("required to use Discord Messenger in real time.") - TEXT("\n\nThis could be because:") - TEXT("\no Your computer does not trust the certificate that the gateway has declared because it is wrong,") - TEXT("\no Your computer does not trust the certificate that the gateway has declared because it doesn't trust the root certificate,") - TEXT("\no Your computer does not trust the certificate that the gateway has declared because your date and time are incorrect,") - TEXT("\no The website reported a protocol which the client is outdated for and cannot handle, or") - TEXT("\no SOMEONE IS EAVESDROPPING ON YOU RIGHT NOW! (man-in-the-middle attack)") - TEXT("\n\nIt is not recommended to proceed if you see this error. Please ensure you can connect to Discord using a ") - TEXT("capable device on the same network as this one. If you are able to connect, export the root certificate from ") - TEXT("discord.com on that device and import it into Windows, if the OS supports it.") - TEXT("\n\nYou may also disable SSL server verification, and then restart the application. However, you have to ") - TEXT("take into account the risks that this entails.") - ); + _tcscat(buffer, TEXT("\n\n")); + _tcscat(buffer, TmGetTString(IDS_SSL_ERROR_WS)); + _tcscat(buffer, TmGetTString(IDS_SSL_ERROR_2)); } if (mayRetry) { - _tcscat(buffer, TEXT("\n\nClick Retry to try connecting again, or Cancel to quit.")); + _tcscat(buffer, TmGetTString(IDS_CANNOT_CONNECT_WS_2)); } int flags = (mayRetry ? MB_RETRYCANCEL : MB_OK) | (isTLSError ? MB_ICONWARNING : MB_ICONERROR); diff --git a/src/windows/ImageViewer.cpp b/src/windows/ImageViewer.cpp index 52e8522..b3a4db1 100644 --- a/src/windows/ImageViewer.cpp +++ b/src/windows/ImageViewer.cpp @@ -110,7 +110,7 @@ LRESULT CALLBACK ImageViewerChildWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP BITMAP bm; memset(&bm, 0, sizeof(bm)); if (!GetObject(hbm, sizeof(BITMAP), &bm)) { - MessageBox(hWnd, TEXT("Could not show bitmap! Windows API mismatch?"), TmGetTString(IDS_PROGRAM_NAME), MB_ICONERROR); + MessageBox(hWnd, TmGetTString(IDS_CANT_SHOW_BITMAP), TmGetTString(IDS_PROGRAM_NAME), MB_ICONERROR); break; } diff --git a/src/windows/Main.cpp b/src/windows/Main.cpp index 237b80d..5c9ef6f 100644 --- a/src/windows/Main.cpp +++ b/src/windows/Main.cpp @@ -83,7 +83,7 @@ void SetupCachePathIfNeeded() } else { - MessageBox(g_Hwnd, TEXT("Discord Messenger could not locate your Application Data directory. The application cannot save caches of images."), TEXT("Discord Messenger - Non Critical Error"), MB_OK | MB_ICONERROR); + MessageBox(g_Hwnd, TmGetTString(IDS_NO_APPDATA), TmGetTString(IDS_NON_CRITICAL_ERROR), MB_OK | MB_ICONERROR); SetBasePath(""); } @@ -92,7 +92,7 @@ void SetupCachePathIfNeeded() return; _failure: - MessageBox(g_Hwnd, TEXT("Discord Messenger could not create \"DiscordMessenger\\cache\" in your Application Data directory. The application cannot save caches of images."), TEXT("Discord Messenger - Non Critical Error"), MB_OK | MB_ICONERROR); + MessageBox(g_Hwnd, TmGetTString(IDS_NO_CACHE_DIR), TmGetTString(IDS_NON_CRITICAL_ERROR), MB_OK | MB_ICONERROR); SetBasePath(""); @@ -359,32 +359,15 @@ int OnSSLError(const std::string& url) { LPTSTR urlt = ConvertCppStringToTString(url); static TCHAR buffer[8192]; - _tcscpy(buffer, TEXT("WARNING: Your connection may not be private\n\nDiscord Messenger could not verify that it is connecting to the following URL: ")); + _tcscat(buffer, TmGetTString(IDS_SSL_ERROR_1)); _tcscat(buffer, urlt); - _tcscat(buffer, - TEXT("\n\nThis could be because:") - TEXT("\no Your computer does not trust the certificate that the service has declared because it is wrong,") - TEXT("\no Your computer does not trust the certificate that the service has declared because it doesn't trust the root certificate,") - TEXT("\no Your computer does not trust the certificate that the service has declared because your date and time are incorrect,") - TEXT("\no The website reported a protocol which the client is outdated for and cannot handle, or") - TEXT("\no SOMEONE IS EAVESDROPPING ON YOU RIGHT NOW! (man-in-the-middle attack)") - TEXT("\n\nIt is not recommended to proceed if you see this error. Please ensure you can connect to the URL using a ") - TEXT("capable device on the same network as this one. If you are able to connect, export the root certificate from ") - TEXT("that device and import it into Windows, so that you won't get this error again.") - TEXT("\n\nYou may also disable SSL server verification, and then restart the application. However, you have to ") - TEXT("take into account the risks that this entails.") - TEXT("\n\nUse one of the following buttons to determine how to proceed:") - TEXT("\no ABORT: Declare this HTTP request a failure.") - TEXT("\no RETRY: Retry this HTTP request. Keep in mind that you will need to restart the app if you have installed a new certificate.") - TEXT("\no IGNORE: This error and future SSL errors will be ignored. This option is RISKY because it could expose you to man-in-the-middle attacks. ") - TEXT("If you wish to enable SSL server verification again after clicking Ignore, you can go to the File > Preferences menu, Connection tab, and check ") - TEXT("the relevant checkbox.") - ); + _tcscat(buffer, TmGetTString(IDS_SSL_ERROR_2)); + _tcscat(buffer, TmGetTString(IDS_SSL_ERROR_3)); free(urlt); size_t l = _tcslen(buffer); - return MessageBox(g_Hwnd, buffer, TEXT("Discord Messenger - SECURITY ALERT"), MB_ABORTRETRYIGNORE | MB_ICONWARNING); + return MessageBox(g_Hwnd, buffer, TmGetTString(IDS_SSL_ERROR_TITLE), MB_ABORTRETRYIGNORE | MB_ICONWARNING); } BOOL HandleCommand(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -473,7 +456,7 @@ BOOL HandleCommand(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) HBITMAP hbm = NULL; HDC hdc = NULL; BYTE* pBytes = nullptr; - LPTSTR fileName = nullptr; + LPCTSTR fileName = nullptr; std::vector data; bool isClipboardClosed = false; bool hadToUseLegacyBitmap = false; @@ -557,7 +540,7 @@ BOOL HandleCommand(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) CloseClipboard(); isClipboardClosed = true; - fileName = TEXT("unknown.png"); + fileName = TmGetTString(IDS_UNKNOWN_FILE_NAME); UploadDialogShowWithFileData(data.data(), data.size(), fileName); _fail: @@ -631,7 +614,7 @@ LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } case WM_FORCERESTART: { - MessageBox(hWnd, TEXT("The application will now restart due to a change in the configuration."), TEXT("Setting Modification"), MB_OK | MB_ICONINFORMATION); + MessageBox(hWnd, TmGetTString(IDS_RESTART_CONFIG_CHANGE), TmGetTString(IDS_PROGRAM_NAME), MB_OK | MB_ICONINFORMATION); if (InSendMessage()) ReplyMessage(0); SendMessage(hWnd, WM_DESTROY, 0, 0); diff --git a/src/windows/MessageEditor.cpp b/src/windows/MessageEditor.cpp index 6c1fffd..fe3ab84 100644 --- a/src/windows/MessageEditor.cpp +++ b/src/windows/MessageEditor.cpp @@ -689,7 +689,7 @@ MessageEditor* MessageEditor::Create(HWND hwnd, LPRECT pRect) newThis->m_send_hwnd = CreateWindowEx( 0, TEXT("BUTTON"), - TEXT("Send"), + TmGetTString(IDS_SEND_MESSAGE), WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, width - sendButtonWidth, (height - sendButtonHeight) / 2, @@ -702,13 +702,15 @@ MessageEditor* MessageEditor::Create(HWND hwnd, LPRECT pRect) ); // Add the mention items - LPCTSTR editingText = TEXT("Editing Message"); - newThis->m_editingMessage_hwnd = CreateWindow(WC_STATIC, editingText, WS_CHILD | SS_SIMPLE | SS_CENTERIMAGE, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEEDITINGLBL, g_hInstance, NULL); - newThis->m_mentionText_hwnd = CreateWindow(WC_STATIC, TEXT("Replying to"), WS_CHILD | SS_SIMPLE | SS_CENTERIMAGE, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEREPLYTO, g_hInstance, NULL); - newThis->m_mentionName_hwnd = CreateWindow(WC_STATIC, TEXT("UserNameHere"), WS_CHILD | SS_SIMPLE | SS_CENTERIMAGE, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEREPLYUSER, g_hInstance, NULL); - newThis->m_mentionCheck_hwnd = CreateWindow(WC_BUTTON, TEXT("Mention"), WS_CHILD | BS_AUTOCHECKBOX, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEMENTCHECK, g_hInstance, NULL); - newThis->m_mentionCancel_hwnd = CreateWindow(WC_BUTTON, TEXT(""), WS_CHILD | BS_PUSHBUTTON | BS_ICON, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEREPLYCANCEL, g_hInstance, NULL); - newThis->m_mentionJump_hwnd = CreateWindow(WC_BUTTON, TEXT(""), WS_CHILD | BS_PUSHBUTTON | BS_ICON, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEREPLYJUMP, g_hInstance, NULL); + LPCTSTR editingText = TmGetTString(IDS_EDITING_MESSAGE); + LPCTSTR replyingText = TmGetTString(IDS_REPLYING_TO_MESSAGE); + LPCTSTR mentionText = TmGetTString(IDS_MENTION); + newThis->m_editingMessage_hwnd = CreateWindow(WC_STATIC, editingText, WS_CHILD | SS_SIMPLE | SS_CENTERIMAGE, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEEDITINGLBL, g_hInstance, NULL); + newThis->m_mentionText_hwnd = CreateWindow(WC_STATIC, replyingText, WS_CHILD | SS_SIMPLE | SS_CENTERIMAGE, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEREPLYTO, g_hInstance, NULL); + newThis->m_mentionName_hwnd = CreateWindow(WC_STATIC, TEXT("UNH"), WS_CHILD | SS_SIMPLE | SS_CENTERIMAGE, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEREPLYUSER, g_hInstance, NULL); + newThis->m_mentionCheck_hwnd = CreateWindow(WC_BUTTON, mentionText, WS_CHILD | BS_AUTOCHECKBOX, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEMENTCHECK, g_hInstance, NULL); + newThis->m_mentionCancel_hwnd = CreateWindow(WC_BUTTON, TEXT(""), WS_CHILD | BS_PUSHBUTTON | BS_ICON, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEREPLYCANCEL, g_hInstance, NULL); + newThis->m_mentionJump_hwnd = CreateWindow(WC_BUTTON, TEXT(""), WS_CHILD | BS_PUSHBUTTON | BS_ICON, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEREPLYJUMP, g_hInstance, NULL); // Add icon buttons newThis->m_btnUpload_hwnd = CreateWindow(WC_BUTTON, TEXT(""), WS_CHILD | BS_PUSHBUTTON | BS_ICON, 0, 0, 1, 1, newThis->m_hwnd, (HMENU)CID_MESSAGEUPLOAD, g_hInstance, NULL); @@ -718,11 +720,11 @@ MessageEditor* MessageEditor::Create(HWND hwnd, LPRECT pRect) HGDIOBJ objOld = SelectObject(hdc, g_SendButtonFont); RECT rcMeasure{}; - DrawText(hdc, TEXT("Mention"), -1, &rcMeasure, DT_CALCRECT); + DrawText(hdc, mentionText, -1, &rcMeasure, DT_CALCRECT); newThis->m_mentionTextWidth = rcMeasure.right - rcMeasure.left + 1; SetRectEmpty(&rcMeasure); - DrawText(hdc, TEXT("Replying to "), -1, &rcMeasure, DT_CALCRECT); + DrawText(hdc, replyingText, -1, &rcMeasure, DT_CALCRECT); newThis->m_replyToTextWidth = rcMeasure.right - rcMeasure.left + 1; SelectObject(hdc, objOld); diff --git a/src/windows/MessageList.cpp b/src/windows/MessageList.cpp index 018430c..a08e684 100644 --- a/src/windows/MessageList.cpp +++ b/src/windows/MessageList.cpp @@ -1624,17 +1624,17 @@ void MessageList::DetermineMessageData( break; } - messagePart1 = TEXT("Welcome to the beginning of the "); - messagePart2 = TEXT(" channel."); + messagePart1 = TmGetTString(IDS_WELCOME_TO_START_1); + messagePart2 = TmGetTString(IDS_WELCOME_TO_START_2); break; } case MessageType::CHANNEL_PINNED_MESSAGE: { messagePart1 = TEXT(""); - messagePart2 = TEXT(" pinned "); - messagePart3 = TEXT(" to this channel."); - clickableString = TEXT("a message"); + messagePart2 = TmGetTString(IDS_PINNED_1); + messagePart3 = TmGetTString(IDS_PINNED_3); + clickableString = TmGetTString(IDS_PINNED_2); clickableLink = CreateMessageLink(refMsgGuildID, refMsgChannelID, refMsgMessageID); icon = IDI_PIN; break; @@ -1643,7 +1643,7 @@ void MessageList::DetermineMessageData( case MessageType::GUILD_BOOST: { messagePart1 = TEXT(""); - messagePart2 = TEXT(" has boosted the server!"); + messagePart2 = TmGetTString(IDS_BOOSTED_GUILD); icon = IDI_BOOST; break; } @@ -1657,20 +1657,15 @@ void MessageList::DetermineMessageData( if (pGld) guildName = pGld->m_name; - freedStringSpace = ConvertCppStringToTString(" has boosted the server! " + guildName + " has achieved "); + freedStringSpace = ConvertCppStringToTString(TmGetString(IDS_BOOSTED_GUILD) + guildName + TmGetString(IDS_BOOSTED_ACHIEVED)); messagePart1 = TEXT(""); messagePart2 = freedStringSpace; messagePart3 = TEXT("!"); int tier = int(msgType) - int(MessageType::GUILD_BOOST_TIER_1); - const LPCTSTR tiers[] = { - TEXT("Level 1"), - TEXT("Level 2"), - TEXT("Level 3"), - }; + clickableString = TmGetTString(IDS_BOOSTED_TIER_1 + tier); - clickableString = tiers[tier]; icon = IDI_BOOST; break; } @@ -1679,7 +1674,7 @@ void MessageList::DetermineMessageData( { freedStringSpace = ConvertCppStringToTString(content); messagePart1 = TEXT(""); - messagePart2 = TEXT(" started "); + messagePart2 = TmGetTString(IDS_STAGE_STARTED); clickableString = freedStringSpace; break; } @@ -1688,7 +1683,7 @@ void MessageList::DetermineMessageData( { freedStringSpace = ConvertCppStringToTString(content); messagePart1 = TEXT(""); - messagePart2 = TEXT(" ended "); + messagePart2 = TmGetTString(IDS_STAGE_ENDED); clickableString = freedStringSpace; break; } @@ -1697,7 +1692,7 @@ void MessageList::DetermineMessageData( { freedStringSpace = ConvertCppStringToTString(content); messagePart1 = TEXT(""); - messagePart2 = TEXT(" changed the Stage topic: "); + messagePart2 = TmGetTString(IDS_STAGE_TOPIC); clickableString = freedStringSpace; break; } @@ -1705,7 +1700,7 @@ void MessageList::DetermineMessageData( case MessageType::STAGE_SPEAKER: { messagePart1 = TEXT(""); - messagePart2 = TEXT(" is now a speaker."); + messagePart2 = TmGetTString(IDS_STAGE_SPEAKER); break; } @@ -1717,19 +1712,19 @@ void MessageList::DetermineMessageData( if (msgType == MessageType::RECIPIENT_ADD) { icon = IDI_USER_JOIN; - messagePart2 = TEXT(" added "); - messagePart3 = TEXT(" to the group."); + messagePart2 = TmGetTString(IDS_GROUP_JOIN_1); + messagePart3 = TmGetTString(IDS_GROUP_JOIN_2); clickableString = TEXT("who?"); } else if (clickableSF == authorId) { icon = IDI_USER_LEAVE; - messagePart2 = TEXT(" left the group."); + messagePart2 = TmGetTString(IDS_GROUP_SELF_REMOVE); break; } else { icon = IDI_USER_LEAVE; - messagePart2 = TEXT(" removed "); - messagePart3 = TEXT(" from the group."); + messagePart2 = TmGetTString(IDS_GROUP_REMOVE_1); + messagePart3 = TmGetTString(IDS_GROUP_REMOVE_2); clickableString = TEXT("who?"); } @@ -1746,7 +1741,7 @@ void MessageList::DetermineMessageData( freedStringSpace = ConvertCppStringToTString(content); messagePart1 = TEXT(""); - messagePart2 = TEXT(" has changed the channel name: "); + messagePart2 = TmGetTString(IDS_CHANNEL_RENAME); clickableString = freedStringSpace; break; } @@ -1795,7 +1790,7 @@ LRESULT MessageList::OpenLinkMsgBoxHook(int code, WPARAM wParam, LPARAM lParam) HWND item = GetDlgItem(hWnd, IDOK); if (item) - SetWindowText(item, TEXT("Yep!")); + SetWindowText(item, TmGetTString(IDS_EXCITED_YES)); } LRESULT res = CallNextHookEx(g_MsgBoxHookTemp, code, wParam, lParam); @@ -2847,7 +2842,7 @@ LRESULT CALLBACK MessageList::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA if (amount != 1) { - MessageBox(g_Hwnd, TEXT("I currently only take one file at a time!"), TmGetTString(IDS_PROGRAM_NAME), MB_ICONWARNING | MB_OK); + MessageBox(g_Hwnd, TmGetTString(IDS_CANT_UPLOAD_SEVERAL), TmGetTString(IDS_PROGRAM_NAME), MB_ICONWARNING | MB_OK); DragFinish(hDrop); return 0; } diff --git a/src/windows/OptionsDialog.cpp b/src/windows/OptionsDialog.cpp index fc13160..788487a 100644 --- a/src/windows/OptionsDialog.cpp +++ b/src/windows/OptionsDialog.cpp @@ -211,9 +211,7 @@ INT_PTR CALLBACK ChildDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa break; } case IDC_LOG_OUT: { - if (MessageBox(hWnd, - TEXT("Are you sure you want to log out?\n\nThis won't revoke your token, so you can log in with the same token again."), - TmGetTString(IDS_PROGRAM_NAME), MB_YESNO | MB_ICONQUESTION) == IDYES) + if (MessageBox(hWnd, TmGetTString(IDS_LOG_OUT_MESSAGE), TmGetTString(IDS_PROGRAM_NAME), MB_YESNO | MB_ICONQUESTION) == IDYES) { // Log them out! EndDialog(hWnd, 0); @@ -312,14 +310,7 @@ INT_PTR CALLBACK ChildDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPa { bool state = IsDlgButtonChecked(hWnd, IDC_ENABLE_TLS_CHECKS); if (!state) { - if (MessageBox( - hWnd, - TEXT("WARNING:\n\nYou are about to change the TLS certificate verification setting. This may expose you to MITM (man-in-the-middle) ") - TEXT("attacks. It is recommended you instead import the required certificates into Windows.\n\nAre you sure you want to do this? ") - TEXT("(you can re-enable it anytime in the preferences menu)"), - TmGetTString(IDS_PROGRAM_NAME), - MB_ICONWARNING | MB_YESNO - ) != IDYES) + if (MessageBox(hWnd, TmGetTString(IDS_CERT_SETTING_CONFIRM), TmGetTString(IDS_PROGRAM_NAME), MB_ICONWARNING | MB_YESNO) != IDYES) { CheckDlgButton(hWnd, IDC_ENABLE_TLS_CHECKS, BST_CHECKED); break; diff --git a/src/windows/ProgressDialog.cpp b/src/windows/ProgressDialog.cpp index 29fbbc7..d7bb338 100644 --- a/src/windows/ProgressDialog.cpp +++ b/src/windows/ProgressDialog.cpp @@ -95,7 +95,7 @@ BOOL ProgressDialog::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) switch (uMsg) { case WM_INITDIALOG: { - SetWindowText(hWnd, m_bDirection ? TEXT("File Upload") : TEXT("File Download")); + SetWindowText(hWnd, TmGetTString(m_bDirection ? IDS_FILE_UPLOAD : IDS_FILE_DOWNLOAD)); LONG_PTR lp = GetWindowLongPtr(hWnd, GWLP_WNDPROC); SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)&WndProc); @@ -106,8 +106,8 @@ BOOL ProgressDialog::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) SetDlgItemText(hWnd, IDC_UPLOADING_FILENAME, fileName); free(fileName); - SetDlgItemText(hWnd, IDC_UPLOADING_ETA, TEXT("Calculating...")); - SetDlgItemText(hWnd, IDC_UPLOADING_ACTION, m_bDirection ? TEXT("Uploading:") : TEXT("Downloading:")); + SetDlgItemText(hWnd, IDC_UPLOADING_ETA, TmGetTString(IDS_CALCULATING)); + SetDlgItemText(hWnd, IDC_UPLOADING_ACTION, TmGetTString(m_bDirection ? IDS_UPLOADING : IDS_DOWNLOADING)); SendMessage(GetDlgItem(hWnd, IDC_UPLOADING_PROGRESS), PBM_SETRANGE, 0, MAKELPARAM(0, 1000)); SendMessage(GetDlgItem(hWnd, IDC_UPLOADING_PROGRESS), PBM_SETPOS, 0, 0); @@ -158,17 +158,17 @@ BOOL ProgressDialog::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) std::string etaStr; if (bytesPerSec) { uint64_t eta = bytesPerSec ? (uint64_t(m_length - m_offset) / bytesPerSec) : 0; - etaStr = FormatDuration(eta) + " (" + strProgress + " uploaded)"; + etaStr = Format(TmGetString(IDS_ETA_STRING).c_str(), FormatDuration(eta).c_str(), strProgress.c_str()); } else { - etaStr = "Calculating..."; + etaStr = TmGetString(IDS_CALCULATING); } LPTSTR tstr = ConvertCppStringToTString(etaStr); SetDlgItemText(hWnd, IDC_UPLOADING_ETA, tstr); free(tstr); - std::string transferRate = bytesPerSec ? (std::to_string(bytesPerSec / 1024) + " KB/Sec") : "Calculating..."; + std::string transferRate = bytesPerSec ? Format(TmGetString(IDS_KB_PER_SEC).c_str(), bytesPerSec / 1024) : TmGetString(IDS_CALCULATING); tstr = ConvertCppStringToTString(transferRate); SetDlgItemText(hWnd, IDC_UPLOADING_XFERRATE, tstr); free(tstr); @@ -184,7 +184,7 @@ BOOL ProgressDialog::DlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_COMMAND: if (wParam == IDCANCEL) { - SetDlgItemText(hWnd, IDC_UPLOADING_ETA, TEXT("Cancelling...")); + SetDlgItemText(hWnd, IDC_UPLOADING_ETA, TmGetTString(IDS_CANCELLING)); m_bCanceling = true; } break; diff --git a/src/windows/StatusBar.cpp b/src/windows/StatusBar.cpp index eea72b6..f87bb57 100644 --- a/src/windows/StatusBar.cpp +++ b/src/windows/StatusBar.cpp @@ -216,9 +216,9 @@ void StatusBar::DrawItem(LPDRAWITEMSTRUCT lpDIS) { TypingUser& tu = m_typingUsers[i]; if (i != 0) { - LPTSTR separator; + LPCTSTR separator; if (i == sz - 1) - separator = TEXT(" and "); + separator = TmGetTString(IDS_AND); else separator = TEXT(", "); @@ -249,7 +249,7 @@ void StatusBar::DrawItem(LPDRAWITEMSTRUCT lpDIS) if (sz != 0) { SelectObject(hdc, g_TypingRegFont); - LPCTSTR typingEnd = sz == 1 ? TEXT(" is typing...") : TEXT(" are typing..."); + LPCTSTR typingEnd = TmGetTString(sz == 1 ? IDS_IS_TYPING : IDS_ARE_TYPING); DrawText(hdc, typingEnd, -1, &rc, DT_WORD_ELLIPSIS | DT_NOPREFIX | DT_VCENTER | DT_SINGLELINE); } diff --git a/src/windows/UploadDialog.cpp b/src/windows/UploadDialog.cpp index c8d80f6..79882e1 100644 --- a/src/windows/UploadDialog.cpp +++ b/src/windows/UploadDialog.cpp @@ -309,7 +309,7 @@ void UploadDialogShow2() ofn.nMaxFileTitle = MAX_FILE; ofn.lpstrFileTitle = buffer2; ofn.lpstrFilter = TEXT("All files\0*.*\0\0"); - ofn.lpstrTitle = TEXT("Upload file"); + ofn.lpstrTitle = TmGetTString(IDS_FILE_UPLOAD); if (!GetOpenFileName(&ofn)) { // maybe they cancelled. hope there's no error! diff --git a/src/windows/WinUtils.cpp b/src/windows/WinUtils.cpp index 0109051..700a583 100644 --- a/src/windows/WinUtils.cpp +++ b/src/windows/WinUtils.cpp @@ -549,23 +549,26 @@ void LaunchURL(const std::string& link) { LPTSTR tstr = ConvertCppStringToTString(link); INT_PTR res = (INT_PTR) ShellExecute(g_Hwnd, TEXT("open"), tstr, NULL, NULL, SW_SHOWNORMAL); - free(tstr); - if (res > 32) return; // was fine + if (res > 32) { + free(tstr); + return; // was fine + } TCHAR buff[4096]; switch (res) { case 0: - WAsnprintf(buff, _countof(buff), TEXT("Whoa, like, can't launch the URL " ASCIIZ_STR_FMT "! Yer outa memory, duuude!"), link.c_str()); + WAsnprintf(buff, _countof(buff), TmGetTString(IDS_CANT_LAUNCH_URL_MEM), tstr); break; default: - WAsnprintf(buff, _countof(buff), TEXT("Can't launch URL " ASCIIZ_STR_FMT ", ShellExecute returned error %d. Look \"ShellExecute error %d\" if you care."), link.c_str(), res, res); + WAsnprintf(buff, _countof(buff), TmGetTString(IDS_CANT_LAUNCH_URL_ERR), tstr, res, res); break; } - MessageBox(g_Hwnd, buff, TEXT("Whoops"), MB_ICONERROR | MB_OK); + free(tstr); + MessageBox(g_Hwnd, buff, TmGetTString(IDS_PROGRAM_NAME), MB_ICONERROR | MB_OK); } bool IsChildOf(HWND child, HWND of)