Skip to content

Commit

Permalink
Output Browser - "ConsolidateImages" - Check for existence of .txt fi…
Browse files Browse the repository at this point in the history
…le sidecar with same filename as image, and attempts to move alongside image if image move is successful (Issue LykosAI#248)

Output Browser - "DeleteImage/DeleteAllSelected" - Check for existence of .txt file sidecar with same filename as image(s), and attempts to move alongside image(s) if image delete is successful
  • Loading branch information
Targren committed Dec 4, 2023
1 parent 43430e7 commit 229d49b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions StabilityMatrix.Avalonia/ViewModels/OutputsPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 229d49b

Please sign in to comment.