Skip to content

Commit

Permalink
restore old CA-based setup
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhngtu committed Oct 30, 2022
1 parent 30b73b5 commit 74536fc
Show file tree
Hide file tree
Showing 4 changed files with 177 additions and 47 deletions.
132 changes: 132 additions & 0 deletions VietTypeATL/Register.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
#include <AccCtrl.h>
#include <AclAPI.h>

static std::vector<GUID> SupportedCategories = {
GUID_TFCAT_TIP_KEYBOARD,
GUID_TFCAT_TIPCAP_UIELEMENTENABLED, // UI-less
GUID_TFCAT_TIPCAP_COMLESS, // Google says this is required for WoW apps
GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT, // store apps?
GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT, // systray on win8+?
GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, // display attributes for composition
};

extern "C" typedef HRESULT(__cdecl* funtype)();

static void ShowRunError(HWND hWnd, HRESULT hr) {
Expand Down Expand Up @@ -112,6 +121,129 @@ extern "C" __declspec(dllexport) void CALLBACK
DoRunFunction(SetSettingsKeyAcl, hWnd, hInst, lpszCmdLine, nCmdShow);
}

static HRESULT RegisterProfiles() {
HRESULT hr;

if (!VietType::Globals::DllInstance) {
DBG_DPRINT(L"%s", L"VietType::Globals::DllInstance is invalid");
return E_UNEXPECTED;
}

WCHAR dllPath[MAX_PATH] = {0};

auto dllPathLength = GetModuleFileName(VietType::Globals::DllInstance, dllPath, MAX_PATH);
if (dllPathLength == 0) {
WINERROR_GLE_RETURN_HRESULT(L"%s", L"GetModuleFileName failed");
}
if (dllPathLength >= MAX_PATH) {
dllPathLength--;
}
dllPath[dllPathLength] = 0;
DBG_DPRINT(L"found text service DLL: %s", dllPath);

CComPtr<ITfInputProcessorProfileMgr> profileMgr;
hr = profileMgr.CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER);
HRESULT_CHECK_RETURN(hr, L"%s", L"profileMgr.CoCreateInstance failed");

hr = profileMgr->RegisterProfile(
VietType::Globals::CLSID_TextService,
VietType::Globals::TextServiceLangId,
VietType::Globals::GUID_Profile,
VietType::Globals::TextServiceDescription.c_str(),
static_cast<LONG>(VietType::Globals::TextServiceDescription.length()),
dllPath,
dllPathLength,
static_cast<ULONG>(-IDI_IMELOGO),
NULL,
0,
FALSE,
0);
HRESULT_CHECK_RETURN(hr, L"%s", L"profileMgr->RegisterProfile failed");

return S_OK;
}

extern "C" __declspec(dllexport) void CALLBACK
RunRegisterProfilesW(HWND hWnd, HINSTANCE hInst, LPWSTR lpszCmdLine, int nCmdShow) {
DoRunFunction(RegisterProfiles, hWnd, hInst, lpszCmdLine, nCmdShow);
}

static HRESULT UnregisterProfiles() {
HRESULT hr;

CComPtr<ITfInputProcessorProfileMgr> profileMgr;
hr = profileMgr.CoCreateInstance(CLSID_TF_InputProcessorProfiles, NULL, CLSCTX_INPROC_SERVER);
HRESULT_CHECK_RETURN(hr, L"%s", L"profileMgr.CoCreateInstance failed");

hr = profileMgr->UnregisterProfile(
VietType::Globals::CLSID_TextService,
VietType::Globals::TextServiceLangId,
VietType::Globals::GUID_Profile,
TF_URP_ALLPROFILES);

return S_OK;
}

extern "C" __declspec(dllexport) void CALLBACK
RunUnregisterProfilesW(HWND hWnd, HINSTANCE hInst, LPWSTR lpszCmdLine, int nCmdShow) {
DoRunFunction(UnregisterProfiles, hWnd, hInst, lpszCmdLine, nCmdShow);
}

