Browse Source

Fix more nullability warnings

pull/55/head
Ionite 1 year ago
parent
commit
0e85741a95
No known key found for this signature in database
  1. 11
      StabilityMatrix.Avalonia/Models/ObservableDictionary.cs
  2. 38
      StabilityMatrix.Avalonia/ViewModels/CheckpointBrowserViewModel.cs
  3. 25
      StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs
  4. 2
      StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs
  5. 2
      StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs
  6. 2
      StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs
  7. 2
      StabilityMatrix.Core/Models/Packages/BasePackage.cs
  8. 2
      StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

11
StabilityMatrix.Avalonia/Models/ObservableDictionary.cs

@ -2,14 +2,14 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
namespace StabilityMatrix.Avalonia.Models; namespace StabilityMatrix.Avalonia.Models;
public class ObservableDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>, public class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>,
IDictionary<TKey, TValue>,
INotifyCollectionChanged, INotifyPropertyChanged where TKey : notnull INotifyCollectionChanged, INotifyPropertyChanged where TKey : notnull
{ {
protected readonly IDictionary<TKey, TValue> dictionary; private readonly IDictionary<TKey, TValue> dictionary;
public event NotifyCollectionChangedEventHandler? CollectionChanged; public event NotifyCollectionChangedEventHandler? CollectionChanged;
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
@ -91,7 +91,7 @@ public class ObservableDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey,
CollectionChanged?.Invoke(this, CollectionChanged?.Invoke(this,
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove,
new KeyValuePair<TKey, TValue>(key, value))); new KeyValuePair<TKey, TValue>(key, value!)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Count)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Keys))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Keys)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Values))); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Values)));
@ -99,7 +99,8 @@ public class ObservableDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey,
return success; return success;
} }
public bool TryGetValue(TKey key, out TValue value) => dictionary.TryGetValue(key, out value); public bool TryGetValue([NotNull] TKey key, [MaybeNullWhen(false)] out TValue value)
=> dictionary.TryGetValue(key, out value);
public TValue this[TKey key] public TValue this[TKey key]
{ {

38
StabilityMatrix.Avalonia/ViewModels/CheckpointBrowserViewModel.cs

@ -58,7 +58,7 @@ public partial class CheckpointBrowserViewModel : PageViewModelBase
[ObservableProperty] private bool canGoToPreviousPage; [ObservableProperty] private bool canGoToPreviousPage;
[ObservableProperty] private bool isIndeterminate; [ObservableProperty] private bool isIndeterminate;
[ObservableProperty] private bool noResultsFound; [ObservableProperty] private bool noResultsFound;
[ObservableProperty] private string noResultsText; [ObservableProperty] private string noResultsText = string.Empty;
private List<CheckpointBrowserCardViewModel> allModelCards = new(); private List<CheckpointBrowserCardViewModel> allModelCards = new();
@ -321,56 +321,38 @@ public partial class CheckpointBrowserViewModel : PageViewModelBase
await TrySearchAgain(false); await TrySearchAgain(false);
} }
// On changes to ModelCards, update the view source
partial void OnModelCardsChanged(ObservableCollection<CheckpointBrowserCardViewModel>? value)
{
// if (value is null)
// {
// ModelCardsView = null;
// }
// // Create new view
// var view = new DataGridCollectionView(value)
// {
// Filter = FilterModelCardsPredicate,
// };
// ModelCardsView = view;
}
partial void OnShowNsfwChanged(bool value) partial void OnShowNsfwChanged(bool value)
{ {
settingsManager.Transaction(s => s.ModelBrowserNsfwEnabled = value); settingsManager.Transaction(s => s.ModelBrowserNsfwEnabled, value);
// ModelCardsView?.Refresh(); // ModelCardsView?.Refresh();
var updateCards = allModelCards var updateCards = allModelCards
.Select(model => new CheckpointBrowserCardViewModel(model.CivitModel,
downloadService, settingsManager, dialogFactory, notificationService))
.Where(FilterModelCardsPredicate); .Where(FilterModelCardsPredicate);
ModelCards = new ObservableCollection<CheckpointBrowserCardViewModel>(updateCards); ModelCards = new ObservableCollection<CheckpointBrowserCardViewModel>(updateCards);
if (!HasSearched) if (!HasSearched) return;
return;
UpdateResultsText(); UpdateResultsText();
} }
partial void OnSelectedPeriodChanged(CivitPeriod oldValue, CivitPeriod newValue) partial void OnSelectedPeriodChanged(CivitPeriod value)
{ {
TrySearchAgain().SafeFireAndForget(); TrySearchAgain().SafeFireAndForget();
settingsManager.Transaction(s => s.ModelSearchOptions = new ModelSearchOptions( settingsManager.Transaction(s => s.ModelSearchOptions = new ModelSearchOptions(
newValue, SortMode, SelectedModelType)); value, SortMode, SelectedModelType));
} }
partial void OnSortModeChanged(CivitSortMode oldValue, CivitSortMode newValue) partial void OnSortModeChanged(CivitSortMode value)
{ {
TrySearchAgain().SafeFireAndForget(); TrySearchAgain().SafeFireAndForget();
settingsManager.Transaction(s => s.ModelSearchOptions = new ModelSearchOptions( settingsManager.Transaction(s => s.ModelSearchOptions = new ModelSearchOptions(
SelectedPeriod, newValue, SelectedModelType)); SelectedPeriod, value, SelectedModelType));
} }
partial void OnSelectedModelTypeChanged(CivitModelType oldValue, CivitModelType newValue) partial void OnSelectedModelTypeChanged(CivitModelType value)
{ {
TrySearchAgain().SafeFireAndForget(); TrySearchAgain().SafeFireAndForget();
settingsManager.Transaction(s => s.ModelSearchOptions = new ModelSearchOptions( settingsManager.Transaction(s => s.ModelSearchOptions = new ModelSearchOptions(
SelectedPeriod, SortMode, newValue)); SelectedPeriod, SortMode, value));
} }
private async Task TrySearchAgain(bool shouldUpdatePageNumber = true) private async Task TrySearchAgain(bool shouldUpdatePageNumber = true)
@ -390,7 +372,7 @@ public partial class CheckpointBrowserViewModel : PageViewModelBase
private void UpdateResultsText() private void UpdateResultsText()
{ {
NoResultsFound = ModelCards?.Count <= 0; NoResultsFound = ModelCards?.Count <= 0;
NoResultsText = allModelCards?.Count > 0 NoResultsText = allModelCards.Count > 0
? $"{allModelCards.Count} results hidden by filters" ? $"{allModelCards.Count} results hidden by filters"
: "No results found"; : "No results found";
} }

