Skip to content

Commit 39d541e

Browse files
committed
refactor(Weasel.Setup): slightly format the codes
1 parent 5cd07b1 commit 39d541e

File tree

3 files changed

+17
-37
lines changed

3 files changed

+17
-37
lines changed

Weasel.Setup/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private static void Run(string arg)
5858
if (arg.StartsWith("/userdir:")) // 设置用户目录
5959
{
6060
var dir = arg.Substring(arg.IndexOf(':') + 1);
61-
if (!string.IsNullOrEmpty(arg))
61+
if (dir != null)
6262
{
6363
Utils.Reg.SetValue(Registry.CurrentUser, WEASEL_PROG_REG_KEY, "RimeUserDir", dir);
6464
}
@@ -124,7 +124,7 @@ private static void Run(string arg)
124124
}
125125
catch (Exception ex)
126126
{
127-
MessageBox.Show(Localization.Resources.STR_ERROR, ex.Message);
127+
MessageBox.Show(ex.Message, Localization.Resources.STR_ERROR);
128128
}
129129
}
130130

Weasel.Setup/Setup.cs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,8 @@ public static void NormalInstall(bool isHant, bool isSilentMode = true)
6262
Utils.Reg.SetValue(Registry.LocalMachine, WEASEL_PROG_REG_KEY, "ServerExecutable", WEASEL_SERVER_EXE);
6363

6464
// 启用键盘布局和文本服务
65-
if (isHant)
66-
{
67-
PInvoke.Input.InstallLayoutOrTip(PSZTITLE_HANT, 0);
68-
}
69-
else
70-
{
71-
PInvoke.Input.InstallLayoutOrTip(PSZTITLE_HANS, 0);
72-
}
65+
var psz = isHant ? PSZTITLE_HANT : PSZTITLE_HANS;
66+
PInvoke.Input.InstallLayoutOrTip(psz, 0);
7367

7468
// 收集用户模式转储
7569
// https://learn.microsoft.com/zh-cn/windows/win32/wer/collecting-user-mode-dumps
@@ -94,14 +88,8 @@ public static void Uninstall(bool isSilentMode)
9488
var isHant = Convert.ToBoolean(
9589
Utils.Reg.GetValue(Registry.CurrentUser, WEASEL_PROG_REG_KEY, "Hant", 0)
9690
);
97-
if (isHant)
98-
{
99-
PInvoke.Input.InstallLayoutOrTip(PSZTITLE_HANT, PInvoke.Input.ILOT.ILOT_UNINSTALL);
100-
}
101-
else
102-
{
103-
PInvoke.Input.InstallLayoutOrTip(PSZTITLE_HANS, PInvoke.Input.ILOT.ILOT_UNINSTALL);
104-
}
91+
var psz = isHant ? PSZTITLE_HANT : PSZTITLE_HANS;
92+
PInvoke.Input.InstallLayoutOrTip(psz, PInvoke.Input.ILOT.ILOT_UNINSTALL);
10593

10694
UninstallImeFiles("weasel.dll", (imePath) =>
10795
{
@@ -186,7 +174,8 @@ private static void InstallImeFiles(string srcPath, Action<string> updateService
186174
}
187175
else
188176
{
189-
if (File.Exists(srcPath)) {
177+
if (File.Exists(srcPath))
178+
{
190179
File.Copy(srcPath, destPath, true);
191180
updateService(destPath);
192181
}
@@ -247,16 +236,10 @@ private static void UpdateServiceState(string libPath, bool enable, bool isHant)
247236
if (!enable) UpdateProfile(false, isHant);
248237
var value = isHant ? "hant" : "hans";
249238
Environment.SetEnvironmentVariable("TEXTSERVICE_PROFILE", value);
250-
string regsvr32Path;
251239
var sysarm32Dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "SysArm32");
252-
if (Directory.Exists(sysarm32Dir))
253-
{
254-
regsvr32Path = Path.Combine(sysarm32Dir, "regsvr32.exe");
255-
}
256-
else
257-
{
258-
regsvr32Path = "regsvr32.exe";
259-
}
240+
var regsvr32Path = Directory.Exists(sysarm32Dir)
241+
? Path.Combine(sysarm32Dir, "regsvr32.exe")
242+
: "regsvr32.exe";
260243
var args = enable ? $"/s \"{libPath}\"" : $"/s /u \"{libPath}\"";
261244
var updateInfo = new ProcessStartInfo
262245
{

Weasel.Setup/SetupOptionDialog.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ private void InstallOptionDialog_Load(object sender, System.EventArgs e)
2626
selectButton.Enabled = !string.IsNullOrEmpty(UserDir);
2727
customPathBox.Text = UserDir;
2828

29-
if (IsInstalled) {
29+
if (IsInstalled)
30+
{
3031
confirmButton.Text = Localization.Resources.STR_OK;
3132
}
3233
removeButton.Enabled = IsInstalled;
@@ -38,7 +39,7 @@ private void DefaultFolderRadio_CheckedChanged(object sender, System.EventArgs e
3839
{
3940
customPathBox.Text = string.Empty;
4041
customPathBox.Enabled = false;
41-
selectButton.Enabled= false;
42+
selectButton.Enabled = false;
4243
}
4344
}
4445

@@ -54,13 +55,9 @@ private void CustomFolderRadio_CheckedChanged(object sender, System.EventArgs e)
5455
private void ConfirmButton_Click(object sender, System.EventArgs e)
5556
{
5657
IsHant = chtRadio.Checked;
57-
if (customFolderRadio.Checked)
58-
{
59-
UserDir = customPathBox.Text;
60-
} else
61-
{
62-
UserDir = string.Empty;
63-
}
58+
UserDir = customFolderRadio.Checked
59+
? customPathBox.Text
60+
: string.Empty;
6461
DialogResult = DialogResult.OK;
6562
Close();
6663
}

0 commit comments

Comments
 (0)