diff --git a/WeaselSetup/WeaselSetup.cpp b/WeaselSetup/WeaselSetup.cpp index 865e4855c..5e9378bbc 100644 --- a/WeaselSetup/WeaselSetup.cpp +++ b/WeaselSetup/WeaselSetup.cpp @@ -151,6 +151,26 @@ static int Run(LPTSTR lpCmdLine) { if (uninstalling) return uninstall(silent); + auto setLanguage = [](const wchar_t* language) { + const WCHAR KEY[] = L"Software\\Rime\\Weasel"; + HKEY hKey; + LSTATUS ret = RegOpenKey(HKEY_CURRENT_USER, KEY, &hKey); + if (ret == ERROR_SUCCESS) { + ret = RegSetValueEx(hKey, L"Language", 0, REG_SZ, (const BYTE*)language, + (wcslen(language) + 1) * sizeof(wchar_t)); + RegCloseKey(hKey); + } + return ret; + }; + + if (!wcscmp(L"/ls", lpCmdLine)) { + return setLanguage(L"chs"); + } else if (!wcscmp(L"/lt", lpCmdLine)) { + return setLanguage(L"cht"); + } else if (!wcscmp(L"/le", lpCmdLine)) { + return setLanguage(L"eng"); + } + bool hans = !wcscmp(L"/s", lpCmdLine); if (hans) return install(false, silent, old_ime_support); diff --git a/WeaselTSF/LanguageBar.cpp b/WeaselTSF/LanguageBar.cpp index 7e535e343..13198cf72 100644 --- a/WeaselTSF/LanguageBar.cpp +++ b/WeaselTSF/LanguageBar.cpp @@ -34,21 +34,6 @@ static void HMENU2ITfMenu(HMENU hMenu, ITfMenu* pTfMenu) { } } -static LONG RegGetStringValue(HKEY key, - LPCWSTR lpSubKey, - LPCWSTR lpValue, - std::wstring& value) { - TCHAR szValue[MAX_PATH]; - DWORD dwBufLen = MAX_PATH; - - LONG lRes = RegGetValue(key, lpSubKey, lpValue, RRF_RT_REG_SZ, NULL, szValue, - &dwBufLen); - if (lRes == ERROR_SUCCESS) { - value = std::wstring(szValue); - } - return lRes; -} - static LPCWSTR GetWeaselRegName() { LPCWSTR WEASEL_REG_NAME_; if (is_wow64()) diff --git a/include/WeaselUtility.h b/include/WeaselUtility.h index 942cd8ab9..100766c62 100644 --- a/include/WeaselUtility.h +++ b/include/WeaselUtility.h @@ -197,7 +197,32 @@ inline std::wstring get_weasel_ime_name() { } } +inline LONG RegGetStringValue(HKEY key, + LPCWSTR lpSubKey, + LPCWSTR lpValue, + std::wstring& value) { + TCHAR szValue[MAX_PATH]; + DWORD dwBufLen = MAX_PATH; + + LONG lRes = RegGetValue(key, lpSubKey, lpValue, RRF_RT_REG_SZ, NULL, szValue, + &dwBufLen); + if (lRes == ERROR_SUCCESS) { + value = std::wstring(szValue); + } + return lRes; +} + inline LANGID get_language_id() { + std::wstring lang{}; + if (RegGetStringValue(HKEY_CURRENT_USER, L"Software\\Rime\\Weasel", + L"Language", lang) == ERROR_SUCCESS) { + if (lang == L"chs") + return MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); + else if (lang == L"cht") + return MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL); + else if (lang == L"eng") + return MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); + } LANGID langId = GetUserDefaultUILanguage(); if (langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) || langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE)) { @@ -210,4 +235,4 @@ inline LANGID get_language_id() { langId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); } return langId; -} \ No newline at end of file +}