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
Keep the original file dates as a preset option, and put EPUB on the PDF donut
KnifeLemonba4cb43a9d08
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.jsonindex 4e38f5ee..8c0f2a39 100644--- a/src/Filee.App/Assets/i18n/en.json+++ b/src/Filee.App/Assets/i18n/en.json@@ -299,6 +299,8 @@"presets.browse": "Browse…","presets.pattern": "File name","presets.pattern_hint": "{name} {ext} {preset} {date} {time} {index}",+ "presets.keep_dates": "Keep the original file dates",+ "presets.keep_dates_hint": "Converted files get the created and modified dates of the original, so photos still sort by date.","presets.conflict": "If the file exists","presets.conflict.Rename": "Add a number","presets.conflict.Overwrite": "Replace it",diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.jsonindex 39c89cf3..823f1490 100644--- a/src/Filee.App/Assets/i18n/ko.json+++ b/src/Filee.App/Assets/i18n/ko.json@@ -299,6 +299,8 @@"presets.browse": "찾아보기…","presets.pattern": "파일 이름","presets.pattern_hint": "{name} {ext} {preset} {date} {time} {index}",+ "presets.keep_dates": "원본 파일 날짜 유지",+ "presets.keep_dates_hint": "변환된 파일에 원본의 만든 날짜와 수정한 날짜를 그대로 넣어요. 날짜순으로 정렬한 사진도 순서가 그대로예요.","presets.conflict": "같은 파일이 있으면","presets.conflict.Rename": "번호 붙이기","presets.conflict.Overwrite": "덮어쓰기",diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.jsonindex ab4eae4c..b75e1808 100644--- a/src/Filee.App/Assets/i18n/zh-CN.json+++ b/src/Filee.App/Assets/i18n/zh-CN.json@@ -299,6 +299,8 @@"presets.browse": "浏览…","presets.pattern": "文件名","presets.pattern_hint": "{name} {ext} {preset} {date} {time} {index}",+ "presets.keep_dates": "保留原文件日期",+ "presets.keep_dates_hint": "转换后的文件沿用原文件的创建和修改日期,按日期排序的照片顺序不变。","presets.conflict": "文件已存在时","presets.conflict.Rename": "添加编号","presets.conflict.Overwrite": "覆盖",diff --git a/src/Filee.App/ViewModels/PresetEditorViewModel.cs b/src/Filee.App/ViewModels/PresetEditorViewModel.csindex 05bc90d9..50820b29 100644--- a/src/Filee.App/ViewModels/PresetEditorViewModel.cs+++ b/src/Filee.App/ViewModels/PresetEditorViewModel.cs@@ -100,6 +100,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject_subfolderName = _edit.Output.SubfolderName;_customFolder = _edit.Output.CustomFolder;_pattern = _edit.Output.FileNamePattern;+ _keepDates = _edit.Output.KeepDates;}public string PresetId => _original.Id;@@ -176,6 +177,7 @@ public sealed partial class PresetEditorViewModel : ObservableObject[ObservableProperty] private string _subfolderName;[ObservableProperty] private string _customFolder;[ObservableProperty] private string _pattern;+ [ObservableProperty] private bool _keepDates;[ObservableProperty] private Choice<MediaQuality> _mediaQuality;[ObservableProperty] private Choice<int> _maxHeight;[ObservableProperty] private Choice<int> _audioBitrate;@@ -272,6 +274,7 @@ public sealed partial class PresetEditorViewModel : ObservableObjectoutput.CustomFolder = CustomFolder.Trim();output.FileNamePattern = string.IsNullOrWhiteSpace(Pattern) ? "{name}" : Pattern.Trim();output.Conflict = Conflict.Value;+ output.KeepDates = KeepDates;return true;}diff --git a/src/Filee.App/Views/PresetEditorView.axaml b/src/Filee.App/Views/PresetEditorView.axamlindex c6e7a860..f952bf93 100644--- a/src/Filee.App/Views/PresetEditorView.axaml+++ b/src/Filee.App/Views/PresetEditorView.axaml@@ -190,6 +190,8 @@<TextBox Text="{Binding Pattern}" PlaceholderText="{}{name}" /><TextBlock Classes="caption" Text="{DynamicResource presets.pattern_hint}" Margin="2,4,0,0" /></StackPanel>+ <CheckBox Content="{DynamicResource presets.keep_dates}" IsChecked="{Binding KeepDates}"+ ToolTip.Tip="{DynamicResource presets.keep_dates_hint}" /></StackPanel></Border></StackPanel>diff --git a/src/Filee.Cli/Cli.cs b/src/Filee.Cli/Cli.csindex 1c147005..63ea707b 100644--- a/src/Filee.Cli/Cli.cs+++ b/src/Filee.Cli/Cli.cs@@ -235,6 +235,8 @@ internal static class Clipreset.Image.Quality = quality;if (options.Conflict is { } conflict)preset.Output.Conflict = conflict;+ if (options.KeepDates)+ preset.Output.KeepDates = true;return preset;}diff --git a/src/Filee.Cli/CliOptions.cs b/src/Filee.Cli/CliOptions.csindex aa1f1c83..9631a2f9 100644--- a/src/Filee.Cli/CliOptions.cs+++ b/src/Filee.Cli/CliOptions.cs@@ -18,6 +18,7 @@ internal sealed record CliOptionspublic bool Json { get; set; }public bool Quiet { get; set; }public bool MoveOriginals { get; set; }+ public bool KeepDates { get; set; }public double? SettleSeconds { get; set; }public string? Error { get; set; }@@ -91,6 +92,9 @@ internal sealed record CliOptionscase "--move-originals":options.MoveOriginals = true;break;+ case "--keep-dates":+ options.KeepDates = true;+ break;case "--settle":var settle = Value();if (settle is not null)diff --git a/src/Filee.Cli/Help.cs b/src/Filee.Cli/Help.csindex ff1bc650..9893c579 100644--- a/src/Filee.Cli/Help.cs+++ b/src/Filee.Cli/Help.cs@@ -54,6 +54,7 @@ internal static class Help-q, --quality <1-100> Image quality for JPG, WebP, AVIF, …--overwrite Replace existing output files (default: add a number)--skip Leave existing output files alone+ --keep-dates Give converted files the created and modified dates of the originals--json Print the result as JSON (for scripts and other programs)--quiet Print nothing but errors@@ -73,6 +74,7 @@ internal static class Help--move-originals Move converted sources to <folder>\originals; files already waiting areconverted at start--settle <seconds> How long a file must stay unchanged (default 2)+ --keep-dates Give converted files the created and modified dates of the originals--quiet Print nothing but errors""";diff --git a/src/Filee.Core/Conversion/JobQueue.cs b/src/Filee.Core/Conversion/JobQueue.csindex e0474b95..000b3cfd 100644--- a/src/Filee.Core/Conversion/JobQueue.cs+++ b/src/Filee.Core/Conversion/JobQueue.cs@@ -222,6 +222,34 @@ public sealed class JobQueue : IAsyncDisposable}}+ /// <summary>Gives the outputs the creation and modification dates of the source (<see cref="OutputRule.KeepDates"/>).</summary>+ private void CopyDates(string source, IEnumerable<string> outputs)+ {+ try+ {+ var created = File.GetCreationTimeUtc(source);+ var modified = File.GetLastWriteTimeUtc(source);+ foreach (var output in outputs)+ {+ if (File.Exists(output))+ {+ File.SetCreationTimeUtc(output, created);+ File.SetLastWriteTimeUtc(output, modified);+ }+ else if (Directory.Exists(output))+ {+ Directory.SetCreationTimeUtc(output, created);+ Directory.SetLastWriteTimeUtc(output, modified);+ }+ }+ }+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)+ {+ // The conversion itself worked: keep the files, only the dates are new.+ _log.LogWarning(ex, "Could not copy the dates of {Source}", source);+ }+ }+/// <summary>/// Converts one source file along its planned route./// With <paramref name="finalOutput"/> false, results stay in the work directory (used for merging).@@ -287,7 +315,11 @@ public sealed class JobQueue : IAsyncDisposable}if (finalOutput)+ {file.Outputs.AddRange(inputs);+ if (job.Preset.Output.KeepDates)+ CopyDates(file.SourcePath, inputs);+ }file.State = inputs.Count == 0 && finalOutput ? FileState.Skipped : FileState.Done;file.Progress = 1;Notify(job);diff --git a/src/Filee.Core/Presets/BuiltInData.cs b/src/Filee.Core/Presets/BuiltInData.csindex 6f0584f7..5e81b976 100644--- a/src/Filee.Core/Presets/BuiltInData.cs+++ b/src/Filee.Core/Presets/BuiltInData.cs@@ -160,7 +160,7 @@ public static class BuiltInData{Id = "pdf", NameKey = "profile.pdf",Extensions = ["pdf"],- PresetIds = ["to-png", "to-jpg", "to-docx", "to-txt", "to-hwpx", "to-tiff", "pdf-split", "merge-pdf"],+ PresetIds = ["to-png", "to-jpg", "to-docx", "to-txt", "to-epub", "to-hwpx", "to-tiff", "pdf-split", "merge-pdf"],},new(){diff --git a/src/Filee.Core/Presets/OutputRule.cs b/src/Filee.Core/Presets/OutputRule.csindex e9bdf579..62d046c5 100644--- a/src/Filee.Core/Presets/OutputRule.cs+++ b/src/Filee.Core/Presets/OutputRule.cs@@ -42,5 +42,11 @@ public sealed class OutputRulepublic ConflictPolicy Conflict { get; set; } = ConflictPolicy.Rename;+ /// <summary>+ /// Give converted files the creation and modification dates of their source, e.g. so converted photos still sort+ /// by when they were taken. Not for merged PDFs or combined archives, which come from many files.+ /// </summary>+ public bool KeepDates { get; set; }+public OutputRule Clone() => (OutputRule)MemberwiseClone();}diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.csindex b69d51be..51cb09a4 100644--- a/src/Filee.Core/Settings/AppSettings.cs+++ b/src/Filee.Core/Settings/AppSettings.cs@@ -48,7 +48,7 @@ public sealed class DonutSettingspublic sealed class AppSettings{/// <summary>Current schema version. Increase when the format changes and add a migration.</summary>- public const int CurrentSchemaVersion = 6;+ public const int CurrentSchemaVersion = 7;public int SchemaVersion { get; set; } = CurrentSchemaVersion;diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.csindex 1975d5f1..43c195fc 100644--- a/src/Filee.Core/Settings/UserDataStore.cs+++ b/src/Filee.Core/Settings/UserDataStore.cs@@ -313,6 +313,10 @@ internal static class SettingsMigrations// gets "compress into one ZIP".if (from < 6)changed |= AddCatalog(presets, profiles);++ // v7: PDF → EPUB (PDF → DOCX → EPUB, built in) is on the PDF donut.+ if (from < 7)+ changed |= Offer(presets, profiles, "pdf", "to-epub", "to-txt");return changed;}@@ -352,21 +356,26 @@ internal static class SettingsMigrationschanged = true;}- void Offer(string profileId, string presetId, string? after)- {- if (profiles.FirstOrDefault(p => p.Id == profileId) is not { } profile- || profile.PresetIds.Contains(presetId) || profile.PresetIds.Count >= ToolbarProfile.MaxSlices- || !presetIds.Contains(presetId))- return;- var index = after is null ? -1 : profile.PresetIds.IndexOf(after);- profile.PresetIds.Insert(index < 0 ? profile.PresetIds.Count : index + 1, presetId);- changed = true;- }- Offer("pdf", "to-docx", "to-jpg");- Offer(profiles.FirstOrDefault(p => p.IsFallback)?.Id ?? "mixed", "zip-all", "merge-pdf");+ changed |= Offer(presets, profiles, "pdf", "to-docx", "to-jpg");+ changed |= Offer(presets, profiles, profiles.FirstOrDefault(p => p.IsFallback)?.Id ?? "mixed", "zip-all", "merge-pdf");return changed;}+ /// <summary>+ /// Puts a preset on a donut after <paramref name="after"/> (or at the end), unless the donut is missing, full or+ /// has it already. Returns true when it was added.+ /// </summary>+ private static bool Offer(List<Preset> presets, List<ToolbarProfile> profiles, string profileId, string presetId, string? after)+ {+ if (profiles.FirstOrDefault(p => p.Id == profileId) is not { } profile+ || profile.PresetIds.Contains(presetId) || profile.PresetIds.Count >= ToolbarProfile.MaxSlices+ || presets.All(p => p.Id != presetId))+ return false;+ var index = after is null ? -1 : profile.PresetIds.IndexOf(after);+ profile.PresetIds.Insert(index < 0 ? profile.PresetIds.Count : index + 1, presetId);+ return true;+ }+private static void InsertBefore(List<string> list, string id, string before){if (list.Contains(id))diff --git a/tests/Filee.Cli.Tests/CliTests.cs b/tests/Filee.Cli.Tests/CliTests.csindex 787342d7..d0225cfa 100644--- a/tests/Filee.Cli.Tests/CliTests.cs+++ b/tests/Filee.Cli.Tests/CliTests.cs@@ -48,6 +48,19 @@ public sealed class CliTests : IDisposableAssert.True(File.Exists(Path.Combine(outFolder, "b.jpg")));}+ [Fact]+ public async Task Keep_dates_copies_the_dates_of_the_originals()+ {+ var source = Png("old.png");+ var modified = new DateTime(2018, 5, 4, 12, 0, 0, DateTimeKind.Utc);+ File.SetLastWriteTimeUtc(source, modified);++ var (code, _, _) = await Run("convert", source, "--to", "jpg", "--keep-dates");++ Assert.Equal(Cli.Success, code);+ Assert.Equal(modified, File.GetLastWriteTimeUtc(Path.Combine(_folder, "old.jpg")));+ }+[Fact]public async Task Json_output_lists_every_file(){diff --git a/tests/Filee.Core.Tests/JobQueueTests.cs b/tests/Filee.Core.Tests/JobQueueTests.csindex 8a5fe370..ead005c5 100644--- a/tests/Filee.Core.Tests/JobQueueTests.cs+++ b/tests/Filee.Core.Tests/JobQueueTests.cs@@ -28,6 +28,32 @@ public class JobQueueTestsAssert.Equal(1, job.Progress);}+ [Fact]+ public async Task Keep_dates_gives_outputs_the_dates_of_their_source()+ {+ using var dir = new TempDir();+ var taken = dir.File("taken.jpg");+ var plain = dir.File("plain.jpg");+ var created = new DateTime(2019, 7, 1, 9, 30, 0, DateTimeKind.Utc);+ var modified = new DateTime(2019, 7, 2, 18, 5, 0, DateTimeKind.Utc);+ foreach (var source in new[] { taken, plain })+ {+ File.SetCreationTimeUtc(source, created);+ File.SetLastWriteTimeUtc(source, modified);+ }+ await using var queue = new JobQueue(new ConverterCatalog([new FakeConverter("magick", new ConversionEdge("jpg", "png"))]));++ var keep = new Preset { TargetFormat = "png", Output = { KeepDates = true } };+ await Run(queue, [taken], keep);+ await Run(queue, [plain], new Preset { TargetFormat = "png" });++ var output = Path.Combine(dir.Path, "taken.png");+ Assert.Equal(created, File.GetCreationTimeUtc(output));+ Assert.Equal(modified, File.GetLastWriteTimeUtc(output));+ // Without the option the output has the time it was made.+ Assert.True(File.GetLastWriteTimeUtc(Path.Combine(dir.Path, "plain.png")) > DateTime.UtcNow.AddMinutes(-5));+ }+[Fact]public async Task Multi_step_route_keeps_intermediates_out_of_the_output_folder(){diff --git a/tests/Filee.Core.Tests/UserDataStoreTests.cs b/tests/Filee.Core.Tests/UserDataStoreTests.csindex 7c227112..ae35709d 100644--- a/tests/Filee.Core.Tests/UserDataStoreTests.cs+++ b/tests/Filee.Core.Tests/UserDataStoreTests.cs@@ -151,6 +151,20 @@ public class UserDataStoreTestsAssert.Equal(all.Count, all.Distinct(StringComparer.OrdinalIgnoreCase).Count());}+ [Fact]+ public void Version_6_libraries_get_epub_on_the_pdf_donut()+ {+ // As written by 1.3.0: no EPUB on the PDF donut.+ var presets = BuiltInData.CreatePresets();+ var profiles = BuiltInData.CreateProfiles();+ profiles.Single(p => p.Id == "pdf").PresetIds.Remove("to-epub");++ Assert.True(SettingsMigrations.ApplyToLibrary(6, presets, profiles));++ Assert.Equal(["to-png", "to-jpg", "to-docx", "to-txt", "to-epub"], profiles.Single(p => p.Id == "pdf").PresetIds.Take(5));+ Assert.False(SettingsMigrations.ApplyToLibrary(6, presets, profiles)); // once only+ }+[Fact]public void Catalog_migration_ignores_extensions_checked_on_mixed_profiles(){