|
|
|
@ -4,6 +4,7 @@ using System.Diagnostics;
|
|
|
|
|
using System.Linq; |
|
|
|
|
using System.Threading.Tasks; |
|
|
|
|
using System.Windows; |
|
|
|
|
using System.Windows.Threading; |
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel; |
|
|
|
|
using CommunityToolkit.Mvvm.Input; |
|
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
@ -48,19 +49,34 @@ public partial class InstallerViewModel : ObservableObject
|
|
|
|
|
private string installName; |
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private ObservableCollection<GithubRelease> availableVersions; |
|
|
|
|
private ObservableCollection<PackageVersion> availableVersions; |
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private GithubRelease selectedVersion; |
|
|
|
|
private PackageVersion selectedVersion; |
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private ObservableCollection<BasePackage> availablePackages; |
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private ObservableCollection<GithubCommit> availableCommits; |
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private GithubCommit selectedCommit; |
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private string releaseNotes; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private bool isReleaseMode; |
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
private bool isReleaseModeEnabled; |
|
|
|
|
|
|
|
|
|
public Visibility ProgressBarVisibility => ProgressValue > 0 || IsIndeterminate ? Visibility.Visible : Visibility.Collapsed; |
|
|
|
|
|
|
|
|
|
public string ReleaseLabelText => IsReleaseMode ? "Version" : "Branch"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InstallerViewModel(ISettingsManager settingsManager, ILogger<InstallerViewModel> logger, IPyRunner pyRunner, |
|
|
|
|
IPackageFactory packageFactory) |
|
|
|
|
{ |
|
|
|
@ -74,6 +90,8 @@ public partial class InstallerViewModel : ObservableObject
|
|
|
|
|
ProgressValue = 0; |
|
|
|
|
InstallPath = |
|
|
|
|
$"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\\StabilityMatrix\\Packages"; |
|
|
|
|
IsReleaseMode = true; |
|
|
|
|
IsReleaseModeEnabled = true; |
|
|
|
|
|
|
|
|
|
AvailablePackages = new ObservableCollection<BasePackage>(packageFactory.GetAllAvailablePackages()); |
|
|
|
|
if (!AvailablePackages.Any()) return; |
|
|
|
@ -93,27 +111,102 @@ public partial class InstallerViewModel : ObservableObject
|
|
|
|
|
if (SelectedPackage == null) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
var releases = (await SelectedPackage.GetVersions()).ToList(); |
|
|
|
|
var releases = (await SelectedPackage.GetAllReleases()).ToList(); |
|
|
|
|
if (!releases.Any()) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
AvailableVersions = new ObservableCollection<GithubRelease>(releases); |
|
|
|
|
{ |
|
|
|
|
IsReleaseMode = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var versions = (await SelectedPackage.GetAllVersions()).ToList(); |
|
|
|
|
AvailableVersions = new ObservableCollection<PackageVersion>(versions); |
|
|
|
|
if (!AvailableVersions.Any()) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
SelectedVersion = AvailableVersions[0]; |
|
|
|
|
ReleaseNotes = releases.First().Body; |
|
|
|
|
ReleaseNotes = versions.First().ReleaseNotesMarkdown; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
partial void OnSelectedPackageChanged(BasePackage value) |
|
|
|
|
partial void OnSelectedPackageChanged(BasePackage? value) |
|
|
|
|
{ |
|
|
|
|
InstallName = $"{value.DisplayName}-{SelectedVersion}"; |
|
|
|
|
if (value == null) return; |
|
|
|
|
|
|
|
|
|
InstallName = value.DisplayName; |
|
|
|
|
ReleaseNotes = string.Empty; |
|
|
|
|
AvailableVersions?.Clear(); |
|
|
|
|
|
|
|
|
|
// This can swallow exceptions if you don't explicity try/catch |
|
|
|
|
// Idk how to make it better tho |
|
|
|
|
Task.Run(async () => |
|
|
|
|
{ |
|
|
|
|
var releases = (await SelectedPackage.GetAllReleases()).ToList(); |
|
|
|
|
if (!releases.Any()) |
|
|
|
|
{ |
|
|
|
|
Application.Current.Dispatcher.Invoke(() => |
|
|
|
|
{ |
|
|
|
|
IsReleaseMode = false; |
|
|
|
|
IsReleaseModeEnabled = false; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
Application.Current.Dispatcher.Invoke(() => { IsReleaseModeEnabled = true; }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var versions = (await value.GetAllVersions(IsReleaseMode)).ToList(); |
|
|
|
|
if (!versions.Any()) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
Application.Current.Dispatcher.Invoke(() => |
|
|
|
|
{ |
|
|
|
|
AvailableVersions = new ObservableCollection<PackageVersion>(versions); |
|
|
|
|
SelectedVersion = AvailableVersions[0]; |
|
|
|
|
ReleaseNotes = versions.First().ReleaseNotesMarkdown; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
if (!IsReleaseMode) |
|
|
|
|
{ |
|
|
|
|
var commits = await value.GetAllCommits(SelectedVersion.TagName); |
|
|
|
|
Application.Current.Dispatcher.Invoke(() => |
|
|
|
|
{ |
|
|
|
|
AvailableCommits = new ObservableCollection<GithubCommit>(commits); |
|
|
|
|
SelectedCommit = AvailableCommits[0]; |
|
|
|
|
SelectedVersion = AvailableVersions.First(x => x.TagName == "master"); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
partial void OnSelectedVersionChanged(GithubRelease? value) |
|
|
|
|
|
|
|
|
|
partial void OnIsReleaseModeChanged(bool oldValue, bool newValue) |
|
|
|
|
{ |
|
|
|
|
InstallName = $"{SelectedPackage.DisplayName}-{value?.TagName}"; |
|
|
|
|
ReleaseNotes = value?.Body ?? string.Empty; |
|
|
|
|
OnSelectedPackageChanged(SelectedPackage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
partial void OnSelectedVersionChanged(PackageVersion? value) |
|
|
|
|
{ |
|
|
|
|
ReleaseNotes = value?.ReleaseNotesMarkdown ?? string.Empty; |
|
|
|
|
if (value == null) return; |
|
|
|
|
|
|
|
|
|
SelectedCommit = null; |
|
|
|
|
AvailableCommits?.Clear(); |
|
|
|
|
|
|
|
|
|
if (!IsReleaseMode) |
|
|
|
|
{ |
|
|
|
|
Task.Run(async () => |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
var hashes = await SelectedPackage.GetAllCommits(value.TagName); |
|
|
|
|
AvailableCommits = new ObservableCollection<GithubCommit>(hashes); |
|
|
|
|
await Task.Delay(10); // or it doesn't work sometimes? lolwut? |
|
|
|
|
SelectedCommit = AvailableCommits[0]; |
|
|
|
|
} |
|
|
|
|
catch (Exception e) |
|
|
|
|
{ |
|
|
|
|
logger.LogError(e, "Error getting commits"); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async Task ActuallyInstall() |
|
|
|
|