diff --git a/docs/PORTABLE.md b/docs/PORTABLE.md
index 49395d84d..21f667af8 100644
--- a/docs/PORTABLE.md
+++ b/docs/PORTABLE.md
@@ -11,7 +11,10 @@ Conversion work folders, temporary files and engine caches keep their existing b
A proxy set in Settings → General → Network is kept in `data/settings.json` as well, so the copy downloads engines
and updates through it on any computer without touching that computer's proxy settings.
An explicit `FILEE_DATA_DIR` still takes precedence.
-Installer packages keep using the normal user profile.
+Installer packages keep using the normal user profile. A distribution package made from the Linux archive must
+leave out `filee.portable` and any `data` folder (`installer/linux/INSTALL.txt` says so for packagers), or every user
+of it gets portable mode in a folder they can't write to. When the data folder can't be written, Filee shows the
+error in the UI language's fonts and writes it to stderr too, with the cause, since the log would be in that folder.
Update a marked copy by replacing its application files while keeping `filee.portable` and `data`.
### Bringing existing data along
diff --git a/installer/linux/INSTALL.txt b/installer/linux/INSTALL.txt
index 1fa126c83..3e1ee673f 100644
--- a/installer/linux/INSTALL.txt
+++ b/installer/linux/INSTALL.txt
@@ -4,6 +4,11 @@ in data beside the executable. On first start the app offers to copy existing
profile data and downloaded engines into unused portable data, leaving originals intact.
Installing with install.sh uses the normal user profile instead.
+Packagers: delete filee.portable (and any data folder) from an installed copy,
+for example after cp -a into /opt/filee, as install.sh does. With the marker,
+Filee keeps its data in data beside the executable; where users can't write
+there, it shows an error and does not start.
+
Run ./install.sh to install for the current user. It requires Python 3, creates
an application launcher and ~/.local/bin/filee, and does not require root.
Run ./install.sh --upgrade to safely upgrade an existing installation in place
diff --git a/src/Filee.App/PortableStartupFailure.cs b/src/Filee.App/PortableStartupFailure.cs
index 896d1a04f..5b8a62fa8 100644
--- a/src/Filee.App/PortableStartupFailure.cs
+++ b/src/Filee.App/PortableStartupFailure.cs
@@ -1,25 +1,36 @@
-// A portable copy with an unwritable data folder shows an error without loading settings or logging elsewhere.
+// A portable copy with an unwritable data folder shows an error without loading settings or logging elsewhere. The
+// message also goes to stderr, with the cause in English, since the log lives in that same folder (#1590).
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Layout;
using Avalonia.Media;
+using Filee.App.Services;
+using Filee.Core.Settings;
namespace Filee.App;
internal static class PortableStartupFailure
{
- public static int Show(string message)
+ public static int Show(string message, PortableStorageException error)
{
Console.Error.WriteLine(message);
+ Console.Error.WriteLine(Cause(error));
if (OperatingSystem.IsWindows())
Filee.Platform.Windows.Elevation.ShowWarning(message);
else
{
try
{
+ // Filee's own fonts, as in the app: without them Avalonia drew Chinese and other scripts the system's
+ // default font lacks as empty boxes (#1590).
AppBuilder.Configure(() => new FailureApplication(message)).UsePlatformDetect()
+ .ConfigureFonts(fonts =>
+ {
+ fonts.AddFontCollection(new FileeFontCollection());
+ fonts.AddFontCollection(new SystemUiFontCollection());
+ })
.StartWithClassicDesktopLifetime([], ShutdownMode.OnMainWindowClose);
}
catch (Exception ex) when (ex is not OutOfMemoryException)
@@ -31,6 +42,37 @@ public static int Show(string message)
return 1;
}
+ ///
+ /// The line for stderr after the message: the folder, why it failed, and the marker that asked for it, in English
+ /// for a bug report or a packager's terminal.
+ ///
+ internal static string Cause(PortableStorageException error) =>
+ $"Filee: {error.Message} ({error.InnerException?.Message ?? "unknown error"}). The {PortableMode.MarkerName} file " +
+ "beside Filee turns on portable mode; delete it to use the normal user profile. Installed packages must not include it.";
+
+ /// The message window, in the UI font chain of and its reading direction.
+ internal static Window CreateWindow(string message, string language)
+ {
+ var close = new Button { Content = LocalizationService.EarlyText("common.close"), HorizontalAlignment = HorizontalAlignment.Right };
+ var window = new Window
+ {
+ Title = "Filee",
+ Width = 520,
+ SizeToContent = SizeToContent.Height,
+ CanResize = false,
+ FontFamily = SoftPalette.FontFamilyFor(language),
+ FlowDirection = SoftPalette.IsRightToLeft(language) ? FlowDirection.RightToLeft : FlowDirection.LeftToRight,
+ Content = new StackPanel
+ {
+ Margin = new Thickness(24),
+ Spacing = 18,
+ Children = { new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap }, close },
+ },
+ };
+ close.Click += (_, _) => window.Close();
+ return window;
+ }
+
private sealed class FailureApplication(string message) : Application
{
public override void Initialize() => Styles.Add(new Avalonia.Themes.Fluent.FluentTheme());
@@ -38,24 +80,7 @@ private sealed class FailureApplication(string message) : Application
public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
- {
- var close = new Button { Content = Services.LocalizationService.EarlyText("common.close"), HorizontalAlignment = HorizontalAlignment.Right };
- var window = new Window
- {
- Title = "Filee",
- Width = 520,
- SizeToContent = SizeToContent.Height,
- CanResize = false,
- Content = new StackPanel
- {
- Margin = new Thickness(24),
- Spacing = 18,
- Children = { new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap }, close },
- },
- };
- close.Click += (_, _) => window.Close();
- desktop.MainWindow = window;
- }
+ desktop.MainWindow = CreateWindow(message, LocalizationService.Resolve("auto"));
base.OnFrameworkInitializationCompleted();
}
}
diff --git a/src/Filee.App/Program.cs b/src/Filee.App/Program.cs
index 7cd9ee4ed..4441c1807 100644
--- a/src/Filee.App/Program.cs
+++ b/src/Filee.App/Program.cs
@@ -54,7 +54,7 @@ public static int Main(string[] args)
{
var message = string.Format(System.Globalization.CultureInfo.CurrentCulture,
LocalizationService.EarlyText("startup.portable_unwritable"), ex.DataDirectory);
- return PortableStartupFailure.Show(message);
+ return PortableStartupFailure.Show(message, ex);
}
using var portableScope = portable;
// ImageMagick reads its policy once, at its first use; the app also calls it directly (crop, previews).
diff --git a/tests/Filee.App.Tests/PortableStartupFailureTests.cs b/tests/Filee.App.Tests/PortableStartupFailureTests.cs
new file mode 100644
index 000000000..a4f92866a
--- /dev/null
+++ b/tests/Filee.App.Tests/PortableStartupFailureTests.cs
@@ -0,0 +1,38 @@
+// The window and stderr line of a portable copy whose data folder can't be written (#1590): drawn in the UI language's
+// fonts, and the cause written where a packager or bug report sees it.
+
+using Avalonia.Controls;
+using Avalonia.Headless.XUnit;
+using Avalonia.Media;
+using Filee.App.Services;
+using Filee.Core.Settings;
+
+namespace Filee.App.Tests;
+
+public class PortableStartupFailureTests
+{
+ [AvaloniaTheory]
+ [InlineData("zh-CN", FlowDirection.LeftToRight)]
+ [InlineData("ar", FlowDirection.RightToLeft)]
+ [InlineData("en", FlowDirection.LeftToRight)]
+ public void The_window_uses_the_ui_fonts_and_direction_of_the_language(string language, FlowDirection direction)
+ {
+ var window = PortableStartupFailure.CreateWindow("Filee 无法写入便携数据文件夹", language);
+
+ Assert.Equal(SoftPalette.FontFamilyFor(language), window.FontFamily);
+ Assert.Equal(direction, window.FlowDirection);
+ Assert.Contains(((StackPanel)window.Content!).Children.OfType(), t => t.Text == "Filee 无法写入便携数据文件夹");
+ }
+
+ [Fact]
+ public void Stderr_names_the_folder_the_reason_and_the_marker()
+ {
+ var error = new PortableStorageException("/opt/filee/data", new UnauthorizedAccessException("Access to the path '/opt/filee/data' is denied."));
+
+ var line = PortableStartupFailure.Cause(error);
+
+ Assert.Contains("/opt/filee/data", line);
+ Assert.Contains("is denied", line);
+ Assert.Contains(PortableMode.MarkerName, line);
+ }
+}