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