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.

Merge main into feature/clip-trim (schema 43, after the print studio)

KnifeLemonc4c67e527c8f
diff --cc docs/ARCHITECTURE.md
index eb389ee8,2a837abc..55735270
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@@ -164,29 -166,25 +166,48 @@@ multi-frame pictures refused, the EXIF
- `Controls/CropMath` holds the arithmetic (ratios and their portrait forms, nudging by whole pixels, the frame in
pixels, where the size chip goes, where the dial opens) and is unit tested.
+## Clip window
+
+The Cut a clip tool (`tool-clip`, first on the back of the video donut) opens `Views/ClipWindow` instead of running a
+job. The window only chooses the clip; writing it is an ordinary conversion.
+
+- `Core/Presets/ClipCutter` does every edit without the window: the parts of the clip (start, end, speed, volume,
+ mute), gaps left by Delete, the blade, edge trims that take back or cut away, music on A2, fades, Remove silence and
+ undo / redo (one step per drag). The result is a `ClipEdit`, unit tested on its own.
+- `ClipWindowViewModel` holds the window's state: the overview of the whole video (`Controls/ClipTimeline`: 16
+ frames, the loudness, the handles) and the sequence under it (`Controls/ClipSequence`: V1 pictures, A1 the video's
+ sound, A2 music). Both are custom-drawn controls; their pictures and loudness are taken again only when the clip's
+ ends rest.
+- Space plays the clip as it will be written: `Engines/Media/ClipPreview` runs the same filter graph as the output,
+ the pictures as raw BGRA frames over a pipe and the sound through `ffplay` (when it sits next to Filee's FFmpeg;
+ without it the preview is silent). FFmpeg for the window runs below normal priority.
+- Save calls `ClipTool.ConversionOf`, which carries the `ClipEdit` in `MediaOptions.Clip`, so the toast, cancel, the
+ output rules (`{name}_clip` next to the video) and the history work as for any conversion. `FfmpegConverter`
+ copies one plain stretch with `-ss/-to` and `-c copy` (*Fast, no re-encoding*), or encodes the exact cut.
+- Anything else is one filter graph (`MediaEncoding.ClipGraphOf`): the video is read once, `split`/`trim` per piece,
+ `setpts` and chained `atempo` for speed, `volume`, `color`/`anullsrc` for gaps, `concat`, the music as a second
+ input (`atrim`, `volume`, `afade`, `adelay`, `amix`), then `fade`/`afade`. It is encoded with the preset's quality,
+ size and codec.
+
+ ## Spreadsheet print studio
+
+ The `tool-sheet-studio` tool opens an independent `Views/SpreadsheetPrintStudioWindow` for each dropped XLSX workbook
+ instead of starting a normal conversion job. `SpreadsheetPrintStudioViewModel` owns an ordered, non-destructive print plan: each visible
+ sheet starts as one region and the user can add more regions, change paper, orientation, scale, margins, page order,
+ hidden rows and manual breaks, then see the PDF that those settings will produce.
+
+ - `SpreadsheetPrintInspector` reads workbook metadata and streams the large worksheet data with `XmlReader`; opening
+ a large workbook neither builds nor retains an `XDocument` for every sheet.
+ - `SpreadsheetPrintPackage` makes a disposable XLSX under `JobQueue.DefaultWorkRoot`. It keeps every worksheet and
+ named range so cross-sheet formulas remain valid, hides the sheets not being rendered, and changes only the chosen
+ sheet's print settings. A new print area is written only after the user explicitly changes or accepts the range.
+ - `SpreadsheetPrintService` runs LibreOffice once for each region. Preview and export use the same disposable-workbook
+ path; export then joins the region PDFs in the chosen order with PDFsharp. The ordinary XLSX → PDF donut conversion
+ can still differ because route planning may select Filee's built-in spreadsheet reader instead of LibreOffice.
+ - `PdfPreviewDocument` caches a PDF's bytes and page geometry. The studio asks PDFium/PDFtoImage for small thumbnails
+ and only one large selected page, all decoded away from the UI thread; exporting never performs preview rendering.
+ Cancellation closes LibreOffice and the temporary job folder is removed on success, error or window close.
+
## Settings and data
`UserDataStore` owns `settings.json`, `presets.json`, `profiles.json` and `history.json`
diff --cc src/Filee.App/Services/PresetAvailability.cs
index 9cfef645,19eea6e6..07d28c00
--- a/src/Filee.App/Services/PresetAvailability.cs
+++ b/src/Filee.App/Services/PresetAvailability.cs
@@@ -88,23 -88,24 +88,38 @@@ public sealed class PresetAvailabilit
private PresetJudgement Evaluate(Preset preset, IReadOnlyList<FileFormat> formats,
Func<RoutePlanner> installedPlanner, Func<Func<RoutePlanner, bool>, EnginePackageState?> packageEnabling)
{
+ if (preset.IsClipTool)
+ {
+ // Any video among the files: the others are left out when the clip window opens.
+ var videos = formats.Where(f => f.Category == FormatCategory.Video).ToList();
+ if (videos.Count == 0)
+ return new(PresetUse.Unusable, _loc["error.unsupported_source"]);
+ bool CanCut(RoutePlanner planner) => videos.Any(f => ClipTool.CanCut(f.Id, planner));
+ if (CanCut(installedPlanner()))
+ return new(PresetUse.Usable, null);
+ return packageEnabling(CanCut) is { } needed
+ ? new(PresetUse.NeedsPackage, _loc.Format("engine.reason.needs_package", needed.Name))
+ : new(PresetUse.Unusable, _loc["error.no_route"]);
+ }
+
if (preset.IsTool)
{
+ if (preset.Id == "tool-sheet-studio")
+ {
+ if (formats.Count > 0 && formats.All(format => format.Id == "xlsx"))
+ {
+ var libreOffice = _catalog.All.FirstOrDefault(converter => converter.Id == "libreoffice");
+ if (libreOffice?.GetStatus().IsAvailable == true)
+ return new(PresetUse.Usable, null);
+ var libreOfficePackage = _packages.FirstOrDefault(item => !item.IsInstalled
+ && item.Package.ConverterIds.Contains("libreoffice"));
+ return libreOfficePackage is not null
+ ? new(PresetUse.NeedsPackage, _loc.Format("engine.reason.needs_package", libreOfficePackage.Name))
+ : new(PresetUse.Unusable, _loc["error.no_route"]);
+ }
+ return new(PresetUse.Unusable, _loc["error.unsupported_source"]);
+ }
- if (formats.Count > 0 && formats.All(f => WritableSingleFrameRasterFormats.Contains(f.Id)))
+ if (preset.IsCropTool && formats.Count > 0 && formats.All(f => WritableSingleFrameRasterFormats.Contains(f.Id)))
return new(PresetUse.Usable, null);
return new(PresetUse.Unusable, _loc["error.unsupported_source"]);
}
diff --cc src/Filee.App/Services/WindowService.cs
index ffb1e949,9673a780..53143126
--- a/src/Filee.App/Services/WindowService.cs
+++ b/src/Filee.App/Services/WindowService.cs
@@@ -34,9 -32,9 +34,12 @@@ public sealed class WindowService(ILoca
internal FormatRequestNoticeWindow? FormatRequestNotice => _formatRequestNotice;
private CropOverlayWindow? _cropOverlay;
+ private ClipWindow? _clipWindow;
+
+ internal ClipWindow? ClipWindow => _clipWindow;
+ private readonly HashSet<SpreadsheetPrintStudioWindow> _spreadsheetStudios = [];
+
+ internal IReadOnlyCollection<SpreadsheetPrintStudioWindow> SpreadsheetStudios => _spreadsheetStudios;
private MergeOrderWindow? _mergeOrder;
internal MergeOrderWindow? MergeOrder => _mergeOrder;
@@@ -64,45 -62,6 +67,54 @@@
public MainWindow? Main => _main;
- /// <summary>Opens the window of a tool preset (crop, cut a clip) on the files. A tool this version doesn't know opens nothing.</summary>
++ /// <summary>
++ /// Opens the window of a tool preset (crop, cut a clip, the spreadsheet print studio: one per workbook) on the files.
++ /// A tool this version doesn't know opens nothing.
++ /// </summary>
+ public void ShowTool(IReadOnlyList<string> files, Preset preset, PixelPoint? near = null)
+ {
+ if (preset.IsClipTool)
+ ShowClipWindow(files, preset, near);
++ // Before the crop: the print studio has no Tool of its own, which reads as a crop.
++ else if (preset.Id == "tool-sheet-studio")
++ {
++ foreach (var workbook in files.Where(file => Path.GetExtension(file).Equals(".xlsx", StringComparison.OrdinalIgnoreCase)))
++ ShowSpreadsheetPrintStudio(workbook);
++ }
+ else if (preset.IsCropTool)
+ ShowCropOverlay(files, preset, near);
+ }
+
+ /// <summary>
+ /// Opens the "Cut a clip" window on the videos among the files. Each clip is written by an ordinary conversion,
+ /// shown in the toast.
+ /// </summary>
+ public void ShowClipWindow(IReadOnlyList<string> files, Preset preset, PixelPoint? near = null)
+ {
+ var videos = files.Where(f => FormatRegistry.Detect(f)?.Category == FormatCategory.Video).ToList();
+ if (videos.Count == 0)
+ return;
+ _clipWindow?.Close();
+ var store = services.GetRequiredService<UserDataStore>();
+ var catalog = services.GetRequiredService<ConverterCatalog>();
+ var conversions = services.GetRequiredService<ConversionService>();
+ var log = services.GetService<ILogger<ClipWindowViewModel>>();
+ var vm = new ClipWindowViewModel(videos, preset, loc, store, new FfmpegFrameSource(),
+ path => ClipTool.TargetFor(FormatRegistry.Detect(path)?.Id ?? ClipTool.FallbackTarget, catalog.CreatePlanner()),
+ (path, conversion) => conversions.Start([path], conversion), log);
+ var win = new ClipWindow { DataContext = vm };
+ win.PositionOnScreen(near);
+ win.Closed += (_, _) =>
+ {
+ if (_clipWindow == win)
+ _clipWindow = null;
+ trimmer.Request();
+ };
+ _clipWindow = win;
+ win.Show();
+ win.Activate();
+ }
+
/// <summary>Opens the interactive crop overlay for the files.</summary>
public void ShowCropOverlay(IReadOnlyList<string> files, Preset preset, PixelPoint? near = null)
{
diff --cc src/Filee.Core/Presets/BuiltInData.cs
index 6fdd70ad,07d58294..4319e501
--- a/src/Filee.Core/Presets/BuiltInData.cs
+++ b/src/Filee.Core/Presets/BuiltInData.cs
@@@ -115,19 -119,6 +120,19 @@@ public static class BuiltInDat
new() { Id = "motion-photo-android", NameKey = "preset.motion_photo_android", TargetFormat = "jpg", Media = { LivePhoto = LivePhotoKind.Android } },
];
+ /// <summary>
- /// "Cut a clip" (added in settings schema 42): a part of a video, chosen on a timeline, as a file of its own. First on
++ /// "Cut a clip" (added in settings schema 43): a part of a video, chosen on a timeline, as a file of its own. First on
+ /// the back of the video donut, as "Crop" is on the images donut.
+ /// </summary>
+ public static List<Preset> ClipPresets() =>
+ [
+ new()
+ {
+ Id = "tool-clip", NameKey = "preset.clip", TargetFormat = SameAsSource,
+ Kind = PresetKind.Tool, Tool = Preset.ClipTool, Output = { FileNamePattern = "{name}_clip" },
+ },
+ ];
+
/// <summary>
/// "Trim transparent borders" (issue #332, added in settings schema 33): a copy cropped to the visible pixels, in the
/// same format. On the images donut's back face after "Remove background".
diff --cc src/Filee.Core/Settings/AppSettings.cs
index ef6a3867,ef6a3867..e0021201
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@@ -123,7 -123,7 +123,7 @@@ public sealed class DonutSetting
public sealed class AppSettings
{
/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>
-- public const int CurrentSchemaVersion = 42;
++ public const int CurrentSchemaVersion = 43;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --cc src/Filee.Core/Settings/UserDataStore.cs
index f802ca0d,7a63fcee..ea5b1891
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@@ -807,13 -808,24 +808,31 @@@ internal static class SettingsMigration
// v41: PNG/JPEG download aliases learn the images donut; custom claims stay put.
if (from < 41)
changed |= LearnExtensions(profiles, out _, ["png_large", "jpg_large"]);
- // v42: "Cut a clip" (a part of a video as a file of its own), after "Motion Photo (Android)" as in a new library,
+ // v42: the print studio for XLSX → PDF (a tool), after "Crop" as in a new library, and first on the back of the
+ // spreadsheets donut when it has room and the user hasn't put it on either face.
+ if (from < 42)
+ {
+ const string id = "tool-sheet-studio";
+ if (presets.All(p => p.Id != id))
+ {
+ var at = presets.FindIndex(p => p.Id == "tool-crop");
+ presets.Insert(at < 0 ? presets.Count : at + 1, BuiltInData.CreatePresets().Single(p => p.Id == id));
+ changed = true;
+ }
+ if (profiles.FirstOrDefault(p => p.Id == "spreadsheets") is { BackPresetIds: { } back } spreadsheets
+ && !back.Contains(id) && !spreadsheets.PresetIds.Contains(id) && back.Count < ToolbarProfile.MaxSlices)
+ {
+ back.Insert(0, id);
+ changed = true;
+ }
+ }
++ // v43: "Cut a clip" (a part of a video as a file of its own), after "Motion Photo (Android)" as in a new library,
+ // and first on the back of the video donut in place of FLAC (which stays in the library), when the user
+ // hasn't put it elsewhere on the donut and the face has room.
- // Present already but saved since by a Filee before 42: that one dropped the tool's name, which made it a
++ // Present already but saved since by a Filee before 43: that one dropped the tool's name, which made it a
+ // crop, so it is put back. The user's own changes (name, file name pattern) stay.
- if (from < 42)
++ if (from < 43)
+ changed |= AddClipTool(presets, profiles);
return changed;
}
diff --cc tests/Filee.Core.Tests/ClipToolTests.cs
index 4623a5b5,00000000..1a189767
mode 100644,000000..100644
--- a/tests/Filee.Core.Tests/ClipToolTests.cs
+++ b/tests/Filee.Core.Tests/ClipToolTests.cs
@@@ -1,283 -1,0 +1,283 @@@
+// "Cut a clip": the range kept inside the video, the times as shown and as FFmpeg reads them, the conversion the tool
- // becomes, and the preset arriving in libraries from before it (settings schema 42).
++// becomes, and the preset arriving in libraries from before it (settings schema 43).
+
+using System.Globalization;
+using System.Text.Json;
+using Filee.Core.Conversion;
+using Filee.Core.Presets;
+using Filee.Core.Profiles;
+using Filee.Core.Settings;
+
+namespace Filee.Core.Tests;
+
+public class ClipToolTests
+{
+ // ───────────────────────── Times ─────────────────────────
+
+ [Theory]
+ [InlineData(0, "0:00.0")]
+ [InlineData(7.5, "0:07.5")]
+ [InlineData(7.54, "0:07.5")]
+ [InlineData(7.55, "0:07.6")]
+ [InlineData(59.96, "1:00.0")]
+ [InlineData(245, "4:05.0")]
+ [InlineData(599.9, "9:59.9")]
+ [InlineData(3725.3, "1:02:05.3")]
+ [InlineData(-3, "0:00.0")]
+ [InlineData(double.NaN, "0:00.0")]
+ public void Times_show_as_minutes_seconds_and_tenths(double seconds, string expected) =>
+ Assert.Equal(expected, ClipRange.Display(seconds));
+
+ [Theory]
+ [InlineData("ru")]
+ [InlineData("ar")]
+ [InlineData("de")]
+ public void Times_never_take_the_languages_decimal_comma(string culture)
+ {
+ var before = CultureInfo.CurrentCulture;
+ try
+ {
+ CultureInfo.CurrentCulture = new CultureInfo(culture);
+ Assert.Equal("1:05.3", ClipRange.Display(65.3));
+ Assert.Equal("65.300", ClipRange.Ffmpeg(65.3));
+ }
+ finally
+ {
+ CultureInfo.CurrentCulture = before;
+ }
+ }
+
+ [Theory]
+ [InlineData(0, "0.000")]
+ [InlineData(12.3456, "12.346")]
+ [InlineData(600, "600.000")]
+ [InlineData(-1, "0.000")]
+ [InlineData(double.PositiveInfinity, "0.000")]
+ public void Ffmpeg_reads_seconds_with_three_decimals(double seconds, string expected) =>
+ Assert.Equal(expected, ClipRange.Ffmpeg(seconds));
+
+ // ───────────────────────── The range ─────────────────────────
+
+ [Fact]
+ public void A_clip_inside_the_video_stays_as_it_is() =>
+ Assert.Equal(new ClipRange(12.5, 42.5), ClipRange.Clamp(12.5, 42.5, 600));
+
+ [Fact]
+ public void The_end_never_goes_past_the_video()
+ {
+ var clip = ClipRange.Clamp(580, 640, 600);
+ Assert.Equal(new ClipRange(580, 600), clip);
+ Assert.Equal(20, clip.Length);
+ }
+
+ [Fact]
+ public void The_start_is_never_before_the_video_or_after_the_end()
+ {
+ Assert.Equal(new ClipRange(0, 10), ClipRange.Clamp(-5, 10, 600));
+ // Given the wrong way round: swapped.
+ Assert.Equal(new ClipRange(10, 30), ClipRange.Clamp(30, 10, 600));
+ }
+
+ [Fact]
+ public void A_clip_is_never_shorter_than_the_least_length()
+ {
+ Assert.Equal(new ClipRange(5, 5 + ClipRange.MinLength), ClipRange.Clamp(5, 5, 600));
+ // At the very end it grows backwards.
+ var atEnd = ClipRange.Clamp(600, 600, 600);
+ Assert.Equal(600, atEnd.End);
+ Assert.Equal(600 - ClipRange.MinLength, atEnd.Start, 6);
+ // Past the end altogether: the video's last moment.
+ var past = ClipRange.Clamp(700, 800, 600);
+ Assert.Equal(600, past.End);
+ Assert.True(past.Start < past.End);
+ }
+
+ [Fact]
+ public void Without_a_known_duration_only_the_start_is_kept_at_zero()
+ {
+ Assert.Equal(new ClipRange(0, 30), ClipRange.Clamp(-1, 30, null));
+ Assert.Equal(new ClipRange(100, 130), ClipRange.Clamp(100, 130, 0));
+ Assert.Equal(new ClipRange(4, 4 + ClipRange.MinLength), ClipRange.Clamp(4, double.NaN, null));
+ Assert.Equal(new ClipRange(0, 600), ClipRange.Clamp(double.NaN, double.NaN, 600));
+ }
+
+ // ───────────────────────── The conversion ─────────────────────────
+
+ private static Preset Tool() => BuiltInData.CreatePresets().Single(p => p.Id == "tool-clip");
+
+ [Fact]
+ public void The_built_in_tool_names_its_clips_name_clip_and_copies_by_default()
+ {
+ var tool = Tool();
+ Assert.True(tool.IsTool);
+ Assert.True(tool.IsClipTool);
+ Assert.False(tool.IsCropTool);
+ Assert.Equal("preset.clip", tool.NameKey);
+ Assert.Equal("{name}_clip", tool.Output.FileNamePattern);
+ Assert.False(tool.Media.ExactCut);
+ Assert.Null(tool.Media.Clip);
+ // The crop tool stays the crop, also as saved before tools had names.
+ var crop = BuiltInData.CreatePresets().Single(p => p.Id == "tool-crop");
+ Assert.True(crop.IsCropTool);
+ Assert.False(crop.IsClipTool);
+ Assert.True(new Preset { Kind = PresetKind.Tool, Tool = "crop" }.IsCropTool);
+ // A tool from a newer Filee is neither.
+ var unknown = new Preset { Kind = PresetKind.Tool, Tool = "stabilize" };
+ Assert.False(unknown.IsCropTool || unknown.IsClipTool);
+ }
+
+ [Fact]
+ public void The_tool_becomes_a_conversion_of_the_clip_into_the_target()
+ {
+ var tool = Tool();
+ tool.Name = "Highlights";
+ tool.Media.ExactCut = true;
+ tool.Media.Quality = MediaQuality.Small;
+ tool.Media.LivePhoto = LivePhotoKind.Apple; // a hand-edited file: never a Live Photo of the clip
+
+ var conversion = ClipTool.ConversionOf(tool, "mkv", new ClipRange(12.5, 42.5));
+
+ Assert.Equal(PresetKind.Convert, conversion.Kind);
+ Assert.False(conversion.IsTool);
+ Assert.Null(conversion.Tool);
+ Assert.Equal("mkv", conversion.TargetFormat);
+ var part = Assert.Single(conversion.Media.Clip!.Parts);
+ Assert.Equal((12.5, 42.5), (part.Start, part.End));
+ Assert.True(conversion.Media.ExactCut);
+ Assert.Equal(MediaQuality.Small, conversion.Media.Quality);
+ Assert.Equal(LivePhotoKind.None, conversion.Media.LivePhoto);
+ Assert.Equal(("tool-clip", "Highlights", "{name}_clip"), (conversion.Id, conversion.Name, conversion.Output.FileNamePattern));
+ Assert.True(conversion.CutsClipOf("mp4"));
+ Assert.False(conversion.CutsClipOf("mp3")); // only videos
+ // The tool itself is untouched.
+ Assert.True(tool.IsClipTool);
+ Assert.Null(tool.Media.Clip);
+ Assert.False(new Preset { TargetFormat = "mp4" }.CutsClipOf("mp4"));
+ }
+
+ [Fact]
+ public void A_clip_keeps_the_videos_format_where_one_engine_writes_it_else_mp4()
+ {
+ var videos = new FakeConverter("ffmpeg", new ConversionEdge("mp4", "mp4"), new ConversionEdge("mkv", "mkv"), new ConversionEdge("mkv", "mp4"),
+ new ConversionEdge("rm", "mp4"));
+ var planner = new ConverterCatalog([videos]).CreatePlanner();
+
+ Assert.Equal("mp4", ClipTool.TargetFor("mp4", planner));
+ Assert.Equal("mkv", ClipTool.TargetFor("mkv", planner));
+ Assert.Equal("mp4", ClipTool.TargetFor("rm", planner)); // RealVideo can't be written
+ Assert.True(ClipTool.CanCut("rm", planner));
+ Assert.False(ClipTool.CanCut("mov", planner)); // no engine reads it here
+ Assert.False(ClipTool.CanCut("mp3", planner)); // not a video
+ }
+
+ [Fact]
+ public void Clip_options_survive_saving_and_the_times_never_reach_a_saved_tool()
+ {
+ var tool = Tool();
+ tool.Media.ExactCut = true;
+ var json = JsonSerializer.Serialize(new List<Preset> { tool }, FileeJsonContext.Default.ListPreset);
+ Assert.Contains("\"tool\": \"clip\"", json);
+ Assert.DoesNotContain("\"clip\":", json); // the times of a clip, never on the tool
+
+ var read = JsonSerializer.Deserialize(json, FileeJsonContext.Default.ListPreset)!.Single();
+ Assert.True(read.IsClipTool);
+ Assert.True(read.Media.ExactCut);
+
+ // A conversion of a clip (kept in the history for "Retry") keeps its times.
+ var conversion = ClipTool.ConversionOf(read, "mp4", new ClipRange(1, 2));
+ var again = JsonSerializer.Deserialize(JsonSerializer.Serialize(new List<Preset> { conversion }, FileeJsonContext.Default.ListPreset),
+ FileeJsonContext.Default.ListPreset)!.Single();
+ Assert.Equal((1.0, 2.0), (again.Media.Clip!.Parts[0].Start, again.Media.Clip.Parts[0].End));
+ // Other presets don't write a tool at all.
+ Assert.DoesNotContain("\"tool\"", JsonSerializer.Serialize(new List<Preset> { new() { TargetFormat = "png" } }, FileeJsonContext.Default.ListPreset));
+ }
+
- // ───────────────────────── Settings schema 42 ─────────────────────────
++ // ───────────────────────── Settings schema 43 ─────────────────────────
+
+ [Fact]
+ public void A_new_library_has_the_clip_tool_first_behind_the_video_donut()
+ {
+ var presets = BuiltInData.CreatePresets();
+ var clip = presets.Single(p => p.Id == "tool-clip");
+ Assert.Equal("motion-photo-android", presets[presets.IndexOf(clip) - 1].Id);
+ var video = BuiltInData.CreateProfiles().Single(p => p.Id == "video");
+ Assert.Equal("tool-clip", video.BackPresetIds![0]);
+ Assert.DoesNotContain("tool-clip", video.PresetIds);
+ Assert.DoesNotContain("to-flac", video.BackPresetIds);
+ Assert.Contains(presets, p => p.Id == "to-flac");
+ Assert.InRange(video.BackPresetIds.Count, 1, ToolbarProfile.MaxSlices);
+ }
+
+ [Fact]
- public void Version_41_libraries_get_the_clip_tool_and_it_goes_behind_the_video_donut()
++ public void Version_42_libraries_get_the_clip_tool_and_it_goes_behind_the_video_donut()
+ {
+ var presets = BuiltInData.CreatePresets();
+ presets.RemoveAll(p => p.Id == "tool-clip");
+ var profiles = BuiltInData.CreateProfiles();
+ var video = profiles.Single(p => p.Id == "video");
- // The back face of 41: FLAC after WAV, no clip tool.
++ // The back face of 42: FLAC after WAV, no clip tool.
+ video.BackPresetIds!.Remove("tool-clip");
+ video.BackPresetIds.Insert(video.BackPresetIds.IndexOf("to-wav") + 1, "to-flac");
+
- Assert.True(SettingsMigrations.ApplyToLibrary(41, presets, profiles));
++ Assert.True(SettingsMigrations.ApplyToLibrary(42, presets, profiles));
+
+ Assert.Equal(BuiltInData.CreatePresets().Select(p => p.Id), presets.Select(p => p.Id));
+ Assert.True(presets.Single(p => p.Id == "tool-clip").IsClipTool);
+ Assert.Equal(BuiltInData.CreateProfiles().Single(p => p.Id == "video").BackPresetIds, video.BackPresetIds);
- Assert.False(SettingsMigrations.ApplyToLibrary(41, presets, profiles)); // once only
++ Assert.False(SettingsMigrations.ApplyToLibrary(42, presets, profiles)); // once only
+
+ // A full back face makes room by giving up FLAC; one the user filled up without FLAC, or with the tool on the
+ // front, stays as it is.
+ var withFlac = BuiltInData.CreateProfiles();
+ var withFlacBack = withFlac.Single(p => p.Id == "video").BackPresetIds!;
+ withFlacBack.Remove("tool-clip");
+ withFlacBack.Add("to-flac");
+ while (withFlacBack.Count < ToolbarProfile.MaxSlices)
+ withFlacBack.Add("to-mp3");
- SettingsMigrations.ApplyToLibrary(41, BuiltInData.CreatePresets(), withFlac);
++ SettingsMigrations.ApplyToLibrary(42, BuiltInData.CreatePresets(), withFlac);
+ Assert.Equal("tool-clip", withFlacBack[0]);
+ Assert.DoesNotContain("to-flac", withFlacBack);
+ Assert.Equal(ToolbarProfile.MaxSlices, withFlacBack.Count);
+
+ var full = BuiltInData.CreateProfiles();
+ var fullBack = full.Single(p => p.Id == "video").BackPresetIds!;
+ fullBack.Remove("tool-clip");
+ while (fullBack.Count < ToolbarProfile.MaxSlices)
+ fullBack.Add("to-mp3");
+ var before = fullBack.ToList();
- SettingsMigrations.ApplyToLibrary(41, BuiltInData.CreatePresets(), full);
++ SettingsMigrations.ApplyToLibrary(42, BuiltInData.CreatePresets(), full);
+ Assert.Equal(before, fullBack);
+
+ var front = BuiltInData.CreateProfiles();
+ var frontVideo = front.Single(p => p.Id == "video");
+ frontVideo.BackPresetIds!.Remove("tool-clip");
+ frontVideo.PresetIds[^1] = "tool-clip";
- SettingsMigrations.ApplyToLibrary(41, BuiltInData.CreatePresets(), front);
++ SettingsMigrations.ApplyToLibrary(42, BuiltInData.CreatePresets(), front);
+ Assert.DoesNotContain("tool-clip", frontVideo.BackPresetIds);
+ }
+
+ [Fact]
+ public void Back_from_an_older_Filee_the_clip_tool_cuts_clips_again_and_keeps_the_users_changes()
+ {
- // A Filee from 26 to 41 reads the unknown "tool" as nothing (a crop) and saves it so.
++ // A Filee from 26 to 42 reads the unknown "tool" as nothing (a crop) and saves it so.
+ var presets = BuiltInData.CreatePresets();
+ var clip = presets.Single(p => p.Id == "tool-clip");
+ clip.Tool = null;
+ clip.Name = "Highlights";
+ clip.Output.FileNamePattern = "{name}_best";
+ Assert.True(clip.IsCropTool);
+
- Assert.True(SettingsMigrations.ApplyToLibrary(41, presets, BuiltInData.CreateProfiles()));
++ Assert.True(SettingsMigrations.ApplyToLibrary(42, presets, BuiltInData.CreateProfiles()));
+
+ Assert.True(clip.IsClipTool);
+ Assert.Equal(("Highlights", "{name}_best"), (clip.Name, clip.Output.FileNamePattern));
+ Assert.Single(presets, p => p.Id == "tool-clip");
+
+ // A Filee before 26 read it as a group.
+ clip.Kind = PresetKind.Group;
+ clip.TargetFormat = Preset.GroupTarget;
- Assert.True(SettingsMigrations.ApplyToLibrary(41, presets, BuiltInData.CreateProfiles()));
++ Assert.True(SettingsMigrations.ApplyToLibrary(42, presets, BuiltInData.CreateProfiles()));
+ Assert.True(clip.IsClipTool);
+ Assert.Equal(BuiltInData.SameAsSource, clip.TargetFormat);
+ }
+}
diff --cc tests/Filee.Core.Tests/MediaToolTests.cs
index b8ba6db9,b8ba6db9..0c69c915
--- a/tests/Filee.Core.Tests/MediaToolTests.cs
+++ b/tests/Filee.Core.Tests/MediaToolTests.cs
@@@ -145,7 -145,7 +145,8 @@@ public class MediaToolTest
Assert.True(SettingsMigrations.ApplyToLibrary(36, presets, profiles));
-- Assert.Equal(["mp4-av1", "to-wav", "compress-video", "merge-videos", "extract-audio", "zip-all"], video.BackPresetIds);
++ // "Cut a clip" (schema 43) comes in first as well.
++ Assert.Equal(["tool-clip", "mp4-av1", "to-wav", "compress-video", "merge-videos", "extract-audio", "zip-all"], video.BackPresetIds);
}
[Fact]