static HRESULT RegisterCategories() {
HRESULT hr;

CComPtr<ITfCategoryMgr> categoryMgr;
hr = categoryMgr.CoCreateInstance(CLSID_TF_CategoryMgr, NULL, CLSCTX_INPROC_SERVER);
HRESULT_CHECK_RETURN(hr, L"%s", L"categoryMgr.CoCreateInstance failed");

for (const auto& cat : SupportedCategories) {
DBG_DPRINT(L"registering " GUID_WFORMAT, GUID_COMPONENTS(cat));
hr = categoryMgr->RegisterCategory(
VietType::Globals::CLSID_TextService, cat, VietType::Globals::CLSID_TextService);
HRESULT_CHECK_RETURN(hr, L"%s", L"categoryMgr->RegisterCategory failed");
}

return S_OK;
}

extern "C" __declspec(dllexport) void CALLBACK
RunRegisterCategoriesW(HWND hWnd, HINSTANCE hInst, LPWSTR lpszCmdLine, int nCmdShow) {
DoRunFunction(RegisterCategories, hWnd, hInst, lpszCmdLine, nCmdShow);
}

static HRESULT UnregisterCategories() {
HRESULT hr;

CComPtr<ITfCategoryMgr> categoryMgr;
hr = categoryMgr.CoCreateInstance(CLSID_TF_CategoryMgr, NULL, CLSCTX_INPROC_SERVER);
HRESULT_CHECK_RETURN(hr, L"%s", L"categoryMgr.CoCreateInstance failed");

CComPtr<IEnumGUID> registeredCategories;
hr = categoryMgr->EnumCategoriesInItem(VietType::Globals::CLSID_TextService, &registeredCategories);
HRESULT_CHECK_RETURN(hr, L"%s", L"categoryMgr->EnumCategoriesInItem failed");

GUID cat = {0};
ULONG fetched = 0;
while (1) {
hr = registeredCategories->Next(1, &cat, &fetched);
if (hr == S_OK) {
DBG_DPRINT(L"unregistering " GUID_WFORMAT, GUID_COMPONENTS(cat));
hr = categoryMgr->UnregisterCategory(
VietType::Globals::CLSID_TextService, cat, VietType::Globals::CLSID_TextService);
HRESULT_CHECK_RETURN(hr, L"%s", L"categoryMgr->UnregisterCategory failed");
} else {
break;
}
}

return S_OK;
}

extern "C" __declspec(dllexport) void CALLBACK
RunUnregisterCategoriesW(HWND hWnd, HINSTANCE hInst, LPWSTR lpszCmdLine, int nCmdShow) {
DoRunFunction(UnregisterCategories, hWnd, hInst, lpszCmdLine, nCmdShow);
}

