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. 27
      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.Specialized;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
namespace StabilityMatrix.Avalonia.Models;
public class ObservableDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey, TValue>>,
IDictionary<TKey, TValue>,
public class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>,
INotifyCollectionChanged, INotifyPropertyChanged where TKey : notnull
{
protected readonly IDictionary<TKey, TValue> dictionary;
private readonly IDictionary<TKey, TValue> dictionary;
public event NotifyCollectionChangedEventHandler? CollectionChanged;
public event PropertyChangedEventHandler? PropertyChanged;
@ -91,7 +91,7 @@ public class ObservableDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey,
CollectionChanged?.Invoke(this,
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(Keys)));
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Values)));
@ -99,7 +99,8 @@ public class ObservableDictionary<TKey, TValue> : ICollection<KeyValuePair<TKey,
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]
{

38
StabilityMatrix.Avalonia/ViewModels/CheckpointBrowserViewModel.cs

@ -58,7 +58,7 @@ public partial class CheckpointBrowserViewModel : PageViewModelBase
[ObservableProperty] private bool canGoToPreviousPage;
[ObservableProperty] private bool isIndeterminate;
[ObservableProperty] private bool noResultsFound;
[ObservableProperty] private string noResultsText;
[ObservableProperty] private string noResultsText = string.Empty;
private List<CheckpointBrowserCardViewModel> allModelCards = new();
@ -320,57 +320,39 @@ public partial class CheckpointBrowserViewModel : PageViewModelBase
CurrentPageNumber++;
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)
{
settingsManager.Transaction(s => s.ModelBrowserNsfwEnabled = value);
settingsManager.Transaction(s => s.ModelBrowserNsfwEnabled, value);
// ModelCardsView?.Refresh();
var updateCards = allModelCards
.Select(model => new CheckpointBrowserCardViewModel(model.CivitModel,
downloadService, settingsManager, dialogFactory, notificationService))
.Where(FilterModelCardsPredicate);
ModelCards = new ObservableCollection<CheckpointBrowserCardViewModel>(updateCards);
if (!HasSearched)
return;
if (!HasSearched) return;
UpdateResultsText();
}
partial void OnSelectedPeriodChanged(CivitPeriod oldValue, CivitPeriod newValue)
partial void OnSelectedPeriodChanged(CivitPeriod value)
{
TrySearchAgain().SafeFireAndForget();
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();
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();
settingsManager.Transaction(s => s.ModelSearchOptions = new ModelSearchOptions(
SelectedPeriod, SortMode, newValue));
SelectedPeriod, SortMode, value));
}
private async Task TrySearchAgain(bool shouldUpdatePageNumber = true)
@ -390,7 +372,7 @@ public partial class CheckpointBrowserViewModel : PageViewModelBase
private void UpdateResultsText()
{
NoResultsFound = ModelCards?.Count <= 0;
NoResultsText = allModelCards?.Count > 0
NoResultsText = allModelCards.Count > 0
? $"{allModelCards.Count} results hidden by filters"
: "No results found";
}

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

@ -18,8 +18,8 @@ using NLog;
using Octokit;
using StabilityMatrix.Avalonia.Services;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Helper.Factory;
using StabilityMatrix.Core.Models;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Models.Packages;
using StabilityMatrix.Core.Models.Progress;
using StabilityMatrix.Core.Processes;
@ -52,7 +52,6 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
[ObservableProperty] private GitHubCommit? selectedCommit;
[ObservableProperty] private string? releaseNotes;
// [ObservableProperty] private bool isReleaseMode;
// Version types (release or commit)
[ObservableProperty]
@ -78,14 +77,12 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
[ObservableProperty] private string? installName;
internal event EventHandler? PackageInstalled;
public ProgressViewModel InstallProgress { get; } = new()
{
};
public ProgressViewModel InstallProgress { get; } = new();
public InstallerViewModel(
ISettingsManager settingsManager,
IPackageFactory packageFactory,
IPyRunner pyRunner,
IDownloadService downloadService, INotificationService notificationService,
ISharedFolders sharedFolders,
@ -98,7 +95,9 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
this.sharedFolders = sharedFolders;
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()
@ -148,13 +147,13 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
{
notificationService.Show(new Notification("Package name is empty",
"Please enter a name for the package", NotificationType.Error));
return;
}
await InstallGitIfNecessary();
var libraryDir = new DirectoryPath(settingsManager.LibraryDir, "Packages", InstallName);
SelectedPackage.InstallLocation = $"{settingsManager.LibraryDir}\\Packages\\{InstallName}";
// SelectedPackage.DisplayName = InstallName;
SelectedPackage.InstallLocation = Path.Combine(
settingsManager.LibraryDir, "Packages", InstallName);
if (!PyRunner.PipInstalled || !PyRunner.VenvInstalled)
{
@ -211,7 +210,7 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
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...";
@ -292,10 +291,8 @@ public partial class InstallerViewModel : ContentDialogViewModelBase
// ReSharper disable once UnusedParameterInPartialMethod
partial void OnSelectedVersionTypeChanged(PackageVersionType value) => OnSelectedPackageChanged(SelectedPackage);
partial void OnSelectedPackageChanged(BasePackage? value)
partial void OnSelectedPackageChanged(BasePackage value)
{
if (value == null) return;
ReleaseNotes = string.Empty;
AvailableVersions?.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 subHeaderText;
[ObservableProperty] private string subSubHeaderText;
[ObservableProperty] private string subSubHeaderText = string.Empty;
[ObservableProperty] private bool showInstallButton;
[ObservableProperty] private bool isIndeterminate;
[ObservableProperty] private ObservableCollection<BasePackage> allPackages;

2
StabilityMatrix.Avalonia/ViewModels/PackageManagerViewModel.cs

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

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

@ -97,7 +97,7 @@ public abstract class BaseGitPackage : BasePackage
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)
{
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 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);
public abstract Task InstallPackage(IProgress<ProgressReport>? progress = null);
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));
}
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));

Loading…
Cancel
Save