Skip to content

Commit

Permalink
Merge pull request #176 from chewing/msi-improvement
Browse files Browse the repository at this point in the history
MSI improvements
  • Loading branch information
kanru authored Jun 29, 2024
2 parents 323b8d7 + 04f82dd commit 6cbf814
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
10 changes: 7 additions & 3 deletions installer/windows-chewing-tsf.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
Language="1028"
Manufacturer="新酷音輸入法開發團隊"
Version="1.0.0.1"
UpgradeStrategy="majorUpgrade"
UpgradeCode="8085e4ce-205d-4c44-9450-59ba34163b2a">
<MediaTemplate EmbedCab="yes" />
<MajorUpgrade AllowDowngrades="yes" />
<MediaTemplate CompressionLevel="high" EmbedCab="yes" />
<StandardDirectory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER32" Name="ChewingTextService">
<Directory Id="Dictionary" Name="Dictionary">
Expand Down Expand Up @@ -44,15 +46,17 @@
<!-- Remove NSIS Uninstaller -->
<RemoveFile Name="Uninstall.exe" On="install" />
</Component>
<File Source="chewing.ico" />
</Directory>
</StandardDirectory>
<Binary Id="tsfreg" SourceFile="tsfreg.exe" />
<CustomAction Id="RegisterTSF" BinaryRef="tsfreg" ExeCommand="-r '[INSTALLFOLDER32]ChewingTextService.dll'"
<CustomAction Id="RegisterTSF" BinaryRef="tsfreg"
ExeCommand="-r &quot;[INSTALLFOLDER64]chewing.ico&quot;"
Impersonate="no" Execute="deferred" Return="check" />
<CustomAction Id="UnregisterTSF" BinaryRef="tsfreg" ExeCommand="-u" Impersonate="no"
Execute="deferred" Return="check" />
<InstallExecuteSequence>
<Custom Action="RegisterTSF" Before="InstallFinalize"
<Custom Action="RegisterTSF" After="WriteRegistryValues"
Condition='Installed="" AND PREVIOUSVERSIONSINSTALLED=""' />
<Custom Action="UnregisterTSF" Before="RemoveRegistryValues"
Condition='PREVIOUSVERSIONSINSTALLED="" AND REMOVE="ALL"' />
Expand Down
1 change: 1 addition & 0 deletions scripts/build_installer.bat
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mkdir dist
mkdir nsis
copy installer\* nsis\
copy COPYING.txt nsis\
copy ChewingTextService\mainicon2.ico nsis\chewing.ico
mkdir nsis\Dictionary
copy libchewing\data\*.dat nsis\Dictionary\
copy x64\libchewing\data\*.dat nsis\Dictionary\
Expand Down
42 changes: 29 additions & 13 deletions tsfreg/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![windows_subsystem = "windows"]

use std::{env, process};

use windows::{
Expand All @@ -8,25 +10,29 @@ use windows::{
const CHEWING_TSF_CLSID: GUID = GUID::from_u128(0x13F2EF08_575C_4D8C_88E0_F67BB8052B84);
const CHEWING_PROFILE_GUID: GUID = GUID::from_u128(0xCE45F71D_CE79_41D1_967D_640B65A380E3);

fn register(dllpath: String) -> Result<()> {
fn register(icon_path: String) -> Result<()> {
unsafe {
let input_processor_profiles: ITfInputProcessorProfiles =
let input_processor_profile_mgr: ITfInputProcessorProfileMgr =
CoCreateInstance(&CLSID_TF_InputProcessorProfiles, None, CLSCTX_INPROC_SERVER)?;

input_processor_profiles.Register(&CHEWING_TSF_CLSID)?;

let mut lcid = LocaleNameToLCID(w!("zh-Hant-TW"), 0);
if lcid == 0 {
lcid = LocaleNameToLCID(w!("zh-TW"), 0);
}
let pw_icon_path = dllpath.encode_utf16().collect::<Vec<_>>();
input_processor_profiles.AddLanguageProfile(

let pw_icon_path = icon_path.encode_utf16().collect::<Vec<_>>();

input_processor_profile_mgr.RegisterProfile(
&CHEWING_TSF_CLSID,
lcid.try_into().unwrap(),
lcid as u16,
&CHEWING_PROFILE_GUID,
w!("新酷音輸入法").as_wide(),
&pw_icon_path,
1,
0,
None,
0,
true,
0,
)?;

let category_manager: ITfCategoryMgr =
Expand Down Expand Up @@ -69,10 +75,20 @@ fn register(dllpath: String) -> Result<()> {

fn unregister() -> Result<()> {
unsafe {
let input_processor_profiles: ITfInputProcessorProfiles =
let input_processor_profile_mgr: ITfInputProcessorProfileMgr =
CoCreateInstance(&CLSID_TF_InputProcessorProfiles, None, CLSCTX_INPROC_SERVER)?;

input_processor_profiles.Unregister(&CHEWING_TSF_CLSID)?;
let mut lcid = LocaleNameToLCID(w!("zh-Hant-TW"), 0);
if lcid == 0 {
lcid = LocaleNameToLCID(w!("zh-TW"), 0);
}

input_processor_profile_mgr.UnregisterProfile(
&CHEWING_TSF_CLSID,
lcid as u16,
&CHEWING_PROFILE_GUID,
0,
)?;
}
Ok(())
}
Expand All @@ -83,14 +99,14 @@ fn main() -> Result<()> {

if env::args().len() == 1 {
println!("Usage:");
println!(" tsfreg -r <DllPath> 註冊輸入法");
println!(" tsfreg -r <IconPath> 註冊輸入法");
println!(" tsfreg -u 取消註冊");
process::exit(1);
}

if let Some("-r") = env::args().nth(1).as_ref().map(|s| s.as_str()) {
let dllpath = env::args().nth(2).expect("缺少 DllPath");
register(dllpath)?;
let icon_path = env::args().nth(2).expect("缺少 IconPath");
register(icon_path)?;
} else {
unregister()?;
}
Expand Down

0 comments on commit 6cbf814

Please sign in to comment.