add update test

This commit is contained in:
1415ddfer 2024-03-18 22:59:51 +08:00
parent 670a2de102
commit e18a94cca3
16 changed files with 232 additions and 112 deletions

View File

@ -4,13 +4,38 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="About" Height="384" Width="700">
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
Title="About" Height="384" Width="700" MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Grid>
<Image Source="/res/about1.png" Stretch="Fill"/>
<DockPanel>
<TextBlock Text="关&#13;于" Margin="20" FontSize="50" Foreground="OrangeRed"/>
<StackPanel>
<TextBlock x:Name="info" Text=" 灵依游戏大厅&#13;&#13;The best luancher&#13; Power by DDF" Margin="30,150,30,30" HorizontalAlignment="Center" Foreground="#2e4e7e" FontSize="16"/>
<DockPanel Margin="145,100,150,45">
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal">
<Button Background="Transparent" Height="30" Width="35" Click="Button_Click">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.55" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Button.Style>
<Image Source="/res/close.png" Height="25"/>
</Button>
</StackPanel>
<StackPanel VerticalAlignment="Bottom">
<TextBlock Text="关于" FontSize="35" Foreground="OrangeRed" VerticalAlignment="Top" HorizontalAlignment="Center" Margin="0,0,0,30"/>
<TextBlock x:Name="info" Text=" 灵依游戏大厅&#13;&#13;The best luancher&#13; Power by DDF" HorizontalAlignment="Center" Foreground="#2e4e7e" FontSize="16"/>
<TextBlock Text="Contact me" HorizontalAlignment="Center" Foreground="#FF81EB78"/>
<TextBlock HorizontalAlignment="Center">
<Hyperlink NavigateUri="https://github.com/1415ddfer/ZeroHelper" Click="Hyperlink_Click">

View File

@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
namespace Zerolauncher.AboutDialog
{
@ -14,6 +15,12 @@ namespace Zerolauncher.AboutDialog
InitializeComponent();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// 实现窗口的拖动
DragMove();
}
private void Hyperlink_Click(object sender, RoutedEventArgs e)
{
Process.Start(new ProcessStartInfo("http://github.com/1415ddfer/ZeroHelper") { UseShellExecute = true });
@ -24,5 +31,10 @@ namespace Zerolauncher.AboutDialog
MessageBox.Show("已拷贝到粘贴板", "提示");
Clipboard.SetDataObject("ddfgame@foxmail.com", true);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}

View File

@ -1,4 +1,6 @@
using System.Windows;
using System.Diagnostics;
using System.IO;
using System.Windows;
using Zerolauncher.Manager;
namespace Zerolauncher
@ -8,16 +10,44 @@ namespace Zerolauncher
/// </summary>
public partial class App : Application
{
public static bool needUpdate = false;
static bool TryDeleteDirectory(string path, bool recursive)
{
try
{
Directory.Delete(path, recursive);
return true;
}
catch (IOException)
{
return false;
}
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
if (e.Args.Length == 1)
{
switch (e.Args[0])
{
case "updateDone":
{
for (int i = 0; i < 3 && !TryDeleteDirectory(@"./cache", true); i++)
Thread.Sleep(3000);
}
break;
}
}
Task.Run(async () =>
{
await CloundMananger.TakeQMessage();
UpDateManager.DoCheckUpdate();
if (DownloadTask.state)
if (UpDateManager.state)
{
UpDateManager.DoUpdate();
}
});
DataStream.Load();
@ -28,6 +58,7 @@ namespace Zerolauncher
{
base.OnExit(e);
WebApiManager.StopListener();
if (needUpdate) Process.Start("./cache/upacket.bin");
}
}

View File

@ -30,7 +30,6 @@
</DockPanel>
<ScrollViewer x:Name="memberBG" VerticalScrollBarVisibility="Auto" Margin="10,3,10,10">
<WrapPanel Name="mLayout">
</WrapPanel>
</ScrollViewer>
</DockPanel>

View File

@ -122,27 +122,6 @@ namespace Zerolauncher
EditTeamDialog.CreateDailog(AccountManager.teamName);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
// 创建新的按钮
Button newButton = new Button();
newButton.Content = "新按钮";
// 将新按钮添加到布局中
// 假设你的布局是一个名为"myLayout"的StackPanel
mLayout.Children.Add(newButton);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
LoginManager.LoginTest();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
LoginManager.GameTest();
}
private void Button_Click_3(object sender, RoutedEventArgs e)
{
Close();
@ -153,5 +132,6 @@ namespace Zerolauncher
var ab = new About1();
ab.ShowDialog();
}
}
}

