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.

Donuts get a back face: a second list of slices per profile

KnifeLemond5dd2a9933a0
diff --git a/src/Filee.Core/Presets/BuiltInData.cs b/src/Filee.Core/Presets/BuiltInData.cs
index e5738307..719c1c4a 100644
--- a/src/Filee.Core/Presets/BuiltInData.cs
+++ b/src/Filee.Core/Presets/BuiltInData.cs
@@ -311,7 +311,11 @@ public static class BuiltInData
new() { Id = "to-vcf", Name = "vCard", TargetFormat = "vcf" },
];
- /// <summary>Creates the default toolbar profiles.</summary>
+ /// <summary>
+ /// Creates the default toolbar profiles. Each has a back face (Tab flips the open donut to it, settings schema 29)
+ /// with presets for its files that aren't on its front: less common formats and tools (rotate, merge, compress
+ /// into one ZIP, ...). The fronts are as they were before back faces.
+ /// </summary>
public static List<ToolbarProfile> CreateProfiles() =>
[
new()
@@ -319,18 +323,21 @@ public static class BuiltInData
Id = "images", NameKey = "profile.images",
Extensions = ExtensionsOf(FormatCategory.Image),
PresetIds = ["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size"],
+ BackPresetIds = ["rotate", "flip", "remove-background", "grayscale", "jpg-70", "to-avif", "to-jxl", "to-gif", "merge-pdf", "zip-all"],
},
new()
{
Id = "pdf", NameKey = "profile.pdf",
Extensions = ["pdf"],
PresetIds = [.. PdfDonut],
+ BackPresetIds = ["compress-pdf", "to-webp", "to-tiff", "to-html", "to-odt", "to-rtf", "to-azw3", "to-cbz", "zip-all"],
},
new()
{
Id = "office", NameKey = "profile.office",
Extensions = ExtensionsOf(FormatCategory.Document),
PresetIds = ["to-pdf", "to-hwpx", "to-hwp", "to-docx", "to-odt", "to-txt", "to-html", "to-epub", "to-png", "merge-pdf"],
+ BackPresetIds = ["to-md", "to-rtf", "to-jpg", "pdf-long-image", "to-azw3", "to-kepub", "zip-all"],
},
SpreadsheetProfile(),
PresentationProfile(),
@@ -339,6 +346,7 @@ public static class BuiltInData
Id = "hwp", NameKey = "profile.hwp",
Extensions = ["hwp", "hwpx"],
PresetIds = ["to-pdf", "to-docx", "to-hwpx", "to-hwp", "to-png", "to-jpg", "to-txt", "to-md", "to-epub", "merge-pdf"],
+ BackPresetIds = ["to-html", "to-odt", "to-rtf", "pdf-long-image", "to-azw3", "zip-all"],
},
TextProfile(),
.. WithSubtitleProfile(CatalogProfiles()),
@@ -348,6 +356,7 @@ public static class BuiltInData
{
Id = "mixed", NameKey = "profile.mixed", IsFallback = true,
PresetIds = ["to-pdf", "merge-pdf", "zip-all", "to-png", "to-txt"],
+ BackPresetIds = ["to-jpg", "to-webp", "to-docx", "to-md", "to-html", "compress-pdf"],
},
];
@@ -369,6 +378,7 @@ public static class BuiltInData
NameKey = "profile.spreadsheets",
Extensions = ExtensionsOf(FormatCategory.Spreadsheet),
PresetIds = ["to-pdf", "to-xlsx", "to-csv", "to-json", "to-ods", "to-hwpx", "to-hwp", "to-html", "merge-pdf"],
+ BackPresetIds = ["to-docx", "to-md", "to-txt", "to-yaml", "to-xml", "to-vcf", "to-png", "zip-all"],
};
/// <summary>PowerPoint and OpenDocument slides (split from "office" in settings schema 5).</summary>
@@ -378,6 +388,7 @@ public static class BuiltInData
NameKey = "profile.presentations",
Extensions = ExtensionsOf(FormatCategory.Presentation),
PresetIds = ["to-pdf", "to-png", "to-jpg", "to-pptx", "to-hwpx", "to-hwp", "merge-pdf"],
+ BackPresetIds = ["to-odp", "to-webp", "pdf-long-image", "to-docx", "to-txt", "to-md", "to-html", "zip-all"],
};
/// <summary>Markdown, plain text and HTML (added in settings schema 4, see SettingsMigrations); MHTML (schema 23).</summary>
@@ -387,6 +398,7 @@ public static class BuiltInData
NameKey = "profile.text",
Extensions = ExtensionsOf(FormatCategory.Text),
PresetIds = ["to-pdf", "to-hwpx", "to-hwp", "to-docx", "to-html", "to-txt", "to-epub"],
+ BackPresetIds = ["to-md", "to-odt", "to-rtf", "to-kepub", "merge-pdf", "zip-all"],
};
/// <summary>Donuts of the categories added in settings schema 6, in the order they follow "text".</summary>
@@ -397,42 +409,51 @@ public static class BuiltInData
Id = "ebooks", NameKey = "profile.ebooks",
Extensions = ExtensionsOf(FormatCategory.Ebook),
PresetIds = ["to-pdf", "to-epub", "to-docx", "to-txt", "to-azw3", "to-mobi", "to-kepub", "to-hwpx", "to-hwp", "to-html"],
+ BackPresetIds = ["to-fb2", "to-md", "to-rtf", "to-odt", "merge-pdf", "zip-all"],
},
new()
{
Id = "video", NameKey = "profile.video",
Extensions = ExtensionsOf(FormatCategory.Video),
PresetIds = ["to-mp4", "mp4-720", "mp4-hevc", "to-webm", "to-mov", "to-gif", "to-mp3", "extract-subtitles", "to-mkv", "to-avi"],
+ // Every frame as pictures is on no front (a long video gives thousands of files): behind a flip, a drop that
+ // misses its slice doesn't start it.
+ BackPresetIds = ["mp4-av1", "to-webp", "extract-frames-png", "extract-frames-jpg", "to-m4a", "to-wav", "to-flac", "zip-all"],
},
new()
{
Id = "audio", NameKey = "profile.audio",
Extensions = ExtensionsOf(FormatCategory.Audio),
PresetIds = ["to-mp3", "mp3-128", "to-m4a", "to-wav", "to-flac", "to-ogg", "to-opus", "to-aac"],
+ BackPresetIds = ["to-alac", "zip-all"],
},
new()
{
Id = "vector", NameKey = "profile.vector",
Extensions = ExtensionsOf(FormatCategory.Vector),
PresetIds = ["to-png", "to-pdf", "to-svg", "to-jpg", "to-webp", "to-eps"],
+ BackPresetIds = ["to-tiff", "to-ico", "to-icns", "to-avif", "to-dxf", "merge-pdf", "zip-all"],
},
new()
{
Id = "archives", NameKey = "profile.archives",
Extensions = ExtensionsOf(FormatCategory.Archive),
PresetIds = ["extract", "to-zip", "to-7z", "to-tgz", "to-tar"],
+ BackPresetIds = ["zip-all"],
},
new()
{
Id = "cad", NameKey = "profile.cad",
Extensions = ExtensionsOf(FormatCategory.Cad),
PresetIds = ["to-pdf", "to-png", "to-svg", "to-dxf", "to-dwg"],
+ BackPresetIds = ["to-jpg", "to-webp", "to-tiff", "merge-pdf", "zip-all"],
},
new()
{
Id = "fonts", NameKey = "profile.fonts",
Extensions = ExtensionsOf(FormatCategory.Font),
PresetIds = ["to-woff2", "to-woff", "to-ttf", "to-otf", "to-eot"],
+ BackPresetIds = ["zip-all"],
},
];
@@ -443,6 +464,7 @@ public static class BuiltInData
NameKey = "profile.data",
Extensions = ExtensionsOf(FormatCategory.Data),
PresetIds = ["to-json", "to-yaml", "to-toml", "to-xml", "to-csv", "to-xlsx"],
+ BackPresetIds = ["to-ods", "to-html", "to-md", "zip-all"],
};
/// <summary>Text subtitles: SRT, ASS, WebVTT, SAMI, LRC, ... (added in settings schema 11, after "audio").</summary>
@@ -452,6 +474,7 @@ public static class BuiltInData
NameKey = "profile.subtitles",
Extensions = ExtensionsOf(FormatCategory.Subtitle),
PresetIds = ["to-srt", "to-vtt", "to-ass", "to-smi", "to-lrc", "to-ttml"],
+ BackPresetIds = ["zip-all"],
};
/// <summary><paramref name="profiles"/> with the subtitle donut after the audio donut.</summary>
@@ -468,6 +491,7 @@ public static class BuiltInData
NameKey = "profile.models",
Extensions = ExtensionsOf(FormatCategory.Model3D),
PresetIds = ["to-glb", "to-stl", "to-obj", "to-3mf", "to-ply", "to-png"],
+ BackPresetIds = ["to-gltf", "to-jpg", "to-webp", "zip-all"],
};
/// <summary>Every file extension of the formats in <paramref name="category"/>.</summary>
diff --git a/src/Filee.Core/Profiles/ToolbarProfile.cs b/src/Filee.Core/Profiles/ToolbarProfile.cs
index 95406ab1..cfafc204 100644
--- a/src/Filee.Core/Profiles/ToolbarProfile.cs
+++ b/src/Filee.Core/Profiles/ToolbarProfile.cs
@@ -36,6 +36,14 @@ public sealed class ToolbarProfile
/// <summary>Preset ids in donut order, clockwise starting at 12 o'clock.</summary>
public List<string> PresetIds { get; set; } = [];
+ /// <summary>
+ /// Preset ids of the back face, which Tab flips the open donut to: less common conversions and tools, in the same
+ /// order and up to the same <see cref="MaxSlices"/> as <see cref="PresetIds"/>. Empty: the donut doesn't flip.
+ /// Null only as read from a file without back faces (a Filee from before settings schema 29, or one that saved
+ /// the library since): loading gives a built-in donut its default back face then, and any other none.
+ /// </summary>
+ public List<string>? BackPresetIds { get; set; }
+
/// <summary>Returns true if the extension (with or without dot) belongs to this profile.</summary>
public bool Matches(string extension) =>
Extensions.Contains(extension.TrimStart('.'), StringComparer.OrdinalIgnoreCase);
@@ -48,6 +56,7 @@ public sealed class ToolbarProfile
Extensions = [.. Extensions],
IsFallback = IsFallback,
PresetIds = [.. PresetIds],
+ BackPresetIds = BackPresetIds is null ? null : [.. BackPresetIds],
};
}
diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs
index 79863577..1a3dba66 100644
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@ -65,7 +65,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 = 24;
+ public const int CurrentSchemaVersion = 29;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs
index 17dea6ea..cb457816 100644
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@ -147,8 +147,8 @@ public sealed class UserDataStore
&& (builtIn.IsFallback || !profile.IsFallback || Profiles.Count(p => p.IsFallback) > 1);
/// <summary>
- /// Puts one built-in donut back as a new library has it (name, slices and their order, extensions, normal or mixed)
- /// and leaves the other donuts alone. So no file type opens two donuts, an extension another normal donut takes
+ /// Puts one built-in donut back as a new library has it (name, slices of both faces and their order, extensions,
+ /// normal or mixed) and leaves the other donuts alone. So no file type opens two donuts, an extension another normal donut takes
/// now stays there. Presets are shared by every donut: the ones this donut drops stay in the library, edited ones
/// keep their settings, and a built-in preset of its default slices that the user deleted comes back. A donut that
/// changes kind moves to the border between the normal profiles and the mixed ones, the built-in mixed donut back
@@ -160,7 +160,7 @@ public sealed class UserDataStore
if (!CanResetProfile(profile))
return false;
var builtIn = BuiltInData.CreateProfiles().Single(p => p.Id == profile.Id);
- RestoreBuiltInPresets(builtIn.PresetIds);
+ RestoreBuiltInPresets([.. builtIn.PresetIds, .. builtIn.BackPresetIds ?? []]);
// Extensions checked on a mixed-selection profile only limit that profile; they don't claim files.
var claimed = Profiles.Where(p => p != profile && !p.IsFallback)
@@ -170,6 +170,7 @@ public sealed class UserDataStore
profile.NameKey = builtIn.NameKey;
profile.Extensions = builtIn.IsFallback ? builtIn.Extensions : builtIn.Extensions.Where(e => !claimed.Contains(e)).ToList();
profile.PresetIds = builtIn.PresetIds;
+ profile.BackPresetIds = builtIn.BackPresetIds ?? [];
if (profile.IsFallback != builtIn.IsFallback)
{
profile.IsFallback = builtIn.IsFallback;
@@ -181,12 +182,13 @@ public sealed class UserDataStore
return true;
}
- /// <summary>Adds back the built-in presets among <paramref name="ids"/> that the library no longer has, each after
- /// the built-in preset before it (as a new library orders them).</summary>
+ /// <summary>Adds back the built-in presets among <paramref name="ids"/> that the library no longer has, and those a
+ /// built-in group among them fans out, each after the built-in preset before it (as a new library orders them).</summary>
private void RestoreBuiltInPresets(IEnumerable<string> ids)
{
var defaults = BuiltInData.CreatePresets();
- foreach (var id in ids.Where(id => FindPreset(id) is null))
+ var members = ids.SelectMany(id => defaults.FirstOrDefault(p => p.Id == id) is { IsGroup: true } group ? group.SubPresetIds : []);
+ foreach (var id in ids.Concat(members).Distinct().Where(id => FindPreset(id) is null).ToList())
{
var at = defaults.FindIndex(p => p.Id == id);
if (at < 0)
@@ -220,6 +222,8 @@ public sealed class UserDataStore
Presets.RemoveAll(p => p.Id == preset.Id);
Presets.Add(preset);
}
+ // A bundle from a Filee before back faces has none: a built-in donut gets its default one, as on loading.
+ SettingsMigrations.AddBackFaces(Presets, bundle.Profiles);
// Mixed-selection profiles stay mixed: several may exist, and the catch-all is the first one with nothing
// checked, so an imported one added at the end never replaces ours.
foreach (var profile in bundle.Profiles)
@@ -238,6 +242,8 @@ public sealed class UserDataStore
foreach (var profile in Profiles)
{
profile.PresetIds = profile.PresetIds.Where(ids.Contains).Distinct().Take(ToolbarProfile.MaxSlices).ToList();
+ // No back face known by now (a donut the user made, read from an older file): it has none.
+ profile.BackPresetIds = (profile.BackPresetIds ?? []).Where(ids.Contains).Distinct().Take(ToolbarProfile.MaxSlices).ToList();
}
// A Filee from before groups drops "kind" (and the presets) when it saves a group, which comes back as a
// conversion to "group": still a group, now an empty one, rather than a conversion that can never run.
@@ -257,6 +263,7 @@ public sealed class UserDataStore
{
var mixed = BuiltInData.CreateProfiles().First(p => p.IsFallback);
mixed.PresetIds = mixed.PresetIds.Where(ids.Contains).ToList();
+ mixed.BackPresetIds = (mixed.BackPresetIds ?? []).Where(ids.Contains).ToList();
Profiles.Add(mixed);
}
}
@@ -631,6 +638,31 @@ internal static class SettingsMigrations
// of the user already takes them.
if (from < 24)
changed |= LearnExtensions(profiles, out _, ["potm"]);
+ // v29: every donut gets a back face, which Tab flips the open donut to. A built-in donut gets its default one
+ // (with the presets the library still has), a donut the user made none; no front changes. (Schema 29 may
+ // be renumbered: 25 to 28 are taken by changes still open.) Also at a later schema when a donut has no
+ // back face at all, not even an empty one: a Filee before 29 saved the library since and dropped what it
+ // didn't know, so the built-in back faces come back. One the user emptied is saved empty and stays so.
+ if (from < 29 || profiles.Any(p => p.BackPresetIds is null))
+ changed |= AddBackFaces(presets, profiles);
+ return changed;
+ }
+
+ /// <summary>
+ /// Gives each built-in donut without a back face (<see cref="ToolbarProfile.BackPresetIds"/> null) its default one,
+ /// with only the presets in <paramref name="presets"/>. Donuts the user made are left for
+ /// <see cref="UserDataStore"/> to give an empty one. Returns true when one was added.
+ /// </summary>
+ internal static bool AddBackFaces(List<Preset> presets, IEnumerable<ToolbarProfile> profiles)
+ {
+ var defaults = BuiltInData.CreateProfiles().ToDictionary(p => p.Id);
+ var ids = presets.Select(p => p.Id).ToHashSet();
+ var changed = false;
+ foreach (var profile in profiles.Where(p => p.BackPresetIds is null && defaults.ContainsKey(p.Id)))
+ {
+ profile.BackPresetIds = (defaults[profile.Id].BackPresetIds ?? []).Where(ids.Contains).ToList();
+ changed = true;
+ }
return changed;
}
diff --git a/tests/Filee.Core.Tests/BackFaceTests.cs b/tests/Filee.Core.Tests/BackFaceTests.cs
new file mode 100644
index 00000000..b6201476
--- /dev/null
+++ b/tests/Filee.Core.Tests/BackFaceTests.cs
@@ -0,0 +1,239 @@
+// The back face of a donut (Tab flips the open donut to it): the built-in ones, settings schema 29 that gives existing
+// libraries theirs, a round trip through a Filee from before back faces, "Reset to default" and import.
+
+using System.Text.Json.Nodes;
+using Filee.Core.Presets;
+using Filee.Core.Profiles;
+using Filee.Core.Settings;
+
+namespace Filee.Core.Tests;
+
+public class BackFaceTests
+{
+ private static ToolbarProfile BuiltIn(string id) => BuiltInData.CreateProfiles().Single(p => p.Id == id);
+
+ private static UserDataStore NewStore(TempDir dir)
+ {
+ var store = new UserDataStore(dir.Path);
+ store.Load();
+ return store;
+ }
+
+ private static ToolbarProfile Profile(UserDataStore store, string id) => store.Profiles.Single(p => p.Id == id);
+
+ /// <summary>A library as a Filee from before back faces wrote it: no "backPresetIds" anywhere.</summary>
+ private static void DropBackFaces(TempDir dir, int? schema)
+ {
+ var path = Path.Combine(dir.Path, "profiles.json");
+ var profiles = JsonNode.Parse(File.ReadAllText(path))!.AsArray();
+ foreach (var profile in profiles)
+ profile!.AsObject().Remove("backPresetIds");
+ File.WriteAllText(path, profiles.ToJsonString());
+ if (schema is null)
+ return;
+ var settingsPath = Path.Combine(dir.Path, "settings.json");
+ var settings = JsonNode.Parse(File.ReadAllText(settingsPath))!.AsObject();
+ settings["schemaVersion"] = schema;
+ File.WriteAllText(settingsPath, settings.ToJsonString());
+ }
+
+ [Fact]
+ public void Every_built_in_donut_has_a_back_face_of_other_built_in_presets()
+ {
+ var presets = BuiltInData.CreatePresets().ToDictionary(p => p.Id);
+ foreach (var profile in BuiltInData.CreateProfiles())
+ {
+ var back = profile.BackPresetIds;
+ Assert.NotNull(back);
+ Assert.NotEmpty(back);
+ Assert.True(back.Count <= ToolbarProfile.MaxSlices, profile.Id);
+ Assert.Equal(back.Count, back.Distinct().Count());
+ Assert.All(back, id => Assert.True(presets.ContainsKey(id), $"{profile.Id}: {id}"));
+ // Nothing moved off the front, nothing shown twice.
+ Assert.Empty(back.Intersect(profile.PresetIds));
+ }
+ }
+
+ [Fact]
+ public void The_fronts_stay_as_they_were_before_back_faces()
+ {
+ Assert.Equal(["to-png", "to-jpg", "to-webp", "to-pdf", "trace-svg", "trace-line-art", "to-tiff", "to-bmp", "to-ico", "half-size"],
+ BuiltIn("images").PresetIds);
+ Assert.Equal(BuiltInData.PdfDonut, BuiltIn("pdf").PresetIds);
+ Assert.Equal(["to-pdf", "to-hwpx", "to-hwp", "to-docx", "to-odt", "to-txt", "to-html", "to-epub", "to-png", "merge-pdf"],
+ BuiltIn("office").PresetIds);
+ Assert.Equal(["to-pdf", "merge-pdf", "zip-all", "to-png", "to-txt"], BuiltIn("mixed").PresetIds);
+ Assert.Equal(["to-mp4", "mp4-720", "mp4-hevc", "to-webm", "to-mov", "to-gif", "to-mp3", "extract-subtitles", "to-mkv", "to-avi"],
+ BuiltIn("video").PresetIds);
+ }
+
+ [Fact]
+ public void A_new_library_saves_and_loads_the_back_faces()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var images = Profile(store, "images");
+ Assert.Equal(BuiltIn("images").BackPresetIds, images.BackPresetIds);
+ images.BackPresetIds = ["to-gif", "zip-all"];
+ store.SaveLibrary();
+
+ Assert.Contains("\"backPresetIds\"", File.ReadAllText(Path.Combine(dir.Path, "profiles.json")));
+ var reloaded = NewStore(dir);
+ Assert.Equal(["to-gif", "zip-all"], Profile(reloaded, "images").BackPresetIds);
+ Assert.Equal(BuiltIn("pdf").BackPresetIds, Profile(reloaded, "pdf").BackPresetIds);
+ }
+
+ [Fact]
+ public void Version_24_libraries_get_the_built_in_back_faces_and_keep_their_fronts()
+ {
+ // As written with schema 24: no back faces, the user's own front on the images donut and a donut of their own.
+ var presets = BuiltInData.CreatePresets();
+ var profiles = BuiltInData.CreateProfiles();
+ foreach (var p in profiles)
+ p.BackPresetIds = null;
+ var images = profiles.Single(p => p.Id == "images");
+ images.PresetIds = ["to-webp", "to-png"];
+ var mine = new ToolbarProfile { Id = "mine", Name = "Mine", Extensions = ["xyz"], PresetIds = ["to-pdf"] };
+ profiles.Insert(0, mine);
+ // A preset of the default back face the user deleted stays deleted.
+ presets.RemoveAll(p => p.Id == "to-jxl");
+ var fronts = profiles.ToDictionary(p => p.Id, p => p.PresetIds.ToList());
+
+ Assert.True(SettingsMigrations.ApplyToLibrary(24, presets, profiles));
+
+ foreach (var profile in profiles.Where(p => p != mine))
+ {
+ var expected = BuiltIn(profile.Id).BackPresetIds!.Where(id => id != "to-jxl");
+ Assert.Equal(expected, profile.BackPresetIds);
+ }
+ Assert.Null(mine.BackPresetIds); // the store gives it an empty one (below)
+ Assert.All(profiles, p => Assert.Equal(fronts[p.Id], p.PresetIds));
+ Assert.False(SettingsMigrations.ApplyToLibrary(24, presets, profiles)); // once only
+ Assert.False(SettingsMigrations.ApplyToLibrary(AppSettings.CurrentSchemaVersion, presets, profiles));
+ }
+
+ [Fact]
+ public void An_existing_user_gets_the_back_faces_and_their_own_donuts_none()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ Profile(store, "images").PresetIds = ["to-webp", "to-png"];
+ store.Profiles.Insert(0, new ToolbarProfile { Id = "mine", Name = "Mine", Extensions = ["xyz"], PresetIds = ["to-pdf"] });
+ store.SaveLibrary();
+ store.SaveSettings();
+ DropBackFaces(dir, schema: 24);
+
+ var upgraded = NewStore(dir);
+
+ Assert.Equal(AppSettings.CurrentSchemaVersion, upgraded.Settings.SchemaVersion);
+ Assert.Equal(["to-webp", "to-png"], Profile(upgraded, "images").PresetIds);
+ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(upgraded, "images").BackPresetIds);
+ Assert.Equal(BuiltIn("mixed").BackPresetIds, Profile(upgraded, "mixed").BackPresetIds);
+ Assert.Equal([], Profile(upgraded, "mine").BackPresetIds);
+ // Written at once, so it runs once.
+ Assert.Contains("\"backPresetIds\"", File.ReadAllText(Path.Combine(dir.Path, "profiles.json")));
+ var again = NewStore(dir);
+ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(again, "images").BackPresetIds);
+ Assert.Equal([], Profile(again, "mine").BackPresetIds);
+ }
+
+ [Theory]
+ [InlineData(24)] // the older Filee also saved its settings, with its own schema
+ [InlineData(null)] // it only saved the library: the settings still say 29
+ public void Back_from_an_older_Filee_the_built_in_back_faces_return_and_an_emptied_one_stays_empty(int? schema)
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ Profile(store, "images").BackPresetIds = ["to-gif"];
+ Profile(store, "pdf").BackPresetIds = [];
+ store.SaveLibrary();
+ store.SaveSettings();
+
+ // Opened with this Filee again, the user's back faces are as they left them, the emptied one too.
+ var same = NewStore(dir);
+ Assert.Equal(["to-gif"], Profile(same, "images").BackPresetIds);
+ Assert.Equal([], Profile(same, "pdf").BackPresetIds);
+
+ // An older Filee saved the library in between: it dropped the back faces it didn't know.
+ DropBackFaces(dir, schema);
+ var back = NewStore(dir);
+
+ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(back, "images").BackPresetIds);
+ Assert.Equal(BuiltIn("pdf").BackPresetIds, Profile(back, "pdf").BackPresetIds);
+ Assert.Equal(BuiltIn("images").PresetIds, Profile(back, "images").PresetIds);
+ Assert.Equal(AppSettings.CurrentSchemaVersion, back.Settings.SchemaVersion);
+ Assert.False(File.Exists(Path.Combine(dir.Path, "profiles.json.broken")));
+ }
+
+ [Fact]
+ public void Dangling_and_extra_back_slices_are_dropped()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var images = Profile(store, "images");
+ images.BackPresetIds = ["does-not-exist", "to-gif", "to-gif", .. store.Presets.Select(p => p.Id).Take(20)];
+ store.SaveLibrary();
+
+ Assert.DoesNotContain("does-not-exist", images.BackPresetIds);
+ Assert.Equal(ToolbarProfile.MaxSlices, images.BackPresetIds.Count);
+ Assert.Single(images.BackPresetIds, "to-gif");
+ }
+
+ [Fact]
+ public void Reset_to_default_restores_the_back_face_too()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var images = Profile(store, "images");
+ images.BackPresetIds = ["to-pdf"];
+ // A preset of the default back face and one the "Rotate" group fans out, both deleted.
+ store.Presets.RemoveAll(p => p.Id is "to-avif" or "rotate-180");
+ store.SaveLibrary();
+ Assert.DoesNotContain("rotate-180", store.FindPreset("rotate")!.SubPresetIds);
+
+ Assert.True(store.ResetProfile(images));
+
+ Assert.Equal(BuiltIn("images").BackPresetIds, images.BackPresetIds);
+ Assert.Equal(BuiltIn("images").PresetIds, images.PresetIds);
+ Assert.NotNull(store.FindPreset("to-avif"));
+ Assert.NotNull(store.FindPreset("rotate-180"));
+ Assert.Equal(store.Presets.Count, store.Presets.Select(p => p.Id).Distinct().Count());
+ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(NewStore(dir), "images").BackPresetIds);
+ }
+
+ [Fact]
+ public void Reset_to_default_leaves_the_other_back_faces_alone()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ Profile(store, "pdf").BackPresetIds = ["to-gif"];
+ Profile(store, "images").BackPresetIds = [];
+ store.SaveLibrary();
+
+ Assert.True(store.ResetProfile(Profile(store, "images")));
+
+ Assert.Equal(["to-gif"], Profile(store, "pdf").BackPresetIds);
+ }
+
+ [Fact]
+ public void A_bundle_from_before_back_faces_imports_built_in_donuts_with_theirs()
+ {
+ using var dir = new TempDir();
+ var store = NewStore(dir);
+ var bundle = Path.Combine(dir.Path, "bundle.json");
+ store.Export(bundle);
+ var json = JsonNode.Parse(File.ReadAllText(bundle))!.AsObject();
+ foreach (var profile in json["profiles"]!.AsArray())
+ profile!.AsObject().Remove("backPresetIds");
+ json["profiles"]!.AsArray().Add(new JsonObject { ["id"] = "theirs", ["name"] = "Theirs", ["presetIds"] = new JsonArray("to-png") });
+ File.WriteAllText(bundle, json.ToJsonString());
+
+ using var other = new TempDir();
+ var target = NewStore(other);
+ Profile(target, "images").BackPresetIds = ["to-gif"];
+ target.Import(bundle);
+
+ Assert.Equal(BuiltIn("images").BackPresetIds, Profile(target, "images").BackPresetIds);
+ Assert.Equal([], Profile(target, "theirs").BackPresetIds);
+ }
+}