fix and clear

This commit is contained in:
1415ddfer 2024-08-04 18:10:03 +08:00
parent b5c7241fcb
commit 4d0cf5a012
5 changed files with 84 additions and 75 deletions

View File

@ -28,7 +28,6 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!--<Button x:Name="btn_diy" Content="自定义图片"/>-->
<Button x:Name="btn_clut" Content="注册账号" Grid.Row="1" Click="OpenRegWeb"/>
<Image Grid.Column="1" Grid.RowSpan="2" Source="/res/player_ico1.png"/>
</Grid>
<DockPanel Grid.ColumnSpan="1" Margin="2">

View File

@ -46,15 +46,15 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
</Button>
<Label Grid.Column="0" Grid.Row="2">验证码:</Label>
<TextBox Name="rightMarginTextBox" Grid.Column="1" Grid.Row="2" />
<TextBox Name="RightMarginTextBox" Grid.Column="1" Grid.Row="2" />
<Label Grid.Column="0" Grid.Row="3">注册邮箱:</Label>
<TextBox Name="bottomMarginTextBox" Grid.Column="1" Grid.Row="3" />
<TextBox Name="BottomMarginTextBox" Grid.Column="1" Grid.Row="3" />
<!-- Accept or Cancel -->
<StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Name="okButton" IsDefault="True" Click="okButton_Click" >确定</Button>
<Button Name="cancelButton" IsCancel="True" Click="cancelButton_Click">取消</Button>
<Button Name="OkButton" IsDefault="True" Click="okButton_Click" >确定</Button>
<Button Name="CancelButton" IsCancel="True" Click="cancelButton_Click">取消</Button>
</StackPanel>
</Grid >
</Window>

View File

@ -25,65 +25,65 @@ namespace Zerolauncher.dialog
private async void FleshPic(object _, RoutedEventArgs e)
{
var main_ip = UpDateData.game_url;
HttpResponseMessage? response = null;
try
{
response = await client.GetAsync($"http://{main_ip}/module/captcha.php");
if (response != null)
{
foreach (var item in response.Headers)
Console.WriteLine($"{item.Key}");
}
//var bin = response.Content.ReadAsStream();
//verify = ocr.RunInference(new Bitmap(bin));
//using (var fileStream = File.Create("tmp.png"))
// var main_ip = UpDateData.game_url;
// HttpResponseMessage? response = null;
// try
// {
// bin.Seek(0, SeekOrigin.Begin);//设置复制开始的地方
// bin.CopyTo(fileStream);
// response = await client.GetAsync($"http://{main_ip}/module/captcha.php");
// if (response != null)
// {
// foreach (var item in response.Headers)
// Console.WriteLine($"{item.Key}");
// }
// //var bin = response.Content.ReadAsStream();
// //verify = ocr.RunInference(new Bitmap(bin));
// //using (var fileStream = File.Create("tmp.png"))
// //{
// // bin.Seek(0, SeekOrigin.Begin);//设置复制开始的地方
// // bin.CopyTo(fileStream);
// //}
// using (var stream = response.Content.ReadAsStream())
// {
// BitmapImage bitmap = new BitmapImage();
// bitmap.BeginInit();
// bitmap.CacheOption = BitmapCacheOption.OnLoad;
// bitmap.StreamSource = stream;
// bitmap.EndInit();
// bitmap.Freeze(); // 为了线程安全
//
// CapPic.Source = bitmap; // 设置Image控件的Source
// }
// }
// catch (Exception ex)
// {
// Console.WriteLine($" 网络发生错误,类型:{ex.GetType().Name},消息:{ex.Message}");
// }
using (var stream = response.Content.ReadAsStream())
{
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.CacheOption = BitmapCacheOption.OnLoad;
bitmap.StreamSource = stream;
bitmap.EndInit();
bitmap.Freeze(); // 为了线程安全
CapPic.Source = bitmap; // 设置Image控件的Source
}
}
catch (Exception ex)
{
Console.WriteLine($" 网络发生错误,类型:{ex.GetType().Name},消息:{ex.Message}");
}
}
private async void okButton_Click(object _, RoutedEventArgs e)
{
var main_ip = UpDateData.game_url;
var values = new Dictionary<string, string>
{
{ "rUsername", user },
{ "rPassword", password },
{ "rPasswords", password },
{ "rEmail", bottomMarginTextBox.Text },
{ "rCode", rightMarginTextBox.Text }
};
var content = new FormUrlEncodedContent(values);
try
{
var response = await client.PostAsync($"http://{main_ip}/form/register.php", content);
var src = await response.Content.ReadAsStringAsync();
var jsonObj = JObject.Parse(src);
MessageBox.Show(jsonObj["content"].ToString(), jsonObj["title"].ToString());
if(int.Parse(jsonObj["type"].ToString()) == 0) Close();
}
catch (Exception ex)
{
MessageBox.Show($"类型:{ex.GetType().Name},消息:{ex.Message}", "发生错误喵");
}
// var main_ip = UpDateData.game_url;
// var values = new Dictionary<string, string>
// {
// { "rUsername", user },
// { "rPassword", password },
// { "rPasswords", password },
// { "rEmail", BottomMarginTextBox.Text },
// { "rCode", RightMarginTextBox.Text }
// };
// var content = new FormUrlEncodedContent(values);
// try
// {
// var response = await client.PostAsync($"http://{main_ip}/form/register.php", content);
// var src = await response.Content.ReadAsStringAsync();
// var jsonObj = JObject.Parse(src);
// MessageBox.Show(jsonObj["content"].ToString(), jsonObj["title"].ToString());
// if(int.Parse(jsonObj["type"].ToString()) == 0) Close();
// }
// catch (Exception ex)
// {
// MessageBox.Show($"类型:{ex.GetType().Name},消息:{ex.Message}", "发生错误喵");
// }
}
private void cancelButton_Click(object sender, RoutedEventArgs e)