View File

@ -2,6 +2,7 @@
using System.Net;
using Zerolauncher.Defender;
using Zerolauncher.util;
using System.Diagnostics;
namespace Zerolauncher.Manager
{
@ -10,7 +11,7 @@ namespace Zerolauncher.Manager
public const string QMessageMain = "https://sharechain.qq.com/";
public const string MasterMessage = "54aeb77c47b967d22c2c1396d00d91f0";
public const string SummerMessage = "037846c482eddc948612b0d0f8ed98d5";
public const string LoveMessage = "";
public const string LoveMessage = "539e3389078daa765ac0abdcc97eebce";
}
class UpDateData
@ -19,8 +20,9 @@ namespace Zerolauncher.Manager
public static bool state = false;
public static string version = "";
public static string tis = "";
public static string mini_packet_url = "";
public static string full_packet_url = "";
public static string auto_packet_url = "";
public static string user_packet_url = "";
public const string lanzou = "https://www.lanzoub.com/";
}
class CloundMananger
@ -35,7 +37,7 @@ namespace Zerolauncher.Manager
try
{
client.Timeout = TimeSpan.FromMinutes(3);
response = await client.GetAsync($"{StaticUrl.QMessageMain}{StaticUrl.MasterMessage}");
response = await client.GetAsync($"{StaticUrl.QMessageMain}{StaticUrl.LoveMessage}");
}
catch (Exception _ex)
{
@ -54,12 +56,15 @@ namespace Zerolauncher.Manager
{
message = message.Split("<div class=\"note-content\">")[1].Split("</article>")[0].Replace("</div>", "").Replace("\n", "").Replace("\t", "").Replace("\r", "").Replace("'", "");
var arr = message.Split("<div>");
if (arr.Length >= 7 && FormatSha(arr[6], false) && FormatSha(arr[5], true))
Trace.WriteLine("bababababa" + arr.Length.ToString());
Trace.WriteLine(message);
if (arr.Length == 7 && FormatSha(arr[6], false) && FormatSha(arr[5], true))
{
Trace.WriteLine("bababababa" + arr.Length.ToString());
UpDateData.version = arr[1];
UpDateData.tis = arr[2];
UpDateData.mini_packet_url = arr[3];
UpDateData.full_packet_url = arr[4];
UpDateData.auto_packet_url = arr[3];
UpDateData.user_packet_url = arr[4];
UpDateData.state = true;
return true;
}
@ -68,12 +73,12 @@ namespace Zerolauncher.Manager
static bool FormatSha(string sha0, bool e)
{
if (sha0.Length < 90) return false;
//if (sha0.Length < 80) return false;
int count;
var sha = SpaceEncoder.Decode(sha0, out count);
if (sha == null || sha.Length < 64)
{
//Console.WriteLine($"faile: {count}");
Trace.WriteLine($"faile: {count}");
return false;
}
if (e) CacheSha.PutE(sha);

View File

@ -20,7 +20,7 @@ namespace Zerolauncher.Manager
else
{
dataStream = JsonConvert.DeserializeObject<Data>(
"{\"teamIndex\":0,\"Groups\":[{\"Name\":\"队伍1\", \"Accounts\": [{\"providerId\":0,\"userName\":\"test\",\"userPWD\":\"test\",\"nickName\":\"测试账号\",\"serverId\":\"1\"}]}], \"engine_cache_ver\": 0}");
"{\"teamIndex\":0,\"Groups\":[{\"Name\":\"队伍1\", \"Accounts\": [{\"providerId\":0,\"userName\":\"test\",\"userPWD\":\"test\",\"nickName\":\"测试账号\",\"serverId\":\"1\"}]}], \"ecs\": \"\"}");
}
}
@ -28,7 +28,7 @@ namespace Zerolauncher.Manager
public static void write()
{
string? data = JsonConvert.SerializeObject(dataStream);
Trace.WriteLine(data);
//Trace.WriteLine(data);
if (data == null) return;
File.WriteAllBytes(path, CompressBytes(Encoding.UTF8.GetBytes(data)));
}
@ -85,6 +85,6 @@ namespace Zerolauncher.Manager
{
public int teamIndex;
public List<Group> Groups;
public int engine_cache_ver;
public string ecs;
}
}

