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.

Replace the original: same extension or a spelling of it; Korean in the app's tone

KnifeLemon45a9dcf315b4
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index ea72801d..470619bf 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -49,7 +49,8 @@
writing, but only at a path that was its alone: nothing was there before and no other conversion was handed the
same name ("Overwrite"). It frees its names and removes an output folder it made if that is left empty.
*Replace the original* (`OutputRule.ReplaceOriginal`, off by default) comes after that, for a finished result of
- the source's own format (for TXT, which also covers scripts and logs, the same extension). The result is first
+ the source's own format and extension, or another spelling of it (`.jpeg` / `.jpg`; TXT also covers scripts and
+ logs, PPT also `.pps` and `.pot`, so those need the same extension). The result is first
moved next to the source under a temporary name, then the source goes to the Recycle Bin / Trash
(`IPlatformServices.MoveToTrash`, in the app and the command line), then the result takes its name. Windows only
ever recycles (IFileOperation with a sink that refuses a delete it can't recycle). When the source can't go there
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 653a55d3..9b992394 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -110,16 +110,16 @@
"error.geo_unsupported_shape": "지원하지 않는 도형 종류예요",
"error.geo_too_large": "Shapefile의 한계인 2GB를 넘어요",
"notice.pdf_not_smaller": "더 작게 만들 수 없어서 그대로 복사했어요",
- "notice.original_kept": "원본을 그대로 두고 결과를 사본으로 저장했습니다",
- "notice.original_in_trash": "원본은 휴지통에 있고 결과는 자기 이름을 유지했습니다",
- "notice.original_unchanged": "더 작게 만들지 못해 원본을 그대로 두었습니다",
- "trash.no_recycle_bin": "이 드라이브에는 휴지통이 없습니다",
- "trash.in_use": "다른 프로그램에서 파일을 열고 있습니다",
- "trash.read_only": "읽기 전용 파일입니다",
- "trash.other_drive": "휴지통이 다른 드라이브에 있습니다",
- "trash.no_folder": "휴지통 폴더가 없습니다",
- "trash.failed": "휴지통으로 옮기지 못했습니다",
- "trash.cannot_place": "원본 폴더에 결과를 저장하지 못했습니다",
+ "notice.original_kept": "원본은 그대로 두고 결과를 사본으로 저장했어요",
+ "notice.original_in_trash": "원본은 휴지통으로 옮겼고, 결과는 저장된 이름 그대로예요",
+ "notice.original_unchanged": "더 작게 만들지 못해서 원본을 그대로 두었어요",
+ "trash.no_recycle_bin": "이 드라이브에는 휴지통이 없어요",
+ "trash.in_use": "다른 프로그램에서 파일을 열고 있어요",
+ "trash.read_only": "읽기 전용 파일이에요",
+ "trash.other_drive": "휴지통이 다른 드라이브에 있어요",
+ "trash.no_folder": "휴지통 폴더가 없어요",
+ "trash.failed": "휴지통으로 옮기지 못했어요",
+ "trash.cannot_place": "원본 폴더에 결과를 저장하지 못했어요",
"notice.empty_spreadsheet_pages_removed": "스프레드시트의 빈 페이지를 제거했어요",
"notice.live_photo_pair": "같은 이름의 사진과 MOV로 저장했어요. 두 파일을 함께 가져오면(iCloud 사진, AirDrop, Mac의 사진 앱) 라이브 포토가 돼요",
"notice.geo_datum_assumed": "측지계가 WGS 84가 아니라서 같은 것으로 보고 변환했어요. 위치가 수백 m까지 어긋날 수 있어요",
@@ -634,7 +634,7 @@
"presets.zip_result": "결과를 ZIP으로 저장",
"presets.zip_result_hint": "결과 파일들(Shapefile의 .shp, .shx, .dbf, .prj, .cpg)을 낱개로 두지 않고 원본 옆에 ZIP 하나로 묶어요.",
"presets.replace_original": "원본 바꾸기",
- "presets.replace_original_hint": "결과가 원본의 이름과 위치를 가져가고 원본은 휴지통으로 이동합니다. 결과가 같은 형식일 때만 적용되며, 감시 폴더나 브라우저에서 가져온 파일에는 적용되지 않습니다. 원본을 휴지통으로 옮길 수 없으면 원본은 그대로 두고 결과를 사본으로 저장합니다. 결과는 '저장 위치'와 관계없이 원본 폴더에 저장됩니다.",
+ "presets.replace_original_hint": "결과가 원본의 이름과 자리를 이어받고, 원본은 휴지통으로 옮겨요. 결과가 같은 형식일 때만 바꾸고, 감시 폴더나 브라우저에서 가져온 파일은 바꾸지 않아요. 원본을 휴지통으로 옮길 수 없으면 원본은 그대로 두고 결과를 사본으로 저장해요. 결과는 '저장 위치'와 상관없이 원본 폴더에 저장돼요.",
"presets.conflict": "같은 파일이 있으면",
"presets.conflict.Rename": "번호 붙이기",
"presets.conflict.Overwrite": "덮어쓰기",
diff --git a/src/Filee.Core/Conversion/JobQueue.cs b/src/Filee.Core/Conversion/JobQueue.cs
index 7386ff8b..3453d186 100644
--- a/src/Filee.Core/Conversion/JobQueue.cs
+++ b/src/Filee.Core/Conversion/JobQueue.cs
@@ -1025,9 +1025,9 @@ public sealed class JobQueue : IAsyncDisposable
|| FormatRegistry.Detect(output) is not { } format || format.Id != sourceFormat
|| string.Equals(Path.GetFullPath(output), Path.GetFullPath(source), Platform.FileSystemPaths.Comparison))
return output;
- // TXT also covers scripts and logs (.bat, .py, .log): there only the same extension replaces. Elsewhere the
- // extensions are spellings of one format (.jpeg / .jpg).
- if (format.Id == "txt" && !string.Equals(Path.GetExtension(output), Path.GetExtension(source), StringComparison.OrdinalIgnoreCase))
+ // One format can cover different kinds of file (TXT: .bat, .py, .log; PPT: .pot; AIFF: .aifc), and the result
+ // takes the original's name: only the same extension, or another spelling of it (.jpeg / .jpg), replaces.
+ if (!SameKindOfFile(Path.GetExtension(output), Path.GetExtension(source)))
return output;
if (copiedSource)
{
@@ -1078,12 +1078,21 @@ public sealed class JobQueue : IAsyncDisposable
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
- // The original is in the Trash already: the result stays next to where it was, under its temporary name.
+ // The original is in the Trash already: the result goes back to the name it was saved under.
_log.LogWarning(ex, "Could not rename {Staged} to {Source}", staged, source);
file.NoticeKey = "notice.original_in_trash";
file.NoticeReasonKey = "trash.cannot_place";
file.NoticeDetail = ex.Message;
- return staged;
+ try
+ {
+ File.Move(staged, output);
+ return output;
+ }
+ catch (Exception again) when (again is IOException or UnauthorizedAccessException)
+ {
+ _log.LogWarning(again, "Could not move {Staged} back to {Output}", staged, output);
+ return staged;
+ }
}
string Kept(Platform.TrashRefusal why, string result)
@@ -1096,6 +1105,18 @@ public sealed class JobQueue : IAsyncDisposable
}
}
+ /// <summary>Extensions that only spell the same kind of file differently ("Replace the original" may swap them).</summary>
+ private static readonly string[][] Spellings =
+ [
+ [".jpg", ".jpeg", ".jpe", ".jfif"], [".tiff", ".tif"], [".html", ".htm"], [".md", ".markdown"], [".yaml", ".yml"],
+ [".mpg", ".mpeg"], [".wav", ".wave"], [".aiff", ".aif"], [".ogg", ".oga"], [".3gp", ".3gpp"], [".m2ts", ".mts"],
+ [".mov", ".qt"], [".tex", ".latex"],
+ ];
+
+ private static bool SameKindOfFile(string a, string b) =>
+ string.Equals(a, b, StringComparison.OrdinalIgnoreCase)
+ || Spellings.Any(s => s.Contains(a, StringComparer.OrdinalIgnoreCase) && s.Contains(b, StringComparer.OrdinalIgnoreCase));
+
/// <summary>Lets go of <paramref name="path"/> (under the lock): free once nobody holds it.</summary>
private void Unreserve(string path)
{
diff --git a/tests/Filee.Core.Tests/ReplaceOriginalTests.cs b/tests/Filee.Core.Tests/ReplaceOriginalTests.cs
index 8826daac..e7ed8627 100644
--- a/tests/Filee.Core.Tests/ReplaceOriginalTests.cs
+++ b/tests/Filee.Core.Tests/ReplaceOriginalTests.cs
@@ -199,6 +199,29 @@ public class ReplaceOriginalTests
Assert.Equal([Path.Combine(dir.Path, "run.txt")], job.Outputs);
}
+ [Fact]
+ public async Task Another_kind_of_file_in_the_same_format_is_not_replaced_but_another_spelling_is()
+ {
+ using var dir = new TempDir();
+ using var bin = new TempDir();
+ var show = dir.File("talk.pps");
+ var trash = new FakeTrash(bin.Path);
+ await using (var queue = new JobQueue(new ConverterCatalog([new FakeConverter("office", new ConversionEdge("ppt", "ppt"))]), moveToTrash: trash.Move))
+ {
+ var job = new ConversionJob([show], new Preset { TargetFormat = "ppt", Output = { ReplaceOriginal = true } }, "Test");
+ await queue.RunAsync(job);
+ Assert.Equal([Path.Combine(dir.Path, "talk.ppt")], job.Outputs);
+ }
+ Assert.Empty(trash.Moved);
+ Assert.Equal("x", File.ReadAllText(show));
+
+ var photo = dir.File("photo.jpeg");
+ var replaced = await Run(trash, photo, new Preset { TargetFormat = "jpg", Output = { ReplaceOriginal = true } });
+
+ Assert.Equal([photo], trash.Moved);
+ Assert.Equal([photo], replaced.Outputs);
+ }
+
[Fact]
public async Task Only_if_smaller_leaves_an_unchanged_original_alone()
{