Files
Febe/src/Febe.Installer/SetupFlow.cs
T
Alby96andClaude Opus 5.5 be662f2d28 Correzioni della revisione di C6: installatore, CI senza jq, caratteri e schermate senza Node
Le 14 osservazioni della revisione di funzione/senza-terzi, ciascuna con la prova che l'avrebbe trovata.

Installatore: un aggiornamento senza /D= va nella cartella già installata (InstallLocation)
invece che in quella predefinita, che lasciava la vecchia copia. Una cartella senza permessi
non sembra più «Febe aperto». La dimensione in «App installate» conta solo i due file
dell'installatore. I file in sola lettura si sostituiscono e si tolgono. «Febe» in Esegui
all'avvio si toglie solo se avvia quella copia, non un Febe portatile. Febe parte alla fine
solo con «Fine» e la casella spuntata. /PROVA= rifiuta la radice di un disco.

CI: jq non c'era ed era un componente esterno. JSON letto e scritto con .gitea/scripts/json.sh
(json-campi.awk e json-stringa.awk sul lettore json.awk) per gitleaks, Trivy e la release.
Le credenziali del registro stanno solo in un DOCKER_CONFIG temporaneo della pubblicazione,
con plugin, contesti e contesto corrente del runner, tolto alla fine. Le prove del rilascio
girano in debian:trixie con Chromium, come la verifica, senza prove saltate. Ogni flusso usa
shell: bash.

Caratteri: tolti fonts-liberation e fonts-noto-color-emoji dall'immagine e dalle prove della
CI, perché Chromium non li chiede. Resta fonts-dejavu-core.

Icone: la prova della griglia legge davvero i percorsi SVG (tutti i comandi, archi e curve) e
i punti. La lettura dei nomi delle icone vede ogni forma con cui l'interfaccia li chiede.

Schermate: tools/schermate (Node) diventa tools/Febe.Schermate, in C# con ClientWebSocket e
System.Text.Json, nessun pacchetto, solo verso indirizzi di questo computer. Provato contro
una dimostrazione con Edge su Windows.

Documenti: CLAUDE.md, processo, guida, LEGGIMI e docker.md aggiornati. Righe nuove in
decisioni.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 16:04:39 +01:00

231 lines
8.3 KiB
C#

