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.

Read C, C++ and C# source files as plain text (#864, #828)

KnifeLemon39318ed2554a
diff --git a/docs/ENGINES.md b/docs/ENGINES.md
index 68b044e4..57dd00fe 100644
--- a/docs/ENGINES.md
+++ b/docs/ENGINES.md
@@ -12,7 +12,7 @@ Filee chooses engines automatically. Settings → *Engines* shows their status,
| PDFsharp | built in (library) | images → PDF, merge, split, page ranges, page organising, lossless rotate and crop-box edits, spreadsheet print-studio assembly, **compression** (smaller PDFs, see below), PDFs without their metadata |
| PDFium | built in (library) | PDF → images (multi-page TIFF/GIF supported) |
| Unhwp | built in (library) | HWP/HWPX → TXT, Markdown, HTML (pictures in a `<name>_files` folder next to the Markdown, embedded in the HTML) |
-| Text & Markdown (Markdig) | built in (library) | **Markdown → HTML, TXT**; **TXT, LOG, PY, PAC, BAT, CMD, COMMAND, LUA, CSS, PS1, SQL, AHK, INI, RSC → UTF-8 TXT**, preserving source text without running scripts (and → PDF / DOCX through the HWPX writer, rhwp or LibreOffice) |
+| Text & Markdown (Markdig) | built in (library) | **Markdown → HTML, TXT**; **TXT, LOG, PY, PAC, BAT, CMD, COMMAND, LUA, CSS, PS1, SQL, AHK, INI, RSC, C, H, CPP, CC, CXX, HPP, HH, HXX, CS → UTF-8 TXT**, preserving source text without running scripts (and → PDF / DOCX through the HWPX writer, rhwp or LibreOffice) |
| Spreadsheets (ExcelDataReader for XLS) | built in (library) | **XLSX, XLS, ODS, CSV, TSV → XLSX, ODS, CSV, TSV** (one CSV / TSV per sheet) |
| Office Open XML | built in | **DOCM / DOTX / DOTM ↔ DOCX, XLSM / XLTX ↔ XLSX, PPTM / POTX / POTM / PPSX ↔ PPTX** (macros removed for macro-free types) |
| Fonts | built in | **TTF, OTF, WOFF, WOFF2, EOT ↔ each other**; **FON (NE monochrome FNT v2/v3, supported single-byte charsets) → TTF, OTF, WOFF, WOFF2, EOT only**; CFF (PostScript) outlines become TrueType for TTF and EOT |
diff --git a/src/Filee.Core/Formats/FormatRegistry.cs b/src/Filee.Core/Formats/FormatRegistry.cs
index 41bb022d..d797260a 100644
--- a/src/Filee.Core/Formats/FormatRegistry.cs
+++ b/src/Filee.Core/Formats/FormatRegistry.cs
@@ -141,10 +141,11 @@ public static class FormatRegistry
new("sda", "SDA", FormatCategory.Presentation, ["sda", "sdd"], Writable: false),
// Plain text / markup
- // Text logs, source/proxy scripts, style sheets and settings files are read as plain text, never executed (issues
- // #273, #284, #254, #388, #368, #607, #536, #630, #661, #660).
+ // Text logs, source code, proxy scripts, style sheets and settings files are read as plain text, never executed or
+ // compiled (issues #273, #284, #254, #388, #368, #607, #536, #630, #661, #660, #864, #828).
new("txt", "TXT", FormatCategory.Text,
- ["txt", "log", "py", "pac", "bat", "cmd", "command", "lua", "css", "ps1", "sql", "ahk", "ini", "rsc"]),
+ ["txt", "log", "py", "pac", "bat", "cmd", "command", "lua", "css", "ps1", "sql", "ahk", "ini", "rsc",
+ "c", "h", "cpp", "cc", "cxx", "hpp", "hh", "hxx", "cs"]),
new("md", "Markdown", FormatCategory.Text, ["md", "markdown"]),
new("html", "HTML", FormatCategory.Text, ["html", "htm", "xhtml"]),
// A web page saved with its pictures in one MIME file (Chrome, Edge, Word); read as the page it holds.
diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.cs
index 45db4a43..f200e3fb 100644
--- a/src/Filee.Core/Settings/AppSettings.cs
+++ b/src/Filee.Core/Settings/AppSettings.cs
@@ -123,7 +123,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 = 57;
+ public const int CurrentSchemaVersion = 58;
public int SchemaVersion { get; set; } = CurrentSchemaVersion;
diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.cs
index 23b47ec9..6f13384c 100644
--- a/src/Filee.Core/Settings/UserDataStore.cs
+++ b/src/Filee.Core/Settings/UserDataStore.cs
@@ -951,6 +951,10 @@ internal static class SettingsMigrations
// v57: "Caption" preset (Whisper AI) outputs SRT directly; added to Video and Audio donut profiles
if (from < 57)
changed |= AddCaptionPreset(presets, profiles);
+ // v58: C, C++ and C# source files (#864, #828) learn the text donut; custom claims stay put. (Schema 58 may be
+ // renumbered if another change takes it first.)
+ if (from < 58)
+ changed |= LearnExtensions(profiles, out _, ["c", "h", "cpp", "cc", "cxx", "hpp", "hh", "hxx", "cs"]);
return changed;
}
diff --git a/tests/Filee.Core.Tests/ScriptTextTests.cs b/tests/Filee.Core.Tests/ScriptTextTests.cs
index 7f730314..df50b27c 100644
--- a/tests/Filee.Core.Tests/ScriptTextTests.cs
+++ b/tests/Filee.Core.Tests/ScriptTextTests.cs
@@ -1,5 +1,6 @@
-// Lua, PowerShell, AutoHotkey and batch scripts, SQL, INI files, RouterOS exports and CSS style sheets are plain text
-// (issues #388, #368, #442, #607, #536, #630, #661, #660): recognised, and learnt by existing text donuts.
+// Lua, PowerShell, AutoHotkey and batch scripts, SQL, INI files, RouterOS exports, CSS style sheets and C, C++ and C#
+// source files are plain text (issues #388, #368, #442, #607, #536, #630, #661, #660, #864, #828): recognised, and
+// learnt by existing text donuts.
using Filee.Core.Formats;
using Filee.Core.Presets;
@@ -19,6 +20,15 @@ public class ScriptTextTests
[InlineData("router-export.rsc")]
[InlineData("install.cmd")]
[InlineData("query.sql")]
+ [InlineData("main.c")]
+ [InlineData("stdio.h")]
+ [InlineData("Widget.CPP")]
+ [InlineData("parser.cc")]
+ [InlineData("parser.cxx")]
+ [InlineData("vector.hpp")]
+ [InlineData("vector.hh")]
+ [InlineData("vector.hxx")]
+ [InlineData("MyBot.cs")]
public void Scripts_and_style_sheets_are_text(string name) => Assert.Equal("txt", FormatRegistry.Detect(name)?.Id);
[Fact]
@@ -69,4 +79,22 @@ public class ScriptTextTests
Assert.DoesNotContain("rsc", text); // the user's own donut has it
Assert.False(SettingsMigrations.ApplyToLibrary(48, presets, profiles));
}
+
+ [Fact]
+ public void Version_57_text_donuts_learn_c_cpp_and_cs_without_taking_custom_claims()
+ {
+ string[] added = ["c", "h", "cpp", "cc", "cxx", "hpp", "hh", "hxx", "cs"];
+ var presets = BuiltInData.CreatePresets();
+ var profiles = BuiltInData.CreateProfiles();
+ foreach (var profile in profiles)
+ profile.Extensions.RemoveAll(added.Contains);
+ profiles.Insert(0, new ToolbarProfile { Id = "my-trading", Name = "cTrader", Extensions = ["cs"] });
+
+ Assert.True(SettingsMigrations.ApplyToLibrary(57, presets, profiles));
+
+ var text = profiles.Single(p => p.Id == "text").Extensions;
+ Assert.All(added.Where(e => e != "cs"), e => Assert.Contains(e, text));
+ Assert.DoesNotContain("cs", text); // the user's own donut has it
+ Assert.False(SettingsMigrations.ApplyToLibrary(57, presets, profiles));
+ }
}