diff --git a/MiHoYoStarter/FormInput.cs b/MiHoYoStarter/FormInput.cs
index c621f69..1140255 100644
--- a/MiHoYoStarter/FormInput.cs
+++ b/MiHoYoStarter/FormInput.cs
@@ -13,6 +13,7 @@ namespace MiHoYoStarter
public partial class FormInput : Form
{
private string gameNameEN;
+
public FormInput(string gameNameEN)
{
InitializeComponent();
@@ -27,41 +28,48 @@ private void btnSave_Click(object sender, EventArgs e)
return;
}
- MiHoYoAccount acct = null;
- if (gameNameEN == "Genshin")
- {
- acct = new GenshinAccount();
-
- }
- else if (gameNameEN == "Genshin*")
- {
- acct = new GenshinOverseaAccount();
- }
- else if (gameNameEN == "GenshinCloud")
- {
- acct = new GenshinCloudAccount();
- }
- else if (gameNameEN == "StarRail")
+ try
{
- acct = new StarRailAccount();
- }
- else if (gameNameEN == "StarRail*")
- {
- acct = new StarRailOverseaAccount();
- }
- else if (gameNameEN == "HonkaiImpact3")
- {
- acct = new HonkaiImpact3Account();
+ MiHoYoAccount acct = null;
+ if (gameNameEN == "Genshin")
+ {
+ acct = new GenshinAccount();
+ }
+ else if (gameNameEN == "Genshin*")
+ {
+ acct = new GenshinOverseaAccount();
+ }
+ else if (gameNameEN == "GenshinCloud")
+ {
+ acct = new GenshinCloudAccount();
+ }
+ else if (gameNameEN == "StarRail")
+ {
+ acct = new StarRailAccount();
+ }
+ else if (gameNameEN == "StarRail*")
+ {
+ acct = new StarRailOverseaAccount();
+ }
+ else if (gameNameEN == "HonkaiImpact3")
+ {
+ acct = new HonkaiImpact3Account();
+ }
+ else
+ {
+ MessageBox.Show("未知的游戏账户类型", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+ return;
+ }
+
+ acct.ReadFromRegistry();
+ acct.Name = txtAcctName.Text;
+ acct.WriteToDisk();
+ this.Close();
}
- else
+ catch (Exception ex)
{
- MessageBox.Show("未知的游戏账户类型", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- return;
+ MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
- acct.ReadFromRegistry();
- acct.Name = txtAcctName.Text;
- acct.WriteToDisk();
- this.Close();
}
}
-}
+}
\ No newline at end of file
diff --git a/MiHoYoStarter/GameFormControl.cs b/MiHoYoStarter/GameFormControl.cs
index 57d01b7..180b4bb 100644
--- a/MiHoYoStarter/GameFormControl.cs
+++ b/MiHoYoStarter/GameFormControl.cs
@@ -230,6 +230,11 @@ private void btnChoosePathClick(object sender, EventArgs e)
private void btnAddClick(object sender, EventArgs e)
{
+ // 是否国际服
+ if (cboServer != null)
+ {
+ IsOversea = cboServer.SelectedIndex == 1;
+ }
string GameNameENX = GameNameEN;
if (IsOversea)
{
diff --git a/MiHoYoStarter/MiHoYoAccount.cs b/MiHoYoStarter/MiHoYoAccount.cs
index 5b68cb7..716c54f 100644
--- a/MiHoYoStarter/MiHoYoAccount.cs
+++ b/MiHoYoStarter/MiHoYoAccount.cs
@@ -15,6 +15,7 @@ namespace MiHoYoStarter
public class MiHoYoAccount
{
public string Name { get; set; }
+
///
/// 每个游戏保存的数据存在不同的目录
///
@@ -24,10 +25,12 @@ public class MiHoYoAccount
/// 注册表记住账户信息的键值位置
///
public string AccountRegKeyName { get; set; }
+
///
/// 注册表记住账户信息的键值名
///
public string AccountRegValueName { get; set; }
+
///
/// 注册表记住账户信息的键值数据
///
@@ -47,7 +50,8 @@ public MiHoYoAccount(string saveFolderName, string accountRegKeyName, string acc
public void WriteToDisk()
{
- File.WriteAllText(Path.Combine(Application.StartupPath, "UserData", SaveFolderName, Name), new JavaScriptSerializer().Serialize(this));
+ File.WriteAllText(Path.Combine(Application.StartupPath, "UserData", SaveFolderName, Name),
+ new JavaScriptSerializer().Serialize(this));
}
public static void DeleteFromDisk(string userDataPath, string name)
@@ -76,6 +80,10 @@ public void WriteToRegistry()
protected string GetStringFromRegistry(string key)
{
object value = Registry.GetValue(AccountRegKeyName, key, "");
+ if (value == null)
+ {
+ throw new Exception($@"注册表{AccountRegKeyName}\{key}中没有找到账户信息");
+ }
return Encoding.UTF8.GetString((byte[])value);
}
@@ -83,6 +91,5 @@ protected void SetStringToRegistry(string key, string value)
{
Registry.SetValue(AccountRegKeyName, key, Encoding.UTF8.GetBytes(value));
}
-
}
-}
+}
\ No newline at end of file