2024-03-07 21:04:59 +08:00
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using Zerolauncher.Manager;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Zerolauncher.dialog
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// UseAccDataTextAdd.xaml 的交互逻辑
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public partial class UseAccDataTextAdd : UserControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public UseAccDataTextAdd()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//创建一个打开文件式的对话框
|
|
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
|
|
|
|
//设置这个对话框的起始打开路径
|
|
|
|
|
|
ofd.InitialDirectory = @"C:\";
|
|
|
|
|
|
//设置打开的文件的类型,注意过滤器的语法
|
|
|
|
|
|
ofd.Filter = "账号文本|*.txt|其他格式|*.";
|
|
|
|
|
|
//调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
|
|
|
|
|
|
if (ofd.ShowDialog() == true)
|
|
|
|
|
|
{
|
|
|
|
|
|
string[] lines = File.ReadAllLines(ofd.FileName, Encoding.UTF8);
|
|
|
|
|
|
for (int i = 0; i < lines.Length; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var accTexts = lines[i].Split(input_split.Text);
|
|
|
|
|
|
if (accTexts.Length != 5)
|
|
|
|
|
|
{
|
2024-08-04 17:59:09 +08:00
|
|
|
|
MessageBox.Show($"文本在{i}行非法喵!\n{lines[i]}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
2024-03-07 21:04:59 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-08-04 17:59:09 +08:00
|
|
|
|
var acc = new Account { };
|
2024-03-07 21:04:59 +08:00
|
|
|
|
if (!int.TryParse(accTexts[0], out acc.providerId))
|
|
|
|
|
|
{
|
2024-08-04 17:59:09 +08:00
|
|
|
|
MessageBox.Show($"输入的服务器代号错误喵!在{i}行\n错误:[{lines[i]}]无法转换成服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
2024-03-07 21:04:59 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if(0 < acc.providerId || acc.providerId > ServicesStaticInfo.ServicesName.Length)
|
|
|
|
|
|
{
|
2024-08-04 17:59:09 +08:00
|
|
|
|
MessageBox.Show($"输入的服务器代号错误喵!在{i}行\n错误:[{acc.providerId}]不是有效的服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
|
2024-03-07 21:04:59 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-08-04 17:59:09 +08:00
|
|
|
|
acc.serverId = accTexts[1];
|
2024-03-07 21:04:59 +08:00
|
|
|
|
acc.userName = accTexts[2];
|
|
|
|
|
|
acc.userPWD = accTexts[3];
|
|
|
|
|
|
acc.nickName = accTexts[4];
|
|
|
|
|
|
if (!AccountManager.AddAccounts(acc))
|
|
|
|
|
|
{
|
2024-08-04 17:59:09 +08:00
|
|
|
|
MessageBox.Show($"文本在{i}行出错喵!\n警告:[{acc.nickName}]昵称冲突,将跳过添加此账号", "Warring", MessageBoxButton.OK, MessageBoxImage.Error);
|
2024-03-07 21:04:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-04 17:59:09 +08:00
|
|
|
|
MessageBox.Show("添加完成喵!", "提示");
|
2024-03-07 21:04:59 +08:00
|
|
|
|
AccountManager.saveEdit();
|
|
|
|
|
|
AddMemebersDialog.Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("没有选择文件");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|