namespace Febe.Installer;
/// <summary>The exit codes of the installer and of the uninstaller.</summary>
internal static class ExitCodes
{
public const int Done = 0;
/// <summary>Alberto said no: «Annulla».</summary>
public const int Cancelled = 1;
/// <summary>Something went wrong, or Febe is open in silent mode: nothing was changed, or only the part said.</summary>
public const int Failed = 2;
}
/// <summary>
/// The dialogs of the installation: the windows of Windows (<c>DialogInterface</c>) or, with <c>/S</c>, none
/// (<see cref="SilentInterface"/>). The tests use a fake that answers as told.
/// </summary>
internal interface ISetupInterface
{
/// <summary>The first page; null for «Annulla», otherwise whether the desktop shortcut is wanted.</summary>
bool? Welcome(string version, string? installedVersion, string installFolder);
/// <summary>Febe is open: true to try again (after closing it), false to give up.</summary>
bool RetryWhenFebeIsOpen(bool uninstalling);
/// <summary>Runs <paramref name="work"/> showing its progress (0 to 1); its exception comes out of here.</summary>
void RunWithProgress(string version, string installFolder, Action<Action<double>> work);
/// <summary>WebView2 is missing: true to open the page of Microsoft.</summary>
bool OfferWebView2Page();
/// <summary>The last page of the installation: true to start Febe now.</summary>
bool Installed();
bool ConfirmUninstall();
void Uninstalled(string dataFolder, string library);
void Failed(bool uninstalling, string message);
}
/// <summary>
/// <c>/S</c>: no dialog, the answers of the silent mode before: the desktop shortcut yes, Febe open means stop, the page
/// of WebView2 no, Febe not started. A failure goes to the standard error, for whoever started the installer.
/// </summary>
internal sealed class SilentInterface(TextWriter errors) : ISetupInterface
{
public bool? Welcome(string version, string? installedVersion, string installFolder) => true;
public bool RetryWhenFebeIsOpen(bool uninstalling) => false;
public void RunWithProgress(string version, string installFolder, Action<Action<double>> work) => work(_ => { });
public bool OfferWebView2Page() => false;
public bool Installed() => false;
public bool ConfirmUninstall() => true;
public void Uninstalled(string dataFolder, string library)
{
}
public void Failed(bool uninstalling, string message)
{
try
{
errors.WriteLine((uninstalling ? Texts.UninstallFailed : Texts.InstallFailed) + ": " + message);
errors.Flush();
}
catch (IOException)
{
// No one is reading: the exit code says it.
}
}
}
/// <summary>
/// The steps of the installer and of the uninstaller, in the order they always had: first page, Febe closed, copy,
/// WebView2, last page; for the uninstaller: a copy of itself in %TEMP% (an executable cannot delete itself),
/// confirmation, Febe closed, removal, where the data stayed.
/// </summary>
internal sealed class SetupFlow(ISystemAccess system, Locations locations, ISetupInterface ui)
{
private readonly SetupActions _actions = new(system, locations);
/// <summary>The installer: <paramref name="packagePath"/> is this program, with Febe.exe inside.</summary>
public int Install(string packagePath, PackageInfo package, CommandLine line)
{
// Without /D= an update goes where Febe already is, not to the default folder: otherwise the old program would
// stay there, orphaned, while the entry and the shortcuts moved to a second copy.
var folder = line.InstallFolder ?? _actions.InstalledFolder() ?? locations.DefaultInstallFolder;
var desktop = ui.Welcome(package.Version, _actions.InstalledVersion(), folder);
if (desktop is null)
{
return ExitCodes.Cancelled;
}
if (!WaitUntilFebeIsClosed(folder, uninstalling: false, line.Silent))
{
return line.Silent ? ExitCodes.Failed : ExitCodes.Cancelled;
}
try
{
ui.RunWithProgress(package.Version, folder, progress =>
_actions.Install(new InstallRequest(packagePath, package, folder, desktop.Value), progress));
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or InvalidOperationException)
{
ui.Failed(uninstalling: false, Texts.Failure(ex));
return ExitCodes.Failed;
}
// WebView2: without it Febe cannot show anything. Febe says it too on its first start.
if (_actions.WebView2Version() is null && ui.OfferWebView2Page())
{
system.OpenAddress(Product.WebView2Page);
}
if (ui.Installed())
{
try
{
system.Start(Path.Combine(folder, Product.Executable), [], folder);
}
catch (Exception ex) when (ex is System.ComponentModel.Win32Exception or InvalidOperationException or IOException)
{
// Febe is installed all the same; it opens from the Start menu.
}
}
return ExitCodes.Done;
}
/// <summary>
/// The uninstaller. Started from the program folder (<paramref name="selfPath"/> is «Disinstalla Febe.exe» there), it
/// copies itself into %TEMP%, starts the copy and ends; the copy waits for it, then does the work and can delete
/// the original.
/// </summary>
public int Uninstall(string selfPath, CommandLine line)
{
if (line.UninstallFolder is null)
{
var installFolder = Path.GetDirectoryName(Path.GetFullPath(selfPath))!;
Directory.CreateDirectory(locations.Temp);
var copy = Path.Combine(locations.Temp, $"{Product.UninstallerCopyPrefix}{Environment.ProcessId}.exe");
File.Copy(selfPath, copy, overwrite: true);
system.Start(copy, [.. line.PassOn(), "/_?=" + installFolder, $"/ATTENDI={Environment.ProcessId}"], locations.Temp);
return ExitCodes.Done;
}
if (line.WaitFor is { } parent)
{
system.WaitForExit(parent, TimeSpan.FromSeconds(30));
}
var folder = line.UninstallFolder;
if (!ui.ConfirmUninstall())
{
return ExitCodes.Cancelled;
}
if (!WaitUntilFebeIsClosed(folder, uninstalling: true, line.Silent))
{
return line.Silent ? ExitCodes.Failed : ExitCodes.Cancelled;
}
// Read before anything is removed, to say at the end where the data stayed.
var dataFolder = _actions.DataFolder();
try
{
_actions.Uninstall(folder);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
ui.Failed(uninstalling: true, Texts.Failure(ex));
return ExitCodes.Failed;
}
ui.Uninstalled(dataFolder, locations.Library);
return ExitCodes.Done;
}
/// <summary>
/// Copies of the uninstaller left in %TEMP% by earlier uninstallations (a running program cannot delete itself):
/// removed when they are no longer running. Never anything else.
/// </summary>
public static void RemoveOldUninstallerCopies(Locations locations, string? selfPath)
{
try
{
if (!Directory.Exists(locations.Temp))
{
return;
}
foreach (var copy in Directory.EnumerateFiles(locations.Temp, Product.UninstallerCopyPrefix + "*.exe"))
{
if (selfPath is null || !string.Equals(Path.GetFullPath(copy), Path.GetFullPath(selfPath), StringComparison.OrdinalIgnoreCase))
{
Package.TryDelete(copy);
}
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
}
}
private bool WaitUntilFebeIsClosed(string folder, bool uninstalling, bool silent)
{
while (SetupActions.IsFebeOpen(folder))
{
if (silent)
{
ui.Failed(uninstalling, Texts.FebeOpenSilent);
return false;
}
if (!ui.RetryWhenFebeIsOpen(uninstalling))
{
return false;
}
}
return true;
}
}