Skip to content

Commit

Permalink
* Add a bunch more strings to the resources.
Browse files Browse the repository at this point in the history
This allows easier localization when needed.
  • Loading branch information
iProgramMC committed Jun 1, 2024
1 parent c326848 commit cd437f8
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 114 deletions.
14 changes: 14 additions & 0 deletions src/discord/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
{
Expand Down
1 change: 1 addition & 0 deletions src/discord/Util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);
Expand Down
60 changes: 58 additions & 2 deletions src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
75 changes: 75 additions & 0 deletions src/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 13 additions & 23 deletions src/windows/Frontend_Win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/windows/ImageViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
35 changes: 9 additions & 26 deletions src/windows/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}

Expand All @@ -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("");

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<uint8_t> data;
bool isClipboardClosed = false;
bool hadToUseLegacyBitmap = false;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit cd437f8

Please sign in to comment.