Skip to content

Commit be2c706

Browse files
committed
修复一些问题
1 parent 82d9891 commit be2c706

File tree

3 files changed

+55
-35
lines changed

3 files changed

+55
-35
lines changed

MiHoYoStarter/FormInput.cs

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace MiHoYoStarter
1313
public partial class FormInput : Form
1414
{
1515
private string gameNameEN;
16+
1617
public FormInput(string gameNameEN)
1718
{
1819
InitializeComponent();
@@ -27,41 +28,48 @@ private void btnSave_Click(object sender, EventArgs e)
2728
return;
2829
}
2930

30-
MiHoYoAccount acct = null;
31-
if (gameNameEN == "Genshin")
32-
{
33-
acct = new GenshinAccount();
34-
35-
}
36-
else if (gameNameEN == "Genshin*")
37-
{
38-
acct = new GenshinOverseaAccount();
39-
}
40-
else if (gameNameEN == "GenshinCloud")
41-
{
42-
acct = new GenshinCloudAccount();
43-
}
44-
else if (gameNameEN == "StarRail")
31+
try
4532
{
46-
acct = new StarRailAccount();
47-
}
48-
else if (gameNameEN == "StarRail*")
49-
{
50-
acct = new StarRailOverseaAccount();
51-
}
52-
else if (gameNameEN == "HonkaiImpact3")
53-
{
54-
acct = new HonkaiImpact3Account();
33+
MiHoYoAccount acct = null;
34+
if (gameNameEN == "Genshin")
35+
{
36+
acct = new GenshinAccount();
37+
}
38+
else if (gameNameEN == "Genshin*")
39+
{
40+
acct = new GenshinOverseaAccount();
41+
}
42+
else if (gameNameEN == "GenshinCloud")
43+
{
44+
acct = new GenshinCloudAccount();
45+
}
46+
else if (gameNameEN == "StarRail")
47+
{
48+
acct = new StarRailAccount();
49+
}
50+
else if (gameNameEN == "StarRail*")
51+
{
52+
acct = new StarRailOverseaAccount();
53+
}
54+
else if (gameNameEN == "HonkaiImpact3")
55+
{
56+
acct = new HonkaiImpact3Account();
57+
}
58+
else
59+
{
60+
MessageBox.Show("未知的游戏账户类型", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
61+
return;
62+
}
63+
64+
acct.ReadFromRegistry();
65+
acct.Name = txtAcctName.Text;
66+
acct.WriteToDisk();
67+
this.Close();
5568
}
56-
else
69+
catch (Exception ex)
5770
{
58-
MessageBox.Show("未知的游戏账户类型", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
59-
return;
71+
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
6072
}
61-
acct.ReadFromRegistry();
62-
acct.Name = txtAcctName.Text;
63-
acct.WriteToDisk();
64-
this.Close();
6573
}
6674
}
67-
}
75+
}

MiHoYoStarter/GameFormControl.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ private void btnChoosePathClick(object sender, EventArgs e)
230230

231231
private void btnAddClick(object sender, EventArgs e)
232232
{
233+
// 是否国际服
234+
if (cboServer != null)
235+
{
236+
IsOversea = cboServer.SelectedIndex == 1;
237+
}
233238
string GameNameENX = GameNameEN;
234239
if (IsOversea)
235240
{

MiHoYoStarter/MiHoYoAccount.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace MiHoYoStarter
1515
public class MiHoYoAccount
1616
{
1717
public string Name { get; set; }
18+
1819
/// <summary>
1920
/// 每个游戏保存的数据存在不同的目录
2021
/// </summary>
@@ -24,10 +25,12 @@ public class MiHoYoAccount
2425
/// 注册表记住账户信息的键值位置
2526
/// </summary>
2627
public string AccountRegKeyName { get; set; }
28+
2729
/// <summary>
2830
/// 注册表记住账户信息的键值名
2931
/// </summary>
3032
public string AccountRegValueName { get; set; }
33+
3134
/// <summary>
3235
/// 注册表记住账户信息的键值数据
3336
/// </summary>
@@ -47,7 +50,8 @@ public MiHoYoAccount(string saveFolderName, string accountRegKeyName, string acc
4750

4851
public void WriteToDisk()
4952
{
50-
File.WriteAllText(Path.Combine(Application.StartupPath, "UserData", SaveFolderName, Name), new JavaScriptSerializer().Serialize(this));
53+
File.WriteAllText(Path.Combine(Application.StartupPath, "UserData", SaveFolderName, Name),
54+
new JavaScriptSerializer().Serialize(this));
5155
}
5256

5357
public static void DeleteFromDisk(string userDataPath, string name)
@@ -76,13 +80,16 @@ public void WriteToRegistry()
7680
protected string GetStringFromRegistry(string key)
7781
{
7882
object value = Registry.GetValue(AccountRegKeyName, key, "");
83+
if (value == null)
84+
{
85+
throw new Exception($@"注册表{AccountRegKeyName}\{key}中没有找到账户信息");
86+
}
7987
return Encoding.UTF8.GetString((byte[])value);
8088
}
8189

8290
protected void SetStringToRegistry(string key, string value)
8391
{
8492
Registry.SetValue(AccountRegKeyName, key, Encoding.UTF8.GetBytes(value));
8593
}
86-
8794
}
88-
}
95+
}

0 commit comments

Comments
 (0)