diff --git a/StabilityMatrix.Avalonia/ViewModels/OutputsPageViewModel.cs b/StabilityMatrix.Avalonia/ViewModels/OutputsPageViewModel.cs index 2b845f9eb..0e1772691 100644 --- a/StabilityMatrix.Avalonia/ViewModels/OutputsPageViewModel.cs +++ b/StabilityMatrix.Avalonia/ViewModels/OutputsPageViewModel.cs @@ -28,6 +28,7 @@ using StabilityMatrix.Avalonia.ViewModels.Dialogs; using StabilityMatrix.Avalonia.ViewModels.OutputsPage; using StabilityMatrix.Core.Attributes; +using StabilityMatrix.Core.Exceptions; using StabilityMatrix.Core.Extensions; using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Helper.Factory; @@ -323,6 +324,12 @@ public async Task DeleteImage(OutputImageViewModel? item) { return; } + //Attempt to remove .txt sidecar if it exists + var sideCar = new FilePath(Path.ChangeExtension(imageFile, ".txt")); + if (File.Exists(sideCar)) + { + await notificationService.TryAsync(sideCar.DeleteAsync()); + } OutputsCache.Remove(item.ImageFile); @@ -388,6 +395,14 @@ public async Task DeleteAllSelected() { continue; } + + //Attempt to remove .txt sidecar if it exists + var sideCar = new FilePath(Path.ChangeExtension(imageFile, ".txt")); + if (File.Exists(sideCar)) + { + await notificationService.TryAsync(sideCar.DeleteAsync()); + } + OutputsCache.Remove(output.ImageFile); // Invalidate cache @@ -485,6 +500,14 @@ var path in Directory.EnumerateFiles( } await file.MoveToWithIncrementAsync(newPath); + + var sideCar = new FilePath(Path.ChangeExtension(file, ".txt")); + //If a .txt sidecar file exists, and the image was moved successfully, try to move the sidecar along with the image + if (File.Exists(newPath) && File.Exists(sideCar)) + { + var newSidecar = new FilePath(Path.ChangeExtension(newPath, ".txt")); + await sideCar.MoveToWithIncrementAsync(newSidecar); + } } catch (Exception e) {