Skip to content

Commit

Permalink
修复一些问题
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyadanli committed Aug 5, 2023
1 parent 82d9891 commit be2c706
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 35 deletions.
72 changes: 40 additions & 32 deletions MiHoYoStarter/FormInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace MiHoYoStarter
public partial class FormInput : Form
{
private string gameNameEN;

public FormInput(string gameNameEN)
{
InitializeComponent();
Expand All @@ -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();
}
}
}
}
5 changes: 5 additions & 0 deletions MiHoYoStarter/GameFormControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
13 changes: 10 additions & 3 deletions MiHoYoStarter/MiHoYoAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace MiHoYoStarter
public class MiHoYoAccount
{
public string Name { get; set; }

/// <summary>
/// 每个游戏保存的数据存在不同的目录
/// </summary>
Expand All @@ -24,10 +25,12 @@ public class MiHoYoAccount
/// 注册表记住账户信息的键值位置
/// </summary>
public string AccountRegKeyName { get; set; }

/// <summary>
/// 注册表记住账户信息的键值名
/// </summary>
public string AccountRegValueName { get; set; }

/// <summary>
/// 注册表记住账户信息的键值数据
/// </summary>
Expand All @@ -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)
Expand Down Expand Up @@ -76,13 +80,16 @@ 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);
}

protected void SetStringToRegistry(string key, string value)
{
Registry.SetValue(AccountRegKeyName, key, Encoding.UTF8.GetBytes(value));
}

}
}
}

0 comments on commit be2c706

Please sign in to comment.