*.exp
*.pdb
*.lib
+*.ods#
*.dll
*.exe
ComboBox_SetItemData(hLanguageList, itemId, lang.fileName.c_str());
}
}
- ComboBox_SelectString(hLanguageList, 0, WMi18n::GetInstance().GetcurrentLanguageName().c_str());
+ ComboBox_SelectString(hLanguageList, 0, WMi18n::GetInstance().GetCurrentLanguageName().c_str());
}
INT_PTR CALLBACK Settings_GeneralDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
const wchar_t *selectedLang = reinterpret_cast<const wchar_t *>(ComboBox_GetItemData(hLanguageSelector, curLangSel));
if (selectedLang != nullptr) {
if (!WMi18n::GetInstance().LoadLanguage(selectedLang)) {
- TaskDialog(hDlg,
- hglobInstance,
- PROGRAM_NAME,
- L"Failed to load selected language.",
- L"Please report this error to the WinMute issue tracker.",
- TDCBF_OK_BUTTON,
- TD_ERROR_ICON,
- nullptr);
+ TaskDialog(
+ hDlg,
+ hglobInstance,
+ PROGRAM_NAME,
+ L"Failed to load selected language.",
+ L"Please report this error to the WinMute issue tracker.",
+ TDCBF_OK_BUTTON,
+ TD_ERROR_ICON,
+ nullptr);
+ } else {
+ dlgData->settings->SetValue(SettingsKey::APP_LANGUAGE, selectedLang);
}
}
}
continue;
}
wchar_t langName[255 + 1];
- if (LoadStringW(hLangFile, IDI_LANG_NAME, langName, ARRAY_SIZE(langName)) <= 0) {
+ if (LoadStringW(hLangFile, IDS_LANG_NAME, langName, ARRAY_SIZE(langName)) <= 0) {
WMLog &log = WMLog::GetInstance();
log.WriteWindowsError(L"LoadStringW", GetLastError());
log.Write(L"Failed to load language %ls", wfd.cFileName);
return curModuleName_;
}
-std::wstring WMi18n::GetcurrentLanguageName() const
+std::wstring WMi18n::GetCurrentLanguageName() const
{
- return GetString(IDI_LANG_NAME);
+ return GetString(IDS_LANG_NAME);
}
// https://learn.microsoft.com/en-us/windows/win32/intl/creating-a-multilingual-user-interface-application
if (!langModPath.has_value()) {
return false;
}
- fs::path pathDllName{ dllName };
+ const fs::path pathDllName{ dllName };
*langModPath /= pathDllName.filename(); // Sanitize
if (!fs::exists(*langModPath)) {
- // TODO: Error
+ WMLog::GetInstance().Write(L"Language module \"%s\" does not exist", langModPath->c_str());
} else {
auto newLangModule = LoadLibraryExW(
langModPath->c_str(), nullptr,
LOAD_LIBRARY_AS_IMAGE_RESOURCE | LOAD_LIBRARY_AS_DATAFILE);
if (newLangModule == nullptr) {
- // TODO: Error
+ WMLog::GetInstance().WriteWindowsError(L"LoadLibraryW", GetLastError());
} else {
UnloadLanguage();
langModule_ = newLangModule;
std::optional<fs::path> GetLanguageModulesPath() const;
std::wstring GetCurrentLanguageModule() const;
- std::wstring GetcurrentLanguageName() const;
+ std::wstring GetCurrentLanguageName() const;
std::wstring GetString(UINT id) const;
}
}
-int WINAPI wWinMain(_In_ HINSTANCE hInstance,
+static bool InitWindowsComponents()
+{
+ INITCOMMONCONTROLSEX initComCtrl;
+ initComCtrl.dwSize = sizeof(INITCOMMONCONTROLSEX);
+ initComCtrl.dwICC = ICC_LINK_CLASS;
+ if (InitCommonControlsEx(&initComCtrl) == FALSE) {
+ WMLog::GetInstance().WriteWindowsError(L"InitCommonControlsEx", GetLastError());
+ return FALSE;
+ } else if (CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED) != S_OK) {
+ WMLog::GetInstance().WriteWindowsError(L"CoInitializeEx", GetLastError());
+ return FALSE;
+ }
+ return TRUE;
+}
+
+int WINAPI wWinMain(
+ _In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE,
_In_ PWSTR,
_In_ int)
{
+ hglobInstance = hInstance;
WMSettings settings;
WMi18n& i18n = WMi18n::GetInstance();
if (!settings.Init()) {
- TaskDialog(nullptr,
- nullptr,
- PROGRAM_NAME,
- L"Failed to initialize settings",
- L"Critical error while initializing WinMute",
- TDCBF_OK_BUTTON,
- TD_ERROR_ICON,
- nullptr);
+ TaskDialog(
+ nullptr,
+ nullptr,
+ PROGRAM_NAME,
+ i18n.GetString(IDS_MAIN_ERROR_SETTINGS_INIT_TITLE).c_str(),
+ i18n.GetString(IDS_MAIN_ERROR_SETTINGS_INIT_TEXT).c_str(),
+ TDCBF_OK_BUTTON,
+ TD_ERROR_ICON,
+ nullptr);
return FALSE;
}
LoadLanguage(settings, i18n);
- HANDLE hMutex = CreateMutexW(nullptr, TRUE, L"LxSystemsWinMute");
+ HANDLE hMutex = CreateMutexW(nullptr, TRUE, L"LxSystemsWinMuteMtx");
if (hMutex == nullptr) {
return FALSE;
} else if (GetLastError() == ERROR_ALREADY_EXISTS) {
nullptr,
nullptr,
PROGRAM_NAME,
- L"WinMute is already running",
- L"Please look for a white speaker icon in your Windows "
- L" taskbar notification area.",
+ i18n.GetString(IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TITLE).c_str(),
+ i18n.GetString(IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TEXT).c_str(),
TDCBF_OK_BUTTON,
TD_INFORMATION_ICON,
nullptr);
SetWorkingDirectory();
- hglobInstance = hInstance;
HeapSetInformation(nullptr, HeapEnableTerminationOnCorruption, nullptr, 0);
- INITCOMMONCONTROLSEX initComCtrl;
- initComCtrl.dwSize = sizeof(INITCOMMONCONTROLSEX);
- initComCtrl.dwICC = ICC_LINK_CLASS;
- if (InitCommonControlsEx(&initComCtrl) == FALSE) {
- TaskDialog(
- nullptr,
- nullptr,
- PROGRAM_NAME,
- L"Failed to start WinMute.",
- L"WinMute encountered a critical error while initializing and must shut down.",
- TDCBF_OK_BUTTON,
- TD_ERROR_ICON,
- nullptr);
- WMLog::GetInstance().WriteWindowsError(L"InitCommonControlsEx", GetLastError());
- ReleaseMutex(hMutex);
- return FALSE;
- } else if (CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED) != S_OK) {
- WMLog::GetInstance().WriteWindowsError(L"CoInitializeEx", GetLastError());
+ if (!InitWindowsComponents()) {
TaskDialog(
nullptr,
nullptr,
PROGRAM_NAME,
- L"Failed to start WinMute.",
- L"WinMute encountered a critical error while initializing and must shut down.",
+ i18n.GetString(IDS_MAIN_ERROR_INIT_WINMUTE_TITLE).c_str(),
+ i18n.GetString(IDS_MAIN_ERROR_INIT_WINMUTE_TEXT).c_str(),
TDCBF_OK_BUTTON,
TD_ERROR_ICON,
nullptr);
END
END
+#endif // German (Germany) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////////////////////////////////////
+// English (United Kingdom) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENG)
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_UK
+#pragma code_page(1252)
/////////////////////////////////////////////////////////////////////////////
//
STRINGTABLE
BEGIN
- IDI_LANG_NAME "English"
+ IDS_LANG_NAME "English"
+ IDS_MAIN_ERROR_SETTINGS_INIT_TITLE "Failed to initialize settings"
+ IDS_MAIN_ERROR_SETTINGS_INIT_TEXT
+ "Critical error while initializing WinMute"
+ IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TITLE "WinMute is already running"
+ IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TEXT
+ "Please look for a white speaker icon in your Windows taskbar notification area."
+ IDS_MAIN_ERROR_INIT_WINMUTE_TITLE "Failed to start WinMute."
+ IDS_MAIN_ERROR_INIT_WINMUTE_TEXT
+ "WinMute encountered a critical error while initializing and must shut down."
END
-#endif // German (Germany) resources
+#endif // English (United Kingdom) resources
/////////////////////////////////////////////////////////////////////////////
//
#define IDI_APP 5
#define IDD_ABOUT 9
-#define IDI_LANG_NAME 101
+#define IDS_LANG_NAME 101
+#define IDS_MAIN_ERROR_SETTINGS_INIT_TITLE 102
+#define IDS_MAIN_ERROR_SETTINGS_INIT_TEXT 103
#define IDI_TRAY_BRIGHT 104
+#define IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TITLE 104
#define IDI_TRAY_DARK 105
+#define IDS_MAIN_ERROR_WINMUTE_ALREADY_RUNNING_TEXT 105
#define IDR_TRAYMENU 106
+#define IDS_MAIN_ERROR_INIT_WINMUTE_TITLE 106
+#define IDS_MAIN_ERROR_INIT_WINMUTE_TEXT 107
#define IDD_SETTINGS 109
#define IDD_SETTINGS_GENERAL 114
#define IDD_SETTINGS_QUIETHOURS 116