Skip to content

Commit

Permalink
fix: the UI language was incorrectly determined by "Region Format"
Browse files Browse the repository at this point in the history
  • Loading branch information
ccyybn committed Jun 9, 2024
1 parent 3234006 commit 44f7fd2
Show file tree
Hide file tree
Showing 5 changed files with 604 additions and 595 deletions.
179 changes: 90 additions & 89 deletions WeaselDeployer/WeaselDeployer.cpp
Original file line number Diff line number Diff line change
@@ -1,90 +1,91 @@
// WeaselDeployer.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <WeaselUtility.h>
#include <fstream>
#include "WeaselDeployer.h"
#include "Configurator.h"

CAppModule _Module;

static int Run(LPTSTR lpCmdLine);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance);

LCID lcid = GetUserDefaultLCID();
LANGID langId;
if (lcid == 2052 || lcid == 3072 || lcid == 4100) {
langId = SetThreadUILanguage(
MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED));
} else if (lcid == 1028 || lcid == 3076 || lcid == 5124) {
langId = SetThreadUILanguage(
MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL));
} else {
langId = SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
}
SetThreadLocale(langId);

HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call
// instead to make the EXE free threaded. This means that calls come in on a
// random RPC thread.
// HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
ATLASSERT(SUCCEEDED(hRes));

// this resolves ATL window thunking problem when Microsoft Layer for Unicode
// (MSLU) is used
::DefWindowProc(NULL, 0, 0, 0L);

AtlInitCommonControls(
ICC_BAR_CLASSES); // add flags to support other controls

hRes = _Module.Init(NULL, hInstance);
ATLASSERT(SUCCEEDED(hRes));

CreateDirectory(WeaselUserDataPath().c_str(), NULL);

int ret = 0;
HANDLE hMutex = CreateMutex(NULL, TRUE, L"WeaselDeployerExclusiveMutex");
if (!hMutex) {
ret = 1;
} else if (GetLastError() == ERROR_ALREADY_EXISTS) {
ret = 1;
} else {
ret = Run(lpCmdLine);
}

if (hMutex) {
CloseHandle(hMutex);
}
_Module.Term();
::CoUninitialize();

return ret;
}

static int Run(LPTSTR lpCmdLine) {
Configurator configurator;
configurator.Initialize();
bool deployment_scheduled = !wcscmp(L"/deploy", lpCmdLine);
if (deployment_scheduled) {
return configurator.UpdateWorkspace();
}

bool dict_management = !wcscmp(L"/dict", lpCmdLine);
if (dict_management) {
return configurator.DictManagement();
}

bool sync_user_dict = !wcscmp(L"/sync", lpCmdLine);
if (sync_user_dict) {
return configurator.SyncUserData();
}

bool installing = !wcscmp(L"/install", lpCmdLine);
return configurator.Run(installing);
// WeaselDeployer.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include <WeaselUtility.h>
#include <fstream>
#include "WeaselDeployer.h"
#include "Configurator.h"

CAppModule _Module;

static int Run(LPTSTR lpCmdLine);

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow) {
UNREFERENCED_PARAMETER(hPrevInstance);

LANGID langId = GetUserDefaultUILanguage();
if (langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) ||
langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SINGAPORE)) {
langId = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED);
} else if (langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL) ||
langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_HONGKONG) ||
langId == MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_MACAU)) {
langId = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_TRADITIONAL);
} else {
langId = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
}
SetThreadUILanguage(langId);
SetThreadLocale(langId);

HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call
// instead to make the EXE free threaded. This means that calls come in on a
// random RPC thread.
// HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
ATLASSERT(SUCCEEDED(hRes));

// this resolves ATL window thunking problem when Microsoft Layer for Unicode
// (MSLU) is used
::DefWindowProc(NULL, 0, 0, 0L);

AtlInitCommonControls(
ICC_BAR_CLASSES); // add flags to support other controls

hRes = _Module.Init(NULL, hInstance);
ATLASSERT(SUCCEEDED(hRes));

CreateDirectory(WeaselUserDataPath().c_str(), NULL);

int ret = 0;
HANDLE hMutex = CreateMutex(NULL, TRUE, L"WeaselDeployerExclusiveMutex");
if (!hMutex) {
ret = 1;
} else if (GetLastError() == ERROR_ALREADY_EXISTS) {
ret = 1;
} else {
ret = Run(lpCmdLine);
}

if (hMutex) {
CloseHandle(hMutex);
}
_Module.Term();
::CoUninitialize();

return ret;
}

static int Run(LPTSTR lpCmdLine) {
Configurator configurator;
configurator.Initialize();
bool deployment_scheduled = !wcscmp(L"/deploy", lpCmdLine);
if (deployment_scheduled) {
return configurator.UpdateWorkspace();
}

bool dict_management = !wcscmp(L"/dict", lpCmdLine);
if (dict_management) {
return configurator.DictManagement();
}

bool sync_user_dict = !wcscmp(L"/sync", lpCmdLine);
if (sync_user_dict) {
return configurator.SyncUserData();
}

bool installing = !wcscmp(L"/install", lpCmdLine);
return configurator.Run(installing);
}
Loading

0 comments on commit 44f7fd2

Please sign in to comment.