Browse Source

Show tooltip explaining why you cant import cuz your hard drive is full

pull/341/head
JT 11 months ago
parent
commit
5494868af2
  1. 51
      StabilityMatrix.Avalonia/ViewModels/Dialogs/SelectModelVersionViewModel.cs
  2. 3
      StabilityMatrix.Avalonia/Views/Dialogs/SelectModelVersionDialog.axaml
  3. 4
      StabilityMatrix.Core/Helper/SystemInfo.cs
  4. 2
      StabilityMatrix.Core/Models/Packages/BaseGitPackage.cs
  5. 2
      StabilityMatrix.Core/Services/SettingsManager.cs

51
StabilityMatrix.Avalonia/ViewModels/Dialogs/SelectModelVersionViewModel.cs

@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using Avalonia.Media.Imaging;
using Avalonia.Threading;
@ -8,6 +10,8 @@ using FluentAvalonia.UI.Controls;
using StabilityMatrix.Avalonia.Models;
using StabilityMatrix.Avalonia.ViewModels.Base;
using StabilityMatrix.Core.Attributes;
using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Services;
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
@ -49,12 +53,12 @@ public partial class SelectModelVersionViewModel : ContentDialogViewModelBase
[NotifyPropertyChangedFor(nameof(DisplayedPageNumber))]
private int selectedImageIndex;
[ObservableProperty]
private string importTooltip = string.Empty;
public int DisplayedPageNumber => SelectedImageIndex + 1;
public SelectModelVersionViewModel(
ISettingsManager settingsManager,
IDownloadService downloadService
)
public SelectModelVersionViewModel(ISettingsManager settingsManager, IDownloadService downloadService)
{
this.settingsManager = settingsManager;
this.downloadService = downloadService;
@ -70,7 +74,9 @@ public partial class SelectModelVersionViewModel : ContentDialogViewModelBase
{
var nsfwEnabled = settingsManager.Settings.ModelBrowserNsfwEnabled;
var allImages = value
?.ModelVersion?.Images?.Where(img => nsfwEnabled || img.Nsfw == "None")
?.ModelVersion
?.Images
?.Where(img => nsfwEnabled || img.Nsfw == "None")
?.Select(x => new ImageSource(x.Url))
.ToList();
@ -84,18 +90,35 @@ public partial class SelectModelVersionViewModel : ContentDialogViewModelBase
CanGoToNextImage = allImages.Count > 1;
}
Dispatcher.UIThread.Post(() =>
{
CanGoToPreviousImage = false;
SelectedFile = SelectedVersionViewModel?.CivitFileViewModels.FirstOrDefault();
ImageUrls = new ObservableCollection<ImageSource>(allImages);
SelectedImageIndex = 0;
});
Dispatcher
.UIThread
.Post(() =>
{
CanGoToPreviousImage = false;
SelectedFile = SelectedVersionViewModel?.CivitFileViewModels.FirstOrDefault();
ImageUrls = new ObservableCollection<ImageSource>(allImages);
SelectedImageIndex = 0;
});
}
partial void OnSelectedFileChanged(CivitFileViewModel? value)
{
IsImportEnabled = value?.CivitFile != null;
var canImport = true;
if (settingsManager.IsLibraryDirSet)
{
var fileSizeBytes = value?.CivitFile.SizeKb * 1024;
var freeSizeBytes = SystemInfo.GetDiskFreeSpaceBytes(settingsManager.ModelsDirectory);
canImport = fileSizeBytes < freeSizeBytes;
ImportTooltip = canImport
? $"Free space after download: {Size.FormatBytes(Convert.ToUInt64(freeSizeBytes - fileSizeBytes))}"
: $"Not enough space on disk. Need {Size.FormatBytes(Convert.ToUInt64(fileSizeBytes))} but only have {Size.FormatBytes(Convert.ToUInt64(freeSizeBytes))}";
}
else
{
ImportTooltip = "Please set the library directory in settings";
}
IsImportEnabled = value?.CivitFile != null && canImport;
}
public void Cancel()

3
StabilityMatrix.Avalonia/Views/Dialogs/SelectModelVersionDialog.axaml

@ -11,6 +11,7 @@
xmlns:models="clr-namespace:StabilityMatrix.Avalonia.Models"
xmlns:avalonia="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia"
xmlns:lang="clr-namespace:StabilityMatrix.Avalonia.Languages"
xmlns:markupExtensions="clr-namespace:StabilityMatrix.Avalonia.MarkupExtensions"
d:DataContext="{x:Static designData:DesignData.SelectModelVersionViewModel}"
x:Class="StabilityMatrix.Avalonia.Views.Dialogs.SelectModelVersionDialog">
@ -190,6 +191,8 @@
Content="{x:Static lang:Resources.Action_Import}"
Command="{Binding Import}"
IsEnabled="{Binding IsImportEnabled}"
ToolTip.Tip="{Binding ImportTooltip}"
markupExtensions:ShowDisabledTooltipExtension.ShowOnDisabled="True"
Classes="accent" />
</StackPanel>

4
StabilityMatrix.Core/Helper/SystemInfo.cs

@ -5,8 +5,8 @@ namespace StabilityMatrix.Core.Helper;
public static class SystemInfo
{
public const long Gigabyte = 1024 * 1024 * 1024;
public const long Megabyte = 1024 * 1024;
public const long Gibibyte = 1024 * 1024 * 1024;
public const long Mebibyte = 1024 * 1024;
[DllImport("UXTheme.dll", SetLastError = true, EntryPoint = "#138")]
public static extern bool ShouldUseDarkMode();

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

@ -172,7 +172,7 @@ public abstract class BaseGitPackage : BasePackage
IProgress<ProgressReport>? progress = null
)
{
const long fiveGigs = 5 * SystemInfo.Gigabyte;
const long fiveGigs = 5 * SystemInfo.Gibibyte;
if (SystemInfo.GetDiskFreeSpaceBytes(installLocation) is < fiveGigs)
{
throw new ApplicationException(

2
StabilityMatrix.Core/Services/SettingsManager.cs

@ -650,7 +650,7 @@ public class SettingsManager : ISettingsManager
if (!isLoaded)
return;
if (SystemInfo.GetDiskFreeSpaceBytes(SettingsPath) is < 1 * SystemInfo.Megabyte)
if (SystemInfo.GetDiskFreeSpaceBytes(SettingsPath) is < 1 * SystemInfo.Mebibyte)
{
Logger.Warn("Not enough disk space to save settings");
return;

Loading…
Cancel
Save