ZeroLauncher/App.xaml.cs

62 lines
1.6 KiB
C#
Raw Normal View History

2024-03-18 22:59:51 +08:00
using System.Diagnostics;
using System.IO;
using System.Windows;
2024-03-07 21:04:59 +08:00
using Zerolauncher.Manager;
namespace Zerolauncher
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
2024-03-18 22:59:51 +08:00
public static bool needUpdate = false;
static bool TryDeleteDirectory(string path, bool recursive)
{
try
{
Directory.Delete(path, recursive);
return true;
}
2024-03-19 12:09:31 +08:00
catch (UnauthorizedAccessException)
2024-03-18 22:59:51 +08:00
{
return false;
}
}
2024-03-07 21:04:59 +08:00
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
2024-03-18 22:59:51 +08:00
2024-03-11 10:57:12 +08:00
Task.Run(async () =>
2024-03-09 18:29:16 +08:00
{
2024-03-11 10:57:12 +08:00
await CloundMananger.TakeQMessage();
UpDateManager.DoCheckUpdate();
2024-03-18 22:59:51 +08:00
if (UpDateManager.state)
2024-03-11 10:57:12 +08:00
{
2024-03-18 22:59:51 +08:00
UpDateManager.DoUpdate();
2024-03-11 10:57:12 +08:00
}
});
2024-03-19 12:09:31 +08:00
Task.Run(async () =>
{
if (Directory.Exists("./cache/"))
{
for (int i = 0; i < 3 && !TryDeleteDirectory(@"./cache", true); i++) await Task.Delay(3000);
}
});
2024-03-11 10:57:12 +08:00
DataStream.Load();
_ = WebApiManager.StartListener();
2024-03-19 12:09:31 +08:00
AccountManager.initLoadData();
}
2024-03-09 18:29:16 +08:00
protected override void OnExit(ExitEventArgs e)
{
base.OnExit(e);
WebApiManager.StopListener();
2024-03-18 22:59:51 +08:00
if (needUpdate) Process.Start("./cache/upacket.bin");
2024-03-07 21:04:59 +08:00
}
}
}