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.

Filee takes Setup's language and knows its new uninstaller

KnifeLemon79d74fbb0d7a
diff --git a/src/Filee.App/App.axaml.cs b/src/Filee.App/App.axaml.cs
index 49d1e2f7..837d2d69 100644
--- a/src/Filee.App/App.axaml.cs
+++ b/src/Filee.App/App.axaml.cs
@@ -300,17 +300,21 @@ public partial class App : Application
}
/// <summary>
- /// Options ticked on the installer's task page. Saving applies them through SystemIntegrationService
- /// as if they had been switched on the General page.
+ /// Options ticked in Setup, and the language picked there. Saving applies them (SystemIntegrationService, the
+ /// language) as if they had been switched on the General page.
/// </summary>
private static void ApplyInstallerChoices(CommandLine options, UserDataStore store)
{
- if (options.StartWithWindows is null && options.ContextMenu is null)
+ // Only Filee's languages; anything else keeps the setting (normally "auto", Windows' language).
+ var language = LocalizationService.Languages.FirstOrDefault(l => l.Code.Equals(options.Language, StringComparison.OrdinalIgnoreCase)).Code;
+ if (options.StartWithWindows is null && options.ContextMenu is null && language is null)
return;
if (options.StartWithWindows is { } start)
store.Settings.StartWithSystem = start;
if (options.ContextMenu is { } menu)
store.Settings.ContextMenuEnabled = menu;
+ if (language is not null)
+ store.Settings.Language = language;
store.SaveSettings();
}
diff --git a/src/Filee.App/Services/CommandLine.cs b/src/Filee.App/Services/CommandLine.cs
index d9a9c6f5..53cacd45 100644
--- a/src/Filee.App/Services/CommandLine.cs
+++ b/src/Filee.App/Services/CommandLine.cs
@@ -5,11 +5,12 @@
// Filee.exe --convert a b ... open the donut for these files (Explorer context menu / Send To)
// Filee.exe --convert-list <file> same, with one path per line in a UTF-8 file (Windows 11 Explorer menu, for
// selections too long for a command line); the app deletes the file afterwards
-// Used by the installer (installer/Filee.iss):
+// Used by the installer (src/Filee.Setup, Installer.LaunchArguments):
// Filee.exe --install-engines=a,b download these engine packages (EngineDownloads ids) in the engine window;
// an empty list means the user chose none, so the first-run choice is skipped
// Filee.exe --start-with-windows=on|off, --context-menu=on|off
// set the matching options on the General page
+// Filee.exe --language=ko the language picked in Setup (one of LocalizationService.Languages)
// Filee.exe --quit ask a running Filee to exit, and wait until it has (no window otherwise)
// Filee.exe --uninstall-cleanup quit Filee, then remove what it registered for this user (UninstallCleanup)
@@ -22,6 +23,7 @@ namespace Filee.App.Services;
/// <param name="InstallEngines">Engine packages chosen in the installer; null when the option is absent.</param>
/// <param name="StartWithWindows">Value of <c>--start-with-windows</c>; null when absent.</param>
/// <param name="ContextMenu">Value of <c>--context-menu</c>; null when absent.</param>
+/// <param name="Language">Value of <c>--language</c>; null when absent.</param>
public sealed record CommandLine(
bool Background,
bool ShowSettings,
@@ -31,7 +33,8 @@ public sealed record CommandLine(
bool UninstallCleanup = false,
IReadOnlyList<string>? InstallEngines = null,
bool? StartWithWindows = null,
- bool? ContextMenu = null)
+ bool? ContextMenu = null,
+ string? Language = null)
{
/// <summary>File name prefix of list files written by FileeExplorerMenu.dll (LIST_PREFIX there) into %TEMP%.</summary>
public const string ListFilePrefix = "Filee-convert-";
@@ -49,6 +52,7 @@ public sealed record CommandLine(
List<string>? engines = null;
bool? startWithWindows = null;
bool? contextMenu = null;
+ string? language = null;
foreach (var arg in args)
{
@@ -72,6 +76,9 @@ public sealed record CommandLine(
case "--context-menu" when OnOff(value) is { } on:
contextMenu = on;
break;
+ case "--language" when !string.IsNullOrWhiteSpace(value):
+ language = value.Trim();
+ break;
case "--quit":
quit = true;
break;
@@ -97,7 +104,7 @@ public sealed record CommandLine(
break;
}
}
- return new CommandLine(background, settings, files, listFile, quit, cleanup, engines, startWithWindows, contextMenu);
+ return new CommandLine(background, settings, files, listFile, quit, cleanup, engines, startWithWindows, contextMenu, language);
}
/// <summary>"--Name=Value" → ("--name", "Value"); "--name" → ("--name", null).</summary>
diff --git a/src/Filee.App/Services/UpdateService.cs b/src/Filee.App/Services/UpdateService.cs
index 8e22c3c5..12d5d617 100644
--- a/src/Filee.App/Services/UpdateService.cs
+++ b/src/Filee.App/Services/UpdateService.cs
@@ -84,11 +84,14 @@ public sealed partial class UpdateService : ObservableObject
public const string WebsiteUrl = "https://filee.sh/";
/// <summary>
- /// True when this copy was installed by Setup (Inno Setup puts its uninstaller next to Filee.exe). Only then can
- /// the new installer update it in place; the portable zip and a copy run from source have no uninstaller.
+ /// True when this copy was installed by Setup, which puts its uninstaller next to Filee.exe (uninstall.exe; the
+ /// Inno Setup installer of 1.x put unins000.exe there). Only then can the new installer update it in place; the
+ /// portable zip and a copy run from source have no uninstaller.
/// </summary>
- public static bool IsInstalled { get; } = OperatingSystem.IsWindows()
- && File.Exists(Path.Combine(AppContext.BaseDirectory, "unins000.exe"));
+ public static bool IsInstalled { get; } = OperatingSystem.IsWindows() && IsInstalledIn(AppContext.BaseDirectory);
+
+ internal static bool IsInstalledIn(string folder) =>
+ File.Exists(Path.Combine(folder, "uninstall.exe")) || File.Exists(Path.Combine(folder, "unins000.exe"));
/// <summary>Whether <see cref="UpdateAsync"/> installs by itself (<see cref="IsInstalled"/>; tests set it).</summary>
internal bool InstallsItself { get; init; } = IsInstalled;
diff --git a/tests/Filee.App.Tests/InstallerTests.cs b/tests/Filee.App.Tests/InstallerTests.cs
index b3ca636a..77622cd6 100644
--- a/tests/Filee.App.Tests/InstallerTests.cs
+++ b/tests/Filee.App.Tests/InstallerTests.cs
@@ -1,47 +1,23 @@
-// Keeps the installer script (installer/Filee.iss) and the app in step: the options Setup starts Filee with, the
-// Explorer menu package it registers and the engine folders it looks into.
+// The options Setup (src/Filee.Setup) starts Filee with and the commands it runs. Filee.Setup.Tests checks that what
+// Setup writes is what these parse.
-using System.Reflection;
-using System.Text.RegularExpressions;
using Avalonia.Headless.XUnit;
using Filee.App.Services;
using Filee.App.ViewModels;
using Filee.Core.Localization;
-using Filee.Engines.Infrastructure;
-using Filee.Platform.Windows;
namespace Filee.App.Tests;
public class InstallerTests
{
- private static string Script
- {
- get
- {
- var dir = AppContext.BaseDirectory;
- while (!File.Exists(Path.Combine(dir, "Filee.slnx")))
- dir = Path.GetDirectoryName(dir) ?? throw new InvalidOperationException("Repository root not found.");
- return File.ReadAllText(Path.Combine(dir, "installer", "Filee.iss"));
- }
- }
-
- [Fact]
- public void Script_passes_only_options_the_app_knows()
- {
- // Each option below is checked by a parse test; a new one in the script must be added here.
- var used = Regex.Matches(Script, @"--[a-z][a-z-]+=?").Select(m => m.Value).ToHashSet();
- Assert.Equal(
- new HashSet<string> { "--background", "--quit", "--uninstall-cleanup", "--install-engines=", "--start-with-windows=", "--context-menu=" },
- used);
- }
-
[Fact]
public void Installer_choices_are_parsed()
{
- var options = CommandLine.Parse(["--install-engines=pandoc, FFmpeg,pandoc", "--start-with-windows=off", "--context-menu=on"]);
+ var options = CommandLine.Parse(["--install-engines=pandoc, FFmpeg,pandoc", "--start-with-windows=off", "--context-menu=on", "--language=ko"]);
Assert.Equal(["pandoc", "ffmpeg"], options.InstallEngines);
Assert.False(options.StartWithWindows);
Assert.True(options.ContextMenu);
+ Assert.Equal("ko", options.Language);
Assert.False(options.Background);
Assert.Empty(options.ConvertFiles);
@@ -50,6 +26,7 @@ public class InstallerTests
Assert.Null(CommandLine.Parse(["--background"]).InstallEngines);
Assert.Null(CommandLine.Parse(["--start-with-windows=maybe"]).StartWithWindows);
Assert.Null(CommandLine.Parse([]).ContextMenu);
+ Assert.Null(CommandLine.Parse(["--language="]).Language);
Assert.True(CommandLine.Parse(["--start-with-system=on"]).StartWithWindows);
}
@@ -61,6 +38,28 @@ public class InstallerTests
Assert.False(CommandLine.Parse(["--background"]).Quit);
}
+ [Fact]
+ public void Installed_copies_are_recognised_by_their_uninstaller()
+ {
+ var folder = Path.Combine(Path.GetTempPath(), "filee-installed-" + Guid.NewGuid().ToString("N")[..8]);
+ Directory.CreateDirectory(folder);
+ try
+ {
+ Assert.False(UpdateService.IsInstalledIn(folder));
+ // Filee's own Setup (2.0 and later).
+ File.WriteAllText(Path.Combine(folder, "uninstall.exe"), "");
+ Assert.True(UpdateService.IsInstalledIn(folder));
+ // Inno Setup (1.x), until Setup takes the installation over.
+ File.Delete(Path.Combine(folder, "uninstall.exe"));
+ File.WriteAllText(Path.Combine(folder, "unins000.exe"), "");
+ Assert.True(UpdateService.IsInstalledIn(folder));
+ }
+ finally
+ {
+ Directory.Delete(folder, recursive: true);
+ }
+ }
+
[AvaloniaFact]
public void Engines_from_the_installer_start_only_when_something_is_left_to_install()
{
@@ -70,26 +69,4 @@ public class InstallerTests
Assert.False(vm.InstallNow([]));
Assert.False(vm.Started);
}
-
- [Fact]
- public void Script_uses_the_explorer_menu_package_identity()
- {
- var script = Script;
- Assert.Contains($"ExplorerMenuName = '{ExplorerMenuPackage.PackageName}';", script);
- Assert.Contains($"ExplorerMenuFamily = '{ExplorerMenuPackage.FamilyName}';", script);
- Assert.Contains($"ExplorerMenuDll = '{ExplorerMenuPackage.DllFileName}';", script);
- Assert.Contains($"ExplorerMenuPackageFile = '{ExplorerMenuPackage.PackageFileName}';", script);
- Assert.Contains($"ExplorerMenuMinimumBuild = {ExplorerMenuPackage.MinimumBuild};", script);
- }
-
- [Fact]
- public void Script_finds_downloaded_engines_where_the_app_puts_them()
- {
- var marker = typeof(EngineInstaller).GetField("MarkerName", BindingFlags.NonPublic | BindingFlags.Static)?.GetRawConstantValue();
- Assert.Contains($"EngineMarker = '{marker}';", Script);
- Assert.Equal(
- Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Filee", "engines"),
- EngineEnvironment.DownloadRoot);
- Assert.Contains(@"ExpandConstant('{localappdata}\Filee\engines\')", Script);
- }
}