Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

Address review feedback on crop tool and refine tool preset editing

smjrifle4ccb6e3a0501
diff --git a/src/Filee.App/Controls/CropCanvas.cs b/src/Filee.App/Controls/CropCanvas.cs
index d0cad03e..7d756a49 100644
--- a/src/Filee.App/Controls/CropCanvas.cs
+++ b/src/Filee.App/Controls/CropCanvas.cs
@@ -70,6 +70,8 @@ public sealed class CropCanvas : Control
private static readonly IBrush DimMaskBrush = new SolidColorBrush(Color.FromArgb(175, 0, 0, 0));
private static readonly IPen CropBorderPen = new Pen(Brushes.White, 1.5);
private static readonly IPen GridPen = new Pen(new SolidColorBrush(Color.FromArgb(80, 255, 255, 255)), 1);
+ private static readonly IPen HandlePen = new Pen(Brushes.White, 3.5);
+ private static readonly IPen HandleShadowPen = new Pen(new SolidColorBrush(Color.FromArgb(140, 0, 0, 0)), 5.0);
private static double SafeClamp(double val, double min, double max) =>
min > max ? Math.Clamp(val, max, min) : Math.Clamp(val, min, max);
@@ -129,8 +131,8 @@ public sealed class CropCanvas : Control
w = Math.Max(MinSizePx, w);
h = Math.Max(MinSizePx, h);
- var x = Math.Clamp(current.Center.X - w / 2.0, imgBounds.Left, Math.Max(imgBounds.Left, imgBounds.Right - w));
- var y = Math.Clamp(current.Center.Y - h / 2.0, imgBounds.Top, Math.Max(imgBounds.Top, imgBounds.Bottom - h));
+ var x = SafeClamp(current.Center.X - w / 2.0, imgBounds.Left, Math.Max(imgBounds.Left, imgBounds.Right - w));
+ var y = SafeClamp(current.Center.Y - h / 2.0, imgBounds.Top, Math.Max(imgBounds.Top, imgBounds.Bottom - h));
SetCropFromScreen(new Rect(x, y, w, h), imgBounds);
}
@@ -166,12 +168,12 @@ public sealed class CropCanvas : Control
if (imgBounds.Width <= 0 || imgBounds.Height <= 0)
return;
- var x = Math.Clamp(screenCrop.X, imgBounds.Left, Math.Max(imgBounds.Left, imgBounds.Right - MinSizePx));
- var y = Math.Clamp(screenCrop.Y, imgBounds.Top, Math.Max(imgBounds.Top, imgBounds.Bottom - MinSizePx));
+ var x = SafeClamp(screenCrop.X, imgBounds.Left, Math.Max(imgBounds.Left, imgBounds.Right - MinSizePx));
+ var y = SafeClamp(screenCrop.Y, imgBounds.Top, Math.Max(imgBounds.Top, imgBounds.Bottom - MinSizePx));
var maxW = imgBounds.Right - x;
var maxH = imgBounds.Bottom - y;
- var w = Math.Clamp(screenCrop.Width, MinSizePx, Math.Max(MinSizePx, maxW));
- var h = Math.Clamp(screenCrop.Height, MinSizePx, Math.Max(MinSizePx, maxH));
+ var w = SafeClamp(screenCrop.Width, MinSizePx, Math.Max(MinSizePx, maxW));
+ var h = SafeClamp(screenCrop.Height, MinSizePx, Math.Max(MinSizePx, maxH));
NormalizedCropRect = new Rect(
(x - imgBounds.Left) / imgBounds.Width,
@@ -238,29 +240,21 @@ public sealed class CropCanvas : Control
private void DrawCornerBracket(DrawingContext context, Point corner, int dirX, int dirY)
{
const double length = 18;
- const double thickness = 3.5;
- var pCorner = new Pen(Brushes.White, thickness);
- var pShadow = new Pen(new SolidColorBrush(Color.FromArgb(140, 0, 0, 0)), thickness + 1.5);
-
var pHoriz = new Point(corner.X + dirX * length, corner.Y);
var pVert = new Point(corner.X, corner.Y + dirY * length);
// Shadow behind bracket for clear visibility on bright/white photos
- context.DrawLine(pShadow, new Point(corner.X - dirX * 0.5, corner.Y), pHoriz);
- context.DrawLine(pShadow, new Point(corner.X, corner.Y - dirY * 0.5), pVert);
+ context.DrawLine(HandleShadowPen, new Point(corner.X - dirX * 0.5, corner.Y), pHoriz);
+ context.DrawLine(HandleShadowPen, new Point(corner.X, corner.Y - dirY * 0.5), pVert);
// Crisp white bracket
- context.DrawLine(pCorner, corner, pHoriz);
- context.DrawLine(pCorner, corner, pVert);
+ context.DrawLine(HandlePen, corner, pHoriz);
+ context.DrawLine(HandlePen, corner, pVert);
}
private void DrawEdgeBar(DrawingContext context, Point center, bool isHorizontal)
{
const double halfLen = 10;
- const double thickness = 3.5;
- var pBar = new Pen(Brushes.White, thickness);
- var pShadow = new Pen(new SolidColorBrush(Color.FromArgb(140, 0, 0, 0)), thickness + 1.5);
-
Point p1, p2;
if (isHorizontal)
{
@@ -273,8 +267,8 @@ public sealed class CropCanvas : Control
p2 = new Point(center.X, center.Y + halfLen);
}
- context.DrawLine(pShadow, p1, p2);
- context.DrawLine(pBar, p1, p2);
+ context.DrawLine(HandleShadowPen, p1, p2);
+ context.DrawLine(HandlePen, p1, p2);
}
private CropHandle HitTestHandle(Point pt, Rect crop, Rect imgBounds)
@@ -582,15 +576,15 @@ public sealed class CropCanvas : Control
}
else
{
- newW = Math.Clamp(crop.Width * zoomFactor, MinSizePx, imgBounds.Width);
- newH = Math.Clamp(crop.Height * zoomFactor, MinSizePx, imgBounds.Height);
+ newW = SafeClamp(crop.Width * zoomFactor, MinSizePx, imgBounds.Width);
+ newH = SafeClamp(crop.Height * zoomFactor, MinSizePx, imgBounds.Height);
}
- newW = Math.Max(MinSizePx, newW);
- newH = Math.Max(MinSizePx, newH);
+ newW = Math.Max(1, newW);
+ newH = Math.Max(1, newH);
- var newX = Math.Clamp(crop.Center.X - newW / 2.0, imgBounds.Left, imgBounds.Right - newW);
- var newY = Math.Clamp(crop.Center.Y - newH / 2.0, imgBounds.Top, imgBounds.Bottom - newH);
+ var newX = SafeClamp(crop.Center.X - newW / 2.0, imgBounds.Left, imgBounds.Right - newW);
+ var newY = SafeClamp(crop.Center.Y - newH / 2.0, imgBounds.Top, imgBounds.Bottom - newH);
SetCropFromScreen(new Rect(newX, newY, newW, newH), imgBounds);
e.Handled = true;
diff --git a/src/Filee.App/Services/CropService.cs b/src/Filee.App/Services/CropService.cs
index 964129d7..f25e7e34 100644
--- a/src/Filee.App/Services/CropService.cs
+++ b/src/Filee.App/Services/CropService.cs
@@ -2,17 +2,49 @@
using System.IO;
using Avalonia.Media.Imaging;
-using Filee.Core.History;
using Filee.Core.Localization;
using Filee.Core.Presets;
using Filee.Core.Settings;
+using Filee.Engines.Magick;
using ImageMagick;
using Microsoft.Extensions.Logging;
namespace Filee.App.Services;
+public enum CropStatus
+{
+ Success,
+ SkippedExists,
+ Failed,
+}
+
+public sealed record CropResult(CropStatus Status, string? OutputPath, string? ErrorKey, string? ErrorDetail);
+
public static class CropService
{
+ private static MagickReadSettings CreateReadSettings(string inputPath)
+ {
+ var ext = Path.GetExtension(inputPath).TrimStart('.').ToLowerInvariant();
+ var settings = new MagickReadSettings();
+ if (ImageEncoder.ExplicitCoder.Contains(ext))
+ settings.Format = ImageEncoder.ToMagickFormat(ext);
+ return settings;
+ }
+
+ private static void EnsureNotAnimated(string inputPath)
+ {
+ if (inputPath.EndsWith(".png", StringComparison.OrdinalIgnoreCase) && Apng.IsAnimated(inputPath))
+ throw new NotSupportedException("Animated PNG files cannot be cropped interactively.");
+
+ var readSettings = CreateReadSettings(inputPath);
+ var infos = readSettings.Format != MagickFormat.Unknown
+ ? MagickImageInfo.ReadCollection(inputPath, readSettings).ToList()
+ : MagickImageInfo.ReadCollection(inputPath).ToList();
+
+ if (infos.Count > 1)
+ throw new NotSupportedException("Multi-frame / animated images cannot be cropped interactively.");
+ }
+
/// <summary>
/// Loads an image as a standard Avalonia Bitmap along with its true pixel dimensions,
/// properly oriented according to EXIF.
@@ -21,7 +53,13 @@ public static class CropService
{
return await Task.Run(() =>
{
- using var image = new MagickImage(inputPath);
+ EnsureNotAnimated(inputPath);
+
+ var readSettings = CreateReadSettings(inputPath);
+ using var image = readSettings.Format != MagickFormat.Unknown
+ ? new MagickImage(inputPath, readSettings)
+ : new MagickImage(inputPath);
+
image.AutoOrient();
var origWidth = (int)image.Width;
var origHeight = (int)image.Height;
@@ -46,7 +84,7 @@ public static class CropService
/// Crops the image at <paramref name="inputPath"/> with the given pixel coordinates and saves the result using
/// the preset's output rule and the application's default output settings.
/// </summary>
- public static async Task<string?> CropFileAsync(
+ public static async Task<CropResult> CropFileAsync(
string inputPath,
int x, int y, int width, int height,
Preset preset,
@@ -56,64 +94,71 @@ public static class CropService
{
return await Task.Run(() =>
{
- var ext = Path.GetExtension(inputPath).TrimStart('.');
- var appliedPreset = store.Settings.WithDefaultOutput(preset);
- var tokens = new OutputPathResolver.Tokens(inputPath, loc.DisplayName(appliedPreset), 1, DateTime.Now);
- var outputPath = OutputPathResolver.Resolve(appliedPreset.Output, tokens, ext, File.Exists);
- if (outputPath is null)
+ try
{
- log?.LogInformation("Skipping crop of {Input} as conflict policy resolved to null", inputPath);
- return null;
- }
+ EnsureNotAnimated(inputPath);
- var outDir = Path.GetDirectoryName(outputPath);
- if (!string.IsNullOrEmpty(outDir))
- Directory.CreateDirectory(outDir);
+ var ext = Path.GetExtension(inputPath).TrimStart('.');
+ var appliedPreset = store.Settings.WithDefaultOutput(preset);
+ var tokens = new OutputPathResolver.Tokens(inputPath, loc.DisplayName(appliedPreset), 1, DateTime.Now);
+ var outputPath = OutputPathResolver.Resolve(appliedPreset.Output, tokens, ext, File.Exists);
+ if (outputPath is null)
+ {
+ log?.LogInformation("Skipping crop of {Input} as conflict policy resolved to null (file exists)", inputPath);
+ return new CropResult(CropStatus.SkippedExists, null, "toast.skipped", Path.GetFileName(inputPath));
+ }
- using var image = new MagickImage(inputPath);
- image.AutoOrient();
+ var outDir = Path.GetDirectoryName(outputPath);
+ if (!string.IsNullOrEmpty(outDir))
+ Directory.CreateDirectory(outDir);
- var clampedX = Math.Clamp(x, 0, Math.Max(0, (int)image.Width - 1));
- var clampedY = Math.Clamp(y, 0, Math.Max(0, (int)image.Height - 1));
- var clampedW = (uint)Math.Clamp(width, 1, Math.Max(1, (int)image.Width - clampedX));
- var clampedH = (uint)Math.Clamp(height, 1, Math.Max(1, (int)image.Height - clampedY));
+ var readSettings = CreateReadSettings(inputPath);
+ using var image = readSettings.Format != MagickFormat.Unknown
+ ? new MagickImage(inputPath, readSettings)
+ : new MagickImage(inputPath);
- image.Crop(new MagickGeometry(clampedX, clampedY, clampedW, clampedH));
- image.ResetPage();
+ image.AutoOrient();
- if (appliedPreset.Image.Quality is > 0 and <= 100)
- image.Quality = (uint)appliedPreset.Image.Quality;
+ var clampedX = Math.Clamp(x, 0, Math.Max(0, (int)image.Width - 1));
+ var clampedY = Math.Clamp(y, 0, Math.Max(0, (int)image.Height - 1));
+ var clampedW = (uint)Math.Clamp(width, 1, Math.Max(1, (int)image.Width - clampedX));
+ var clampedH = (uint)Math.Clamp(height, 1, Math.Max(1, (int)image.Height - clampedY));
- image.Write(outputPath);
+ image.Crop(new MagickGeometry(clampedX, clampedY, clampedW, clampedH));
+ image.ResetPage();
- if (appliedPreset.Output.KeepDates || store.Settings.KeepFileDates)
- {
- try
+ // Drop EXIF thumbnail so viewers don't show the uncropped preview
+ if (image.GetExifProfile() is { } exif && exif.ThumbnailLength > 0)
{
- File.SetCreationTimeUtc(outputPath, File.GetCreationTimeUtc(inputPath));
- File.SetLastWriteTimeUtc(outputPath, File.GetLastWriteTimeUtc(inputPath));
+ exif.RemoveThumbnail();
+ image.SetProfile(exif);
}
- catch
+
+ if (appliedPreset.Image.Quality is > 0 and <= 100)
+ image.Quality = (uint)appliedPreset.Image.Quality;
+
+ image.Write(outputPath);
+
+ if (appliedPreset.Output.KeepDates || store.Settings.KeepFileDates)
{
- // Ignore date preservation failures on read-only/virtual filesystems
+ try
+ {
+ File.SetCreationTimeUtc(outputPath, File.GetCreationTimeUtc(inputPath));
+ File.SetLastWriteTimeUtc(outputPath, File.GetLastWriteTimeUtc(inputPath));
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
+ {
+ log?.LogDebug(ex, "Could not preserve file timestamps for {Path}", outputPath);
+ }
}
- }
- if (store.Settings.KeepHistory)
+ return new CropResult(CropStatus.Success, outputPath, null, null);
+ }
+ catch (Exception ex)
{
- store.AddHistory(new HistoryEntry
- {
- JobId = Guid.NewGuid().ToString("N")[..12],
- FinishedAt = DateTime.Now,
- PresetId = preset.Id,
- PresetName = loc.DisplayName(preset),
- State = Filee.Core.Conversion.JobState.Completed,
- Sources = [inputPath],
- Outputs = [outputPath],
- });
+ log?.LogError(ex, "Failed to crop {File}", inputPath);
+ return new CropResult(CropStatus.Failed, null, "error.conversion_failed", ex.Message);
}
-
- return outputPath;
});
}
}
diff --git a/src/Filee.App/Services/PresetAvailability.cs b/src/Filee.App/Services/PresetAvailability.cs
index b82d63c8..0859cefa 100644
--- a/src/Filee.App/Services/PresetAvailability.cs
+++ b/src/Filee.App/Services/PresetAvailability.cs
@@ -11,7 +11,7 @@ public sealed class PresetAvailability(ConverterCatalog catalog, ILocalizer loc,
{
private static readonly HashSet<string> WritableSingleFrameRasterFormats =
[
- "jpg", "png", "webp", "bmp", "avif", "heic", "jxl", "jp2", "tga", "qoi", "dds", "pcx",
+ "jpg", "png", "webp", "bmp", "avif", "jxl", "jp2", "tga", "qoi", "dds", "pcx",
];
/// <summary>
/// Returns <c>null</c> when at least one of <paramref name="formats"/> can be converted with the preset,
diff --git a/src/Filee.App/Services/WindowService.cs b/src/Filee.App/Services/WindowService.cs
index e907cfc8..b2dc013e 100644
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@ -214,8 +214,6 @@ public sealed class WindowService(ILocalizer loc, IServiceProvider services, Mem
// A group converts nothing: it gets its own editor (name and the presets it fans out).
if (preset.IsGroup)
return await EditGroupAsync(preset, owner);
- if (preset.IsTool)
- return false;
var dialog = new PresetEditorWindow
{
DataContext = new PresetEditorViewModel(preset, loc),
diff --git a/src/Filee.App/ViewModels/CropOverlayViewModel.cs b/src/Filee.App/ViewModels/CropOverlayViewModel.cs
index 553e830f..97b662c8 100644
--- a/src/Filee.App/ViewModels/CropOverlayViewModel.cs
+++ b/src/Filee.App/ViewModels/CropOverlayViewModel.cs
@@ -6,6 +6,8 @@ using Avalonia.Media.Imaging;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Filee.App.Services;
+using Filee.Core.Conversion;
+using Filee.Core.History;
using Filee.Core.Localization;
using Filee.Core.Presets;
using Filee.Core.Settings;
@@ -21,6 +23,11 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
private readonly UserDataStore _store;
private readonly ILogger? _log;
+ private readonly List<string> _processedSources = [];
+ private readonly List<string> _outputs = [];
+ private readonly List<HistoryFailure> _failures = [];
+ private bool _historyRecorded;
+
[ObservableProperty] private int _currentIndex;
[ObservableProperty] private string _currentFileName = "";
[ObservableProperty] private string _counterText = "";
@@ -35,19 +42,21 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
[NotifyPropertyChangedFor(nameof(IsAspectFree))]
[NotifyPropertyChangedFor(nameof(IsAspectOriginal))]
[NotifyPropertyChangedFor(nameof(IsAspectSquare))]
- [NotifyPropertyChangedFor(nameof(IsAspect45))]
- [NotifyPropertyChangedFor(nameof(IsAspect916))]
- [NotifyPropertyChangedFor(nameof(IsAspect169))]
[NotifyPropertyChangedFor(nameof(IsAspect43))]
+ [NotifyPropertyChangedFor(nameof(IsAspect169))]
private string _selectedAspect = "free";
+ [ObservableProperty]
+ [NotifyPropertyChangedFor(nameof(HasStatusNotice))]
+ private string _statusNotice = "";
+
+ public bool HasStatusNotice => !string.IsNullOrWhiteSpace(StatusNotice);
+
public bool IsAspectFree => SelectedAspect == "free";
public bool IsAspectOriginal => SelectedAspect == "original";
public bool IsAspectSquare => SelectedAspect == "1:1";
- public bool IsAspect45 => SelectedAspect == "4:5";
- public bool IsAspect916 => SelectedAspect == "9:16";
- public bool IsAspect169 => SelectedAspect == "16:9";
public bool IsAspect43 => SelectedAspect == "4:3";
+ public bool IsAspect169 => SelectedAspect == "16:9";
public event Action? CloseRequested;
public event Action? ResetRequested;
@@ -71,7 +80,7 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
{
if (index < 0 || index >= _files.Count)
{
- CloseRequested?.Invoke();
+ FinishAndClose();
return;
}
@@ -84,8 +93,10 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
try
{
var (bitmap, origW, origH) = await CropService.LoadPreviewAsync(path);
- PreviewImage?.Dispose();
+ var old = PreviewImage;
PreviewImage = bitmap;
+ old?.Dispose();
+
OriginalWidth = origW;
OriginalHeight = origH;
SelectedAspect = "free";
@@ -98,10 +109,20 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
catch (Exception ex)
{
_log?.LogError(ex, "Failed to load preview for {File}", path);
+ _processedSources.Add(path);
+ var errKey = ex is NotSupportedException ? "error.unsupported_source" : "error.conversion_failed";
+ _failures.Add(new HistoryFailure
+ {
+ Source = path,
+ ErrorKey = errKey,
+ ErrorDetail = ex.Message,
+ });
+ StatusNotice = $"{Path.GetFileName(path)}: {_loc[errKey]}";
+
if (index < _files.Count - 1)
await LoadFileAsync(index + 1);
else
- CloseRequested?.Invoke();
+ FinishAndClose();
}
finally
{
@@ -125,6 +146,8 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
IsBusy = true;
var path = _files[CurrentIndex];
+ _processedSources.Add(path);
+
var x = (int)Math.Round(CurrentCropRect.X * OriginalWidth);
var y = (int)Math.Round(CurrentCropRect.Y * OriginalHeight);
var w = (int)Math.Round(CurrentCropRect.Width * OriginalWidth);
@@ -132,11 +155,42 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
try
{
- await CropService.CropFileAsync(path, x, y, w, h, _preset, _store, _loc, _log);
+ var result = await CropService.CropFileAsync(path, x, y, w, h, _preset, _store, _loc, _log);
+ if (result.Status == CropStatus.Success && result.OutputPath is not null)
+ {
+ _outputs.Add(result.OutputPath);
+ }
+ else if (result.Status == CropStatus.SkippedExists)
+ {
+ _failures.Add(new HistoryFailure
+ {
+ Source = path,
+ ErrorKey = result.ErrorKey,
+ ErrorDetail = result.ErrorDetail,
+ });
+ StatusNotice = $"{Path.GetFileName(path)}: {_loc["toast.skipped"]}";
+ }
+ else
+ {
+ _failures.Add(new HistoryFailure
+ {
+ Source = path,
+ ErrorKey = result.ErrorKey ?? "error.conversion_failed",
+ ErrorDetail = result.ErrorDetail,
+ });
+ StatusNotice = $"{Path.GetFileName(path)}: {_loc["error.conversion_failed"]}";
+ }
}
catch (Exception ex)
{
_log?.LogError(ex, "Failed to crop {File}", path);
+ _failures.Add(new HistoryFailure
+ {
+ Source = path,
+ ErrorKey = "error.conversion_failed",
+ ErrorDetail = ex.Message,
+ });
+ StatusNotice = $"{Path.GetFileName(path)}: {_loc["error.conversion_failed"]}";
}
finally
{
@@ -149,7 +203,7 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
}
else
{
- CloseRequested?.Invoke();
+ FinishAndClose();
}
}
@@ -162,7 +216,7 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
if (CurrentIndex < _files.Count - 1)
await LoadFileAsync(CurrentIndex + 1);
else
- CloseRequested?.Invoke();
+ FinishAndClose();
}
[RelayCommand]
@@ -177,7 +231,7 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
[RelayCommand]
public void Cancel()
{
- CloseRequested?.Invoke();
+ FinishAndClose();
}
[RelayCommand]
@@ -189,18 +243,47 @@ public sealed partial class CropOverlayViewModel : ObservableObject, IDisposable
"free" => 0,
"original" => OriginalHeight > 0 ? (double)OriginalWidth / OriginalHeight : 0,
"1:1" => 1.0,
- "4:5" => 4.0 / 5.0,
- "9:16" => 9.0 / 16.0,
- "16:9" => 16.0 / 9.0,
"4:3" => 4.0 / 3.0,
+ "16:9" => 16.0 / 9.0,
_ => 0,
};
AspectRatio = ratio;
AspectRatioChanged?.Invoke(ratio);
}
+ private void FinishAndClose()
+ {
+ RecordHistoryOnce();
+ CloseRequested?.Invoke();
+ }
+
+ private void RecordHistoryOnce()
+ {
+ if (_historyRecorded || !_store.Settings.KeepHistory || _processedSources.Count == 0)
+ return;
+
+ _historyRecorded = true;
+ var state = _failures.Count == 0
+ ? JobState.Completed
+ : (_outputs.Count > 0 ? JobState.CompletedWithErrors : JobState.Failed);
+
+ _store.AddHistory(new HistoryEntry
+ {
+ JobId = Guid.NewGuid().ToString("N")[..12],
+ FinishedAt = DateTime.Now,
+ PresetId = _preset.Id,
+ PresetName = _loc.DisplayName(_preset),
+ State = state,
+ Sources = [.. _processedSources],
+ Outputs = [.. _outputs],
+ Failures = [.. _failures],
+ Preset = _failures.Count > 0 ? _preset.Clone() : null,
+ });
+ }
+
public void Dispose()
{
+ RecordHistoryOnce();
PreviewImage?.Dispose();
PreviewImage = null;
}
diff --git a/src/Filee.App/ViewModels/PresetEditorViewModel.cs b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
index 11c47f9a..a0bbf07e 100644
--- a/src/Filee.App/ViewModels/PresetEditorViewModel.cs
+++ b/src/Filee.App/ViewModels/PresetEditorViewModel.cs
@@ -155,6 +155,9 @@ public sealed partial class PresetEditorViewModel : ObservableObject
}
public string PresetId => _original.Id;
+ public bool IsTool => _original.IsTool;
+ public bool CanChangeTarget => !IsTool;
+ public bool ShowImageTools => !IsTool;
public IReadOnlyList<Choice<string>> Targets { get; }
public IReadOnlyList<Choice<ResizeMode>> ResizeModes { get; }
@@ -390,7 +393,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject
public bool ShowMultiPageTiff => TargetId is "tiff";
public bool ShowIco => TargetId == "ico";
/// <summary>PDF options (also used when a PDF source becomes images) mean nothing for media, archive, font, subtitle, data, e-mail and 3D targets.</summary>
- public bool ShowPdf => TargetCategory is not (FormatCategory.Video or FormatCategory.Audio or FormatCategory.Archive or FormatCategory.Font
+ public bool ShowPdf => !IsTool && TargetCategory is not (FormatCategory.Video or FormatCategory.Audio or FormatCategory.Archive or FormatCategory.Font
or FormatCategory.Subtitle or FormatCategory.Data or FormatCategory.Model3D) && TargetId != "eml";
public bool ShowPdfBuild => TargetId == "pdf";
public bool ShowPdfSplit => TargetId == "pdf";
@@ -425,7 +428,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject
/// <summary>"Extract" has nothing to set; a line says what it does instead.</summary>
public bool ShowExtractNote => TargetId == FormatRegistry.Folder;
/// <summary>"Save every frame" of a video: PNG and JPG (format ids, <see cref="MediaOptions.FrameTargets"/>).</summary>
- public bool ShowSaveEveryFrame => MediaOptions.FrameTargets.Contains(TargetId);
+ public bool ShowSaveEveryFrame => !IsTool && MediaOptions.FrameTargets.Contains(TargetId);
/// <summary>
/// Tracing options: raster images reach SVG (and DXF / DWG through it) only by tracing. For other sources (a
/// drawing, a CAD file) the options are ignored.
diff --git a/src/Filee.App/Views/CropOverlayWindow.axaml b/src/Filee.App/Views/CropOverlayWindow.axaml
index 068f2b61..15fa44ae 100644
--- a/src/Filee.App/Views/CropOverlayWindow.axaml
+++ b/src/Filee.App/Views/CropOverlayWindow.axaml
@@ -64,6 +64,10 @@
<Border IsVisible="{Binding HasMultipleFiles}" Background="{DynamicResource AccentSoftBrush}" CornerRadius="10" Padding="8,2">
<TextBlock Text="{Binding CounterText}" FontSize="11" Foreground="{DynamicResource TextPrimaryBrush}" />
</Border>
+
+ <Border IsVisible="{Binding HasStatusNotice}" Background="{DynamicResource CardShadow}" CornerRadius="10" Padding="8,2">
+ <TextBlock Text="{Binding StatusNotice}" FontSize="11" Foreground="{DynamicResource TextSecondaryBrush}" />
+ </Border>
</StackPanel>
</DockPanel>
</Border>
diff --git a/src/Filee.App/Views/PresetEditorView.axaml b/src/Filee.App/Views/PresetEditorView.axaml
index 0cfff9b0..657da87d 100644
--- a/src/Filee.App/Views/PresetEditorView.axaml
+++ b/src/Filee.App/Views/PresetEditorView.axaml
@@ -24,6 +24,7 @@
<StackPanel Grid.Column="2">
<TextBlock Classes="label" Text="{DynamicResource presets.target}" />
<ComboBox x:Name="TargetBox" Classes="targets" ItemsSource="{Binding Targets}" SelectedItem="{Binding Target}"
+ IsEnabled="{Binding CanChangeTarget}"
HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" MaxDropDownHeight="420">
<ComboBox.ItemTemplate>
<DataTemplate x:DataType="vm:IChoice">
@@ -48,73 +49,75 @@
</DockPanel>
<Slider Minimum="1" Maximum="100" Value="{Binding Quality}" TickFrequency="1" IsSnapToTickEnabled="True" />
</StackPanel>
- <Grid ColumnDefinitions="*,12,*">
- <StackPanel>
- <TextBlock Classes="label" Text="{DynamicResource presets.resize}" />
- <ComboBox ItemsSource="{Binding ResizeModes}" SelectedItem="{Binding Resize}" HorizontalAlignment="Stretch" />
- </StackPanel>
- <StackPanel Grid.Column="2" IsVisible="{Binding ShowPercent}">
- <TextBlock Classes="label" Text="{DynamicResource presets.percent}" />
- <NumericUpDown Value="{Binding ResizePercent}" Minimum="1" Maximum="1000" Increment="5" FormatString="0" />
- </StackPanel>
- <StackPanel Grid.Column="2" IsVisible="{Binding ShowLongEdge}">
- <TextBlock Classes="label" Text="{DynamicResource presets.long_edge}" />
- <NumericUpDown Value="{Binding LongEdge}" Minimum="16" Maximum="20000" Increment="100" FormatString="0" />
- </StackPanel>
- <StackPanel Grid.Column="2" IsVisible="{Binding ShowWidth}">
- <TextBlock Classes="label" Text="{DynamicResource presets.width}" />
- <NumericUpDown Value="{Binding Width}" Minimum="16" Maximum="20000" Increment="100" FormatString="0" />
- </StackPanel>
- </Grid>
- <Grid ColumnDefinitions="*,12,*">
- <StackPanel>
- <TextBlock Classes="label" Text="{DynamicResource presets.rotation}" />
- <ComboBox ItemsSource="{Binding Rotations}" SelectedItem="{Binding Rotation}" HorizontalAlignment="Stretch" />
- </StackPanel>
- <StackPanel Grid.Column="2">
- <TextBlock Classes="label" Text="{DynamicResource presets.flip}" />
- <ComboBox ItemsSource="{Binding Flips}" SelectedItem="{Binding Flip}" HorizontalAlignment="Stretch" />
+ <StackPanel Spacing="10" IsVisible="{Binding ShowImageTools}">
+ <Grid ColumnDefinitions="*,12,*">
+ <StackPanel>
+ <TextBlock Classes="label" Text="{DynamicResource presets.resize}" />
+ <ComboBox ItemsSource="{Binding ResizeModes}" SelectedItem="{Binding Resize}" HorizontalAlignment="Stretch" />
+ </StackPanel>
+ <StackPanel Grid.Column="2" IsVisible="{Binding ShowPercent}">
+ <TextBlock Classes="label" Text="{DynamicResource presets.percent}" />
+ <NumericUpDown Value="{Binding ResizePercent}" Minimum="1" Maximum="1000" Increment="5" FormatString="0" />
+ </StackPanel>
+ <StackPanel Grid.Column="2" IsVisible="{Binding ShowLongEdge}">
+ <TextBlock Classes="label" Text="{DynamicResource presets.long_edge}" />
+ <NumericUpDown Value="{Binding LongEdge}" Minimum="16" Maximum="20000" Increment="100" FormatString="0" />
+ </StackPanel>
+ <StackPanel Grid.Column="2" IsVisible="{Binding ShowWidth}">
+ <TextBlock Classes="label" Text="{DynamicResource presets.width}" />
+ <NumericUpDown Value="{Binding Width}" Minimum="16" Maximum="20000" Increment="100" FormatString="0" />
+ </StackPanel>
+ </Grid>
+ <Grid ColumnDefinitions="*,12,*">
+ <StackPanel>
+ <TextBlock Classes="label" Text="{DynamicResource presets.rotation}" />
+ <ComboBox ItemsSource="{Binding Rotations}" SelectedItem="{Binding Rotation}" HorizontalAlignment="Stretch" />
+ </StackPanel>
+ <StackPanel Grid.Column="2">
+ <TextBlock Classes="label" Text="{DynamicResource presets.flip}" />
+ <ComboBox ItemsSource="{Binding Flips}" SelectedItem="{Binding Flip}" HorizontalAlignment="Stretch" />
+ </StackPanel>
+ </Grid>
+ <Grid ColumnDefinitions="Auto,12,*">
+ <CheckBox Content="{DynamicResource presets.dpi}" IsChecked="{Binding SetDpi}" />
+ <NumericUpDown Grid.Column="2" Value="{Binding Dpi}" Minimum="36" Maximum="2400" Increment="50" FormatString="0" IsEnabled="{Binding SetDpi}" />
+ </Grid>
+ <WrapPanel>
+ <CheckBox Content="{DynamicResource presets.keep_metadata}" IsChecked="{Binding KeepMetadata}" Margin="0,0,18,0" />
+ <CheckBox Content="{DynamicResource presets.keep_color_profile}" IsChecked="{Binding ColorProfileChecked}"
+ IsEnabled="{Binding CanChangeColorProfile}" ToolTip.Tip="{DynamicResource presets.keep_color_profile_hint}" ToolTip.ShowOnDisabled="True" Margin="0,0,18,0" />
+ <CheckBox Content="{DynamicResource presets.grayscale}" IsChecked="{Binding Grayscale}" Margin="0,0,18,0" />
+ <CheckBox Content="{DynamicResource presets.webp_lossless}" IsChecked="{Binding WebpLossless}" IsVisible="{Binding ShowWebp}" />
+ </WrapPanel>
+ <CheckBox Content="{DynamicResource presets.remove_background}" IsChecked="{Binding RemoveBackground}"
+ ToolTip.Tip="{DynamicResource presets.remove_background_hint}" />
+ <StackPanel Spacing="6" IsVisible="{Binding RemoveBackground}">
+ <DockPanel>
+ <TextBlock DockPanel.Dock="Right" Text="{Binding BackgroundTolerance}" FontWeight="SemiBold" />
+ <TextBlock Classes="label" Text="{DynamicResource presets.background_tolerance}" />
+ </DockPanel>
+ <Slider Minimum="0" Maximum="100" Value="{Binding BackgroundTolerance}" TickFrequency="1" IsSnapToTickEnabled="True"
+ ToolTip.Tip="{DynamicResource presets.background_tolerance_hint}" />
+ <CheckBox Content="{DynamicResource presets.keep_enclosed_background}" IsChecked="{Binding KeepEnclosedBackground}"
+ ToolTip.Tip="{DynamicResource presets.keep_enclosed_background_hint}" />
</StackPanel>
- </Grid>
- <Grid ColumnDefinitions="Auto,12,*">
- <CheckBox Content="{DynamicResource presets.dpi}" IsChecked="{Binding SetDpi}" />
- <NumericUpDown Grid.Column="2" Value="{Binding Dpi}" Minimum="36" Maximum="2400" Increment="50" FormatString="0" IsEnabled="{Binding SetDpi}" />
- </Grid>
- <WrapPanel>
- <CheckBox Content="{DynamicResource presets.keep_metadata}" IsChecked="{Binding KeepMetadata}" Margin="0,0,18,0" />
- <CheckBox Content="{DynamicResource presets.keep_color_profile}" IsChecked="{Binding ColorProfileChecked}"
- IsEnabled="{Binding CanChangeColorProfile}" ToolTip.Tip="{DynamicResource presets.keep_color_profile_hint}" ToolTip.ShowOnDisabled="True" Margin="0,0,18,0" />
- <CheckBox Content="{DynamicResource presets.grayscale}" IsChecked="{Binding Grayscale}" Margin="0,0,18,0" />
- <CheckBox Content="{DynamicResource presets.webp_lossless}" IsChecked="{Binding WebpLossless}" IsVisible="{Binding ShowWebp}" />
- </WrapPanel>
- <CheckBox Content="{DynamicResource presets.remove_background}" IsChecked="{Binding RemoveBackground}"
- ToolTip.Tip="{DynamicResource presets.remove_background_hint}" />
- <StackPanel Spacing="6" IsVisible="{Binding RemoveBackground}">
- <DockPanel>
- <TextBlock DockPanel.Dock="Right" Text="{Binding BackgroundTolerance}" FontWeight="SemiBold" />
- <TextBlock Classes="label" Text="{DynamicResource presets.background_tolerance}" />
- </DockPanel>
- <Slider Minimum="0" Maximum="100" Value="{Binding BackgroundTolerance}" TickFrequency="1" IsSnapToTickEnabled="True"
- ToolTip.Tip="{DynamicResource presets.background_tolerance_hint}" />
- <CheckBox Content="{DynamicResource presets.keep_enclosed_background}" IsChecked="{Binding KeepEnclosedBackground}"
- ToolTip.Tip="{DynamicResource presets.keep_enclosed_background_hint}" />
+ <Grid ColumnDefinitions="*,12,*">
+ <StackPanel>
+ <TextBlock Classes="label" Text="{DynamicResource presets.background}" />
+ <TextBox Text="{Binding Background}" PlaceholderText="#FFFFFF" />
+ </StackPanel>
+ <StackPanel Grid.Column="2" IsVisible="{Binding ShowTiff}">
+ <TextBlock Classes="label" Text="{DynamicResource presets.tiff_compression}" />
+ <ComboBox ItemsSource="{Binding TiffCompressions}" SelectedItem="{Binding TiffCompression}" HorizontalAlignment="Stretch" />
+ </StackPanel>
+ <StackPanel Grid.Column="2" IsVisible="{Binding ShowIco}">
+ <TextBlock Classes="label" Text="{DynamicResource presets.ico_sizes}" />
+ <TextBox Text="{Binding IcoSizes}" PlaceholderText="256, 64, 48, 32, 16" />
+ </StackPanel>
+ </Grid>
+ <CheckBox Content="{DynamicResource presets.multipage_tiff}" IsChecked="{Binding MultiPageTiff}" IsVisible="{Binding ShowMultiPageTiff}"
+ ToolTip.Tip="{DynamicResource presets.multipage_tiff_hint}" />
</StackPanel>
- <Grid ColumnDefinitions="*,12,*">
- <StackPanel>
- <TextBlock Classes="label" Text="{DynamicResource presets.background}" />
- <TextBox Text="{Binding Background}" PlaceholderText="#FFFFFF" />
- </StackPanel>
- <StackPanel Grid.Column="2" IsVisible="{Binding ShowTiff}">
- <TextBlock Classes="label" Text="{DynamicResource presets.tiff_compression}" />
- <ComboBox ItemsSource="{Binding TiffCompressions}" SelectedItem="{Binding TiffCompression}" HorizontalAlignment="Stretch" />
- </StackPanel>
- <StackPanel Grid.Column="2" IsVisible="{Binding ShowIco}">
- <TextBlock Classes="label" Text="{DynamicResource presets.ico_sizes}" />
- <TextBox Text="{Binding IcoSizes}" PlaceholderText="256, 64, 48, 32, 16" />
- </StackPanel>
- </Grid>
- <CheckBox Content="{DynamicResource presets.multipage_tiff}" IsChecked="{Binding MultiPageTiff}" IsVisible="{Binding ShowMultiPageTiff}"
- ToolTip.Tip="{DynamicResource presets.multipage_tiff_hint}" />
<StackPanel Spacing="6" IsVisible="{Binding ShowSaveEveryFrame}">
<CheckBox Content="{DynamicResource presets.save_every_frame}" IsChecked="{Binding SaveEveryFrame}"
ToolTip.Tip="{DynamicResource presets.save_every_frame_hint}" />
diff --git a/src/Filee.Core/Conversion/IConverter.cs b/src/Filee.Core/Conversion/IConverter.cs
index fbaee33f..1c982b8e 100644
--- a/src/Filee.Core/Conversion/IConverter.cs
+++ b/src/Filee.Core/Conversion/IConverter.cs
@@ -86,6 +86,7 @@ public interface IOutputAllocator
/// <param name="FrameSequence">
/// The step takes a <see cref="ConversionEdge.FrameSequence"/> edge: every frame of the video becomes a picture of
/// format <paramref name="To"/> in one output folder.
+/// </param>
/// <param name="Notice">
/// Records a note on a step that worked, as a localization key (e.g. <c>notice.pdf_not_smaller</c>): shown with the
/// file's result. Null when nobody listens.
diff --git a/src/Filee.Core/Presets/BuiltInData.cs b/src/Filee.Core/Presets/BuiltInData.cs
index a7771eb3..1af772aa 100644
--- a/src/Filee.Core/Presets/BuiltInData.cs
+++ b/src/Filee.Core/Presets/BuiltInData.cs
@@ -349,7 +349,6 @@ public static class BuiltInData
.. WithSubtitleProfile(CatalogProfiles()),
DataProfile(),
ModelProfile(),
-
new()
{
Id = "mixed", NameKey = "profile.mixed", IsFallback = true,
diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs
index f1fde541..f55d3200 100644
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@ -64,7 +64,7 @@ public sealed class DonutSettings
public sealed class AppSettings
{
/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>
- public const int CurrentSchemaVersion = 20;
+ public const int CurrentSchemaVersion = 21;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --git a/src/Filee.Engines/Filee.Engines.csproj b/src/Filee.Engines/Filee.Engines.csproj
index 98695b5f..2da7d6ac 100644
--- a/src/Filee.Engines/Filee.Engines.csproj
+++ b/src/Filee.Engines/Filee.Engines.csproj
@@ -36,6 +36,9 @@
</ItemGroup>
<ItemGroup>
+ <InternalsVisibleTo Include="Filee" />
+ <InternalsVisibleTo Include="Filee.App" />
+ <InternalsVisibleTo Include="Filee.App.Tests" />
<InternalsVisibleTo Include="Filee.Engines.Tests" />
</ItemGroup>
diff --git a/tests/Filee.App.Tests/CropServiceTests.cs b/tests/Filee.App.Tests/CropServiceTests.cs
new file mode 100644
index 00000000..9989d3a9
--- /dev/null
+++ b/tests/Filee.App.Tests/CropServiceTests.cs
@@ -0,0 +1,100 @@
+// Tests for CropService: output resolving, conflict policies, and thumbnail handling.
+
+using System.IO;
+using Avalonia.Headless.XUnit;
+using Filee.App.Services;
+using Filee.Core.Localization;
+using Filee.Core.Presets;
+using Filee.Core.Settings;
+using ImageMagick;
+
+namespace Filee.App.Tests;
+
+public class CropServiceTests
+{
+ private static string CreateTestImage(string folder, string name, int width = 100, int height = 80)
+ {
+ var path = Path.Combine(folder, name);
+ using var image = new MagickImage(MagickColors.Green, (uint)width, (uint)height);
+ image.Write(path, MagickFormat.Png);
+ return path;
+ }
+
+ [AvaloniaFact]
+ public async Task CropFileAsync_resolves_output_path_and_crops_image()
+ {
+ TestServices.EnsureInitialized("en");
+ var folder = Directory.CreateTempSubdirectory("filee-crop-test-").FullName;
+ try
+ {
+ var source = CreateTestImage(folder, "photo.png", 200, 100);
+ var store = AppHost.Get<UserDataStore>();
+ var loc = AppHost.Get<ILocalizer>();
+ var preset = BuiltInData.CreatePresets().Single(p => p.Id == "tool-crop");
+
+ var result = await CropService.CropFileAsync(source, 10, 10, 50, 40, preset, store, loc);
+
+ Assert.Equal(CropStatus.Success, result.Status);
+ Assert.NotNull(result.OutputPath);
+ Assert.True(File.Exists(result.OutputPath));
+ Assert.EndsWith("photo_cropped.png", result.OutputPath);
+
+ using var cropped = new MagickImage(result.OutputPath);
+ Assert.Equal((uint)50, cropped.Width);
+ Assert.Equal((uint)40, cropped.Height);
+ }
+ finally
+ {
+ try { Directory.Delete(folder, true); } catch (IOException) { }
+ }
+ }
+
+ [AvaloniaFact]
+ public async Task CropFileAsync_honors_conflict_policies()
+ {
+ TestServices.EnsureInitialized("en");
+ var folder = Directory.CreateTempSubdirectory("filee-crop-conflict-").FullName;
+ try
+ {
+ var source = CreateTestImage(folder, "sample.png", 100, 100);
+ var expectedOutput = Path.Combine(folder, "sample_cropped.png");
+ File.WriteAllBytes(expectedOutput, [0x89, 0x50, 0x4E, 0x47]); // Existing file
+
+ var store = AppHost.Get<UserDataStore>();
+ var loc = AppHost.Get<ILocalizer>();
+
+ // 1. ConflictPolicy.Rename -> generates (2)
+ var renamePreset = BuiltInData.CreatePresets().Single(p => p.Id == "tool-crop").Clone();
+ renamePreset.Output.Conflict = ConflictPolicy.Rename;
+ var renameResult = await CropService.CropFileAsync(source, 0, 0, 50, 50, renamePreset, store, loc);
+
+ Assert.Equal(CropStatus.Success, renameResult.Status);
+ Assert.NotNull(renameResult.OutputPath);
+ Assert.EndsWith("sample_cropped (2).png", renameResult.OutputPath);
+ Assert.True(File.Exists(renameResult.OutputPath));
+
+ // 2. ConflictPolicy.Skip -> returns SkippedExists and null path
+ var skipPreset = BuiltInData.CreatePresets().Single(p => p.Id == "tool-crop").Clone();
+ skipPreset.Output.Conflict = ConflictPolicy.Skip;
+ var skipResult = await CropService.CropFileAsync(source, 0, 0, 50, 50, skipPreset, store, loc);
+
+ Assert.Equal(CropStatus.SkippedExists, skipResult.Status);
+ Assert.Null(skipResult.OutputPath);
+ Assert.Equal("toast.skipped", skipResult.ErrorKey);
+
+ // 3. ConflictPolicy.Overwrite -> overwrites existing file
+ var overwritePreset = BuiltInData.CreatePresets().Single(p => p.Id == "tool-crop").Clone();
+ overwritePreset.Output.Conflict = ConflictPolicy.Overwrite;
+ var overwriteResult = await CropService.CropFileAsync(source, 0, 0, 30, 30, overwritePreset, store, loc);
+
+ Assert.Equal(CropStatus.Success, overwriteResult.Status);
+ Assert.Equal(expectedOutput, overwriteResult.OutputPath);
+ using var overwritten = new MagickImage(expectedOutput);
+ Assert.Equal((uint)30, overwritten.Width);
+ }
+ finally
+ {
+ try { Directory.Delete(folder, true); } catch (IOException) { }
+ }
+ }
+}
diff --git a/tests/Filee.App.Tests/DonutGroupTests.cs b/tests/Filee.App.Tests/DonutGroupTests.cs
index a9591bdc..a7c2dc0b 100644
--- a/tests/Filee.App.Tests/DonutGroupTests.cs
+++ b/tests/Filee.App.Tests/DonutGroupTests.cs
@@ -427,6 +427,25 @@ public class DonutGroupTests
Assert.Equal("Rotate and flip work on images only", availability.Check(mergeTurned, [Filee.Core.Formats.FormatRegistry.Get("pdf")]));
}
+ [AvaloniaFact]
+ public void Tool_presets_are_available_only_for_writable_single_frame_raster_formats()
+ {
+ TestServices.EnsureInitialized("en");
+ var availability = AppHost.Get<PresetAvailability>();
+ var crop = BuiltInData.CreatePresets().Single(p => p.Id == "tool-crop");
+
+ Assert.Null(availability.Check(crop, [Filee.Core.Formats.FormatRegistry.Get("png")]));
+ Assert.Null(availability.Check(crop, [Filee.Core.Formats.FormatRegistry.Get("jpg")]));
+ Assert.Null(availability.Check(crop, [Filee.Core.Formats.FormatRegistry.Get("webp")]));
+
+ Assert.Equal("This file type isn't supported", availability.Check(crop, [Filee.Core.Formats.FormatRegistry.Get("pdf")]));
+ Assert.Equal("This file type isn't supported", availability.Check(crop, [Filee.Core.Formats.FormatRegistry.Get("svg")]));
+ Assert.Equal("This file type isn't supported", availability.Check(crop, [Filee.Core.Formats.FormatRegistry.Get("heic")]));
+
+ Assert.Equal("This file type isn't supported", availability.Check(crop, [Filee.Core.Formats.FormatRegistry.Get("png"), Filee.Core.Formats.FormatRegistry.Get("pdf")]));
+ Assert.Equal("This file type isn't supported", availability.Check(crop, []));
+ }
+
[AvaloniaFact]
public void A_group_left_without_presets_says_why_on_the_donut()
{
diff --git a/tests/Filee.Cli.Tests/CliTests.cs b/tests/Filee.Cli.Tests/CliTests.cs
index 7d2c6af6..4e485c58 100644
--- a/tests/Filee.Cli.Tests/CliTests.cs
+++ b/tests/Filee.Cli.Tests/CliTests.cs
@@ -303,4 +303,14 @@ public sealed class CliTests : IDisposable
Assert.True(File.Exists(result));
Assert.True(File.Exists(source));
}
+
+ [Fact]
+ public async Task Refuses_tool_presets()
+ {
+ var source = Png("photo.png");
+ var (code, _, errors) = await Run("convert", source, "--preset", "tool-crop");
+
+ Assert.Equal(Cli.UsageError, code);
+ Assert.Contains("is an interactive tool, not a conversion", errors);
+ }
}