-
Notifications
You must be signed in to change notification settings - Fork 1
/
AutoUpdate.cs
42 lines (34 loc) · 1.18 KB
/
AutoUpdate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Windows;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
namespace HellDivers2OneKeyStratagem;
public static class AutoUpdate
{
public static async Task<bool> HasUpdate()
{
var headers = await HttpHelper.GetHeaders(Settings.UpdateUrl);
var updateTime = headers?.LastModified;
if (updateTime == null)
return false;
var dllTime = File.GetLastWriteTime(AppSettings.ExePath);
return updateTime - dllTime > TimeSpan.FromMinutes(1);
}
public static bool Update()
{
Process.Start(new ProcessStartInfo
{
FileName = "powershell.exe",
Arguments = $"""
-ExecutionPolicy Bypass -File "AutoUpdate.ps1" "{Settings.UpdateUrl}"
""",
WorkingDirectory = AppSettings.ExeDirectory,
UseShellExecute = true,
});
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
lifetime.MainWindow?.Close();
return true;
}
}