extern "C" __declspec(dllexport) HRESULT __cdecl ActivateProfiles() {
HRESULT hr;
LSTATUS err;
Expand Down
4 changes: 4 additions & 0 deletions VietTypeATL/VietTypeATL.def
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ EXPORTS
DllUnregisterServer PRIVATE
DllInstall PRIVATE
RunSetSettingsKeyAclW
RunRegisterProfilesW
RunUnregisterProfilesW
RunRegisterCategoriesW
RunUnregisterCategoriesW
RunActivateProfilesW
RunDeactivateProfilesW
ActivateProfiles
Expand Down
84 changes: 37 additions & 47 deletions VietTypeSetup/Product.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ SPDX-License-Identifier: GPL-3.0-only
<?define upgradeCode = "{E00AC838-881D-4301-AAC5-0A723BB0B0EF}" ?>
<?endif ?>

<?define CLSID_TextService = "{C0DD01A1-0DEB-454B-8B42-D22CED1B4B23}" ?>
<?define GUID_Profile = "{8D93D10A-203B-4C5F-A122-8898EF9C56F5}" ?>
<?define GUID_TFCAT_TIP_KEYBOARD = "{34745C63-B2F0-4784-8B67-5E12C8701A31}" ?>
<?define GUID_TFCAT_TIPCAP_UIELEMENTENABLED = "{49D2F9CF-1F5E-11D7-A6D3-00065B84435C}" ?>
<?define GUID_TFCAT_TIPCAP_COMLESS = "{364215D9-75BC-11D7-A6EF-00065B84435C}" ?>
<?define GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT = "{13A016DF-560B-46CD-947A-4C3AF1E0E35D}" ?>
<?define GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT = "{25504FB4-7BAB-4BC1-9C69-CF81890F0EF5}" ?>
<?define GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER = "{046B8C80-1647-40F7-9B21-B93B81AABC1B}" ?>

<Product
Id="*"
Name="VietType"
Expand All @@ -44,7 +35,6 @@ SPDX-License-Identifier: GPL-3.0-only

<Feature Id="ProductFeature" Title="VietType" Absent="disallow" AllowAdvertise="no">
<ComponentGroupRef Id="ProductComponents" />
<ComponentGroupRef Id="RegistrationComponents" />
</Feature>

<Feature Id="ConfigFeature" Title="Configuration tool" AllowAdvertise="no">
Expand All @@ -62,6 +52,18 @@ SPDX-License-Identifier: GPL-3.0-only
<?if $(var.Platform) = x86 ?>
<Condition Message="32-bit setup can only run on a 32-bit OS.">Installed OR (NOT VersionNT64)</Condition>
<?endif ?>

<InstallExecuteSequence>
<Custom Action="RegisterCategoriesRollback" After="InstallFiles">(NOT Installed) OR REINSTALL</Custom>
<Custom Action="RegisterCategories" After="RegisterCategoriesRollback">(NOT Installed) OR REINSTALL</Custom>
<Custom Action="RegisterProfilesRollback" After="RegisterCategories">(NOT Installed) OR REINSTALL</Custom>
<Custom Action="RegisterProfiles" After="RegisterProfilesRollback">(NOT Installed) OR REINSTALL</Custom>

<Custom Action="UnregisterProfilesRollback" After="InstallInitialize">REMOVE OR REINSTALL</Custom>
<Custom Action="UnregisterProfiles" After="UnregisterProfilesRollback">REMOVE OR REINSTALL</Custom>
<Custom Action="UnregisterCategoriesRollback" After="UnregisterProfiles">REMOVE OR REINSTALL</Custom>
<Custom Action="UnregisterCategories" After="UnregisterCategoriesRollback">REMOVE OR REINSTALL</Custom>
</InstallExecuteSequence>
</Product>

<!-- ################################################################################ -->
Expand Down Expand Up @@ -118,43 +120,6 @@ SPDX-License-Identifier: GPL-3.0-only
</ComponentGroup>
</Fragment>

<!-- ################################################################################ -->
<!-- text service registration -->

<Fragment>
<ComponentGroup Id="RegistrationComponents">
<Component Win64="no" Directory="INSTALLFOLDER">
<RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\CTF\TIP\$(var.CLSID_TextService)">
<RegistryKey Key="Category">
<RegistryKey Key="Category\$(var.GUID_TFCAT_TIP_KEYBOARD)\$(var.CLSID_TextService)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="Category\$(var.GUID_TFCAT_TIPCAP_UIELEMENTENABLED)\$(var.CLSID_TextService)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="Category\$(var.GUID_TFCAT_TIPCAP_COMLESS)\$(var.CLSID_TextService)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="Category\$(var.GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT)\$(var.CLSID_TextService)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="Category\$(var.GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT)\$(var.CLSID_TextService)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="Category\$(var.GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER)\$(var.CLSID_TextService)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="Item\$(var.CLSID_TextService)">
<RegistryKey Key="$(var.GUID_TFCAT_TIP_KEYBOARD)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="$(var.GUID_TFCAT_TIPCAP_UIELEMENTENABLED)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="$(var.GUID_TFCAT_TIPCAP_COMLESS)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="$(var.GUID_TFCAT_TIPCAP_IMMERSIVESUPPORT)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="$(var.GUID_TFCAT_TIPCAP_SYSTRAYSUPPORT)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Key="$(var.GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER)" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
</RegistryKey>
</RegistryKey>

<!-- 0x0000042a = vi-VN -->
<RegistryKey Key="LanguageProfile\0x0000042a\$(var.GUID_Profile)">
<RegistryValue Type="string" Name="Description" Value="VietType" />
<RegistryValue Type="integer" Name="Enable" Value="0" />
<RegistryValue Type="string" Name="IconFile" Value="[#VietTypeATL32.dll]" />
<!-- -202 -->
<RegistryValue Type="integer" Name="IconIndex" Value="4294967094" />
</RegistryKey>
</RegistryKey>
</Component>
</ComponentGroup>
</Fragment>

<!-- ################################################################################ -->
<!-- shortcuts -->

Expand Down Expand Up @@ -201,6 +166,31 @@ SPDX-License-Identifier: GPL-3.0-only
</ComponentGroup>
</Fragment>

<!-- ################################################################################ -->
<!-- custom actions -->

<Fragment>
<SetProperty Id="RegisterCategories" Value='"[%SystemRoot]\System32\rundll32.exe" "[#VietTypeATL32.dll]",RunRegisterCategories' After="CostFinalize" Sequence="execute" />
<SetProperty Id="RegisterCategoriesRollback" Value='"[%SystemRoot]\System32\rundll32.exe" "[#VietTypeATL32.dll]",RunUnregisterCategories' After="CostFinalize" Sequence="execute" />
<SetProperty Id="UnregisterCategories" Value='"[%SystemRoot]\System32\rundll32.exe" "[#VietTypeATL32.dll]",RunUnregisterCategories' After="CostFinalize" Sequence="execute" />
<SetProperty Id="UnregisterCategoriesRollback" Value='"[%SystemRoot]\System32\rundll32.exe" "[#VietTypeATL32.dll]",RunRegisterCategories' After="CostFinalize" Sequence="execute" />

<SetProperty Id="RegisterProfiles" Value='"[%SystemRoot]\System32\rundll32.exe" "[#VietTypeATL32.dll]",RunRegisterProfiles' After="CostFinalize" Sequence="execute" />
<SetProperty Id="RegisterProfilesRollback" Value='"[%SystemRoot]\System32\rundll32.exe" "[#VietTypeATL32.dll]",RunUnregisterProfiles' After="CostFinalize" Sequence="execute" />
<SetProperty Id="UnregisterProfiles" Value='"[%SystemRoot]\System32\rundll32.exe" "[#VietTypeATL32.dll]",RunUnregisterProfiles' After="CostFinalize" Sequence="execute" />
<SetProperty Id="UnregisterProfilesRollback" Value='"[%SystemRoot]\System32\rundll32.exe" "[#VietTypeATL32.dll]",RunRegisterProfiles' After="CostFinalize" Sequence="execute" />

<CustomAction Id="RegisterCategories" BinaryKey="WixCA" DllEntry="WixQuietExec" Impersonate="no" Execute="deferred" />
<CustomAction Id="RegisterCategoriesRollback" BinaryKey="WixCA" DllEntry="WixQuietExec" Impersonate="no" Execute="rollback" />
<CustomAction Id="UnregisterCategories" BinaryKey="WixCA" DllEntry="WixQuietExec" Impersonate="no" Execute="deferred" />
<CustomAction Id="UnregisterCategoriesRollback" BinaryKey="WixCA" DllEntry="WixQuietExec" Impersonate="no" Execute="rollback" />

<CustomAction Id="RegisterProfiles" BinaryKey="WixCA" DllEntry="WixQuietExec" Impersonate="no" Execute="deferred" />
<CustomAction Id="RegisterProfilesRollback" BinaryKey="WixCA" DllEntry="WixQuietExec" Impersonate="no" Execute="rollback" />
<CustomAction Id="UnregisterProfiles" BinaryKey="WixCA" DllEntry="WixQuietExec" Impersonate="no" Execute="deferred" />
<CustomAction Id="UnregisterProfilesRollback" BinaryKey="WixCA" DllEntry="WixQuietExec" Impersonate="no" Execute="rollback" />
</Fragment>

<!-- ################################################################################ -->
<!-- after install -->

Expand Down
4 changes: 4 additions & 0 deletions VietTypeSetup/VietTypeSetup.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<Compile Include="Product.wxs" />
</ItemGroup>
<ItemGroup>
<WixExtension Include="WixUtilExtension">
<HintPath>$(WixExtDir)\WixUtilExtension.dll</HintPath>
<Name>WixUtilExtension</Name>
</WixExtension>
<WixExtension Include="WixUIExtension">
<HintPath>$(WixExtDir)\WixUIExtension.dll</HintPath>
<Name>WixUIExtension</Name>
Expand Down

0 comments on commit 74536fc

Please sign in to comment.