Skip to content

Commit

Permalink
refactor(Weasel.Setup): slightly format the codes
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Jan 12, 2025
1 parent 327e415 commit 9910e33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 37 deletions.
4 changes: 2 additions & 2 deletions Weasel.Setup/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}

Expand Down
35 changes: 9 additions & 26 deletions Weasel.Setup/Setup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) =>
{
Expand Down Expand Up @@ -186,7 +174,8 @@ private static void InstallImeFiles(string srcPath, Action<string> updateService
}
else
{
if (File.Exists(srcPath)) {
if (File.Exists(srcPath))
{
File.Copy(srcPath, destPath, true);
updateService(destPath);
}
Expand Down Expand Up @@ -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
{
Expand Down
15 changes: 6 additions & 9 deletions Weasel.Setup/SetupOptionDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}

Expand All @@ -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();
}
Expand Down

0 comments on commit 9910e33

Please sign in to comment.