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
Use your own FFmpeg, calibre, Pandoc, Ghostscript or LibreOffice instead of downloading Filee's
KnifeLemon38ad808ac757
diff --git a/src/Filee.App/App.axaml.cs b/src/Filee.App/App.axaml.csindex c5391aa8..70387e44 100644--- a/src/Filee.App/App.axaml.cs+++ b/src/Filee.App/App.axaml.cs@@ -11,6 +11,7 @@ using Filee.Core.Conversion;using Filee.Core.Localization;using Filee.Core.Platform;using Filee.Core.Settings;+using Filee.Engines.Infrastructure;using Microsoft.Extensions.Logging;namespace Filee.App;@@ -106,6 +107,11 @@ public partial class App : Application/// <summary>Applies everything derived from settings. Called at start-up and whenever settings are saved.</summary>private static void ApplySettings(AppSettings settings){+ // Before the catalog is created (the first time) or re-checked: engines look for the user's own copies first.+ var ownCopiesChanged = !EngineEnvironment.OwnCopies.OrderBy(p => p.Key).SequenceEqual(settings.EngineOwnCopies.OrderBy(p => p.Key));+ if (ownCopiesChanged)+ EngineEnvironment.OwnCopies = new Dictionary<string, string>(settings.EngineOwnCopies);+var loc = AppHost.Get<LocalizationService>();if (loc.NeedsUpdate(settings.Language))loc.SetLanguage(settings.Language);@@ -113,6 +119,11 @@ public partial class App : ApplicationAppHost.Get<ThemeService>().Apply(settings.Theme, loc.Language);AppHost.Get<TriggerService>().Apply(settings);AppHost.Get<ConverterCatalog>().Priority = settings.EnginePriority;+ if (ownCopiesChanged)+ {+ AppHost.Get<ConverterCatalog>().Refresh();+ AppHost.Get<EngineDownloadService>().RefreshStatus();+ }ApplySystemIntegration(settings, loc);}diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.jsonindex 1cead98b..d404f070 100644--- a/src/Filee.App/Assets/i18n/en.json+++ b/src/Filee.App/Assets/i18n/en.json@@ -365,6 +365,12 @@"engines.cancel": "Cancel","engines.remove": "Remove","engines.remove_confirm": "Remove {0}? You can download it again later.",+ "engines.state.own_copy": "Your copy",+ "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}",+ "engines.use_own_missing": "That folder doesn't have everything Filee needs: {0}.",+ "engines.stop_own": "Stop using it","engines.remove_failed": "The engine is in use. Try again after the running conversions have finished.","engines.state.not_installed": "Not installed","engines.state.queued": "Waiting…",diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.jsonindex e1cdce4f..74a41030 100644--- a/src/Filee.App/Assets/i18n/ko.json+++ b/src/Filee.App/Assets/i18n/ko.json@@ -365,6 +365,12 @@"engines.cancel": "취소","engines.remove": "제거","engines.remove_confirm": "{0}을(를) 제거할까요? 나중에 다시 내려받을 수 있어요.",+ "engines.state.own_copy": "내 프로그램 사용 중",+ "engines.use_own": "내 프로그램 쓰기…",+ "engines.use_own_hint": "이미 설치해 둔 게 있다면 실행 파일을 고르세요. Filee가 따로 내려받지 않고 그걸 써요.",+ "engines.use_own_title": "{0} 실행 파일 고르기",+ "engines.use_own_missing": "그 폴더에 Filee에 필요한 파일이 다 있지 않아요: {0}",+ "engines.stop_own": "그만 쓰기","engines.remove_failed": "엔진이 사용 중이에요. 진행 중인 변환이 끝나면 다시 해 보세요.","engines.state.not_installed": "설치 안 됨","engines.state.queued": "대기 중…",diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.jsonindex 0d576873..c8d9f66b 100644--- a/src/Filee.App/Assets/i18n/zh-CN.json+++ b/src/Filee.App/Assets/i18n/zh-CN.json@@ -365,6 +365,12 @@"engines.cancel": "取消","engines.remove": "删除","engines.remove_confirm": "删除 {0}?以后可以重新下载。",+ "engines.state.own_copy": "使用你的副本",+ "engines.use_own": "使用我的程序…",+ "engines.use_own_hint": "已经装过了?选择它的程序,Filee 就直接使用,不再另外下载。",+ "engines.use_own_title": "选择 {0} 的程序",+ "engines.use_own_missing": "该文件夹缺少 Filee 需要的文件:{0}。",+ "engines.stop_own": "停止使用","engines.remove_failed": "引擎正在使用中。请在当前转换完成后重试。","engines.state.not_installed": "未安装","engines.state.queued": "等待中…",diff --git a/src/Filee.App/Services/EngineDownloadService.cs b/src/Filee.App/Services/EngineDownloadService.csindex 39982c9e..aad044d3 100644--- a/src/Filee.App/Services/EngineDownloadService.cs+++ b/src/Filee.App/Services/EngineDownloadService.cs@@ -19,6 +19,8 @@ public enum EnginePackageStatusUnpacking,Installed,Failed,+ /// <summary>The user's own copy is used (Settings → Engines), nothing downloaded.</summary>+ OwnCopy,}/// <summary>Install state of one optional engine package, bound by the Engines page and the first-run setup.</summary>@@ -40,9 +42,14 @@ public sealed partial class EnginePackageState : ObservableObjectFormatBytes(EngineDownloads.DownloadSize(Package)), FormatBytes(Package.InstalledSize));[ObservableProperty]- [NotifyPropertyChangedFor(nameof(StatusText), nameof(IsInstalled), nameof(IsBusy), nameof(CanInstall))]+ [NotifyPropertyChangedFor(nameof(StatusText), nameof(IsInstalled), nameof(IsBusy), nameof(CanInstall), nameof(CanRemove),+ nameof(UsesOwnCopy), nameof(CanUseOwnCopy))]private EnginePackageStatus _status;+ /// <summary>Folder of the user's own copy while <see cref="UsesOwnCopy"/>.</summary>+ [ObservableProperty]+ private string? _ownCopyFolder;+/// <summary>0..100 while downloading or unpacking.</summary>[ObservableProperty][NotifyPropertyChangedFor(nameof(StatusText))]@@ -60,7 +67,11 @@ public sealed partial class EnginePackageState : ObservableObject[ObservableProperty]private bool _selected;- public bool IsInstalled => Status == EnginePackageStatus.Installed;+ /// <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;public bool IsBusy => Status is EnginePackageStatus.Queued or EnginePackageStatus.Downloading or EnginePackageStatus.Unpacking;public bool CanInstall => Status is EnginePackageStatus.NotInstalled or EnginePackageStatus.Failed;@@ -70,6 +81,7 @@ public sealed partial class EnginePackageState : ObservableObjectEnginePackageStatus.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.Failed => _loc.Format("engines.state.failed", Error ?? ""),_ => _loc["engines.state.not_installed"],};@@ -139,7 +151,16 @@ public sealed class EngineDownloadServicepublic void RefreshStatus(){foreach (var state in Packages.Where(p => !p.IsBusy))- state.Status = _installer.IsInstalled(state.Package) ? EnginePackageStatus.Installed : EnginePackageStatus.NotInstalled;+ state.Status = StatusOf(state);+ }++ /// <summary>The user's own copy wins over Filee's download, as in the engines (EngineEnvironment.OwnCopies).</summary>+ private EnginePackageStatus StatusOf(EnginePackageState state)+ {+ state.OwnCopyFolder = EngineEnvironment.OwnCopyFolder(state.Package.Id);+ return state.OwnCopyFolder is not null ? EnginePackageStatus.OwnCopy+ : _installer.IsInstalled(state.Package) ? EnginePackageStatus.Installed+ : EnginePackageStatus.NotInstalled;}/// <summary>Downloads and installs a package; packages queue up and install one after another.</summary>@@ -189,7 +210,7 @@ public sealed class EngineDownloadService}catch (OperationCanceledException){- state.Status = _installer.IsInstalled(state.Package) ? EnginePackageStatus.Installed : EnginePackageStatus.NotInstalled;+ state.Status = StatusOf(state);}catch (Exception ex){diff --git a/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs b/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.csindex 334c1be8..af9eec22 100644--- a/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs+++ b/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs@@ -9,6 +9,7 @@ using Filee.App.Services;using Filee.Core.Conversion;using Filee.Core.Localization;using Filee.Core.Settings;+using Filee.Engines.Infrastructure;namespace Filee.App.ViewModels.Pages;@@ -69,6 +70,26 @@ public sealed partial class EnginesPageViewModel : ObservableObject, IDisposable/// <summary>Removes a package (after the view asked for confirmation). False when its files are in use.</summary>public bool Remove(EnginePackageState package) => _downloads.Uninstall(package);+ /// <summary>+ /// Uses the user's own copy of a package from <paramref name="path"/> (a program they picked). Returns false when+ /// that folder doesn't have the package's programs; nothing is saved then.+ /// </summary>+ public bool UseOwnCopy(EnginePackageState package, string path)+ {+ if (EngineEnvironment.FolderWithPrograms(package.Package.Id, path) is null)+ return false;+ _store.Settings.EngineOwnCopies[package.Package.Id] = path;+ _store.SaveSettings(); // App.ApplySettings re-checks the engines+ return true;+ }++ /// <summary>Goes back to Filee's download (or no engine) for <paramref name="package"/>.</summary>+ public void StopUsingOwnCopy(EnginePackageState package)+ {+ if (_store.Settings.EngineOwnCopies.Remove(package.Package.Id))+ _store.SaveSettings();+ }+// Installing or removing an engine changes the list below (status, supported conversions).private void OnCatalogChanged(object? sender, EventArgs e) => Dispatcher.UIThread.Post(Reload);diff --git a/src/Filee.App/Views/Pages/EnginesPage.axaml b/src/Filee.App/Views/Pages/EnginesPage.axamlindex 56d59e83..e9cc8cd0 100644--- a/src/Filee.App/Views/Pages/EnginesPage.axaml+++ b/src/Filee.App/Views/Pages/EnginesPage.axaml@@ -39,7 +39,10 @@Command="{Binding $parent[ItemsControl].((vm:EnginesPageViewModel)DataContext).InstallCommand}" CommandParameter="{Binding}" /><Button Content="{DynamicResource engines.cancel}" IsVisible="{Binding IsBusy}"Command="{Binding $parent[ItemsControl].((vm:EnginesPageViewModel)DataContext).CancelCommand}" CommandParameter="{Binding}" />- <Button Content="{DynamicResource engines.remove}" IsVisible="{Binding IsInstalled}" Click="OnRemove" />+ <Button Content="{DynamicResource engines.use_own}" IsVisible="{Binding CanUseOwnCopy}" Click="OnUseOwnCopy"+ ToolTip.Tip="{DynamicResource engines.use_own_hint}" />+ <Button Content="{DynamicResource engines.stop_own}" IsVisible="{Binding UsesOwnCopy}" Click="OnStopOwnCopy" />+ <Button Content="{DynamicResource engines.remove}" IsVisible="{Binding CanRemove}" Click="OnRemove" /></StackPanel><StackPanel Spacing="4"><StackPanel Orientation="Horizontal" Spacing="10">@@ -49,7 +52,8 @@</Border></StackPanel><TextBlock Classes="caption" TextWrapping="Wrap" Text="{Binding Description}" />- <TextBlock Classes="caption" Text="{Binding Sizes}" />+ <TextBlock Classes="caption" Text="{Binding Sizes}" IsVisible="{Binding !UsesOwnCopy}" />+ <TextBlock Classes="caption" Text="{Binding OwnCopyFolder}" IsVisible="{Binding UsesOwnCopy}" TextTrimming="CharacterEllipsis" /><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.App/Views/Pages/EnginesPage.axaml.cs b/src/Filee.App/Views/Pages/EnginesPage.axaml.csindex 7f15bfca..da6d247c 100644--- a/src/Filee.App/Views/Pages/EnginesPage.axaml.cs+++ b/src/Filee.App/Views/Pages/EnginesPage.axaml.cs@@ -1,5 +1,6 @@using Avalonia.Controls;using Avalonia.Interactivity;+using Avalonia.Platform.Storage;using Filee.App.Services;using Filee.App.ViewModels.Pages;using Filee.Core.Localization;@@ -10,6 +11,32 @@ public partial class EnginesPage : UserControl{public EnginesPage() => InitializeComponent();+ /// <summary>Picks the program of a copy the user already has (ffmpeg.exe, ebook-convert.exe, …) and uses it.</summary>+ private async void OnUseOwnCopy(object? sender, RoutedEventArgs e)+ {+ if (sender is not Button { DataContext: EnginePackageState package } || DataContext is not EnginesPageViewModel vm ||+ TopLevel.GetTopLevel(this) is not Window window)+ return;+ var loc = AppHost.Get<ILocalizer>();+ var programs = Filee.Engines.Infrastructure.EngineEnvironment.OwnCopyPrograms[package.Package.Id];+ var files = await window.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions+ {+ Title = loc.Format("engines.use_own_title", package.Name),+ AllowMultiple = false,+ FileTypeFilter = [new FilePickerFileType(programs[0]) { Patterns = [programs[0]] }, FilePickerFileTypes.All],+ });+ if (files.FirstOrDefault()?.TryGetLocalPath() is not { } path)+ return;+ if (!vm.UseOwnCopy(package, path))+ await AppHost.Get<WindowService>().MessageAsync(window, loc.Format("engines.use_own_missing", string.Join(", ", programs)));+ }++ private void OnStopOwnCopy(object? sender, RoutedEventArgs e)+ {+ if (sender is Button { DataContext: EnginePackageState package } && DataContext is EnginesPageViewModel vm)+ vm.StopUsingOwnCopy(package);+ }+private async void OnRemove(object? sender, RoutedEventArgs e){if (sender is not Button { DataContext: EnginePackageState package } || DataContext is not EnginesPageViewModel vm ||diff --git a/src/Filee.Cli/CliHost.cs b/src/Filee.Cli/CliHost.csindex 26b5a920..9867f551 100644--- a/src/Filee.Cli/CliHost.cs+++ b/src/Filee.Cli/CliHost.cs@@ -28,6 +28,7 @@ internal sealed class CliHost : IAsyncDisposable{var store = new UserDataStore(dataDirectory ?? UserDataStore.DefaultDirectory);store.Load();+ EngineEnvironment.OwnCopies = new Dictionary<string, string>(store.Settings.EngineOwnCopies);var converters = EngineRegistry.CreateAll(new EngineEnvironment(store.Directory));var catalog = new ConverterCatalog(converters) { Priority = store.Settings.EnginePriority };var queue = new JobQueue(catalog, EngineRegistry.FindPdfMerger(converters), combiner: EngineRegistry.FindFileCombiner(converters));diff --git a/src/Filee.Core/Settings/AppSettings.cs b/src/Filee.Core/Settings/AppSettings.csindex e6bf04aa..2ba66371 100644--- a/src/Filee.Core/Settings/AppSettings.cs+++ b/src/Filee.Core/Settings/AppSettings.cs@@ -105,6 +105,12 @@ public sealed class AppSettings/// <summary>Where presets set to "Default" save (Settings → General).</summary>public DefaultOutputSettings DefaultOutput { get; set; } = new();+ /// <summary>+ /// Optional engines the user already has: package id ("ffmpeg", "calibre", …) → the program they picked. Used+ /// instead of Filee's download (Settings → Engines).+ /// </summary>+ public Dictionary<string, string> EngineOwnCopies { get; set; } = [];+/// <summary>Every conversion keeps the created and modified dates of the original, whatever the preset says.</summary>public bool KeepFileDates { get; set; }diff --git a/src/Filee.Engines/Ebooks/CalibreConverter.cs b/src/Filee.Engines/Ebooks/CalibreConverter.csindex 5ea69a93..2398e8e0 100644--- a/src/Filee.Engines/Ebooks/CalibreConverter.cs+++ b/src/Filee.Engines/Ebooks/CalibreConverter.cs@@ -41,7 +41,7 @@ public sealed partial class CalibreConverter : IConverterpublic EngineStatus GetStatus(){_executable = Locate();- return _executable is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_executable, EngineVersions.Component("calibre"));+ return _executable is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_executable, EngineEnvironment.OwnCopyFolder("calibre") is null ? EngineVersions.Component("calibre") : null);}public async Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)@@ -99,8 +99,14 @@ public sealed partial class CalibreConverter : IConverter[GeneratedRegex(@"^\s*(\d{1,3})%\s")]private static partial Regex Percent();- /// <summary>Filee's own calibre (engines/calibre, downloaded on demand), never one installed on the system.</summary>+ /// <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.+ /// </summary>internal static string? Locate() =>+ EngineEnvironment.OwnProgram("calibre", "ebook-convert.exe") ?? LocateBundled();++ private static string? LocateBundled() =>OperatingSystem.IsWindows() && EngineEnvironment.FindBundled("calibre") is { } folder? EngineEnvironment.FirstExisting(Path.Combine(folder, "ebook-convert.exe")): null;diff --git a/src/Filee.Engines/Infrastructure/EngineEnvironment.cs b/src/Filee.Engines/Infrastructure/EngineEnvironment.csindex 5c2b4939..e06adee1 100644--- a/src/Filee.Engines/Infrastructure/EngineEnvironment.cs+++ b/src/Filee.Engines/Infrastructure/EngineEnvironment.cs@@ -1,6 +1,8 @@// Shared context for engines: where Filee's own engine copies live and where engines keep their state.-// Engines never use software installed on the system (Office, a system-wide LibreOffice, tools on the PATH): only-// the copies that ship with the installer or that Filee downloaded, so every user gets the same, tested versions.+// 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.namespace Filee.Engines.Infrastructure;@@ -44,6 +46,47 @@ public sealed class EngineEnvironment(string dataDirectory)return null;}+ /// <summary>+ /// Programs the user chose for an optional engine package instead of Filee's download: package id → the program+ /// they picked (or its folder). Set by the app and the command line from the settings.+ /// </summary>+ public static IReadOnlyDictionary<string, string> OwnCopies { get; set; } = new Dictionary<string, string>();++ /// <summary>Programs that must be in the folder of an own copy, per package (Windows names).</summary>+ public static IReadOnlyDictionary<string, string[]> OwnCopyPrograms { get; } = new Dictionary<string, string[]>+ {+ ["libreoffice"] = ["soffice.exe"],+ ["pandoc"] = ["pandoc.exe"],+ ["ghostscript"] = ["gswin64c.exe"],+ ["ffmpeg"] = ["ffmpeg.exe", "ffprobe.exe"],+ ["calibre"] = ["ebook-convert.exe"],+ };++ /// <summary>The folder of the user's own copy of package <paramref name="id"/>, when it has every program.</summary>+ public static string? OwnCopyFolder(string id) =>+ OwnCopies.TryGetValue(id, out var path) ? FolderWithPrograms(id, path) : null;++ /// <summary>A program of the user's own copy of package <paramref name="id"/>, or null.</summary>+ public static string? OwnProgram(string id, string program) =>+ OwnCopyFolder(id) is { } folder ? Path.Combine(folder, program) : null;++ /// <summary>+ /// The folder with all programs of package <paramref name="id"/>, given a program the user picked or a folder:+ /// that folder itself, or its bin\ or program\ sub folder (FFmpeg builds, LibreOffice). Null when they are missing.+ /// </summary>+ public static string? FolderWithPrograms(string id, string path)+ {+ if (!OperatingSystem.IsWindows() || string.IsNullOrWhiteSpace(path) || !OwnCopyPrograms.TryGetValue(id, out var programs))+ return null;+ var start = File.Exists(path) ? Path.GetDirectoryName(path) : Directory.Exists(path) ? path : null;+ if (start is null)+ return null;+ foreach (var folder in new[] { start, Path.Combine(start, "bin"), Path.Combine(start, "program") })+ if (programs.All(p => File.Exists(Path.Combine(folder, p))))+ return folder;+ return null;+ }+/// <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.csindex 6e9eccbd..a8185bc8 100644--- a/src/Filee.Engines/Media/FfmpegConverter.cs+++ b/src/Filee.Engines/Media/FfmpegConverter.cs@@ -127,6 +127,9 @@ public sealed partial class FfmpegConverter : IConverter/// </summary>internal static (string Ffmpeg, string Ffprobe)? Locate(){+ // The user's own FFmpeg (Settings → Engines) comes first.+ 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;var suffix = OperatingSystem.IsWindows() ? ".exe" : "";diff --git a/src/Filee.Engines/Office/LibreOfficeConverter.cs b/src/Filee.Engines/Office/LibreOfficeConverter.csindex 3e3cdda0..2a2f1842 100644--- a/src/Filee.Engines/Office/LibreOfficeConverter.cs+++ b/src/Filee.Engines/Office/LibreOfficeConverter.cs@@ -71,8 +71,10 @@ public sealed class LibreOfficeConverter : IConverterEdges = BuildEdges(_hasHwpFilter);return _soffice is null? EngineStatus.Unavailable("engine.reason.not_installed")- : EngineStatus.Available(_soffice, EngineVersions.Component("libreoffice")- + (_hasHwpFilter ? $" · H2Orestart {EngineVersions.Component("h2orestart")}" : ""));+ : EngineEnvironment.OwnCopyFolder("libreoffice") is not null+ ? EngineStatus.Available(_soffice, _hasHwpFilter ? "H2Orestart" : null)+ : EngineStatus.Available(_soffice, EngineVersions.Component("libreoffice")+ + (_hasHwpFilter ? $" · H2Orestart {EngineVersions.Component("h2orestart")}" : ""));}public async Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)@@ -263,13 +265,16 @@ public sealed class LibreOfficeConverter : IConverterreturn edges;}- /// <summary>Finds Filee's own copy (engines/libreoffice); a LibreOffice installed on the system is never used.</summary>+ /// <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.+ /// </summary>private void Locate(){var bundled = EngineEnvironment.FindBundled("libreoffice");- _soffice = bundled is null ? null : EngineEnvironment.FirstExisting(+ _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")));_hasHwpFilter = _soffice is not null && HasH2Orestart(_soffice);}diff --git a/src/Filee.Engines/Office/PandocConverter.cs b/src/Filee.Engines/Office/PandocConverter.csindex 242ea97e..eeaffa25 100644--- a/src/Filee.Engines/Office/PandocConverter.cs+++ b/src/Filee.Engines/Office/PandocConverter.cs@@ -66,7 +66,7 @@ public sealed class PandocConverter : IConverterpublic EngineStatus GetStatus(){_pandoc = Locate();- return _pandoc is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_pandoc, EngineVersions.Component("pandoc"));+ return _pandoc is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_pandoc, EngineEnvironment.OwnCopyFolder("pandoc") is null ? EngineVersions.Component("pandoc") : null);}public async Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)@@ -95,6 +95,9 @@ 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();++ private static string? LocateBundled() =>EngineEnvironment.FindBundled("pandoc") is { } bundled? EngineEnvironment.FirstExisting(Path.Combine(bundled, OperatingSystem.IsWindows() ? "pandoc.exe" : "pandoc")): null;diff --git a/src/Filee.Engines/Vector/GhostscriptConverter.cs b/src/Filee.Engines/Vector/GhostscriptConverter.csindex 6a19883b..33e93da4 100644--- a/src/Filee.Engines/Vector/GhostscriptConverter.cs+++ b/src/Filee.Engines/Vector/GhostscriptConverter.cs@@ -41,7 +41,7 @@ public sealed class GhostscriptConverter : IConverterpublic EngineStatus GetStatus(){_executable = Locate();- return _executable is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_executable, EngineVersions.Component("ghostscript"));+ return _executable is null ? EngineStatus.Unavailable("engine.reason.not_installed") : EngineStatus.Available(_executable, EngineEnvironment.OwnCopyFolder("ghostscript") is null ? EngineVersions.Component("ghostscript") : null);}public async Task<IReadOnlyList<string>> ConvertAsync(ConversionStep step, IProgress<double>? progress, CancellationToken cancellationToken)@@ -61,6 +61,9 @@ 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();++ private static string? LocateBundled() =>EngineEnvironment.FindBundled("ghostscript") is { } folder? EngineEnvironment.FirstExisting(Path.Combine(folder, OperatingSystem.IsWindows() ? "gswin64c.exe" : "gs")): null;diff --git a/tests/Filee.Engines.Tests/OwnCopyTests.cs b/tests/Filee.Engines.Tests/OwnCopyTests.csnew file mode 100644index 00000000..0f922a11--- /dev/null+++ b/tests/Filee.Engines.Tests/OwnCopyTests.cs@@ -0,0 +1,69 @@+// A copy of an optional engine the user already has (Settings → Engines → "Use my copy…") is found from the program+// they picked, wins over Filee's download, and is refused when its folder lacks a program the engine needs.++using Filee.Engines.Ebooks;+using Filee.Engines.Infrastructure;+using Filee.Engines.Media;+using Filee.Engines.Office;++namespace Filee.Engines.Tests;++[Collection("EngineEnvironment")] // OwnCopies is process-wide+public sealed class OwnCopyTests : IDisposable+{+ private readonly string _folder = Directory.CreateTempSubdirectory("filee-own-").FullName;++ public void Dispose()+ {+ EngineEnvironment.OwnCopies = new Dictionary<string, string>();+ try { Directory.Delete(_folder, true); } catch (IOException) { }+ }++ private string Program(string relative)+ {+ var path = Path.Combine(_folder, relative);+ Directory.CreateDirectory(Path.GetDirectoryName(path)!);+ File.WriteAllBytes(path, [0x4D, 0x5A]);+ return path;+ }++ [Fact]+ public void The_users_own_copy_wins_over_filees_download()+ {+ if (!OperatingSystem.IsWindows())+ return;+ var ffmpeg = Program(@"ffmpeg\bin\ffmpeg.exe");+ var ffprobe = Program(@"ffmpeg\bin\ffprobe.exe");+ var pandoc = Program(@"pandoc\pandoc.exe");+ var calibre = Program(@"Calibre2\calibre.exe");+ var convert = Program(@"Calibre2\ebook-convert.exe");++ EngineEnvironment.OwnCopies = new Dictionary<string, string>+ {+ ["ffmpeg"] = Path.Combine(_folder, "ffmpeg"), // the folder of an FFmpeg build: its bin\ is found+ ["pandoc"] = pandoc,+ ["calibre"] = calibre, // calibre.exe picked: ebook-convert.exe next to it is used+ };++ Assert.Equal((ffmpeg, ffprobe), FfmpegConverter.Locate());+ Assert.Equal(pandoc, PandocConverter.Locate());+ Assert.Equal(convert, CalibreConverter.Locate());+ }++ [Fact]+ public void A_folder_without_every_program_is_not_used()+ {+ if (!OperatingSystem.IsWindows())+ return;+ var ffmpeg = Program(@"tools\ffmpeg.exe"); // no ffprobe.exe next to it++ Assert.Null(EngineEnvironment.FolderWithPrograms("ffmpeg", ffmpeg));+ EngineEnvironment.OwnCopies = new Dictionary<string, string> { ["ffmpeg"] = ffmpeg };+ Assert.Null(EngineEnvironment.OwnCopyFolder("ffmpeg"));+ Assert.NotEqual(ffmpeg, FfmpegConverter.Locate()?.Ffmpeg);+ }+}++/// <summary>Runs alone: while OwnCopies points at fake programs, no other engine test may convert.</summary>+[CollectionDefinition("EngineEnvironment", DisableParallelization = true)]+public sealed class EngineEnvironmentCollection;