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.

Use FFmpeg, calibre, Pandoc, Ghostscript or LibreOffice already on the PC, and say when one is old

KnifeLemonab2c6ebe6a2b
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index d404f070..360979d3 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -366,6 +366,8 @@
"engines.remove": "Remove",
"engines.remove_confirm": "Remove {0}? You can download it again later.",
"engines.state.own_copy": "Your copy",
+ "engines.state.system_copy": "Found on this PC",
+ "engines.update_recommended": "Update recommended: this copy is {0}, Filee is tested with {1}. Most conversions still work.",
"engines.use_own": "Use my copy…",
"engines.use_own_hint": "Already have it? Pick its program and Filee uses that instead of downloading its own.",
"engines.use_own_title": "Choose the program of your {0}",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 74a41030..5438cc68 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -366,6 +366,8 @@
"engines.remove": "제거",
"engines.remove_confirm": "{0}을(를) 제거할까요? 나중에 다시 내려받을 수 있어요.",
"engines.state.own_copy": "내 프로그램 사용 중",
+ "engines.state.system_copy": "PC에 있는 프로그램 사용 중",
+ "engines.update_recommended": "업데이트 권장: 이 프로그램은 {0} 버전이고 Filee는 {1} 버전으로 테스트했어요. 대부분의 변환은 그대로 돼요.",
"engines.use_own": "내 프로그램 쓰기…",
"engines.use_own_hint": "이미 설치해 둔 게 있다면 실행 파일을 고르세요. Filee가 따로 내려받지 않고 그걸 써요.",
"engines.use_own_title": "{0} 실행 파일 고르기",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index c8d9f66b..3264c821 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -366,6 +366,8 @@
"engines.remove": "删除",
"engines.remove_confirm": "删除 {0}?以后可以重新下载。",
"engines.state.own_copy": "使用你的副本",
+ "engines.state.system_copy": "使用电脑上已有的程序",
+ "engines.update_recommended": "建议更新:此程序为 {0} 版,Filee 使用 {1} 版测试。大多数转换仍可正常进行。",
"engines.use_own": "使用我的程序…",
"engines.use_own_hint": "已经装过了?选择它的程序,Filee 就直接使用,不再另外下载。",
"engines.use_own_title": "选择 {0} 的程序",
diff --git a/src/Filee.App/Services/EngineDownloadService.cs b/src/Filee.App/Services/EngineDownloadService.cs
index aad044d3..a2b85e07 100644
--- a/src/Filee.App/Services/EngineDownloadService.cs
+++ b/src/Filee.App/Services/EngineDownloadService.cs
@@ -2,6 +2,7 @@
// refresh when an engine appears or disappears so donut slices and routes update immediately.
using System.Diagnostics;
+using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using Filee.Core.Conversion;
using Filee.Core.Localization;
@@ -19,7 +20,7 @@ public enum EnginePackageStatus
Unpacking,
Installed,
Failed,
- /// <summary>The user's own copy is used (Settings → Engines), nothing downloaded.</summary>
+ /// <summary>The user's own copy (Settings → Engines) or one found on the PC is used, nothing downloaded.</summary>
OwnCopy,
}
@@ -43,13 +44,22 @@ public sealed partial class EnginePackageState : ObservableObject
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StatusText), nameof(IsInstalled), nameof(IsBusy), nameof(CanInstall), nameof(CanRemove),
- nameof(UsesOwnCopy), nameof(CanUseOwnCopy))]
+ nameof(UsesOwnCopy), nameof(CanUseOwnCopy), nameof(ShowsCopyFolder))]
private EnginePackageStatus _status;
- /// <summary>Folder of the user's own copy while <see cref="UsesOwnCopy"/>.</summary>
+ /// <summary>Folder of the copy in use while the status is <see cref="EnginePackageStatus.OwnCopy"/>.</summary>
[ObservableProperty]
private string? _ownCopyFolder;
+ /// <summary>The copy in use was found on the PC (PATH, Program Files), not chosen by the user.</summary>
+ [ObservableProperty]
+ [NotifyPropertyChangedFor(nameof(StatusText), nameof(CanInstall), nameof(UsesOwnCopy), nameof(CanUseOwnCopy))]
+ private bool _fromSystem;
+
+ /// <summary>"Update recommended: 7.1 here, Filee is tested with 9.0" for an older copy, else null.</summary>
+ [ObservableProperty]
+ private string? _updateNote;
+
/// <summary>0..100 while downloading or unpacking.</summary>
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(StatusText))]
@@ -70,10 +80,15 @@ public sealed partial class EnginePackageState : ObservableObject
/// <summary>The engine is there: Filee's download or the user's own copy.</summary>
public bool IsInstalled => Status is EnginePackageStatus.Installed or EnginePackageStatus.OwnCopy;
public bool CanRemove => Status == EnginePackageStatus.Installed;
- public bool UsesOwnCopy => Status == EnginePackageStatus.OwnCopy;
- public bool CanUseOwnCopy => Status is EnginePackageStatus.NotInstalled or EnginePackageStatus.Failed or EnginePackageStatus.Installed;
+ /// <summary>The user chose this copy ("Stop using it" applies).</summary>
+ public bool UsesOwnCopy => Status == EnginePackageStatus.OwnCopy && !FromSystem;
+ public bool ShowsCopyFolder => Status == EnginePackageStatus.OwnCopy;
+ public bool CanUseOwnCopy => Status is EnginePackageStatus.NotInstalled or EnginePackageStatus.Failed or EnginePackageStatus.Installed
+ || (Status == EnginePackageStatus.OwnCopy && FromSystem);
public bool IsBusy => Status is EnginePackageStatus.Queued or EnginePackageStatus.Downloading or EnginePackageStatus.Unpacking;
- public bool CanInstall => Status is EnginePackageStatus.NotInstalled or EnginePackageStatus.Failed;
+ /// <summary>Also when a copy on the PC is used: Filee's download is the tested version and wins once installed.</summary>
+ public bool CanInstall => Status is EnginePackageStatus.NotInstalled or EnginePackageStatus.Failed
+ || (Status == EnginePackageStatus.OwnCopy && FromSystem);
public string StatusText => Status switch
{
@@ -81,7 +96,7 @@ public sealed partial class EnginePackageState : ObservableObject
EnginePackageStatus.Downloading => _loc.Format("engines.state.downloading", (int)Progress),
EnginePackageStatus.Unpacking => _loc["engines.state.unpacking"],
EnginePackageStatus.Installed => _loc["engines.state.installed"],
- EnginePackageStatus.OwnCopy => _loc["engines.state.own_copy"],
+ EnginePackageStatus.OwnCopy => _loc[FromSystem ? "engines.state.system_copy" : "engines.state.own_copy"],
EnginePackageStatus.Failed => _loc.Format("engines.state.failed", Error ?? ""),
_ => _loc["engines.state.not_installed"],
};
@@ -122,6 +137,7 @@ public sealed partial class EnginePackageState : ObservableObject
public sealed class EngineDownloadService
{
+ private readonly ILocalizer _loc;
private readonly EngineInstaller _installer;
private readonly ConverterCatalog _catalog;
private readonly ILogger<EngineDownloadService> _logger;
@@ -132,6 +148,7 @@ public sealed class EngineDownloadService
{
_catalog = catalog;
_logger = logger;
+ _loc = loc;
// Redirects are followed by the installer (mirrors may use plain HTTP; files are verified by SHA-256).
var http = new HttpClient(new SocketsHttpHandler { AllowAutoRedirect = false }) { Timeout = Timeout.InfiniteTimeSpan };
http.DefaultRequestHeaders.UserAgent.ParseAdd($"Filee/{typeof(EngineDownloadService).Assembly.GetName().Version}");
@@ -154,15 +171,36 @@ public sealed class EngineDownloadService
state.Status = StatusOf(state);
}
- /// <summary>The user's own copy wins over Filee's download, as in the engines (EngineEnvironment.OwnCopies).</summary>
+ /// <summary>
+ /// In the order the engines look: the user's own copy, Filee's download, a copy on the PC. A copy Filee didn't
+ /// download gets its version checked in the background (<see cref="EnginePackageState.UpdateNote"/>).
+ /// </summary>
private EnginePackageStatus StatusOf(EnginePackageState state)
{
- state.OwnCopyFolder = EngineEnvironment.OwnCopyFolder(state.Package.Id);
+ var id = state.Package.Id;
+ var own = EngineEnvironment.OwnCopyFolder(id);
+ var system = own is null && !_installer.IsInstalled(state.Package) ? EngineEnvironment.SystemCopyFolder(id) : null;
+ state.OwnCopyFolder = own ?? system;
+ state.FromSystem = system is not null;
+ state.UpdateNote = null;
+ if (state.OwnCopyFolder is { } folder)
+ _ = CheckVersionAsync(state, folder);
return state.OwnCopyFolder is not null ? EnginePackageStatus.OwnCopy
: _installer.IsInstalled(state.Package) ? EnginePackageStatus.Installed
: EnginePackageStatus.NotInstalled;
}
+ /// <summary>Runs the copy's version check off the UI thread (it starts the program once) and notes an old one.</summary>
+ private async Task CheckVersionAsync(EnginePackageState state, string folder)
+ {
+ var id = state.Package.Id;
+ var (installed, expected) = await Task.Run(() => (CopyVersions.Installed(id, folder), CopyVersions.Expected(id)));
+ if (installed is null || expected is null || installed >= expected || state.OwnCopyFolder != folder)
+ return;
+ await Dispatcher.UIThread.InvokeAsync(() =>
+ state.UpdateNote = _loc.Format("engines.update_recommended", installed.ToString(2), expected.ToString(2)));
+ }
+
/// <summary>Downloads and installs a package; packages queue up and install one after another.</summary>
public async Task InstallAsync(EnginePackageState state)
{
diff --git a/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs b/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs
index af9eec22..eae6fbda 100644
--- a/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs
+++ b/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs
@@ -111,6 +111,7 @@ public sealed partial class EnginesPageViewModel : ObservableObject, IDisposable
[RelayCommand]
private void Recheck()
{
+ EngineEnvironment.ForgetSystemCopies(); // a tool installed meanwhile is found
_downloads.RefreshStatus();
_catalog.Refresh();
}
diff --git a/src/Filee.App/Views/Pages/EnginesPage.axaml b/src/Filee.App/Views/Pages/EnginesPage.axaml
index e9cc8cd0..461bca92 100644
--- a/src/Filee.App/Views/Pages/EnginesPage.axaml
+++ b/src/Filee.App/Views/Pages/EnginesPage.axaml
@@ -53,7 +53,9 @@
</StackPanel>
<TextBlock Classes="caption" TextWrapping="Wrap" Text="{Binding Description}" />
<TextBlock Classes="caption" Text="{Binding Sizes}" IsVisible="{Binding !UsesOwnCopy}" />
- <TextBlock Classes="caption" Text="{Binding OwnCopyFolder}" IsVisible="{Binding UsesOwnCopy}" TextTrimming="CharacterEllipsis" />
+ <TextBlock Classes="caption" Text="{Binding OwnCopyFolder}" IsVisible="{Binding ShowsCopyFolder}" TextTrimming="CharacterEllipsis" />
+ <TextBlock Classes="caption" Foreground="{DynamicResource WarningBrush}" TextWrapping="Wrap" Text="{Binding UpdateNote}"
+ IsVisible="{Binding UpdateNote, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
<ProgressBar Classes="soft" Maximum="100" Value="{Binding Progress}" IsVisible="{Binding IsBusy}" Margin="0,4,0,0" />
<TextBlock Classes="caption" Text="{Binding ProgressDetail}" IsVisible="{Binding ProgressDetail, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
</StackPanel>
diff --git a/src/Filee.Engines/Ebooks/CalibreConverter.cs b/src/Filee.Engines/Ebooks/CalibreConverter.cs
index 2398e8e0..2afb5e94 100644
--- a/src/Filee.Engines/Ebooks/CalibreConverter.cs
+++ b/src/Filee.Engines/Ebooks/CalibreConverter.cs
@@ -41,7 +41,7 @@ public sealed partial class CalibreConverter : IConverter
public EngineStatus GetStatus()
{
_executable = Locate();
- return _executable is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_executable, EngineEnvironment.OwnCopyFolder("calibre") is null ? EngineVersions.Component("calibre") : null);
+ return _executable is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_executable, EngineEnvironment.UsesFileesCopy("calibre") ? EngineVersions.Component("calibre") : null);
}
public async Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)
@@ -101,10 +101,11 @@ public sealed partial class CalibreConverter : IConverter
/// <summary>
/// The user's own calibre when they chose one in Settings → Engines, else Filee's (engines/calibre, downloaded on
- /// demand). A calibre installed on the system is never looked for.
+ /// demand), else a calibre already on the PC.
/// </summary>
internal static string? Locate() =>
- EngineEnvironment.OwnProgram("calibre", "ebook-convert.exe") ?? LocateBundled();
+ EngineEnvironment.OwnProgram("calibre", "ebook-convert.exe") ?? LocateBundled()
+ ?? EngineEnvironment.SystemProgram("calibre", "ebook-convert.exe");
private static string? LocateBundled() =>
OperatingSystem.IsWindows() && EngineEnvironment.FindBundled("calibre") is { } folder
diff --git a/src/Filee.Engines/Infrastructure/CopyVersions.cs b/src/Filee.Engines/Infrastructure/CopyVersions.cs
new file mode 100644
index 00000000..0b211c60
--- /dev/null
+++ b/src/Filee.Engines/Infrastructure/CopyVersions.cs
@@ -0,0 +1,104 @@
+// Versions of engine copies Filee didn't download (the user's own, or one found on the PC), compared with the version
+// Filee is tested with (engines.json). An older copy still works for most conversions; the Engines page only says
+// that an update is recommended.
+
+using System.Collections.Concurrent;
+using System.Diagnostics;
+using System.Text.RegularExpressions;
+
+namespace Filee.Engines.Infrastructure;
+
+public static partial class CopyVersions
+{
+ private static readonly ConcurrentDictionary<string, Version?> Cache = new();
+
+ /// <summary>The version Filee is tested with ("9.0"), from engines.json; null for unknown packages.</summary>
+ public static Version? Expected(string id) => Parse(EngineVersions.Component(id));
+
+ /// <summary>
+ /// The version of the copy in <paramref name="folder"/> (major.minor), or null when it can't be told (e.g. an
+ /// FFmpeg git build named by date). Cached per program and file time.
+ /// </summary>
+ public static Version? Installed(string id, string folder)
+ {
+ var program = id switch
+ {
+ "libreoffice" => Path.Combine(folder, "version.ini"),
+ _ when EngineEnvironment.OwnCopyPrograms.TryGetValue(id, out var programs) => Path.Combine(folder, programs[0]),
+ _ => null,
+ };
+ if (program is null || !File.Exists(program))
+ return null;
+ return Cache.GetOrAdd($"{program}|{File.GetLastWriteTimeUtc(program).Ticks}", _ => ParseVersion(id, Read(id, program)));
+ }
+
+ /// <summary>True when the copy is older (major.minor) than the version Filee is tested with.</summary>
+ public static bool IsOutdated(string id, string folder) =>
+ Installed(id, folder) is { } installed && Expected(id) is { } expected && installed < expected;
+
+ /// <summary>The version in a program's version output (or LibreOffice's version.ini).</summary>
+ internal static Version? ParseVersion(string id, string text)
+ {
+ var match = id switch
+ {
+ "ffmpeg" => FfmpegVersion().Match(text),
+ "pandoc" => PandocVersion().Match(text),
+ "calibre" => CalibreVersion().Match(text),
+ "libreoffice" => LibreOfficeVersion().Match(text),
+ _ => LeadingVersion().Match(text),
+ };
+ return match.Success ? new Version(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value)) : null;
+ }
+
+ private static Version? Parse(string? text)
+ {
+ var match = LeadingVersion().Match(text ?? "");
+ return match.Success ? new Version(int.Parse(match.Groups[1].Value), int.Parse(match.Groups[2].Value)) : null;
+ }
+
+ private static string Read(string id, string program)
+ {
+ if (id == "libreoffice")
+ return File.ReadAllText(program);
+ var arguments = id == "ffmpeg" ? "-hide_banner -version" : "--version";
+ try
+ {
+ using var process = Process.Start(new ProcessStartInfo(program, arguments)
+ {
+ UseShellExecute = false,
+ CreateNoWindow = true,
+ RedirectStandardOutput = true,
+ RedirectStandardError = true,
+ });
+ if (process is null)
+ return "";
+ var output = process.StandardOutput.ReadToEndAsync();
+ var errors = process.StandardError.ReadToEndAsync();
+ if (!process.WaitForExit(10_000))
+ {
+ process.Kill(entireProcessTree: true);
+ return "";
+ }
+ return output.Result + "\n" + errors.Result;
+ }
+ catch (Exception ex) when (ex is System.ComponentModel.Win32Exception or InvalidOperationException or IOException)
+ {
+ return "";
+ }
+ }
+
+ [GeneratedRegex(@"ffmpeg version n?(\d+)\.(\d+)")]
+ private static partial Regex FfmpegVersion();
+
+ [GeneratedRegex(@"^pandoc(?:\.exe)? (\d+)\.(\d+)", RegexOptions.Multiline)]
+ private static partial Regex PandocVersion();
+
+ [GeneratedRegex(@"calibre (\d+)\.(\d+)")]
+ private static partial Regex CalibreVersion();
+
+ [GeneratedRegex(@"MsiProductVersion=(\d+)\.(\d+)")]
+ private static partial Regex LibreOfficeVersion();
+
+ [GeneratedRegex(@"^\s*(\d+)\.(\d+)", RegexOptions.Multiline)]
+ private static partial Regex LeadingVersion();
+}
diff --git a/src/Filee.Engines/Infrastructure/EngineEnvironment.cs b/src/Filee.Engines/Infrastructure/EngineEnvironment.cs
index e06adee1..1ed4ada6 100644
--- a/src/Filee.Engines/Infrastructure/EngineEnvironment.cs
+++ b/src/Filee.Engines/Infrastructure/EngineEnvironment.cs
@@ -1,8 +1,10 @@
// Shared context for engines: where Filee's own engine copies live and where engines keep their state.
-// Engines never look for software installed on the system (Office, a system-wide LibreOffice, tools on the PATH):
-// they use the copies that ship with the installer or that Filee downloaded, so every user gets the same, tested
-// versions. The one exception is a copy the user points Filee to in Settings → Engines (OwnCopies), so nobody has
-// to download a second FFmpeg or calibre they already have.
+// Built-in engines never use software installed on the system (Microsoft Office, Hancom Office). The optional
+// engines (FFmpeg, calibre, Pandoc, Ghostscript, LibreOffice) are looked up in this order: a copy the user chose in
+// Settings → Engines (OwnCopies), Filee's own copy (installer or download, the tested version), then one already on
+// the PC (on the PATH or where its installer puts it), so nobody has to download a second FFmpeg they already have.
+
+using System.Collections.Concurrent;
namespace Filee.Engines.Infrastructure;
@@ -87,6 +89,74 @@ public sealed class EngineEnvironment(string dataDirectory)
return null;
}
+ /// <summary>True when package <paramref name="id"/> runs from Filee's own copy (not the user's or the PC's).</summary>
+ public static bool UsesFileesCopy(string id) => OwnCopyFolder(id) is null && FindBundled(id) is not null;
+
+ /// <summary>Searching the PC for engines; tests turn it off so the machine's tools don't change results.</summary>
+ public static bool SearchSystem { get; set; } = true;
+
+ private static readonly ConcurrentDictionary<string, string?> SystemCopies = new();
+
+ /// <summary>
+ /// The folder of a copy of package <paramref name="id"/> already on the PC: on the PATH (also the user's and the
+ /// machine's PATH as saved, so a tool installed after Filee started is found, e.g. Scoop's shims) or where its
+ /// installer puts it (LibreOffice, calibre, Ghostscript under Program Files). Cached until
+ /// <see cref="ForgetSystemCopies"/>.
+ /// </summary>
+ public static string? SystemCopyFolder(string id) =>
+ SearchSystem && OperatingSystem.IsWindows() ? SystemCopies.GetOrAdd(id, FindOnSystem) : null;
+
+ /// <summary>A program of the copy of package <paramref name="id"/> on the PC, or null.</summary>
+ public static string? SystemProgram(string id, string program) =>
+ SystemCopyFolder(id) is { } folder ? Path.Combine(folder, program) : null;
+
+ /// <summary>Searches the PC again (Settings → Engines → Check again, settings changes).</summary>
+ public static void ForgetSystemCopies() => SystemCopies.Clear();
+
+ private static string? FindOnSystem(string id) =>
+ SystemFolders(id).Select(folder => FolderWithPrograms(id, folder)).FirstOrDefault(found => found is not null);
+
+ private static IEnumerable<string> SystemFolders(string id)
+ {
+ var path = string.Join(';',
+ Environment.GetEnvironmentVariable("PATH"),
+ Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.User),
+ Environment.GetEnvironmentVariable("PATH", EnvironmentVariableTarget.Machine));
+ var folders = path.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
+ .Select(entry => Environment.ExpandEnvironmentVariables(entry.Trim('"')))
+ .ToList();
+ foreach (var root in new[] { Environment.SpecialFolder.ProgramFiles, Environment.SpecialFolder.ProgramFilesX86 }
+ .Select(Environment.GetFolderPath).Where(r => r.Length > 0))
+ {
+ switch (id)
+ {
+ case "libreoffice":
+ folders.Add(Path.Combine(root, "LibreOffice", "program"));
+ break;
+ case "calibre":
+ folders.Add(Path.Combine(root, "Calibre2"));
+ break;
+ case "ghostscript":
+ // C:\Program Files\gs\gs10.04.0\bin, newest first
+ try
+ {
+ var gs = Path.Combine(root, "gs");
+ if (Directory.Exists(gs))
+ folders.AddRange(Directory.EnumerateDirectories(gs).OrderByDescending(d => d, StringComparer.OrdinalIgnoreCase)
+ .Select(d => Path.Combine(d, "bin")));
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
+ {
+ }
+ break;
+ }
+ }
+ // Never Filee's own folders: those are its own copy, found before.
+ return folders.Distinct(StringComparer.OrdinalIgnoreCase)
+ .Where(f => !f.StartsWith(DownloadRoot, StringComparison.OrdinalIgnoreCase)
+ && !f.StartsWith(AppContext.BaseDirectory, StringComparison.OrdinalIgnoreCase));
+ }
+
/// <summary>Returns the first path that exists as a file.</summary>
public static string? FirstExisting(params string?[] candidates) =>
candidates.FirstOrDefault(c => !string.IsNullOrWhiteSpace(c) && File.Exists(c));
diff --git a/src/Filee.Engines/Media/FfmpegConverter.cs b/src/Filee.Engines/Media/FfmpegConverter.cs
index a8185bc8..b53309a1 100644
--- a/src/Filee.Engines/Media/FfmpegConverter.cs
+++ b/src/Filee.Engines/Media/FfmpegConverter.cs
@@ -131,7 +131,9 @@ public sealed partial class FfmpegConverter : IConverter
if (EngineEnvironment.OwnCopyFolder("ffmpeg") is { } own)
return (Path.Combine(own, "ffmpeg.exe"), Path.Combine(own, "ffprobe.exe"));
if (EngineEnvironment.FindBundled("ffmpeg") is not { } folder)
- return null;
+ return EngineEnvironment.SystemCopyFolder("ffmpeg") is { } system
+ ? (Path.Combine(system, "ffmpeg.exe"), Path.Combine(system, "ffprobe.exe"))
+ : null;
var suffix = OperatingSystem.IsWindows() ? ".exe" : "";
var ffmpeg = EngineEnvironment.FirstExisting(Path.Combine(folder, "bin", "ffmpeg" + suffix), Path.Combine(folder, "ffmpeg" + suffix));
var ffprobe = EngineEnvironment.FirstExisting(Path.Combine(folder, "bin", "ffprobe" + suffix), Path.Combine(folder, "ffprobe" + suffix));
diff --git a/src/Filee.Engines/Office/LibreOfficeConverter.cs b/src/Filee.Engines/Office/LibreOfficeConverter.cs
index 2a2f1842..581bf282 100644
--- a/src/Filee.Engines/Office/LibreOfficeConverter.cs
+++ b/src/Filee.Engines/Office/LibreOfficeConverter.cs
@@ -71,7 +71,7 @@ public sealed class LibreOfficeConverter : IConverter
Edges = BuildEdges(_hasHwpFilter);
return _soffice is null
? EngineStatus.Unavailable("engine.reason.not_installed")
- : EngineEnvironment.OwnCopyFolder("libreoffice") is not null
+ : !EngineEnvironment.UsesFileesCopy("libreoffice")
? EngineStatus.Available(_soffice, _hasHwpFilter ? "H2Orestart" : null)
: EngineStatus.Available(_soffice, EngineVersions.Component("libreoffice")
+ (_hasHwpFilter ? $" · H2Orestart {EngineVersions.Component("h2orestart")}" : ""));
@@ -266,15 +266,16 @@ public sealed class LibreOfficeConverter : IConverter
}
/// <summary>
- /// The user's own LibreOffice when they chose one in Settings → Engines, else Filee's copy (engines/libreoffice).
- /// A LibreOffice installed on the system is never looked for.
+ /// The user's own LibreOffice when they chose one in Settings → Engines, else Filee's copy (engines/libreoffice),
+ /// else a LibreOffice installed on the PC. Each conversion uses its own profile, so an open LibreOffice is untouched.
/// </summary>
private void Locate()
{
var bundled = EngineEnvironment.FindBundled("libreoffice");
_soffice = EngineEnvironment.OwnProgram("libreoffice", "soffice.exe") ?? (bundled is null ? null : EngineEnvironment.FirstExisting(
Path.Combine(bundled, "program", OperatingSystem.IsWindows() ? "soffice.exe" : "soffice"),
- Path.Combine(bundled, "Contents", "MacOS", "soffice")));
+ Path.Combine(bundled, "Contents", "MacOS", "soffice")))
+ ?? EngineEnvironment.SystemProgram("libreoffice", "soffice.exe");
_hasHwpFilter = _soffice is not null && HasH2Orestart(_soffice);
}
diff --git a/src/Filee.Engines/Office/PandocConverter.cs b/src/Filee.Engines/Office/PandocConverter.cs
index eeaffa25..cc191eea 100644
--- a/src/Filee.Engines/Office/PandocConverter.cs
+++ b/src/Filee.Engines/Office/PandocConverter.cs
@@ -66,7 +66,7 @@ public sealed class PandocConverter : IConverter
public EngineStatus GetStatus()
{
_pandoc = Locate();
- return _pandoc is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_pandoc, EngineEnvironment.OwnCopyFolder("pandoc") is null ? EngineVersions.Component("pandoc") : null);
+ return _pandoc is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_pandoc, EngineEnvironment.UsesFileesCopy("pandoc") ? EngineVersions.Component("pandoc") : null);
}
public async Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)
@@ -95,7 +95,7 @@ public sealed class PandocConverter : IConverter
/// <summary>Filee's own pandoc (engines/pandoc, downloaded on demand), never one found elsewhere on the system.</summary>
internal static string? Locate() =>
- EngineEnvironment.OwnProgram("pandoc", "pandoc.exe") ?? LocateBundled();
+ EngineEnvironment.OwnProgram("pandoc", "pandoc.exe") ?? LocateBundled() ?? EngineEnvironment.SystemProgram("pandoc", "pandoc.exe");
private static string? LocateBundled() =>
EngineEnvironment.FindBundled("pandoc") is { } bundled
diff --git a/src/Filee.Engines/Vector/GhostscriptConverter.cs b/src/Filee.Engines/Vector/GhostscriptConverter.cs
index 33e93da4..fd936109 100644
--- a/src/Filee.Engines/Vector/GhostscriptConverter.cs
+++ b/src/Filee.Engines/Vector/GhostscriptConverter.cs
@@ -41,7 +41,7 @@ public sealed class GhostscriptConverter : IConverter
public EngineStatus GetStatus()
{
_executable = Locate();
- return _executable is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_executable, EngineEnvironment.OwnCopyFolder("ghostscript") is null ? EngineVersions.Component("ghostscript") : null);
+ return _executable is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_executable, EngineEnvironment.UsesFileesCopy("ghostscript") ? EngineVersions.Component("ghostscript") : null);
}
public async Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)
@@ -61,7 +61,8 @@ public sealed class GhostscriptConverter : IConverter
/// <summary>Filee's own Ghostscript (engines/ghostscript, downloaded on demand), never one installed on the system.</summary>
internal static string? Locate() =>
- EngineEnvironment.OwnProgram("ghostscript", "gswin64c.exe") ?? LocateBundled();
+ EngineEnvironment.OwnProgram("ghostscript", "gswin64c.exe") ?? LocateBundled()
+ ?? EngineEnvironment.SystemProgram("ghostscript", "gswin64c.exe");
private static string? LocateBundled() =>
EngineEnvironment.FindBundled("ghostscript") is { } folder
diff --git a/tests/Filee.Engines.Tests/OwnCopyTests.cs b/tests/Filee.Engines.Tests/OwnCopyTests.cs
index 0f922a11..0d8afdaf 100644
--- a/tests/Filee.Engines.Tests/OwnCopyTests.cs
+++ b/tests/Filee.Engines.Tests/OwnCopyTests.cs
@@ -67,3 +67,47 @@ public sealed class OwnCopyTests : IDisposable
/// <summary>Runs alone: while OwnCopies points at fake programs, no other engine test may convert.</summary>
[CollectionDefinition("EngineEnvironment", DisableParallelization = true)]
public sealed class EngineEnvironmentCollection;
+
+[Collection("EngineEnvironment")] // changes PATH and the system-copy cache
+public sealed class SystemCopyTests : IDisposable
+{
+ private readonly string _folder = Directory.CreateTempSubdirectory("filee-path-").FullName;
+ private readonly string? _path = Environment.GetEnvironmentVariable("PATH");
+
+ public void Dispose()
+ {
+ Environment.SetEnvironmentVariable("PATH", _path);
+ EngineEnvironment.ForgetSystemCopies();
+ try { Directory.Delete(_folder, true); } catch (IOException) { }
+ }
+
+ [Fact]
+ public void A_tool_on_the_path_is_found_when_filee_has_no_copy()
+ {
+ if (!OperatingSystem.IsWindows())
+ return;
+ // Like Scoop's shims folder: ffmpeg.exe and ffprobe.exe side by side, on the PATH.
+ File.WriteAllBytes(Path.Combine(_folder, "ffmpeg.exe"), [0x4D, 0x5A]);
+ File.WriteAllBytes(Path.Combine(_folder, "ffprobe.exe"), [0x4D, 0x5A]);
+ Environment.SetEnvironmentVariable("PATH", _folder + ";" + _path);
+ EngineEnvironment.ForgetSystemCopies();
+
+ Assert.Equal(_folder, EngineEnvironment.SystemCopyFolder("ffmpeg"));
+ Assert.Equal(Path.Combine(_folder, "ffmpeg.exe"), EngineEnvironment.SystemProgram("ffmpeg", "ffmpeg.exe"));
+ }
+
+ [Theory]
+ [InlineData("ffmpeg", "ffmpeg version 7.1.1-full_build-www.gyan.dev Copyright (c) 2000-2025", "7.1")]
+ [InlineData("ffmpeg", "ffmpeg version n8.0 Copyright (c) 2000-2025", "8.0")]
+ [InlineData("ffmpeg", "ffmpeg version 2025-06-02-git-688f3944ce-full_build", null)]
+ [InlineData("pandoc", "pandoc.exe 3.6.4\nFeatures: +server +lua", "3.6")]
+ [InlineData("calibre", "ebook-convert.exe (calibre 8.5.0)\nCreated by: Kovid Goyal", "8.5")]
+ [InlineData("ghostscript", "10.04.0\r\n", "10.4")]
+ [InlineData("libreoffice", "[Version]\nAllLanguages=en-US\nMsiProductVersion=25.2.4.3\n", "25.2")]
+ public void Versions_are_read_from_each_program(string id, string output, string? expected) =>
+ Assert.Equal(expected is null ? null : Version.Parse(expected), CopyVersions.ParseVersion(id, output));
+
+ [Fact]
+ public void Expected_versions_come_from_engines_json() =>
+ Assert.NotNull(CopyVersions.Expected("ffmpeg"));
+}