From 6fecac47fab7d39e8936c84f4367a96df68e7f90 Mon Sep 17 00:00:00 2001 From: SimplestStudio Date: Tue, 28 Jan 2025 10:23:13 +0200 Subject: [PATCH] [win-linux] updatesvc: translator revision --- .../update-daemon/src/classes/csvcmanager.cpp | 40 +++++++++---------- .../classes/platform_linux/capplication.cpp | 2 +- .../update-daemon/src/classes/translator.cpp | 14 ++++--- .../update-daemon/src/classes/translator.h | 2 + .../src/platform_linux/utils.cpp | 2 +- .../update-daemon/src/platform_linux/utils.h | 4 +- .../update-daemon/src/platform_win/main.cpp | 2 +- .../update-daemon/src/platform_win/utils.cpp | 2 +- .../update-daemon/src/platform_win/utils.h | 4 +- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp b/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp index 62631cc19..edeb6eb04 100644 --- a/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp +++ b/win-linux/extras/update-daemon/src/classes/csvcmanager.cpp @@ -171,7 +171,7 @@ auto restartService()->void { wstring fileName = NS_File::appPath() + RESTART_BATCH; if (NS_File::fileExists(fileName) && !NS_File::removeFile(fileName)) { - NS_Logger::WriteLog(_TR("An error occurred while deleting:") + _T(" ") + fileName, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR2) + _T(" ") + fileName, true); return; } @@ -185,7 +185,7 @@ auto restartService()->void }; if (!NS_File::writeToFile(fileName, batch)) { - NS_Logger::WriteLog(_TR("An error occurred while creating:") + _T(" ") + fileName, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR3) + _T(" ") + fileName, true); return; } @@ -197,7 +197,7 @@ auto restartService()->void if (!CreateProcess(NULL, &fileName[0], NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_UNICODE_ENVIRONMENT, NULL, NULL, &si, &pi)) { - NS_Logger::WriteLog(_TR("An error occurred while restarting the service!"), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR4), true); return; } CloseHandle(pi.hProcess); @@ -667,7 +667,7 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res tstring updSubPath = NS_File::fileExists(updPath + SUBFOLDER + APP_LAUNCH_NAME) ? updPath + SUBFOLDER : updPath; tstring tmpPath = NS_File::parentPath(appPath) + BACKUP_PATH; if (!NS_File::dirExists(updPath)) { - NS_Logger::WriteLog(_TR("Update cancelled. Can't find folder:") + _T(" ") + updPath, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR5) + _T(" ") + updPath, true); return; } @@ -678,7 +678,7 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res tstring apps[] = {APP_LAUNCH_NAME, APP_LAUNCH_NAME2, APP_HELPER, DAEMON_NAME}; for (int i = 0; i < sizeof(apps) / sizeof(apps[0]); i++) { if (!NS_File::verifyEmbeddedSignature(updSubPath + apps[i])) { - NS_Logger::WriteLog(_TR("Update cancelled. The file signature is missing:") + _T(" ") + updSubPath + apps[i], true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR6) + _T(" ") + updSubPath + apps[i], true); return; } } @@ -688,7 +688,7 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res // Check backup folder if (NS_File::dirExists(tmpPath) && !NS_File::removeDirRecursively(tmpPath)) { - NS_Logger::WriteLog(_TR("Update cancelled. Can't delete folder:") + _T(" ") + tmpPath, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR7) + _T(" ") + tmpPath, true); return; } @@ -707,7 +707,7 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res sleep(500); if (NS_File::isProcessRunning(app)) { - NS_Logger::WriteLog(_TR("Update cancelled. The program is not closed:") + _T(" ") + app, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR8) + _T(" ") + app, true); return; } } @@ -716,29 +716,29 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res // Replace app path to Backup #ifdef _WIN32_UNUSED if (packageType == TEXT("portable") && !NS_File::dirExists(tmpPath) && !NS_File::makePath(tmpPath)) { - NS_Logger::WriteLog(_TR("Update cancelled. Can't create folder:") + _T(" ") + tmpPath, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR9) + _T(" ") + tmpPath, true); return; } if (!NS_File::replaceFolder(appPath, tmpPath, packageType != TEXT("portable"))) { #else if (!NS_File::replaceFolder(appPath, tmpPath, true)) { #endif - NS_Logger::WriteLog(_TR("Update cancelled. Can't replace files to backup:") + _T(" ") + NS_Utils::GetLastErrorAsString(), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR10) + _T(" ") + NS_Utils::GetLastErrorAsString(), true); if (NS_File::dirExists(tmpPath) && !NS_File::dirIsEmpty(tmpPath) && !NS_File::replaceFolder(tmpPath, appPath)) - NS_Logger::WriteLog(_TR("Can't restore files from backup!"), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR11), true); return; } // Move update path to app path if (!NS_File::replaceFolder(updSubPath, appPath, true)) { - NS_Logger::WriteLog(_TR("Update cancelled. Can't move updates to App path:") + _T(" ") + NS_Utils::GetLastErrorAsString(), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR12) + _T(" ") + NS_Utils::GetLastErrorAsString(), true); if (NS_File::dirExists(appPath) && !NS_File::removeDirRecursively(appPath)) { - NS_Logger::WriteLog(_TR("An error occurred while remove App path:") + _T(" ") + NS_Utils::GetLastErrorAsString(), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR13) + _T(" ") + NS_Utils::GetLastErrorAsString(), true); return; } if (!NS_File::replaceFolder(tmpPath, appPath, true)) - NS_Logger::WriteLog(_TR("An error occurred while restore files from backup:") + _T(" ") + NS_Utils::GetLastErrorAsString(), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR14) + _T(" ") + NS_Utils::GetLastErrorAsString(), true); NS_File::removeDirRecursively(updPath); return; @@ -814,7 +814,7 @@ void CSvcManager::startReplacingFiles(const tstring &packageType, const bool res // Restart program if (restartAfterUpdate) { if (!NS_File::runProcess(appPath + APP_LAUNCH_NAME, _T(""))) - NS_Logger::WriteLog(_TR("An error occurred while restarting the program!"), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR15), true); } // Remove Backup dir @@ -832,7 +832,7 @@ void CSvcManager::startReplacingService(const bool restartAfterUpdate) tstring updPath = NS_File::parentPath(appPath) + UPDATE_PATH; tstring updSubPath = NS_File::fileExists(updPath + SUBFOLDER + APP_LAUNCH_NAME) ? updPath + SUBFOLDER : updPath; if (!NS_File::dirExists(updPath)) { - NS_Logger::WriteLog(_TR("Update cancelled. Can't find folder:") + _T(" ") + updPath, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR5) + _T(" ") + updPath, true); return; } @@ -840,7 +840,7 @@ void CSvcManager::startReplacingService(const bool restartAfterUpdate) # ifndef DONT_VERIFY_SIGNATURE // Verify the signature of executable files if (!NS_File::verifyEmbeddedSignature(updSubPath + DAEMON_NAME)) { - NS_Logger::WriteLog(_TR("Update cancelled. The file signature is missing:") + _T(" ") + updSubPath + DAEMON_NAME, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR6) + _T(" ") + updSubPath + DAEMON_NAME, true); return; } # endif @@ -861,7 +861,7 @@ void CSvcManager::startReplacingService(const bool restartAfterUpdate) sleep(500); if (NS_File::isProcessRunning(app)) { - NS_Logger::WriteLog(_TR("Update cancelled. The program is not closed:") + _T(" ") + app, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR8) + _T(" ") + app, true); return; } } @@ -884,7 +884,7 @@ void CSvcManager::startReplacingService(const bool restartAfterUpdate) // Restart program if (restartAfterUpdate) { if (!NS_File::runProcess(appPath + APP_LAUNCH_NAME, _T(""))) - NS_Logger::WriteLog(_TR("An error occurred while restarting the program!"), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR15), true); } // Remove Update dir @@ -901,7 +901,7 @@ void CSvcManager::startInstallPackage() { // Verify the signature of executable files if (!NS_File::verifyEmbeddedSignature(m_packageData->fileName)) { - NS_Logger::WriteLog(_TR("Update cancelled. The file signature is missing:") + _T(" ") + m_packageData->fileName, true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR6) + _T(" ") + m_packageData->fileName, true); return; } tstring args; @@ -916,6 +916,6 @@ void CSvcManager::startInstallPackage() args += _T("/LANG=") + NS_Utils::GetAppLanguage(); } if (!NS_File::runProcess(m_packageData->fileType == _T("msi") ? _T("msiexec.exe") : m_packageData->fileName, args)) - NS_Logger::WriteLog(_TR("An error occurred while start install updates!"), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR18), true); } #endif diff --git a/win-linux/extras/update-daemon/src/classes/platform_linux/capplication.cpp b/win-linux/extras/update-daemon/src/classes/platform_linux/capplication.cpp index ef372763c..a248dd5ff 100644 --- a/win-linux/extras/update-daemon/src/classes/platform_linux/capplication.cpp +++ b/win-linux/extras/update-daemon/src/classes/platform_linux/capplication.cpp @@ -40,7 +40,7 @@ CApplication::CApplication() { if (SDL_Init(SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0) - NS_Logger::WriteLog(_TR("SDL init error:") + _T(" ") + SDL_GetError(), true); + NS_Logger::WriteLog(_TR(MESSAGE_TEXT_ERR16) + _T(" ") + SDL_GetError(), true); } CApplication::~CApplication() diff --git a/win-linux/extras/update-daemon/src/classes/translator.cpp b/win-linux/extras/update-daemon/src/classes/translator.cpp index 2f5e3b8e9..b9d4fe8f9 100644 --- a/win-linux/extras/update-daemon/src/classes/translator.cpp +++ b/win-linux/extras/update-daemon/src/classes/translator.cpp @@ -134,24 +134,26 @@ tstring Translator::tr(const char *str) if (is_translations_valid) { for (auto &strIdPair : translMap) { //LocaleMap locMap = strIdPair.second; - for (LocaleMap::const_iterator it = strIdPair.second.begin(); it != strIdPair.second.end(); ++it) { + // for (LocaleMap::const_iterator it = strIdPair.second.begin(); it != strIdPair.second.end(); ++it) { //wcout << L"\n\n" << translatedStr << L"\n" << it->second; - if (it->second == translatedStr) { + if (strIdPair.first == translatedStr) { if (strIdPair.second.find(langName) != strIdPair.second.end()) - translatedStr = strIdPair.second[langName]; + return strIdPair.second[langName]; else { tstring primaryLangAndScript = getPrimaryLang(langName, true); if (strIdPair.second.find(primaryLangAndScript) != strIdPair.second.end()) - translatedStr = strIdPair.second[primaryLangAndScript]; + return strIdPair.second[primaryLangAndScript]; else { tstring primaryLang = getPrimaryLang(langName); if (strIdPair.second.find(primaryLang) != strIdPair.second.end()) - translatedStr = strIdPair.second[primaryLang]; + return strIdPair.second[primaryLang]; } } + if (strIdPair.second.find(L"en") != strIdPair.second.end()) + return strIdPair.second[L"en"]; break; } - } + // } } } return translatedStr; diff --git a/win-linux/extras/update-daemon/src/classes/translator.h b/win-linux/extras/update-daemon/src/classes/translator.h index c27c81b26..28bb5f680 100644 --- a/win-linux/extras/update-daemon/src/classes/translator.h +++ b/win-linux/extras/update-daemon/src/classes/translator.h @@ -13,6 +13,8 @@ # define tstring std::string #endif +#define _TR(str) Translator::tr(#str) + using std::unordered_map; typedef unordered_map LocaleMap; diff --git a/win-linux/extras/update-daemon/src/platform_linux/utils.cpp b/win-linux/extras/update-daemon/src/platform_linux/utils.cpp index d02f11243..ddd5fbf80 100644 --- a/win-linux/extras/update-daemon/src/platform_linux/utils.cpp +++ b/win-linux/extras/update-daemon/src/platform_linux/utils.cpp @@ -137,7 +137,7 @@ namespace NS_Utils gtk_init(NULL, NULL); GtkWidget *dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", str.c_str()); - string prod_name = _TR(VER_PRODUCTNAME_STR); + string prod_name = _TR(CAPTION_TEXT); gtk_window_set_title(GTK_WINDOW(dialog), prod_name.c_str()); gtk_window_set_keep_above(GTK_WINDOW(dialog), true); gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 150); diff --git a/win-linux/extras/update-daemon/src/platform_linux/utils.h b/win-linux/extras/update-daemon/src/platform_linux/utils.h index bbf487be4..d71ce4bed 100644 --- a/win-linux/extras/update-daemon/src/platform_linux/utils.h +++ b/win-linux/extras/update-daemon/src/platform_linux/utils.h @@ -41,10 +41,8 @@ using std::string; using std::to_string; using std::list; -#define _TR(str) Translator::tr(str) - #define FUNCTION_INFO string(__FUNCTION__) + " Line: " + to_string(__LINE__) -#define DEFAULT_ERROR_MESSAGE _TR("An error occurred:") + " " + FUNCTION_INFO +#define DEFAULT_ERROR_MESSAGE _TR(MESSAGE_TEXT_ERR1) + " " + FUNCTION_INFO #define ADVANCED_ERROR_MESSAGE DEFAULT_ERROR_MESSAGE + \ " " + NS_Utils::GetLastErrorAsString() diff --git a/win-linux/extras/update-daemon/src/platform_win/main.cpp b/win-linux/extras/update-daemon/src/platform_win/main.cpp index ef18293bd..ab06c28bc 100644 --- a/win-linux/extras/update-daemon/src/platform_win/main.cpp +++ b/win-linux/extras/update-daemon/src/platform_win/main.cpp @@ -152,7 +152,7 @@ int __cdecl _tmain (int argc, TCHAR *argv[]) }; if (StartServiceCtrlDispatcher(DispatchTable) == 0) { - NS_Utils::ShowMessage(_TR("ServiceCtrlDispatcher returned error:") + _T(" ") + NS_Utils::GetLastErrorAsString(), true); + NS_Utils::ShowMessage(_TR(MESSAGE_TEXT_ERR17) + _T(" ") + NS_Utils::GetLastErrorAsString(), true); return GetLastError(); } diff --git a/win-linux/extras/update-daemon/src/platform_win/utils.cpp b/win-linux/extras/update-daemon/src/platform_win/utils.cpp index ce906998a..9611887dd 100644 --- a/win-linux/extras/update-daemon/src/platform_win/utils.cpp +++ b/win-linux/extras/update-daemon/src/platform_win/utils.cpp @@ -174,7 +174,7 @@ namespace NS_Utils { if (showError) str += L" " + GetLastErrorAsString(); - wstring prod_name = _TR(VER_PRODUCTNAME_STR); + wstring prod_name = _TR(CAPTION_TEXT); wchar_t *title = const_cast(prod_name.c_str()); if (isRunAsApp()) { MessageBox(NULL, str.c_str(), title, MB_ICONERROR | MB_SERVICE_NOTIFICATION_NT3X | MB_SETFOREGROUND); diff --git a/win-linux/extras/update-daemon/src/platform_win/utils.h b/win-linux/extras/update-daemon/src/platform_win/utils.h index 1d9b6760d..585dc4f80 100644 --- a/win-linux/extras/update-daemon/src/platform_win/utils.h +++ b/win-linux/extras/update-daemon/src/platform_win/utils.h @@ -41,10 +41,8 @@ using std::wstring; using std::to_wstring; using std::list; -#define _TR(str) Translator::tr(str) - #define FUNCTION_INFO wstring(TEXT(__FUNCTION__)) + L" Line: " + to_wstring(__LINE__) -#define DEFAULT_ERROR_MESSAGE _TR("An error occurred:") + L" " + FUNCTION_INFO +#define DEFAULT_ERROR_MESSAGE _TR(MESSAGE_TEXT_ERR1) + L" " + FUNCTION_INFO #define ADVANCED_ERROR_MESSAGE DEFAULT_ERROR_MESSAGE + \ L" " + NS_Utils::GetLastErrorAsString()