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.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
Ask every time: replace only the confirmed file, a bool of its own, one-file batches
cre8ive-marketing4e26f8f9fb54
diff --git a/src/Filee.App/Services/RadialController.cs b/src/Filee.App/Services/RadialController.csindex b518bb0a..d689f25d 100644--- a/src/Filee.App/Services/RadialController.cs+++ b/src/Filee.App/Services/RadialController.cs@@ -348,10 +348,10 @@ public sealed class RadialController(// "Ask every time" (#521): the save dialog first; the toast shows the job, the donut has closed for the dialog.// shortcut: files from a browser aren't asked about, they save into the download folder as "next to the source".- if (preset.Output.Location == OutputLocation.Ask && web is null)+ if (preset.Output.AskEveryTime && web is null){Close(animate: false);- _ = AskThenConvertAsync(sources, preset, oneResult: sources.Count == 1);+ _ = AskThenConvertAsync(sources, preset);return;}@@ -372,8 +372,8 @@ public sealed class RadialController(try{var ordered = await windows.ChooseMergeOrderAsync(files);- if (ordered is not null && preset.Output.Location == OutputLocation.Ask && web is null)- await AskThenConvertAsync(ordered, preset, oneResult: true); // the merge is one file+ if (ordered is not null && preset.Output.AskEveryTime && web is null)+ await AskThenConvertAsync(ordered, preset);else if (ordered is not null){conversions.Start(ordered, preset, web: web);@@ -390,11 +390,13 @@ public sealed class RadialController(}}- private async Task AskThenConvertAsync(IReadOnlyList<string> sources, Preset preset, bool oneResult)+ private async Task AskThenConvertAsync(IReadOnlyList<string> sources, Preset preset){try{- if (await windows.AskSaveLocationAsync(sources, preset, oneResult) is { } asked)+ // Asked as it will run (a ZIP from Settings › General is a .zip), for one file or a folder as the job makes them.+ var running = store.Settings.WithDefaultOutput(preset);+ if (await windows.AskSaveLocationAsync(sources, running, AskedLocation.MakesOneResult(running, sources.Count)) is { } asked){log.LogInformation("Converting {Count} file(s) with preset {Preset} where the user chose", sources.Count, preset.Id);conversions.Start(sources, asked);diff --git a/src/Filee.App/ViewModels/PresetEditorViewModel.cs b/src/Filee.App/ViewModels/PresetEditorViewModel.csindex 44cb482c..1940480a 100644--- a/src/Filee.App/ViewModels/PresetEditorViewModel.cs+++ b/src/Filee.App/ViewModels/PresetEditorViewModel.cs@@ -91,7 +91,9 @@ public sealed partial class PresetEditorViewModel : ObservableObject.Select(l => new Choice<string>(l.Code, l.NativeName,OcrLanguages.IsInstalled(l.Code) || vision.Reads(l.Code) ? null: loc.Format("presets.ocr_language_size", $"{l.Size / 1_000_000.0:0.#} MB")))];- Locations = Enum.GetValues<OutputLocation>().Select(v => new Choice<OutputLocation>(v, loc[$"presets.location.{v}"])).ToList();+ // "Ask every time" (#521) is a bool of its own on the preset (OutputRule.AskEveryTime): its choice has no location.+ Locations = [.. Enum.GetValues<OutputLocation>().Select(v => new Choice<OutputLocation?>(v, loc[$"presets.location.{v}"])),+ new Choice<OutputLocation?>(null, loc["presets.location.Ask"])];Conflicts = Enum.GetValues<ConflictPolicy>().Select(v => new Choice<ConflictPolicy>(v, loc[$"presets.conflict.{v}"])).ToList();TiffCompressions = Enum.GetValues<TiffCompression>().Select(v => new Choice<TiffCompression>(v, v.ToString().ToUpperInvariant())).ToList();FitsTiffModes = Enum.GetValues<FitsTiffMode>().Select(v => new Choice<FitsTiffMode>(v, loc[$"presets.fits_tiff.{v}"])).ToList();@@ -124,7 +126,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject_pdfPassword = _edit.Pdf.Password;_ocr = _edit.Pdf.Ocr;_ocrLanguage = OcrLanguageChoices.FirstOrDefault(l => l.Value == _edit.Pdf.OcrLanguage) ?? OcrLanguageChoices[0];- _location = Locations.First(l => l.Value == _edit.Output.Location);+ _location = _edit.Output.AskEveryTime ? Locations[^1] : Locations.First(l => l.Value == _edit.Output.Location);_conflict = Conflicts.First(c => c.Value == _edit.Output.Conflict);_tiffCompression = TiffCompressions.First(t => t.Value == _edit.Image.TiffCompression);_fitsTiffMode = FitsTiffModes.FirstOrDefault(m => m.Value == _edit.Image.FitsTiff) ?? FitsTiffModes[0];@@ -211,7 +213,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject/// <summary>PDF → PDF: don't compress, or the level (pictures at 72, 150 or 300 dpi).</summary>public IReadOnlyList<Choice<PdfCompression>> CompressionLevels { get; }- public IReadOnlyList<Choice<OutputLocation>> Locations { get; }+ public IReadOnlyList<Choice<OutputLocation?>> Locations { get; }public IReadOnlyList<Choice<ConflictPolicy>> Conflicts { get; }public IReadOnlyList<Choice<TiffCompression>> TiffCompressions { get; }@@ -373,7 +375,7 @@ public sealed partial class PresetEditorViewModel : ObservableObjectprivate Choice<PdfPageSize> _pageSize;[ObservableProperty, NotifyPropertyChangedFor(nameof(ShowSubfolder), nameof(ShowCustomFolder))]- private Choice<OutputLocation> _location;+ private Choice<OutputLocation?> _location;[ObservableProperty] private Choice<ConflictPolicy> _conflict;[ObservableProperty] private Choice<TiffCompression> _tiffCompression;@@ -516,7 +518,7 @@ public sealed partial class PresetEditorViewModel : ObservableObjectpartial void OnRotationChanged(Choice<ImageRotation>? oldValue, Choice<ImageRotation> newValue) => Choices.Restore(oldValue, newValue, v => Rotation = v);partial void OnFlipChanged(Choice<ImageFlip>? oldValue, Choice<ImageFlip> newValue) => Choices.Restore(oldValue, newValue, v => Flip = v);partial void OnPageSizeChanged(Choice<PdfPageSize>? oldValue, Choice<PdfPageSize> newValue) => Choices.Restore(oldValue, newValue, v => PageSize = v);- partial void OnLocationChanged(Choice<OutputLocation>? oldValue, Choice<OutputLocation> newValue) => Choices.Restore(oldValue, newValue, v => Location = v);+ partial void OnLocationChanged(Choice<OutputLocation?>? oldValue, Choice<OutputLocation?> newValue) => Choices.Restore(oldValue, newValue, v => Location = v);partial void OnConflictChanged(Choice<ConflictPolicy>? oldValue, Choice<ConflictPolicy> newValue) => Choices.Restore(oldValue, newValue, v => Conflict = v);partial void OnTiffCompressionChanged(Choice<TiffCompression>? oldValue, Choice<TiffCompression> newValue) =>Choices.Restore(oldValue, newValue, v => TiffCompression = v);@@ -759,7 +761,10 @@ public sealed partial class PresetEditorViewModel : ObservableObject_original.Cad.Version = ShowCad ? CadVersion.Value : default;var output = _original.Output;- output.Location = Location.Value;+ // Asking keeps the location it had: a Filee that can't ask (or one from before it) saves there.+ output.AskEveryTime = Location.Value is null;+ if (Location.Value is { } location)+ output.Location = location;output.SubfolderName = string.IsNullOrWhiteSpace(SubfolderName) ? "converted" : SubfolderName.Trim();// Only with a subfolder, where it is offered: a box ticked there must not stay on hidden behind another location.output.SubfolderOnlyForSeveralFiles = ShowSubfolder && SubfolderOnlyForSeveralFiles;diff --git a/src/Filee.Core/Presets/AskedLocation.cs b/src/Filee.Core/Presets/AskedLocation.csindex 4bc58201..f5af3b52 100644--- a/src/Filee.Core/Presets/AskedLocation.cs+++ b/src/Filee.Core/Presets/AskedLocation.cs@@ -6,9 +6,20 @@ namespace Filee.Core.Presets;public static class AskedLocation{+ /// <summary>+ /// The batch makes one file, so the dialog asks for its name: one source, or several that become one (a merged+ /// PDF, a multi-page TIFF, one archive, joined videos). Otherwise it asks for a folder.+ /// </summary>+ public static bool MakesOneResult(Preset preset, int sources) =>+ sources == 1+ || preset.TargetFormat == "pdf" && preset.Pdf.MergeIntoSingle+ || preset.Image.MultiPageTiff && preset.TargetFormat == "tiff"+ || preset.PacksIntoOneArchive+ || preset.JoinsIntoOneMedia;+/// <summary>/// The name the save dialog suggests for <paramref name="source"/>: the preset's name pattern and renames, and the- /// target's extension (the source's own for "same as source").+ /// extension the result gets./// </summary>public static string SuggestedName(Preset preset, string presetName, string source){@@ -20,15 +31,19 @@ public static class AskedLocationreturn extension.Length == 0 ? name : $"{name}.{extension}";}- /// <summary>The extension the result gets, without the dot; empty for a folder ("Extract").</summary>+ /// <summary>+ /// The extension the result gets, without the dot: "zip" when it's saved as a ZIP, the source's own for "same as+ /// source", empty for a folder ("Extract"). The preset is the one that runs, with Settings › General applied.+ /// </summary>public static string Extension(Preset preset, string source) =>- preset.TargetFormat == BuiltInData.SameAsSource- ? FormatRegistry.ExtensionOf(source)- : FormatRegistry.FindById(preset.TargetFormat)?.Extensions.FirstOrDefault() ?? "";+ preset.Output.ZipResult ? "zip"+ : preset.TargetFormat == BuiltInData.SameAsSource ? FormatRegistry.ExtensionOf(source)+ : FormatRegistry.FindById(preset.TargetFormat)?.Extensions.FirstOrDefault() ?? "";/// <summary>/// One result, saved as <paramref name="chosenPath"/>: that folder and that name, without the pattern or renames- /// on top. The dialog has already asked about replacing a file there, so it is replaced.+ /// on top. Only that exact path, which the dialog asked about, may replace a file there; pages or a result with+ /// another extension keep the preset's own conflict policy./// </summary>public static Preset ForFile(Preset preset, string chosenPath){@@ -36,7 +51,7 @@ public static class AskedLocation// shortcut: a chosen name with a pattern token in it ("{date}") is expanded, there is no escape; rare enough.copy.Output.FileNamePattern = Path.GetFileNameWithoutExtension(chosenPath);copy.Output.Renames = [];- copy.Output.Conflict = ConflictPolicy.Overwrite;+ copy.Output.ConfirmedPath = Path.GetFullPath(chosenPath);return copy;}@@ -46,10 +61,13 @@ public static class AskedLocationprivate static Preset InFolder(Preset preset, string folder){var copy = preset.Clone();+ copy.Output.AskEveryTime = false;copy.Output.Location = OutputLocation.CustomFolder;copy.Output.CustomFolder = folder;copy.Output.KeepFoldersFrom = "";copy.Output.SubfolderOnlyForSeveralFiles = false;+ // The place the user picked is where the result goes, not back over the original.+ copy.Output.ReplaceOriginal = false;return copy;}}diff --git a/src/Filee.Core/Presets/OutputPathResolver.cs b/src/Filee.Core/Presets/OutputPathResolver.csindex 57fa8d12..bfb5ded7 100644--- a/src/Filee.Core/Presets/OutputPathResolver.cs+++ b/src/Filee.Core/Presets/OutputPathResolver.cs@@ -47,6 +47,9 @@ public static partial class OutputPathResolvervar isSource = PathsEqual(candidate, tokens.SourcePath);if (!isSource && !exists(candidate))return candidate;+ // The save dialog asked about replacing exactly this file ("Ask every time"); any other keeps the policy.+ if (!isSource && rule.ConfirmedPath is { } confirmed && PathsEqual(candidate, confirmed))+ return candidate;if (!isSource && rule.Conflict == ConflictPolicy.Overwrite)return candidate;diff --git a/src/Filee.Core/Presets/OutputRule.cs b/src/Filee.Core/Presets/OutputRule.csindex fe871494..ae79a68b 100644--- a/src/Filee.Core/Presets/OutputRule.cs+++ b/src/Filee.Core/Presets/OutputRule.cs@@ -16,11 +16,6 @@ public enum OutputLocationSubfolder,/// <summary>In a fixed folder (see <see cref="OutputRule.CustomFolder"/>).</summary>CustomFolder,- /// <summary>- /// "Ask every time" (#521): a save dialog that starts in the source's folder, once per batch (see- /// <see cref="AskedLocation"/>). Where nothing can ask (watch folders, the command line), next to the source.- /// </summary>- Ask,}/// <summary>What to do when the output file already exists.</summary>@@ -37,8 +32,24 @@ public enum ConflictPolicy/// <summary>Output placement and naming rules.</summary>public sealed class OutputRule{+ /// <summary>A name this version doesn't know (from a newer Filee) reads as <see cref="OutputLocation.Default"/>.</summary>+ [System.Text.Json.Serialization.JsonConverter(typeof(LenientEnumJsonConverter<OutputLocation>))]public OutputLocation Location { get; set; } = OutputLocation.Default;+ /// <summary>+ /// "Ask every time" (#521): the donut asks where to save first, once per batch, in the source's folder+ /// (<see cref="AskedLocation"/>). Where nothing can ask (the command line, files from a browser, other tools),+ /// <see cref="Location"/> applies. A bool of its own, so a Filee from before it keeps the preset and uses Location.+ /// </summary>+ public bool AskEveryTime { get; set; }++ /// <summary>+ /// The one path the user picked and confirmed in the save dialog: it may replace a file there whatever+ /// <see cref="Conflict"/> says. Set per job, never saved with a preset.+ /// </summary>+ [System.Text.Json.Serialization.JsonIgnore]+ public string? ConfirmedPath { get; set; }+public string SubfolderName { get; set; } = "converted";/// <summary>diff --git a/tests/Filee.Core.Tests/AskedLocationTests.cs b/tests/Filee.Core.Tests/AskedLocationTests.csindex c964fb0f..a35f459a 100644--- a/tests/Filee.Core.Tests/AskedLocationTests.cs+++ b/tests/Filee.Core.Tests/AskedLocationTests.cs@@ -1,6 +1,10 @@-// "Ask every time" (#521): what the save dialog suggests, and where the files go once it is answered.+// "Ask every time" (#521): what the save dialog suggests, and where the files go once it is answered: only the file+// the dialog asked about may replace one, and a preset that asks still loads in a Filee from before it.+using System.Text.Json;+using Filee.Core.Conversion;using Filee.Core.Presets;+using Filee.Core.Settings;namespace Filee.Core.Tests;@@ -11,7 +15,7 @@ public class AskedLocationTestsprivate static Preset Asking(string target = "jpg") => new(){TargetFormat = target,- Output = { Location = OutputLocation.Ask, FileNamePattern = "{name}_small", Renames = [new RenameStep { Kind = RenameKind.Replace, Find = "IMG_", Replace = "Photo_" }] },+ Output = { AskEveryTime = true, FileNamePattern = "{name}_small", Renames = [new RenameStep { Kind = RenameKind.Replace, Find = "IMG_", Replace = "Photo_" }] },};[Fact]@@ -19,40 +23,132 @@ public class AskedLocationTests{Assert.Equal("Photo_0412_small.jpg", AskedLocation.SuggestedName(Asking(), "JPG", At.SourcePath));Assert.Equal("Photo_0412_small.heic", AskedLocation.SuggestedName(Asking(BuiltInData.SameAsSource), "Same", At.SourcePath));+ // Saved as a ZIP (the preset's or Settings › General's): the result is a .zip.+ var zipped = Asking();+ zipped.Output.ZipResult = true;+ Assert.Equal("Photo_0412_small.zip", AskedLocation.SuggestedName(zipped, "JPG", At.SourcePath));}[Fact]- public void Where_nothing_asks_the_result_goes_next_to_the_source()+ public void One_file_is_asked_for_by_name_also_when_several_sources_make_it(){- var path = OutputPathResolver.Resolve(Asking().Output, At, "jpg", _ => false);+ Assert.True(AskedLocation.MakesOneResult(Asking(), 1));+ Assert.False(AskedLocation.MakesOneResult(Asking(), 3));+ Assert.True(AskedLocation.MakesOneResult(new Preset { TargetFormat = "pdf", Pdf = { MergeIntoSingle = true } }, 3));+ Assert.True(AskedLocation.MakesOneResult(new Preset { TargetFormat = "tiff", Image = { MultiPageTiff = true } }, 3));+ Assert.True(AskedLocation.MakesOneResult(BuiltInData.CreatePresets().First(p => p.PacksIntoOneArchive), 3));+ Assert.True(AskedLocation.MakesOneResult(BuiltInData.CreatePresets().First(p => p.JoinsIntoOneMedia), 3));+ }++ [Fact]+ public void Where_nothing_asks_the_presets_location_applies()+ {+ var preset = Asking();+ preset.Output.Location = OutputLocation.SameFolder;+ var path = OutputPathResolver.Resolve(preset.Output, At, "jpg", _ => false);Assert.Equal(Path.Combine(Path.GetDirectoryName(At.SourcePath)!, "Photo_0412_small.jpg"), path);}[Fact]- public void One_result_is_saved_exactly_as_chosen_replacing_what_the_dialog_asked_about()+ public void Only_the_file_the_dialog_asked_about_is_replaced(){var chosen = Path.Combine(Path.GetTempPath(), "out", "holiday.jpg");var preset = Asking();var asked = AskedLocation.ForFile(preset, chosen);- // The name typed in the dialog, without the pattern or renames on top, even though the file exists.+ // The name typed in the dialog, without the pattern or renames on top, replacing what's there.Assert.Equal(chosen, OutputPathResolver.Resolve(asked.Output, At, "jpg", _ => true));- Assert.Equal(OutputLocation.Ask, preset.Output.Location); // the preset itself keeps asking+ // Pages of it, or a result with another extension than the one typed, keep the preset's own policy.+ Assert.Equal(Path.Combine(Path.GetTempPath(), "out", "holiday_p1 (2).jpg"),+ OutputPathResolver.Resolve(asked.Output, At, "jpg", p => !p.Contains("(2)"), "_p1"));+ Assert.Equal(Path.Combine(Path.GetTempPath(), "out", "holiday (2).zip"),+ OutputPathResolver.Resolve(asked.Output, At, "zip", p => !p.Contains("(2)")));+ // The preset itself keeps asking.+ Assert.True(preset.Output.AskEveryTime);Assert.Single(preset.Output.Renames);+ Assert.False(asked.Output.AskEveryTime);+ }++ [Fact]+ public async Task Pages_never_replace_files_the_dialog_didnt_ask_about()+ {+ using var dir = new TempDir();+ var pdf = dir.File("book.pdf");+ var outFolder = Path.Combine(dir.Path, "out");+ Directory.CreateDirectory(outFolder);+ var existing = Path.Combine(outFolder, "holiday_p1.png");+ File.WriteAllText(existing, "keep me");+ await using var queue = new JobQueue(new ConverterCatalog([new FakeConverter("pdfium", new ConversionEdge("pdf", "png")) { OutputsPerInput = 2 }]));+ var asked = AskedLocation.ForFile(new Preset { TargetFormat = "png", Output = { AskEveryTime = true } }, Path.Combine(outFolder, "holiday.png"));++ var job = new ConversionJob([pdf], asked, "PNG");+ await queue.RunAsync(job);++ Assert.Equal("keep me", File.ReadAllText(existing));+ Assert.Contains(Path.Combine(outFolder, "holiday_p1 (2).png"), job.Outputs);}[Fact]public void Several_results_go_into_the_chosen_folder_under_their_own_names(){var folder = Path.Combine(Path.GetTempPath(), "chosen");- var preset = Asking();- preset.Output.Conflict = ConflictPolicy.Rename;- var asked = AskedLocation.ForFolder(preset, folder);+ var asked = AskedLocation.ForFolder(Asking(), folder);Assert.Equal(Path.Combine(folder, "Photo_0412_small.jpg"), OutputPathResolver.Resolve(asked.Output, At, "jpg", _ => false));// An existing file there isn't replaced: only one picked by name in the dialog is.Assert.Equal(Path.Combine(folder, "Photo_0412_small (2).jpg"), OutputPathResolver.Resolve(asked.Output, At, "jpg", p => !p.Contains("(2)")));}++ [Fact]+ public void The_chosen_place_is_where_the_result_goes_not_back_over_the_original()+ {+ var preset = Asking(BuiltInData.SameAsSource);+ preset.Output.ReplaceOriginal = true;++ Assert.False(AskedLocation.ForFolder(preset, Path.GetTempPath()).Output.ReplaceOriginal);+ Assert.False(AskedLocation.ForFile(preset, Path.Combine(Path.GetTempPath(), "x.heic")).Output.ReplaceOriginal);+ Assert.True(preset.Output.ReplaceOriginal);+ }++ [Fact]+ public void A_preset_that_asks_keeps_its_location_for_a_filee_that_cant()+ {+ using var dir = new TempDir();+ var store = new UserDataStore(dir.Path);+ store.Load();+ var preset = new Preset { Id = "asks", TargetFormat = "png", Output = { AskEveryTime = true, Location = OutputLocation.SameFolder } };+ store.Presets.Add(preset);+ store.SaveLibrary();++ var json = File.ReadAllText(Path.Combine(dir.Path, "presets.json"));+ // Only names every version knows: 2.1.0 reads "SameFolder" and skips "AskEveryTime".+ Assert.DoesNotContain("\"Ask\"", json);+ var reloaded = new UserDataStore(dir.Path);+ reloaded.Load();+ var back = reloaded.FindPreset("asks")!;+ Assert.True(back.Output.AskEveryTime);+ Assert.Equal(OutputLocation.SameFolder, back.Output.Location);+ }++ [Fact]+ public void A_location_from_a_newer_filee_reads_as_the_default()+ {+ using var dir = new TempDir();+ var store = new UserDataStore(dir.Path);+ store.Load();+ store.Presets.Add(new Preset { Id = "future", TargetFormat = "png" });+ store.SaveLibrary();+ var path = Path.Combine(dir.Path, "presets.json");+ var json = File.ReadAllText(path);+ File.WriteAllText(path, json.Replace("\"location\": \"Default\"", "\"location\": \"Somewhere\""));+ Assert.Contains("Somewhere", File.ReadAllText(path));++ var reloaded = new UserDataStore(dir.Path);+ reloaded.Load();++ // The user's presets survive (a broken file would be replaced by the factory ones).+ Assert.Equal(OutputLocation.Default, reloaded.FindPreset("future")!.Output.Location);+ }}