installer updating to use r2
This commit is contained in:
parent
a7af608d56
commit
4968f48e8b
@ -1,65 +0,0 @@
|
|||||||
<UserControl xmlns="https://github.com/avaloniaui"
|
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
|
||||||
x:Class="SPTInstaller.CustomControls.UpdateInfoCard"
|
|
||||||
MinHeight="100" MinWidth="300">
|
|
||||||
|
|
||||||
<UserControl.Styles>
|
|
||||||
<Style Selector="Grid">
|
|
||||||
<Setter Property="Opacity" Value="0"/>
|
|
||||||
<Setter Property="Transitions">
|
|
||||||
<Setter.Value>
|
|
||||||
<Transitions>
|
|
||||||
<DoubleTransition Property="Opacity" Duration="0:0:0.2"/>
|
|
||||||
</Transitions>
|
|
||||||
</Setter.Value>
|
|
||||||
</Setter>
|
|
||||||
</Style>
|
|
||||||
<Style Selector="Grid.show">
|
|
||||||
<Setter Property="Opacity" Value="1"/>
|
|
||||||
</Style>
|
|
||||||
<Style Selector="ProgressBar">
|
|
||||||
<Setter Property="IsVisible" Value="False"/>
|
|
||||||
</Style>
|
|
||||||
<Style Selector="ProgressBar.checking">
|
|
||||||
<Setter Property="IsIndeterminate" Value="True"/>
|
|
||||||
<Setter Property="IsVisible" Value="True"/>
|
|
||||||
</Style>
|
|
||||||
<Style Selector="ProgressBar.updating">
|
|
||||||
<Setter Property="IsIndeterminate" Value="false"/>
|
|
||||||
<Setter Property="IsVisible" Value="True"/>
|
|
||||||
</Style>
|
|
||||||
</UserControl.Styles>
|
|
||||||
|
|
||||||
<Grid ColumnDefinitions="10,*,AUTO,AUTO,10" RowDefinitions="10,AUTO,AUTO,10"
|
|
||||||
Classes.show="{Binding ShowUpdateCard, RelativeSource={RelativeSource AncestorType=UserControl}}">
|
|
||||||
<Border Grid.ColumnSpan="5" Grid.RowSpan="4" Background="{StaticResource AKI_Background_Light}"
|
|
||||||
BoxShadow="2 2 10 .1 black" CornerRadius="8"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" MaxWidth="400"
|
|
||||||
Text="{Binding InfoText, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
|
||||||
TextWrapping="Wrap" Margin="0 10"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Button Grid.Column="2" Grid.Row="2" Content="Not now"
|
|
||||||
Classes="outlined"
|
|
||||||
IsVisible="{Binding UpdateAvailable, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
|
||||||
Command="{Binding NotNowCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
|
||||||
/>
|
|
||||||
<Button Grid.Column="3" Grid.Row="2" Content="Update"
|
|
||||||
Classes="yellow" Margin="10 0 0 0"
|
|
||||||
IsVisible="{Binding UpdateAvailable, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
|
||||||
Command="{Binding UpdateInstallerCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<ProgressBar Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="3"
|
|
||||||
Value="{Binding DownloadProgress, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
|
||||||
Classes.updating="{Binding Updating, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
|
||||||
Classes.checking="{Binding IndeterminateProgress, RelativeSource={RelativeSource AncestorType=UserControl}}"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</Grid>
|
|
||||||
</UserControl>
|
|
@ -1,76 +0,0 @@
|
|||||||
using Avalonia;
|
|
||||||
using Avalonia.Controls;
|
|
||||||
using System.Windows.Input;
|
|
||||||
|
|
||||||
namespace SPTInstaller.CustomControls;
|
|
||||||
public partial class UpdateInfoCard : UserControl
|
|
||||||
{
|
|
||||||
public UpdateInfoCard()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool ShowUpdateCard
|
|
||||||
{
|
|
||||||
get => GetValue(ShowUpdateCardProperty);
|
|
||||||
set => SetValue(ShowUpdateCardProperty, value);
|
|
||||||
}
|
|
||||||
public static readonly StyledProperty<bool> ShowUpdateCardProperty =
|
|
||||||
AvaloniaProperty.Register<UpdateInfoCard, bool>(nameof(ShowUpdateCard));
|
|
||||||
|
|
||||||
public bool Updating
|
|
||||||
{
|
|
||||||
get => GetValue(UpdatingProperty);
|
|
||||||
set => SetValue(UpdatingProperty, value);
|
|
||||||
}
|
|
||||||
public static readonly StyledProperty<bool> UpdatingProperty =
|
|
||||||
AvaloniaProperty.Register<UpdateInfoCard, bool>(nameof(Updating));
|
|
||||||
|
|
||||||
public bool UpdateAvailable
|
|
||||||
{
|
|
||||||
get => GetValue(UpdateAvailableProperty);
|
|
||||||
set => SetValue(UpdateAvailableProperty, value);
|
|
||||||
}
|
|
||||||
public static readonly StyledProperty<bool> UpdateAvailableProperty =
|
|
||||||
AvaloniaProperty.Register<UpdateInfoCard, bool>(nameof(UpdateAvailable));
|
|
||||||
|
|
||||||
public bool IndeterminateProgress
|
|
||||||
{
|
|
||||||
get => GetValue(IndeterminateProgressProperty);
|
|
||||||
set => SetValue(IndeterminateProgressProperty, value);
|
|
||||||
}
|
|
||||||
public static readonly StyledProperty<bool> IndeterminateProgressProperty =
|
|
||||||
AvaloniaProperty.Register<UpdateInfoCard, bool>(nameof(IndeterminateProgress));
|
|
||||||
|
|
||||||
public string InfoText
|
|
||||||
{
|
|
||||||
get => GetValue(InfoTextProperty);
|
|
||||||
set => SetValue(InfoTextProperty, value);
|
|
||||||
}
|
|
||||||
public static readonly StyledProperty<string> InfoTextProperty =
|
|
||||||
AvaloniaProperty.Register<UpdateInfoCard, string>(nameof(InfoText));
|
|
||||||
|
|
||||||
public int DownloadProgress
|
|
||||||
{
|
|
||||||
get => GetValue(DownloadProgressProperty);
|
|
||||||
set => SetValue(DownloadProgressProperty, value);
|
|
||||||
}
|
|
||||||
public static readonly StyledProperty<int> DownloadProgressProperty =
|
|
||||||
AvaloniaProperty.Register<UpdateInfoCard, int>(nameof(DownloadProgress));
|
|
||||||
|
|
||||||
public ICommand NotNowCommand
|
|
||||||
{
|
|
||||||
get => GetValue(NotNowCommandProperty);
|
|
||||||
set => SetValue(NotNowCommandProperty, value);
|
|
||||||
}
|
|
||||||
public static readonly StyledProperty<ICommand> NotNowCommandProperty =
|
|
||||||
AvaloniaProperty.Register<UpdateInfoCard, ICommand>(nameof(NotNowCommand));
|
|
||||||
|
|
||||||
public ICommand UpdateInstallerCommand
|
|
||||||
{
|
|
||||||
get => GetValue(UpdateInstallerCommandProperty);
|
|
||||||
set => SetValue(UpdateInstallerCommandProperty, value);
|
|
||||||
}
|
|
||||||
public static readonly StyledProperty<ICommand> UpdateInstallerCommandProperty =
|
|
||||||
AvaloniaProperty.Register<UpdateInfoCard, ICommand>(nameof(UpdateInstallerCommand));
|
|
||||||
}
|
|
@ -9,9 +9,13 @@ public static class DownloadCacheHelper
|
|||||||
{
|
{
|
||||||
private static HttpClient _httpClient = new() { Timeout = TimeSpan.FromHours(1) };
|
private static HttpClient _httpClient = new() { Timeout = TimeSpan.FromHours(1) };
|
||||||
|
|
||||||
public static string CachePath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "spt-installer/cache");
|
public static string CachePath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"spt-installer/cache");
|
||||||
|
|
||||||
public static string ReleaseMirrorUrl = "https://spt-releases.modd.in/release.json";
|
public static string ReleaseMirrorUrl = "https://spt-releases.modd.in/release.json";
|
||||||
public static string PatchMirrorUrl = "https://slugma.waffle-lord.net/mirrors.json";
|
public static string PatchMirrorUrl = "https://slugma.waffle-lord.net/mirrors.json";
|
||||||
|
public static string InstallerUrl = "https://ligma.waffle-lord.net/SPTInstaller.exe";
|
||||||
|
public static string InstallerInfoUrl = "https://ligma.waffle-lord.net/installer.json";
|
||||||
|
|
||||||
public static string GetCacheSizeText()
|
public static string GetCacheSizeText()
|
||||||
{
|
{
|
||||||
@ -90,7 +94,8 @@ public static class DownloadCacheHelper
|
|||||||
/// <param name="progress">A provider for progress updates</param>
|
/// <param name="progress">A provider for progress updates</param>
|
||||||
/// <returns>A <see cref="FileInfo"/> object of the cached file</returns>
|
/// <returns>A <see cref="FileInfo"/> object of the cached file</returns>
|
||||||
/// <remarks>If the file exists, it is deleted before downloading</remarks>
|
/// <remarks>If the file exists, it is deleted before downloading</remarks>
|
||||||
public static async Task<FileInfo?> DownloadFileAsync(string outputFileName, string targetLink, IProgress<double> progress)
|
public static async Task<FileInfo?> DownloadFileAsync(string outputFileName, string targetLink,
|
||||||
|
IProgress<double> progress)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(CachePath);
|
Directory.CreateDirectory(CachePath);
|
||||||
var outputFile = new FileInfo(Path.Join(CachePath, outputFileName));
|
var outputFile = new FileInfo(Path.Join(CachePath, outputFileName));
|
||||||
@ -171,7 +176,8 @@ public static class DownloadCacheHelper
|
|||||||
/// <param name="expectedHash">The expected hash of the cached file</param>
|
/// <param name="expectedHash">The expected hash of the cached file</param>
|
||||||
/// <returns>A <see cref="FileInfo"/> object of the cached file</returns>
|
/// <returns>A <see cref="FileInfo"/> object of the cached file</returns>
|
||||||
/// <remarks>Use <see cref="DownloadFileAsync(string, string, IProgress{double})"/> if you don't have an expected cache file hash</remarks>
|
/// <remarks>Use <see cref="DownloadFileAsync(string, string, IProgress{double})"/> if you don't have an expected cache file hash</remarks>
|
||||||
public static async Task<FileInfo?> GetOrDownloadFileAsync(string fileName, string targetLink, IProgress<double> progress, string expectedHash)
|
public static async Task<FileInfo?> GetOrDownloadFileAsync(string fileName, string targetLink,
|
||||||
|
IProgress<double> progress, string expectedHash)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -195,7 +201,8 @@ public static class DownloadCacheHelper
|
|||||||
/// <param name="expectedHash">The expected hash of the cached file</param>
|
/// <param name="expectedHash">The expected hash of the cached file</param>
|
||||||
/// <returns>A <see cref="FileInfo"/> object of the cached file</returns>
|
/// <returns>A <see cref="FileInfo"/> object of the cached file</returns>
|
||||||
/// <remarks>Use <see cref="DownloadFileAsync(string, Stream)"/> if you don't have an expected cache file hash</remarks>
|
/// <remarks>Use <see cref="DownloadFileAsync(string, Stream)"/> if you don't have an expected cache file hash</remarks>
|
||||||
public static async Task<FileInfo?> GetOrDownloadFileAsync(string fileName, Stream fileDownloadStream, string expectedHash)
|
public static async Task<FileInfo?> GetOrDownloadFileAsync(string fileName, Stream fileDownloadStream,
|
||||||
|
string expectedHash)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
7
SPTInstaller/Models/InstallerInfo.cs
Normal file
7
SPTInstaller/Models/InstallerInfo.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace SPTInstaller.Models;
|
||||||
|
|
||||||
|
public class InstallerInfo
|
||||||
|
{
|
||||||
|
public string LatestVersion { get; set; }
|
||||||
|
public string ChangeLog { get; set; }
|
||||||
|
}
|
@ -3,15 +3,18 @@ using Serilog;
|
|||||||
using SPTInstaller.Helpers;
|
using SPTInstaller.Helpers;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace SPTInstaller.Models;
|
namespace SPTInstaller.Models;
|
||||||
|
|
||||||
public class InstallerUpdateInfo : ReactiveObject
|
public class InstallerUpdateInfo : ReactiveObject
|
||||||
{
|
{
|
||||||
private Version? _newVersion;
|
private Version? _newVersion;
|
||||||
|
|
||||||
public string NewInstallerUrl = "";
|
public string ChangeLog = "";
|
||||||
|
|
||||||
private string _updateInfoText = "";
|
private string _updateInfoText = "";
|
||||||
|
|
||||||
public string UpdateInfoText
|
public string UpdateInfoText
|
||||||
{
|
{
|
||||||
get => _updateInfoText;
|
get => _updateInfoText;
|
||||||
@ -19,6 +22,7 @@ public class InstallerUpdateInfo : ReactiveObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool _show = false;
|
private bool _show = false;
|
||||||
|
|
||||||
public bool Show
|
public bool Show
|
||||||
{
|
{
|
||||||
get => _show;
|
get => _show;
|
||||||
@ -26,6 +30,7 @@ public class InstallerUpdateInfo : ReactiveObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool _updating = false;
|
private bool _updating = false;
|
||||||
|
|
||||||
public bool Updating
|
public bool Updating
|
||||||
{
|
{
|
||||||
get => _updating;
|
get => _updating;
|
||||||
@ -33,6 +38,7 @@ public class InstallerUpdateInfo : ReactiveObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool _updateAvailable = false;
|
private bool _updateAvailable = false;
|
||||||
|
|
||||||
public bool UpdateAvailable
|
public bool UpdateAvailable
|
||||||
{
|
{
|
||||||
get => _updateAvailable;
|
get => _updateAvailable;
|
||||||
@ -40,6 +46,7 @@ public class InstallerUpdateInfo : ReactiveObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool _checkingForUpdates = false;
|
private bool _checkingForUpdates = false;
|
||||||
|
|
||||||
public bool CheckingForUpdates
|
public bool CheckingForUpdates
|
||||||
{
|
{
|
||||||
get => _checkingForUpdates;
|
get => _checkingForUpdates;
|
||||||
@ -47,6 +54,7 @@ public class InstallerUpdateInfo : ReactiveObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int _downloadProgress;
|
private int _downloadProgress;
|
||||||
|
|
||||||
public int DownloadProgress
|
public int DownloadProgress
|
||||||
{
|
{
|
||||||
get => _downloadProgress;
|
get => _downloadProgress;
|
||||||
@ -81,7 +89,11 @@ public class InstallerUpdateInfo : ReactiveObject
|
|||||||
Process.Start(new ProcessStartInfo
|
Process.Start(new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "powershell.exe",
|
FileName = "powershell.exe",
|
||||||
ArgumentList = { "-ExecutionPolicy", "Bypass", "-File", $"{updater.FullName}", $"{newInstallerPath}", $"{Path.Join(Environment.CurrentDirectory, "SPTInstaller.exe")}" }
|
ArgumentList =
|
||||||
|
{
|
||||||
|
"-ExecutionPolicy", "Bypass", "-File", $"{updater.FullName}", $"{newInstallerPath}",
|
||||||
|
$"{Path.Join(Environment.CurrentDirectory, "SPTInstaller.exe")}"
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +103,8 @@ public class InstallerUpdateInfo : ReactiveObject
|
|||||||
|
|
||||||
var progress = new Progress<double>(x => DownloadProgress = (int)x);
|
var progress = new Progress<double>(x => DownloadProgress = (int)x);
|
||||||
|
|
||||||
var file = await DownloadCacheHelper.DownloadFileAsync("SPTInstller.exe", NewInstallerUrl, progress);
|
var file = await DownloadCacheHelper.DownloadFileAsync("SPTInstaller.exe", DownloadCacheHelper.InstallerUrl,
|
||||||
|
progress);
|
||||||
|
|
||||||
if (file == null || !file.Exists)
|
if (file == null || !file.Exists)
|
||||||
{
|
{
|
||||||
@ -115,57 +128,57 @@ public class InstallerUpdateInfo : ReactiveObject
|
|||||||
UpdateAvailable = updateAvailable;
|
UpdateAvailable = updateAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public async Task CheckForUpdates(Version? currentVersion)
|
public async Task CheckForUpdates(Version? currentVersion)
|
||||||
// {
|
{
|
||||||
// if (currentVersion == null)
|
if (currentVersion == null)
|
||||||
// return;
|
return;
|
||||||
//
|
|
||||||
// UpdateInfoText = "Checking for installer updates";
|
UpdateInfoText = "Checking for installer updates";
|
||||||
// Show = true;
|
Show = true;
|
||||||
// CheckingForUpdates = true;
|
CheckingForUpdates = true;
|
||||||
//
|
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
// var repo = new RepositoryApi(Configuration.Default);
|
var installerInfoFile =
|
||||||
//
|
await DownloadCacheHelper.DownloadFileAsync("installer.json", DownloadCacheHelper.InstallerInfoUrl,
|
||||||
// var releases = await repo.RepoListReleasesAsync("CWX", "SPT-AKI-Installer");
|
null);
|
||||||
//
|
|
||||||
// if (releases == null || releases.Count == 0)
|
if (installerInfoFile == null)
|
||||||
// {
|
{
|
||||||
// EndCheck("No releases available", false);
|
EndCheck("Failed to download installer info", false);
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// var latest = releases.FindAll(x => !x.Prerelease)[0];
|
var installerInfo =
|
||||||
//
|
JsonConvert.DeserializeObject<InstallerInfo>(File.ReadAllText(installerInfoFile.FullName));
|
||||||
// if (latest == null)
|
|
||||||
// {
|
if (installerInfo == null)
|
||||||
// EndCheck("could not get latest release", false);
|
{
|
||||||
// return;
|
EndCheck("Failed to parse installer info json", false);
|
||||||
// }
|
return;
|
||||||
//
|
}
|
||||||
// var latestVersion = new Version(latest.TagName);
|
|
||||||
//
|
var latestVersion = new Version(installerInfo.LatestVersion);
|
||||||
// if (latestVersion == null || latestVersion <= currentVersion)
|
|
||||||
// {
|
if (latestVersion <= currentVersion)
|
||||||
// EndCheck("No updates available", false);
|
{
|
||||||
// return;
|
EndCheck("No updates available", false);
|
||||||
// }
|
return;
|
||||||
//
|
}
|
||||||
// _newVersion = latestVersion;
|
|
||||||
//
|
_newVersion = latestVersion;
|
||||||
// NewInstallerUrl = latest.Assets[0].BrowserDownloadUrl;
|
ChangeLog = installerInfo.ChangeLog;
|
||||||
//
|
|
||||||
// EndCheck($"Update available: v{latestVersion}", true);
|
EndCheck($"Update available: v{latestVersion}", true);
|
||||||
//
|
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// catch (Exception ex)
|
catch (Exception ex)
|
||||||
// {
|
{
|
||||||
// EndCheck(ex.Message, false, false);
|
EndCheck(ex.Message, false, false);
|
||||||
// Log.Error(ex, "Failed to check for updates");
|
Log.Error(ex, "Failed to check for updates");
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user