25
StabilityMatrix.Avalonia/ViewModels/Dialogs/InstallerViewModel.cs

@ -18,8 +18,8 @@ using NLog;
using Octokit; using Octokit;
using StabilityMatrix.Avalonia.Services; using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper.Factory;
using StabilityMatrix.Core.Models; using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Models.Packages; using StabilityMatrix.Core.Models.Packages;
using StabilityMatrix.Core.Models.Progress; using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes; using StabilityMatrix.Core.Processes;
@ -52,7 +52,6 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
[ObservableProperty] private GitHubCommit? selectedCommit; [ObservableProperty] private GitHubCommit? selectedCommit;
[ObservableProperty] private string? releaseNotes; [ObservableProperty] private string? releaseNotes;
// [ObservableProperty] private bool isReleaseMode;
// Version types (release or commit) // Version types (release or commit)
[ObservableProperty] [ObservableProperty]
@ -79,13 +78,11 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
internal event EventHandler? PackageInstalled; internal event EventHandler? PackageInstalled;
public ProgressViewModel InstallProgress { get; } = new() public ProgressViewModel InstallProgress { get; } = new();
{
};
public InstallerViewModel( public InstallerViewModel(
ISettingsManager settingsManager, ISettingsManager settingsManager,
IPackageFactory packageFactory,
IPyRunner pyRunner, IPyRunner pyRunner,
IDownloadService downloadService, INotificationService notificationService, IDownloadService downloadService, INotificationService notificationService,
ISharedFolders sharedFolders, ISharedFolders sharedFolders,
@ -98,7 +95,9 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
this.sharedFolders = sharedFolders; this.sharedFolders = sharedFolders;
this.prerequisiteHelper = prerequisiteHelper; this.prerequisiteHelper = prerequisiteHelper;
// AvailablePackages and SelectedPackage need to be set in init // AvailablePackages and SelectedPackage
AvailablePackages = new ObservableCollection<BasePackage>(packageFactory.GetAllAvailablePackages());
SelectedPackage = AvailablePackages[0];
} }
public override void OnLoaded() public override void OnLoaded()
@ -148,13 +147,13 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
{ {
notificationService.Show(new Notification("Package name is empty", notificationService.Show(new Notification("Package name is empty",
"Please enter a name for the package", NotificationType.Error)); "Please enter a name for the package", NotificationType.Error));
return;
} }
await InstallGitIfNecessary(); await InstallGitIfNecessary();
var libraryDir = new DirectoryPath(settingsManager.LibraryDir, "Packages", InstallName); SelectedPackage.InstallLocation = Path.Combine(
SelectedPackage.InstallLocation = $"{settingsManager.LibraryDir}\\Packages\\{InstallName}"; settingsManager.LibraryDir, "Packages", InstallName);
// SelectedPackage.DisplayName = InstallName;
if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled) if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled)
{ {
@ -211,7 +210,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
return branch == null ? version : $"{branch}@{version[..7]}"; return branch == null ? version : $"{branch}@{version[..7]}";
} }
private Task<string?> DownloadPackage(string version, bool isCommitHash) private Task<string> DownloadPackage(string version, bool isCommitHash)
{ {
InstallProgress.Text = "Downloading package..."; InstallProgress.Text = "Downloading package...";
@ -292,10 +291,8 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
// ReSharper disable once UnusedParameterInPartialMethod // ReSharper disable once UnusedParameterInPartialMethod
partial void OnSelectedVersionTypeChanged(PackageVersionType value) => OnSelectedPackageChanged(SelectedPackage); partial void OnSelectedVersionTypeChanged(PackageVersionType value) => OnSelectedPackageChanged(SelectedPackage);
partial void OnSelectedPackageChanged(BasePackage? value) partial void OnSelectedPackageChanged(BasePackage value)
{ {
if (value == null) return;
ReleaseNotes = string.Empty; ReleaseNotes = string.Empty;
AvailableVersions?.Clear(); AvailableVersions?.Clear();
AvailableCommits?.Clear(); AvailableCommits?.Clear();

2
StabilityMatrix.Avalonia/ViewModels/Dialogs/OneClickInstallViewModel.cs

@ -26,7 +26,7 @@ public partial class OneClickInstallViewModel : ViewModelBase
[ObservableProperty] private string headerText; [ObservableProperty] private string headerText;
[ObservableProperty] private string subHeaderText; [ObservableProperty] private string subHeaderText;
[ObservableProperty] private string subSubHeaderText; [ObservableProperty] private string subSubHeaderText = string.Empty;
[ObservableProperty] private bool showInstallButton; [ObservableProperty] private bool showInstallButton;
[ObservableProperty] private bool isIndeterminate; [ObservableProperty] private bool isIndeterminate;
[ObservableProperty] private ObservableCollection<BasePackage> allPackages; [ObservableProperty] private ObservableCollection<BasePackage> allPackages;

2
StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs

@ -270,6 +270,8 @@ public partial class PackageManagerViewModel : PageViewModelBase
private async Task UpdateSelectedPackage() private async Task UpdateSelectedPackage()
{ {
if (SelectedPackage == null) return;
var package = packageFactory.FindPackageByName(SelectedPackage.PackageName); var package = packageFactory.FindPackageByName(SelectedPackage.PackageName);
if (package == null) if (package == null)
{ {

2
StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs

@ -97,7 +97,7 @@ public abstract class BaseGitPackage : BasePackage
return allReleases; return allReleases;
} }
public override async Task<string?> DownloadPackage(string version, bool isCommitHash, public override async Task<string> DownloadPackage(string version, bool isCommitHash,
IProgress<ProgressReport>? progress = null) IProgress<ProgressReport>? progress = null)
{ {
var downloadUrl = GetDownloadUrl(version, isCommitHash); var downloadUrl = GetDownloadUrl(version, isCommitHash);

2
StabilityMatrix.Core/Models/Packages/BasePackage.cs

@ -18,7 +18,7 @@ public abstract class BasePackage
public virtual bool ShouldIgnoreReleases => false; public virtual bool ShouldIgnoreReleases => false;
public virtual bool UpdateAvailable { get; set; } public virtual bool UpdateAvailable { get; set; }
public abstract Task<string?> DownloadPackage(string version, bool isCommitHash, public abstract Task<string> DownloadPackage(string version, bool isCommitHash,
IProgress<ProgressReport>? progress = null); IProgress<ProgressReport>? progress = null);
public abstract Task InstallPackage(IProgress<ProgressReport>? progress = null); public abstract Task InstallPackage(IProgress<ProgressReport>? progress = null);
public abstract Task RunPackage(string installedPackagePath, string arguments); public abstract Task RunPackage(string installedPackagePath, string arguments);

2
StabilityMatrix.Core/Models/Packages/VladAutomatic.cs

@ -176,7 +176,7 @@ public class VladAutomatic : BaseGitPackage
progress?.Report(new ProgressReport(1, isIndeterminate: false)); progress?.Report(new ProgressReport(1, isIndeterminate: false));
} }
public override async Task<string?> DownloadPackage(string version, bool isCommitHash, IProgress<ProgressReport>? progress = null) public override async Task<string> DownloadPackage(string version, bool isCommitHash, IProgress<ProgressReport>? progress = null)
{ {
progress?.Report(new ProgressReport(0.1f, message: "Downloading package...", isIndeterminate: true, type: ProgressType.Download)); progress?.Report(new ProgressReport(0.1f, message: "Downloading package...", isIndeterminate: true, type: ProgressType.Download));

Loading…
Cancel
Save