@ -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,7 +90,9 @@ public partial class SelectModelVersionViewModel : ContentDialogViewModelBase
CanGoToNextImage = allImages . Count > 1 ;
}
Dispatcher . UIThread . Post ( ( ) = >
Dispatcher
. UIThread
. Post ( ( ) = >
{
CanGoToPreviousImage = false ;
SelectedFile = SelectedVersionViewModel ? . CivitFileViewModels . FirstOrDefault ( ) ;
@ -95,7 +103,22 @@ public partial class SelectModelVersionViewModel : ContentDialogViewModelBase
partial void OnSelectedFileChanged ( CivitFileViewModel ? value )
{
IsImportEnabled = value ? . CivitFile ! = null ;
var canImport = true ;
if ( settingsManager . IsLibraryDirSet )
{
var fileSizeBytes = value ? . CivitFile . SizeKb * 1 0 2 4 ;
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 ( )