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
Add FILEE_DATA_DIR to run a test copy next to the user's Filee
KnifeLemon118f3415047e
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex de9d21c2..ade16af2 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -15,6 +15,11 @@ Thanks for helping! Filee is built to be easy to extend: most contributions toucEngines lets you choose a specific copy. Microsoft Office is not used.4. `dotnet run --project src/Filee.App`, `dotnet test`.+To try a build next to the Filee you use every day (testing, measuring memory), set `FILEE_DATA_DIR` to an empty+folder first. Settings, logs and downloaded engines then live there, the copy is its own single instance (later+launches with the same variable, `--quit` included, reach it and never your installed Filee), and it registers no+startup entry, context menu or Explorer menu.+Any IDE works (Visual Studio 2022+, Rider, VS Code with C# Dev Kit).## Linux and macOS developmentdiff --git a/src/Filee.App/Services/SingleInstance.cs b/src/Filee.App/Services/SingleInstance.csindex 64285de3..7871bef6 100644--- a/src/Filee.App/Services/SingleInstance.cs+++ b/src/Filee.App/Services/SingleInstance.cs@@ -3,6 +3,7 @@using System.IO.Pipes;using System.Text.Json;+using Filee.Core.Settings;namespace Filee.App.Services;@@ -10,8 +11,7 @@ namespace Filee.App.Services;public sealed class SingleInstance : IDisposable{// string.GetHashCode() is randomized per process, so a stable hash is required for both processes to agree.- private static readonly string DefaultName = "Filee-" + Convert.ToHexString(- System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(Environment.UserName)))[..12];+ private static readonly string DefaultName = NameFor(Environment.UserName, UserDataStore.OverrideDirectory);private readonly Mutex _mutex;private readonly string _name;private readonly CancellationTokenSource _cts = new();@@ -30,6 +30,16 @@ public sealed class SingleInstance : IDisposablepublic static SingleInstance Acquire() => Acquire(DefaultName);+ /// <summary>+ /// The mutex and pipe name for a user. A copy started with FILEE_DATA_DIR (<paramref name="dataDirectoryOverride"/>)+ /// gets a name of its own, so it neither forwards to nor receives from the Filee the user runs.+ /// </summary>+ internal static string NameFor(string userName, string? dataDirectoryOverride)+ {+ var key = dataDirectoryOverride is null ? userName : userName + "|" + dataDirectoryOverride.ToUpperInvariant();+ return "Filee-" + Convert.ToHexString(System.Security.Cryptography.SHA256.HashData(System.Text.Encoding.UTF8.GetBytes(key)))[..12];+ }+/// <summary>The instance under another name (tests, which must not reach a Filee that is running).</summary>internal static SingleInstance Acquire(string name){diff --git a/src/Filee.App/Services/SystemIntegrationService.cs b/src/Filee.App/Services/SystemIntegrationService.csindex 569da464..a2097700 100644--- a/src/Filee.App/Services/SystemIntegrationService.cs+++ b/src/Filee.App/Services/SystemIntegrationService.cs@@ -12,14 +12,28 @@ public sealed class SystemIntegrationService(IPlatformServices platform, ILocaliprivate (bool Enabled, string Executable, string Label)? _menu;private bool _shortcutApplied;private string? _shortcut;+ private bool _skipLogged;public string? Error { get; private set; }internal bool RegistrationEnabled { get; init; } = UpdateService.IsReleaseBuild;internal string? ExecutablePath { get; init; } = Environment.ProcessPath;+ /// <summary>+ /// A copy started with FILEE_DATA_DIR (<see cref="UserDataStore.DirectoryVariable"/>): its startup entry, context+ /// menu and Explorer menu would replace those of the Filee the user installed, so it registers nothing.+ /// </summary>+ internal bool SeparateDataDirectory { get; init; } = UserDataStore.OverrideDirectory is not null;+public void Apply(AppSettings settings){Error = null;+ if (SeparateDataDirectory)+ {+ if (!_skipLogged)+ log.LogInformation("{Variable} is set: startup entry, context menu and Explorer menu are left alone", UserDataStore.DirectoryVariable);+ _skipLogged = true;+ return;+ }if (!RegistrationEnabled || ExecutablePath is not { } executable)return;var errors = new List<string>();diff --git a/src/Filee.App/Services/UninstallCleanup.cs b/src/Filee.App/Services/UninstallCleanup.csindex 4d5cef3a..8d8a51a7 100644--- a/src/Filee.App/Services/UninstallCleanup.cs+++ b/src/Filee.App/Services/UninstallCleanup.cs@@ -1,6 +1,7 @@// Removes per-user integration and downloaded engines after Filee exits. User settings remain for reinstalling.using Filee.Core.Platform;+using Filee.Core.Settings;using Filee.Platform.Linux;using Filee.Platform.MacOS;using Filee.Platform.Windows;@@ -15,11 +16,16 @@ internal static class UninstallCleanup: OperatingSystem.IsMacOS() ? new MacOSPlatformServices(): OperatingSystem.IsLinux() ? new LinuxPlatformServices() : new NullPlatformServices();var succeeded = true;- Clean(() => platform.SetContextMenu(false, "", ""));- Clean(() => platform.SetStartWithSystem(false, ""));- if (OperatingSystem.IsLinux() && platform is LinuxPlatformServices linux)+ // A copy with its own data folder (FILEE_DATA_DIR) never registered anything: only its engines go.+ var integrated = UserDataStore.OverrideDirectory is null;+ if (integrated)+ {+ Clean(() => platform.SetContextMenu(false, "", ""));+ Clean(() => platform.SetStartWithSystem(false, ""));+ }+ if (integrated && OperatingSystem.IsLinux() && platform is LinuxPlatformServices linux)Clean(() => linux.SetThunarShortcut(null));- if (OperatingSystem.IsWindows() && ExplorerMenuRegistration.IsSupportedOs)+ if (integrated && OperatingSystem.IsWindows() && ExplorerMenuRegistration.IsSupportedOs){Clean(() =>{diff --git a/src/Filee.Core/Settings/UserDataStore.cs b/src/Filee.Core/Settings/UserDataStore.csindex 9b0f3880..3b3033ca 100644--- a/src/Filee.Core/Settings/UserDataStore.cs+++ b/src/Filee.Core/Settings/UserDataStore.cs@@ -26,9 +26,25 @@ public sealed class UserDataStore_log = log ?? (ILogger)NullLogger.Instance;}- /// <summary>Default data directory: %APPDATA%\Filee on Windows, ~/Library/Application Support/Filee on macOS.</summary>+ /// <summary>+ /// Environment variable that moves all of Filee's per-user data (settings, logs, downloaded engines) to another+ /// folder and gives that copy its own single instance: a development or test copy then never touches, or talks+ /// to, the Filee the user runs. A copy started with it also leaves the system integration alone.+ /// </summary>+ public const string DirectoryVariable = "FILEE_DATA_DIR";++ /// <summary>The folder <see cref="DirectoryVariable"/> points to (full path), or null when it is not set.</summary>+ public static string? OverrideDirectory => DirectoryFrom(Environment.GetEnvironmentVariable(DirectoryVariable));++ /// <summary>+ /// Default data directory: %APPDATA%\Filee on Windows, ~/Library/Application Support/Filee on macOS, or the+ /// folder in <see cref="DirectoryVariable"/>.+ /// </summary>public static string DefaultDirectory =>- Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Filee");+ OverrideDirectory ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Filee");++ internal static string? DirectoryFrom(string? value) =>+ string.IsNullOrWhiteSpace(value) ? null : Path.TrimEndingDirectorySeparator(Path.GetFullPath(value.Trim()));public string Directory { get; }diff --git a/src/Filee.Engines/Infrastructure/EngineEnvironment.cs b/src/Filee.Engines/Infrastructure/EngineEnvironment.csindex 77db4ef3..00ab7f8e 100644--- a/src/Filee.Engines/Infrastructure/EngineEnvironment.cs+++ b/src/Filee.Engines/Infrastructure/EngineEnvironment.cs@@ -5,6 +5,7 @@// 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;+using Filee.Core.Settings;namespace Filee.Engines.Infrastructure;@@ -18,10 +19,15 @@ public sealed class EngineEnvironment(string dataDirectory)/// <summary>/// Per-user folder for engines downloaded on demand (see <see cref="EngineInstaller"/>):/// %LOCALAPPDATA%\Filee\engines. It is outside the app folder, so app updates keep it, and inside Filee's- /// install root, so uninstalling removes it.+ /// install root, so uninstalling removes it. With FILEE_DATA_DIR set (<see cref="UserDataStore.DirectoryVariable"/>)+ /// it is the engines folder in there./// </summary>- public static string DownloadRoot { get; set; } =- Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Filee", "engines");+ public static string DownloadRoot { get; set; } = DefaultDownloadRoot(UserDataStore.OverrideDirectory);++ internal static string DefaultDownloadRoot(string? dataDirectoryOverride) =>+ dataDirectoryOverride is not null+ ? Path.Combine(dataDirectoryOverride, "engines")+ : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Filee", "engines");/// <summary>/// Finds an engine directory (<c>engines/<name></c>): next to the executable (bundled with the installer),diff --git a/tests/Filee.App.Tests/SingleInstanceTests.cs b/tests/Filee.App.Tests/SingleInstanceTests.csindex dec9a087..63934b92 100644--- a/tests/Filee.App.Tests/SingleInstanceTests.cs+++ b/tests/Filee.App.Tests/SingleInstanceTests.cs@@ -30,6 +30,18 @@ public class SingleInstanceTestsAssert.Equal(["--quit"], await received.Task.WaitAsync(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken));}+ [Fact]+ public void A_copy_with_its_own_data_folder_never_reaches_the_users_filee()+ {+ // The name without a data folder must stay the same: a new version forwards to an older one that runs.+ var usual = "Filee-" + Convert.ToHexString(System.Security.Cryptography.SHA256.HashData("someone"u8.ToArray()))[..12];+ Assert.Equal(usual, SingleInstance.NameFor("someone", null));+ var test = SingleInstance.NameFor("someone", Path.Combine(Path.GetTempPath(), "filee-a"));+ Assert.NotEqual(usual, test);+ Assert.NotEqual(test, SingleInstance.NameFor("someone", Path.Combine(Path.GetTempPath(), "filee-b")));+ Assert.Equal(test, SingleInstance.NameFor("someone", Path.Combine(Path.GetTempPath(), "filee-a")));+ }+[Fact]public async Task Forwarding_gives_up_when_nobody_listens(){diff --git a/tests/Filee.App.Tests/SystemIntegrationTests.cs b/tests/Filee.App.Tests/SystemIntegrationTests.csindex 6490f63f..396443d0 100644--- a/tests/Filee.App.Tests/SystemIntegrationTests.cs+++ b/tests/Filee.App.Tests/SystemIntegrationTests.cs@@ -53,10 +53,26 @@ public sealed class SystemIntegrationTestsAssert.Equal(0, platform.MenuCalls);}+ [Fact]+ public void A_copy_with_its_own_data_folder_does_not_register_os_integration()+ {+ var platform = new RecordingPlatform();+ var service = new SystemIntegrationService(platform, new Texts(), NullLogger<SystemIntegrationService>.Instance)+ {+ RegistrationEnabled = true,+ SeparateDataDirectory = true,+ ExecutablePath = Path.Combine(Path.GetTempPath(), "Filee test", "Filee"),+ };+ service.Apply(new AppSettings { StartWithSystem = true, ContextMenuEnabled = true });+ Assert.Equal(0, platform.StartupCalls);+ Assert.Equal(0, platform.MenuCalls);+ }+private static SystemIntegrationService Create(RecordingPlatform platform) =>new(platform, new Texts(), NullLogger<SystemIntegrationService>.Instance){RegistrationEnabled = true,+ SeparateDataDirectory = false,ExecutablePath = Path.Combine(Path.GetTempPath(), "Filee test", "Filee"),};diff --git a/tests/Filee.Core.Tests/DataDirectoryTests.cs b/tests/Filee.Core.Tests/DataDirectoryTests.csnew file mode 100644index 00000000..cc51e78f--- /dev/null+++ b/tests/Filee.Core.Tests/DataDirectoryTests.cs@@ -0,0 +1,40 @@+// FILEE_DATA_DIR moves the data folder, so a development or test copy never reads or writes the user's own Filee.++using Filee.Core.Settings;++namespace Filee.Core.Tests;++public class DataDirectoryTests+{+ [Fact]+ public void The_variable_moves_the_default_data_folder()+ {+ using var dir = new TempDir();+ var before = Environment.GetEnvironmentVariable(UserDataStore.DirectoryVariable);+ try+ {+ Environment.SetEnvironmentVariable(UserDataStore.DirectoryVariable, dir.Path + Path.DirectorySeparatorChar);+ Assert.Equal(Path.GetFullPath(dir.Path), UserDataStore.OverrideDirectory);+ Assert.Equal(Path.GetFullPath(dir.Path), UserDataStore.DefaultDirectory);++ Environment.SetEnvironmentVariable(UserDataStore.DirectoryVariable, null);+ Assert.Null(UserDataStore.OverrideDirectory);+ Assert.Equal(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Filee"),+ UserDataStore.DefaultDirectory);+ }+ finally+ {+ Environment.SetEnvironmentVariable(UserDataStore.DirectoryVariable, before);+ }+ }++ [Theory]+ [InlineData(null)]+ [InlineData("")]+ [InlineData(" ")]+ public void An_empty_variable_is_no_override(string? value) => Assert.Null(UserDataStore.DirectoryFrom(value));++ [Fact]+ public void A_relative_folder_is_made_absolute() =>+ Assert.Equal(Path.Combine(Environment.CurrentDirectory, "filee-test"), UserDataStore.DirectoryFrom("filee-test"));+}diff --git a/tests/Filee.Engines.Tests/EngineInstallerTests.cs b/tests/Filee.Engines.Tests/EngineInstallerTests.csindex 0d52a7f1..8faf7ddf 100644--- a/tests/Filee.Engines.Tests/EngineInstallerTests.cs+++ b/tests/Filee.Engines.Tests/EngineInstallerTests.cs@@ -19,6 +19,14 @@ public sealed class EngineInstallerTests : IDisposabletry { Directory.Delete(_root, true); } catch (IOException) { }}+ [Fact]+ public void A_separate_data_folder_keeps_its_own_engines()+ {+ Assert.Equal(Path.Combine(_root, "engines"), EngineEnvironment.DefaultDownloadRoot(_root));+ Assert.Equal(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Filee", "engines"),+ EngineEnvironment.DefaultDownloadRoot(null));+ }+/// <summary>Serves byte arrays by URL; a string value is a redirect target.</summary>private sealed class FakeServer(Dictionary<string, object> content) : HttpMessageHandler{