|
|
@ -71,6 +71,9 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
[ObservableProperty] |
|
|
|
[ObservableProperty] |
|
|
|
private bool isFavorite; |
|
|
|
private bool isFavorite; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ObservableProperty] |
|
|
|
|
|
|
|
private bool showSantaHats = true; |
|
|
|
|
|
|
|
|
|
|
|
public CheckpointBrowserCardViewModel( |
|
|
|
public CheckpointBrowserCardViewModel( |
|
|
|
IDownloadService downloadService, |
|
|
|
IDownloadService downloadService, |
|
|
|
ITrackedDownloadService trackedDownloadService, |
|
|
|
ITrackedDownloadService trackedDownloadService, |
|
|
@ -90,6 +93,8 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
s => s.ModelBrowserNsfwEnabled, |
|
|
|
s => s.ModelBrowserNsfwEnabled, |
|
|
|
_ => Dispatcher.UIThread.Post(UpdateImage) |
|
|
|
_ => Dispatcher.UIThread.Post(UpdateImage) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ShowSantaHats = settingsManager.Settings.EnableHolidayMode; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void CheckIfInstalled() |
|
|
|
private void CheckIfInstalled() |
|
|
@ -115,7 +120,9 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
|
|
|
|
|
|
|
|
var latestVersionInstalled = |
|
|
|
var latestVersionInstalled = |
|
|
|
latestVersion.Files != null |
|
|
|
latestVersion.Files != null |
|
|
|
&& latestVersion.Files.Any( |
|
|
|
&& latestVersion |
|
|
|
|
|
|
|
.Files |
|
|
|
|
|
|
|
.Any( |
|
|
|
file => |
|
|
|
file => |
|
|
|
file is { Type: CivitFileType.Model, Hashes.BLAKE3: not null } |
|
|
|
file is { Type: CivitFileType.Model, Hashes.BLAKE3: not null } |
|
|
|
&& installedModels.Contains(file.Hashes.BLAKE3) |
|
|
|
&& installedModels.Contains(file.Hashes.BLAKE3) |
|
|
@ -124,10 +131,14 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
// check if any of the ModelVersion.Files.Hashes.BLAKE3 hashes are in the installedModels list |
|
|
|
// check if any of the ModelVersion.Files.Hashes.BLAKE3 hashes are in the installedModels list |
|
|
|
var anyVersionInstalled = |
|
|
|
var anyVersionInstalled = |
|
|
|
latestVersionInstalled |
|
|
|
latestVersionInstalled |
|
|
|
|| CivitModel.ModelVersions.Any( |
|
|
|
|| CivitModel |
|
|
|
|
|
|
|
.ModelVersions |
|
|
|
|
|
|
|
.Any( |
|
|
|
version => |
|
|
|
version => |
|
|
|
version.Files != null |
|
|
|
version.Files != null |
|
|
|
&& version.Files.Any( |
|
|
|
&& version |
|
|
|
|
|
|
|
.Files |
|
|
|
|
|
|
|
.Any( |
|
|
|
file => |
|
|
|
file => |
|
|
|
file is { Type: CivitFileType.Model, Hashes.BLAKE3: not null } |
|
|
|
file is { Type: CivitFileType.Model, Hashes.BLAKE3: not null } |
|
|
|
&& installedModels.Contains(file.Hashes.BLAKE3) |
|
|
|
&& installedModels.Contains(file.Hashes.BLAKE3) |
|
|
@ -258,7 +269,8 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
private static string PruneDescription(CivitModel model) |
|
|
|
private static string PruneDescription(CivitModel model) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var prunedDescription = |
|
|
|
var prunedDescription = |
|
|
|
model.Description |
|
|
|
model |
|
|
|
|
|
|
|
.Description |
|
|
|
?.Replace("<br/>", $"{Environment.NewLine}{Environment.NewLine}") |
|
|
|
?.Replace("<br/>", $"{Environment.NewLine}{Environment.NewLine}") |
|
|
|
.Replace("<br />", $"{Environment.NewLine}{Environment.NewLine}") |
|
|
|
.Replace("<br />", $"{Environment.NewLine}{Environment.NewLine}") |
|
|
|
.Replace("</p>", $"{Environment.NewLine}{Environment.NewLine}") |
|
|
|
.Replace("</p>", $"{Environment.NewLine}{Environment.NewLine}") |
|
|
@ -294,10 +306,7 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
/// <param name="modelVersion"></param> |
|
|
|
/// <param name="modelVersion"></param> |
|
|
|
/// <param name="modelFilePath"></param> |
|
|
|
/// <param name="modelFilePath"></param> |
|
|
|
/// <returns>The file path of the saved preview image</returns> |
|
|
|
/// <returns>The file path of the saved preview image</returns> |
|
|
|
private async Task<FilePath?> SavePreviewImage( |
|
|
|
private async Task<FilePath?> SavePreviewImage(CivitModelVersion modelVersion, FilePath modelFilePath) |
|
|
|
CivitModelVersion modelVersion, |
|
|
|
|
|
|
|
FilePath modelFilePath |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
// Skip if model has no images |
|
|
|
// Skip if model has no images |
|
|
|
if (modelVersion.Images == null || modelVersion.Images.Count == 0) |
|
|
|
if (modelVersion.Images == null || modelVersion.Images.Count == 0) |
|
|
@ -309,9 +318,9 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
var imageExtension = Path.GetExtension(image.Url).TrimStart('.'); |
|
|
|
var imageExtension = Path.GetExtension(image.Url).TrimStart('.'); |
|
|
|
if (imageExtension is "jpg" or "jpeg" or "png") |
|
|
|
if (imageExtension is "jpg" or "jpeg" or "png") |
|
|
|
{ |
|
|
|
{ |
|
|
|
var imageDownloadPath = modelFilePath.Directory!.JoinFile( |
|
|
|
var imageDownloadPath = modelFilePath |
|
|
|
$"{modelFilePath.NameWithoutExtension}.preview.{imageExtension}" |
|
|
|
.Directory! |
|
|
|
); |
|
|
|
.JoinFile($"{modelFilePath.NameWithoutExtension}.preview.{imageExtension}"); |
|
|
|
|
|
|
|
|
|
|
|
var imageTask = downloadService.DownloadToFileAsync(image.Url, imageDownloadPath); |
|
|
|
var imageTask = downloadService.DownloadToFileAsync(image.Url, imageDownloadPath); |
|
|
|
await notificationService.TryAsync(imageTask, "Could not download preview image"); |
|
|
|
await notificationService.TryAsync(imageTask, "Could not download preview image"); |
|
|
@ -349,8 +358,7 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Get latest version file |
|
|
|
// Get latest version file |
|
|
|
var modelFile = |
|
|
|
var modelFile = selectedFile ?? modelVersion.Files?.FirstOrDefault(x => x.Type == CivitFileType.Model); |
|
|
|
selectedFile ?? modelVersion.Files?.FirstOrDefault(x => x.Type == CivitFileType.Model); |
|
|
|
|
|
|
|
if (modelFile is null) |
|
|
|
if (modelFile is null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
notificationService.Show( |
|
|
|
notificationService.Show( |
|
|
@ -366,9 +374,7 @@ public partial class CheckpointBrowserCardViewModel : Base.ProgressViewModel |
|
|
|
|
|
|
|
|
|
|
|
var rootModelsDirectory = new DirectoryPath(settingsManager.ModelsDirectory); |
|
|
|
var rootModelsDirectory = new DirectoryPath(settingsManager.ModelsDirectory); |
|
|
|
|
|
|
|
|
|
|
|
var downloadDirectory = rootModelsDirectory.JoinDir( |
|
|
|
var downloadDirectory = rootModelsDirectory.JoinDir(model.Type.ConvertTo<SharedFolderType>().GetStringValue()); |
|
|
|
model.Type.ConvertTo<SharedFolderType>().GetStringValue() |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
// Folders might be missing if user didn't install any packages yet |
|
|
|
// Folders might be missing if user didn't install any packages yet |
|
|
|
downloadDirectory.Create(); |
|
|
|
downloadDirectory.Create(); |
|
|
|
|
|
|
|
|
|
|
|