View File

@ -1,4 +1,6 @@
using System.Diagnostics;
using System.IO;
using System.Security.Cryptography;
using System.Windows;
using Zerolauncher.Defender;
@ -20,7 +22,7 @@ namespace Zerolauncher.Manager
showDialog = false;
if (UpDateData.is_check == false)
{
MessageBox.Show("正在更新数据请等待1-3秒。\n 请检查网络", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
MessageBox.Show("正在更新游戏数据请等待1-3秒。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Warning);
return true;
}
if (UpDateData.state)
@ -34,13 +36,13 @@ namespace Zerolauncher.Manager
switch (CacheSha.errorCode)
{
case 1:
MessageBox.Show("发生网络错误==EMS。\n 请检查网络", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error);
MessageBox.Show("发生网络错误==EMS。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break;
case 2:
MessageBox.Show("发生游戏服务错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error);
MessageBox.Show("发生游戏服务错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break;
default:
MessageBox.Show("发生未知错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error);
MessageBox.Show("发生未知错误==EMS。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break;
}
return true;
@ -50,7 +52,7 @@ namespace Zerolauncher.Manager
mGame[key] = new SingleGame(account);
}catch (Exception _ex)
{
MessageBox.Show("发生错误!\n如重复发生此错误\n请重新下载大厅文件或联系管理员。", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error);
UpDateManager.DoUpdate();
}
return true;
}
@ -121,11 +123,8 @@ namespace Zerolauncher.Manager
class SingleGame
{
Process process;
string? restartUrl;
public int mHandle;
public Account? account;
string gameMode;
@ -136,21 +135,12 @@ namespace Zerolauncher.Manager
gameMode = mod;
mHandle = 0;
process = EngineShell.CheckEngineSafe(gameMode);
if (gameMode != StaticHandleA.UpdateMode)
{
process.OutputDataReceived += Handle;
process.Exited += Process_Exited;
}
process.Start();
if (gameMode != StaticHandleA.UpdateMode)
{
process.BeginOutputReadLine(); // 开始异步读取
if (gameMode == StaticHandleA.Version)
{
process.WaitForExit();
}
}
process.Start();
process.BeginOutputReadLine(); // 开始异步读取
}
private void CreateProcess()
@ -180,10 +170,15 @@ namespace Zerolauncher.Manager
private void Handle(object sender, DataReceivedEventArgs e)
{
var lines = e.Data == null? [""] : e.Data.Split(" ");
var lines = e.Data == null? [""] : e.Data.Split(" ", 2); // 切成两半
switch (lines[0])
{
case StaticHandleC.StartDone:
if (gameMode == StaticHandleA.UpdateMode)
{
UpDateManager.DoUpdate1();
return;
}
if(restartUrl == null)
{
Send($"{StaticHandleS.ShowWindow} {ServicesStaticInfo.ServicesName[account.providerId]}-{account.nickName}");
@ -210,6 +205,9 @@ namespace Zerolauncher.Manager
case StaticHandleC.Version:
mHandle = int.Parse(lines[1]);
break;
case StaticHandleC.DownloadDone:
UpDateManager.OnDownLoadDone(lines[1]);
break;
}
}
@ -231,35 +229,57 @@ namespace Zerolauncher.Manager
class EngineShell
{
static bool needShowTis = true;
static bool is_check = false;
const string engine_file = @"ZeroEngine.exe";
public static Process CheckEngineSafe(string mod)
{
bool is_first_luancher = EngineManager.CheckEmpy();
//if (!is_check && is_first_luancher)
//{
// string? now_bit;
// using (SHA256 sha256 = SHA256.Create())
// {
// using (FileStream fileStream = File.OpenRead(engine_file))
// {
// byte[] hashBytes = sha256.ComputeHash(fileStream);
// now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
// }
// }
// if (EngineCacheSha.Get() != now_bit)
// {
// throw new FileReadException("无法读取文件内容");
// }
// is_check = true;
//}
if (mod == StaticHandleA.UpdateMode)
{
if (DataStream.dataStream.ecs != "")
{
string? now_bit;
using (SHA256 sha256 = SHA256.Create())
{
using (FileStream fileStream = File.OpenRead(engine_file))
{
byte[] hashBytes = sha256.ComputeHash(fileStream);
now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
}
}
if (DataStream.dataStream.ecs != now_bit)
{
Trace.WriteLine("lalalala", DataStream.dataStream.ecs);
throw new FileReadException("error esu1!");
}
}
}
else if (!is_check && is_first_luancher)
{
string? now_bit;
using (SHA256 sha256 = SHA256.Create())
{
using (FileStream fileStream = File.OpenRead(engine_file))
{
byte[] hashBytes = sha256.ComputeHash(fileStream);
now_bit = BitConverter.ToString(hashBytes).Replace("-", string.Empty);
}
}
if (CacheSha.GetE() != now_bit)
{
throw new FileReadException("error esu0!");
}
if (DataStream.dataStream.ecs != now_bit) { DataStream.dataStream.ecs = now_bit; DataStream.write(); }
is_check = true;
}
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = engine_file,
Arguments = $"{mod} {is_first_luancher}",
Arguments = $"{StaticHandleA.GameMode} {needShowTis}",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = true,
@ -267,6 +287,7 @@ namespace Zerolauncher.Manager
},
EnableRaisingEvents = true
};
if (needShowTis) needShowTis = false;
return process;
}
}

View File

@ -2,21 +2,17 @@
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;
using System.Windows;
using Zerolauncher.Defender;
namespace Zerolauncher.Manager
{
class DownloadTask
{
public static bool state = false;
public static string url = "";
}
class UpDateManager
{
const string cache_file = "cache.zip";
public static bool state = false;
static bool isCheeking = false;
static SingleGame? updateProcess;
public static void DoCheckUpdate(bool checkMain=true, bool needEngine = false)
{
@ -50,17 +46,64 @@ namespace Zerolauncher.Manager
}
needEngine = now_bit == CacheSha.GetE() && now_bit != null;
}
if(needEngine && needMian) { isCheeking = false; return; }
DownloadTask.state = true;
if(needEngine == needMian) DownloadTask.url = UpDateData.full_packet_url;
else DownloadTask.url = UpDateData.mini_packet_url;
state = !(needEngine && needMian);
isCheeking = false;
}
public static void OnDownLoadDone()
public static void DoUpdate()
{
ZipFile.ExtractToDirectory(cache_file, ".");
Process.Start("./upacket.bin");
if (CacheSha.errorCode != 0)
{
switch (CacheSha.errorCode)
{
case 1:
MessageBox.Show("检查更新出错。\n 请检查网络", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break;
case 2:
MessageBox.Show("软件已停止服务或服务错误。\n 请联系管理员", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break;
default:
MessageBox.Show("检查更新出错。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
break;
}
return;
}
MessageBoxResult result = MessageBox.Show($"大厅组件需要更新\n是否更新?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
if (result == MessageBoxResult.OK)
{
try
{
updateProcess = new SingleGame(null, StaticHandleA.UpdateMode);
return;
}
catch (Exception _ex)
{
MessageBox.Show("执行自动更新失败!,\n请手动访问链接重新下载大厅文件或联系管理员。", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
public static void DoUpdate1()
{
updateProcess.Send($"{StaticHandleS.ShowWindow} 自助更新");
updateProcess.Send($"{StaticHandleS.UseBrowser} {UpDateData.lanzou + UpDateData.auto_packet_url}");
updateProcess.Send($"{StaticHandleS.UpdateInfo} {UpDateData.tis}");
}
public static void OnDownLoadDone(string path)
{
updateProcess.Send(StaticHandleS.CloseGame);
try
{
ZipFile.ExtractToDirectory(path, "./cache/");
File.Delete(path);
}catch(Exception e)
{
MessageBox.Show($"尝试更新文件时发生错误\n{e.Message}", "错误", MessageBoxButton.OKCancel, MessageBoxImage.Error);
return;
}
App.needUpdate = true;
MainWindow.Instance.Close();
}
}

View File

@ -9,6 +9,7 @@
public const string UseBrowser = "e0";
public const string GameSa = "f0";
public const string CloseGame = "g0";
public const string UpdateInfo = "h0";
}
class StaticHandleC
@ -18,12 +19,13 @@
public const string StartGame = "0c";
public const string GameDone = "0d";
public const string Version = "0e";
public const string DownloadDone = "0f";
}
class StaticHandleA
{
public const string GameMode = "0a";
public const string UpdateMode = "0b";
public const string Version = "0c";
public const string VersionMode = "0c";
}
}

View File

@ -27,6 +27,7 @@
<None Remove="res\about1.png" />
<None Remove="res\btn_close1.png" />
<None Remove="res\btn_mini1.png" />
<None Remove="res\close.png" />
<None Remove="res\config.png" />
<None Remove="res\del.png" />
<None Remove="res\player_ico1.png" />
@ -49,9 +50,16 @@
<Resource Include="res\about1.png" />
<Resource Include="res\btn_close1.png" />
<Resource Include="res\btn_mini1.png" />
<Resource Include="res\close.png" />
<Resource Include="res\config.png" />
<Resource Include="res\del.png" />
<Resource Include="res\player_ico1.png" />
</ItemGroup>
<ItemGroup>
<None Update="ZeroEngine.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -97,14 +97,17 @@ namespace Zerolauncher.controls
changeTeamItem.Items.Add(menuItem);
}
};
return contextMenu;
}
private void delItem_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult result = MessageBox.Show($"即将删除账号{text.Content}", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel);
if (result == MessageBoxResult.OK)
{
AccountManager.DeleteAccount(memberId);
}
}
private void editItem_Click(object sender, RoutedEventArgs e)
{

View File

@ -5,17 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="169" d:DesignWidth="290">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<TextBox Name="edit_name" Grid.Row="2" Margin="10,2,50,2" >
<DockPanel>
<TextBox Name="edit_name" Margin="60" DockPanel.Dock="Top" Height="20">
<TextBox.Resources>
<VisualBrush x:Key="HelpBrush" TileMode="None" Opacity="0.3" Stretch="None" AlignmentX="Left">
<VisualBrush.Visual>
@ -45,5 +36,5 @@
</Button>
<Label/>
</DockPanel>
</Grid>
</DockPanel>
</UserControl>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 903 KiB

After

Width:  |  Height:  |  Size: 846 KiB

BIN
res/about2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 903 KiB

BIN
res/close.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 B