diff --git a/Weasel.Setup/Program.cs b/Weasel.Setup/Program.cs index 977f2ce2e..d17807501 100644 --- a/Weasel.Setup/Program.cs +++ b/Weasel.Setup/Program.cs @@ -58,7 +58,7 @@ private static void Run(string arg) if (arg.StartsWith("/userdir:")) // 设置用户目录 { var dir = arg.Substring(arg.IndexOf(':') + 1); - if (!string.IsNullOrEmpty(arg)) + if (dir != null) { Utils.Reg.SetValue(Registry.CurrentUser, WEASEL_PROG_REG_KEY, "RimeUserDir", dir); } @@ -124,7 +124,7 @@ private static void Run(string arg) } catch (Exception ex) { - MessageBox.Show(Localization.Resources.STR_ERROR, ex.Message); + MessageBox.Show(ex.Message, Localization.Resources.STR_ERROR); } } diff --git a/Weasel.Setup/Setup.cs b/Weasel.Setup/Setup.cs index dc30f1e53..d5bfb6ac3 100644 --- a/Weasel.Setup/Setup.cs +++ b/Weasel.Setup/Setup.cs @@ -62,14 +62,8 @@ public static void NormalInstall(bool isHant, bool isSilentMode = true) Utils.Reg.SetValue(Registry.LocalMachine, WEASEL_PROG_REG_KEY, "ServerExecutable", WEASEL_SERVER_EXE); // 启用键盘布局和文本服务 - if (isHant) - { - PInvoke.Input.InstallLayoutOrTip(PSZTITLE_HANT, 0); - } - else - { - PInvoke.Input.InstallLayoutOrTip(PSZTITLE_HANS, 0); - } + var psz = isHant ? PSZTITLE_HANT : PSZTITLE_HANS; + PInvoke.Input.InstallLayoutOrTip(psz, 0); // 收集用户模式转储 // https://learn.microsoft.com/zh-cn/windows/win32/wer/collecting-user-mode-dumps @@ -94,14 +88,8 @@ public static void Uninstall(bool isSilentMode) var isHant = Convert.ToBoolean( Utils.Reg.GetValue(Registry.CurrentUser, WEASEL_PROG_REG_KEY, "Hant", 0) ); - if (isHant) - { - PInvoke.Input.InstallLayoutOrTip(PSZTITLE_HANT, PInvoke.Input.ILOT.ILOT_UNINSTALL); - } - else - { - PInvoke.Input.InstallLayoutOrTip(PSZTITLE_HANS, PInvoke.Input.ILOT.ILOT_UNINSTALL); - } + var psz = isHant ? PSZTITLE_HANT : PSZTITLE_HANS; + PInvoke.Input.InstallLayoutOrTip(psz, PInvoke.Input.ILOT.ILOT_UNINSTALL); UninstallImeFiles("weasel.dll", (imePath) => { @@ -186,7 +174,8 @@ private static void InstallImeFiles(string srcPath, Action updateService } else { - if (File.Exists(srcPath)) { + if (File.Exists(srcPath)) + { File.Copy(srcPath, destPath, true); updateService(destPath); } @@ -247,16 +236,10 @@ private static void UpdateServiceState(string libPath, bool enable, bool isHant) if (!enable) UpdateProfile(false, isHant); var value = isHant ? "hant" : "hans"; Environment.SetEnvironmentVariable("TEXTSERVICE_PROFILE", value); - string regsvr32Path; var sysarm32Dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "SysArm32"); - if (Directory.Exists(sysarm32Dir)) - { - regsvr32Path = Path.Combine(sysarm32Dir, "regsvr32.exe"); - } - else - { - regsvr32Path = "regsvr32.exe"; - } + var regsvr32Path = Directory.Exists(sysarm32Dir) + ? Path.Combine(sysarm32Dir, "regsvr32.exe") + : "regsvr32.exe"; var args = enable ? $"/s \"{libPath}\"" : $"/s /u \"{libPath}\""; var updateInfo = new ProcessStartInfo { diff --git a/Weasel.Setup/SetupOptionDialog.cs b/Weasel.Setup/SetupOptionDialog.cs index d6932299d..5d829a46e 100644 --- a/Weasel.Setup/SetupOptionDialog.cs +++ b/Weasel.Setup/SetupOptionDialog.cs @@ -26,7 +26,8 @@ private void InstallOptionDialog_Load(object sender, System.EventArgs e) selectButton.Enabled = !string.IsNullOrEmpty(UserDir); customPathBox.Text = UserDir; - if (IsInstalled) { + if (IsInstalled) + { confirmButton.Text = Localization.Resources.STR_OK; } removeButton.Enabled = IsInstalled; @@ -38,7 +39,7 @@ private void DefaultFolderRadio_CheckedChanged(object sender, System.EventArgs e { customPathBox.Text = string.Empty; customPathBox.Enabled = false; - selectButton.Enabled= false; + selectButton.Enabled = false; } } @@ -54,13 +55,9 @@ private void CustomFolderRadio_CheckedChanged(object sender, System.EventArgs e) private void ConfirmButton_Click(object sender, System.EventArgs e) { IsHant = chtRadio.Checked; - if (customFolderRadio.Checked) - { - UserDir = customPathBox.Text; - } else - { - UserDir = string.Empty; - } + UserDir = customFolderRadio.Checked + ? customPathBox.Text + : string.Empty; DialogResult = DialogResult.OK; Close(); }