View File

@ -9,7 +9,7 @@
<TextBlock DockPanel.Dock="Top" Margin="5" Text="文本格式:一行一个账号,如:&#x0a; 服务器---区号---账号---密码---备注&#x0a;服务器填代号:&#x0a; 如[0, 4399大区]意味着4399大区的代号是0&#x0a; 具体查看添加账号时,以列表显示的为准" Foreground="#FFB44242"/>
<DockPanel DockPanel.Dock="Bottom">
<Button DockPanel.Dock="Right" Content="选择文件" Click="Button_Click"/>
<TextBox Name="input_split" DockPanel.Dock="Right" Text="---" Width="100"/>
<TextBox Name="InputSplit" DockPanel.Dock="Right" Text="---" Width="100"/>
<TextBlock DockPanel.Dock="Right" Text="分隔符:" Foreground="#FFEE9595"/>
<Label/>
</DockPanel>

View File

@ -20,24 +20,26 @@ namespace Zerolauncher.dialog
private void Button_Click(object sender, RoutedEventArgs e)
{
//创建一个打开文件式的对话框
OpenFileDialog ofd = new OpenFileDialog();
var ofd = new OpenFileDialog
{
//设置这个对话框的起始打开路径
ofd.InitialDirectory = @"C:\";
InitialDirectory = @"C:\",
//设置打开的文件的类型,注意过滤器的语法
ofd.Filter = "账号文本|*.txt|其他格式|*.";
Filter = "账号文本|*.txt|其他格式|*."
};
//调用ShowDialog()方法显示该对话框,该方法的返回值代表用户是否点击了确定按钮
if (ofd.ShowDialog() == true)
{
string[] lines = File.ReadAllLines(ofd.FileName, Encoding.UTF8);
for (int i = 0; i < lines.Length; i++)
var lines = File.ReadAllLines(ofd.FileName, Encoding.UTF8);
for (var i = 0; i < lines.Length; i++)
{
var accTexts = lines[i].Split(input_split.Text);
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 Account { };
var acc = new AccountNew { };
if (!int.TryParse(accTexts[0], out acc.providerId))
{
MessageBox.Show($"输入的服务器代号错误喵!在{i}行\n错误[{lines[i]}]无法转换成服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
@ -48,14 +50,22 @@ namespace Zerolauncher.dialog
MessageBox.Show($"输入的服务器代号错误喵!在{i}行\n错误[{acc.providerId}]不是有效的服务器代号", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
acc.serverId = accTexts[1];
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))
{
if (AccountManager.AddAccounts(acc)) continue;
MessageBox.Show($"文本在{i}行出错喵!\n警告[{acc.nickName}]昵称冲突,将跳过添加此账号", "Warring", MessageBoxButton.OK, MessageBoxImage.Error);
}
return;
}
MessageBox.Show("添加完成喵!", "提示");
AccountManager.saveEdit();