diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7eeebff3..75a81ac8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,8 @@ jobs: timeout-minutes: 10 run: | set +e - for exe in src/Titano.App/bin/Release/net10.0-windows/Titano.exe src/Titano.Uploader/bin/Release/net10.0-windows/Titano.Uploader.exe; do + for exe in src/Titano.App/bin/Release/net10.0-windows/Titano.exe src/Titano.Uploader/bin/Release/net10.0-windows/Titano.Uploader.exe \ + src/Titano.Setup/bin/Release/net10.0-windows/Titano.Setup.exe; do name=$(basename "$exe" .exe) before=$(ls out/screenshots/*.png 2>/dev/null | wc -l) "$exe" --capture out/screenshots 2> "out/capture-$name.log" & diff --git a/i18n/en/Common.resx b/i18n/en/Common.resx index bcf09a3a..7df05c2e 100644 --- a/i18n/en/Common.resx +++ b/i18n/en/Common.resx @@ -13,4 +13,10 @@ Open Open logs {0} % + {0} B + {0} GB + {0} KB + {0} MB + {0} PB + {0} TB diff --git a/i18n/en/Setup.resx b/i18n/en/Setup.resx index 23dab393..651318ff 100644 --- a/i18n/en/Setup.resx +++ b/i18n/en/Setup.resx @@ -43,6 +43,9 @@ All users Just me {0} needed + {0:N0} more item + {0:N0} more items + Deletes {0} Remove my data {0} Setup Remove {0} diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 11c0ea73..e264dc55 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -479,6 +479,7 @@ Install in Program Files for every account · asks for administrator approval Return to the options without changing anything Choose the installation folder + Close setup without changing anything Close setup Ask the running programs to close · each one handles its unsaved work Install this program @@ -495,7 +496,8 @@ Open the program when setup finishes Open the installed program Already installed here · uninstall it first to change folder or scope - Also delete database, settings and logs in %LOCALAPPDATA%\Titano · photos in archives are not touched + Select at least one program to install + Also delete %LOCALAPPDATA%\Titano: database, backups, cache, settings, logs, the uploader queue and sign-in · photos in archives are kept Run the same step again Add the programs to the Start menu Remove programs, shortcuts and file types · your data is kept unless selected @@ -521,13 +523,16 @@ Title of the new sequence; leave empty to let the server name it Your password; only a sign-in token is kept, encrypted for your Windows account Pause; the queue survives a restart + Nothing queued Space left in your quota on the server Stop watching this folder; files already uploaded stay on the server Resume uploading Try again Try this file again now + Select Sequence to choose one Address of the Titano Server, such as https://nas.local:8443 Server, sign in, bandwidth, startup, tray + Show the first file that failed · press Enter on it to try again Check the server certificate and sign in Sign out and forget the saved token Run when you sign in to Windows diff --git a/i18n/en/Uploader.resx b/i18n/en/Uploader.resx index 4dbacf76..de0537a2 100644 --- a/i18n/en/Uploader.resx +++ b/i18n/en/Uploader.resx @@ -45,7 +45,7 @@ Not connected {0} free of {1} Limit - MB/sinvariant + MB/s Delete after upload Minimise to tray Start with Windows @@ -60,7 +60,9 @@ {0:N0} files Queue {0} left + Files in queue Paused + Upload progress Waiting for server Bandwidth Files @@ -102,6 +104,7 @@ {0}/s {0} · every {1} Every {0} + every {0} Watch folders Remove diff --git a/i18n/it/Common.it.resx b/i18n/it/Common.it.resx index 8794e75b..8f944d39 100644 --- a/i18n/it/Common.it.resx +++ b/i18n/it/Common.it.resx @@ -13,4 +13,10 @@ Apri Apri log {0}% + {0} byte + {0} GB + {0} KB + {0} MB + {0} PB + {0} TB diff --git a/i18n/it/Setup.it.resx b/i18n/it/Setup.it.resx index b2588356..57e525ae 100644 --- a/i18n/it/Setup.it.resx +++ b/i18n/it/Setup.it.resx @@ -43,6 +43,9 @@ Tutti gli utenti Solo per me {0} necessari + {0:N0} altro elemento + altri {0:N0} elementi + Elimina {0} Rimuovi i miei dati Installazione di {0} Rimozione di {0} diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index 94527f4f..f384abea 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -479,6 +479,7 @@ Installa in Programmi per tutti gli account · chiede l'autorizzazione di amministratore Torna alle opzioni senza modificare nulla Scegli la cartella di installazione + Chiudi l'installazione senza modificare nulla Chiudi l'installazione Chiedi ai programmi aperti di chiudersi · ognuno gestisce il lavoro non salvato Installa questo programma @@ -495,7 +496,8 @@ Apri il programma al termine dell'installazione Apri il programma installato Già installato qui · disinstallalo prima per cambiare cartella o ambito - Elimina anche database, impostazioni e log in %LOCALAPPDATA%\Titano · le foto negli archivi non vengono toccate + Seleziona almeno un programma da installare + Elimina anche %LOCALAPPDATA%\Titano: database, backup, cache, impostazioni, log, coda e accesso dell'uploader · le foto negli archivi restano Esegui di nuovo lo stesso passaggio Aggiungi i programmi al menu Start Rimuovi programmi, collegamenti e tipi di file · i dati restano salvo diversa scelta @@ -521,13 +523,16 @@ Titolo della nuova sequenza; lascialo vuoto per farlo scegliere al server La tua password; viene conservato solo un token di accesso, cifrato per il tuo account Windows Metti in pausa; la coda sopravvive a un riavvio + Nessun file in coda Spazio rimasto nella tua quota sul server Smetti di controllare questa cartella; i file già inviati restano sul server Riprendi l'invio Riprova Riprova subito questo file + Seleziona Sequenza per sceglierne una Indirizzo del Titano Server, ad esempio https://nas.local:8443 Server, accesso, banda, avvio, area di notifica + Mostra il primo file non riuscito · premi Invio per riprovarlo Controlla il certificato del server e accedi Esci e dimentica il token salvato Avvia quando accedi a Windows diff --git a/i18n/it/Uploader.it.resx b/i18n/it/Uploader.it.resx index e4eb6bb7..013dcd0c 100644 --- a/i18n/it/Uploader.it.resx +++ b/i18n/it/Uploader.it.resx @@ -43,6 +43,7 @@ Non connesso {0} liberi su {1} Limite + MB/s Elimina dopo l'invio Riduci nell'area notifiche Avvia con Windows @@ -57,7 +58,9 @@ {0:N0} file Coda mancano {0} + File in coda In pausa + Avanzamento caricamento In attesa del server Banda File @@ -99,6 +102,7 @@ {0}/s {0} · ogni {1} Ogni {0} + ogni {0} Cartelle controllate Rimuovi diff --git a/src/Titano.Setup/Engine/UserDataPlan.cs b/src/Titano.Setup/Engine/UserDataPlan.cs new file mode 100644 index 00000000..1e773ba1 --- /dev/null +++ b/src/Titano.Setup/Engine/UserDataPlan.cs @@ -0,0 +1,42 @@ +using System.IO; + +namespace Titano.Setup.Engine; + +/// One top-level file or folder of the user data folder and the bytes it holds. +internal sealed record UserDataEntry(string Name, long Bytes); + +/// +/// Dry run of "Remove my data" (BRIEF §0.2 rule 8: a destructive operation shows its plan first): every top-level +/// entry of the user data folder with its size, largest first. Links are not followed, as the deletion does not +/// follow them either. +/// +internal sealed record UserDataPlan(IReadOnlyList Entries) +{ + private static readonly EnumerationOptions TopLevel = new() { IgnoreInaccessible = true, AttributesToSkip = 0 }; + + private static readonly EnumerationOptions Contents = new() + { + RecurseSubdirectories = true, + IgnoreInaccessible = true, + AttributesToSkip = FileAttributes.ReparsePoint, + }; + + public long TotalBytes => Entries.Sum(e => e.Bytes); + + /// Measures ; empty when it does not exist. Reads sizes only, changes nothing. + public static UserDataPlan Measure(string folder) + { + var root = new DirectoryInfo(folder); + if (!root.Exists) return new UserDataPlan([]); + var entries = root.EnumerateFileSystemInfos("*", TopLevel).Select(e => new UserDataEntry(e.Name, SizeOf(e))); + return new UserDataPlan([.. entries.OrderByDescending(e => e.Bytes).ThenBy(e => e.Name, StringComparer.OrdinalIgnoreCase)]); + } + + private static long SizeOf(FileSystemInfo entry) => entry switch + { + _ when entry.Attributes.HasFlag(FileAttributes.ReparsePoint) => 0, + DirectoryInfo folder => folder.EnumerateFiles("*", Contents).Sum(f => f.Length), + FileInfo file => file.Length, + _ => 0, + }; +} diff --git a/src/Titano.Setup/Program.cs b/src/Titano.Setup/Program.cs index 0b8fb35c..abb738c3 100644 --- a/src/Titano.Setup/Program.cs +++ b/src/Titano.Setup/Program.cs @@ -18,6 +18,8 @@ internal static class Program using var log = new FileLogSink(SetupPaths.LogDirectory, "setup"); Log.SetSink(log); Log.Info("setup", $"Titano.Setup {typeof(Program).Assembly.GetName().Version} {string.Join(' ', args)}"); + // The screenshot mode of every Titano program (CI); it builds its own sample installer. + if (args is ["--capture", var captureDirectory]) return Views.SetupCapture.Run(captureDirectory); SetupArguments arguments; try diff --git a/src/Titano.Setup/Views/ComponentOption.cs b/src/Titano.Setup/Views/ComponentOption.cs index 062ba257..45b8336f 100644 --- a/src/Titano.Setup/Views/ComponentOption.cs +++ b/src/Titano.Setup/Views/ComponentOption.cs @@ -30,20 +30,20 @@ internal sealed class ComponentOption(PayloadComponent component, bool selected, /// Language offered in the picker. internal sealed record LanguageOption(string Code, string Name); -/// Decimal byte sizes as Explorer shows them for drives ("1.5 MB"). +/// Decimal byte sizes as Explorer shows them for drives ("1.5 MB"), units in the UI language ("1,5 Mo"). internal static class ByteSize { - private static readonly string[] Units = ["B", "KB", "MB", "GB", "TB"]; + private static readonly string[] Formats = ["Common.Size.B", "Common.Size.KB", "Common.Size.MB", "Common.Size.GB", "Common.Size.TB"]; public static string Format(long bytes) { double value = bytes; var unit = 0; - while (value >= 1000 && unit < Units.Length - 1) + while (value >= 1000 && unit < Formats.Length - 1) { value /= 1000; unit++; } - return value.ToString(unit == 0 || value >= 100 ? "0" : "0.#", Loc.Culture) + " " + Units[unit]; + return Loc.L(Formats[unit], value.ToString(unit == 0 || value >= 100 ? "0" : "0.#", Loc.Culture)); } } diff --git a/src/Titano.Setup/Views/SetupCapture.cs b/src/Titano.Setup/Views/SetupCapture.cs new file mode 100644 index 00000000..1212b8e9 --- /dev/null +++ b/src/Titano.Setup/Views/SetupCapture.cs @@ -0,0 +1,196 @@ +using System.IO; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Threading; +using Titano.Core.Diagnostics; +using Titano.Core.Packaging; +using Titano.Setup.Cli; +using Titano.Setup.Engine; +using Titano.Ui.Theming; + +namespace Titano.Setup.Views; + +/// +/// Titano.Setup.exe --capture <dir>: renders the setup window in every stage (install options, programs +/// running, installing, installed, failed, uninstall with its data plan) in the dark and light themes, then in +/// Arabic (right to left, dark), from a small sample installer built in a temporary folder. Nothing is installed, +/// removed or registered. +/// +internal static class SetupCapture +{ + private const string Product = "Titano"; + + private static readonly (string Name, SetupStage Stage)[] InstallStages = + [ + ("install", SetupStage.Options), + ("running", SetupStage.Confirm), + ("installing", SetupStage.Working), + ("installed", SetupStage.Done), + ("failed", SetupStage.Failed), + ]; + + /// What a user data folder typically holds; eight entries, so the plan also shows its "more" line. + private static readonly UserDataPlan SamplePlan = new( + [ + new UserDataEntry("cache", 2_140_000_000), + new UserDataEntry("backups", 1_210_000_000), + new UserDataEntry("titano.db", 41_000_000), + new UserDataEntry("logs", 12_400_000), + new UserDataEntry("titano.db-wal", 4_200_000), + new UserDataEntry("uploader-queue.json", 1_900_000), + new UserDataEntry("settings.json", 3_100), + new UserDataEntry("uploader.json", 1_200), + ]); + + /// Returns the process exit code: 0 when every screen was written. + public static int Run(string directory) + { + var work = Directory.CreateTempSubdirectory("titano-setup-capture-").FullName; + try + { + var installer = WriteSampleInstaller(work); + var app = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown }; + ThemeManager.Initialize(app, AppTheme.Dark); + var code = 0; + app.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () => + { + try + { + Directory.CreateDirectory(directory); + CaptureLanguage(installer, directory, "en", string.Empty, [AppTheme.Dark, AppTheme.Light]); + // Mirrored layout with paths and file names kept left to right (BRIEF §16). + CaptureLanguage(installer, directory, "ar", "-ar", [AppTheme.Dark]); + Log.Info("capture", $"Screenshots written to {Path.GetFullPath(directory)}"); + } + catch (Exception ex) + { + Log.Error("capture", "Capture failed", ex); + code = 1; + } + finally + { + app.Shutdown(); + } + }); + app.Run(); + return code; + } + finally + { + try + { + Directory.Delete(work, recursive: true); + } + catch (IOException ex) + { + // The sample installer may still be mapped; the OS temp cleanup takes it. + Log.Warning("capture", $"Sample installer folder '{work}' not removed", ex); + } + } + } + + private static void CaptureLanguage(string installer, string directory, string language, string suffix, IReadOnlyList themes) + { + Program.ApplyLanguage(language); + using var payload = PayloadReader.Open(installer); + using var install = SetupViewModel.ForInstall(new SetupArguments(), payload); + using var uninstall = SetupViewModel.ForUninstall(new SetupArguments(), new InstalledProduct( + SetupPaths.DefaultDirectory(InstallScope.CurrentUser, Product), new InstallLog { Product = Product, Version = "1.0.0" })); + foreach (var theme in themes) + { + ThemeManager.Apply(theme); + var name = suffix + "-" + theme.ToString().ToLowerInvariant(); + Capture(install, [.. InstallStages.Select(s => ("setup-" + s.Name + name, s.Stage, (UserDataPlan?)null))], directory); + Capture(uninstall, [("setup-uninstall" + name, SetupStage.Options, SamplePlan)], directory); + } + } + + /// One window per model; each screen puts the model in its stage and is saved as <file>.png. + private static void Capture(SetupViewModel model, IReadOnlyList<(string File, SetupStage Stage, UserDataPlan? Plan)> screens, string directory) + { + var window = new SetupWindow(model) + { + WindowStartupLocation = WindowStartupLocation.Manual, + Left = -20000, + Top = -20000, + ShowActivated = false, + ShowInTaskbar = false, + }; + window.Show(); + try + { + foreach (var (file, stage, plan) in screens) + { + model.Preview(stage, plan); + Save(window, Path.Combine(directory, file + ".png")); + } + } + finally + { + window.Close(); + } + } + + /// Three components of random (incompressible) bytes, with the shortcuts the real installer carries. + private static string WriteSampleInstaller(string work) + { + var random = new Random(1); + var components = new (string Id, string DisplayName, bool Selected, string Program, int Bytes)[] + { + ("Titano", "Titano", true, "Titano.exe", 2_400_000), + ("Uploader", "Titano Uploader", true, "Titano.Uploader.exe", 900_000), + ("Server", "Titano Server", false, "Titano.Server.exe", 1_600_000), + }; + foreach (var c in components) + { + var folder = Directory.CreateDirectory(Path.Combine(work, c.Id)).FullName; + var bytes = new byte[c.Bytes]; + random.NextBytes(bytes); + File.WriteAllBytes(Path.Combine(folder, c.Program), bytes); + } + var installer = Path.Combine(work, "setup.exe"); + PayloadWriter.Write(Environment.ProcessPath ?? throw new InvalidOperationException("No process path."), new PayloadSource + { + Product = Product, + Version = "1.0.0", + Components = [.. components.Select(c => new PayloadComponentSource(c.Id, c.DisplayName, c.Selected, Path.Combine(work, c.Id)))], + Shortcuts = [.. components.Select(c => new PayloadShortcut { Component = c.Id, Name = c.DisplayName, Target = c.Program, StartMenu = true, Desktop = c.Id != "Server" })], + }, installer); + return installer; + } + + private static void Save(Window window, string path) + { + // Let bindings, templates and deferred layout complete. + window.UpdateLayout(); + window.Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, () => { }); + window.UpdateLayout(); + if (VisualTreeHelper.GetChildrenCount(window) == 0) return; + var root = (FrameworkElement)VisualTreeHelper.GetChild(window, 0); + var dpi = VisualTreeHelper.GetDpi(window); + var width = (int)Math.Ceiling(root.ActualWidth * dpi.DpiScaleX); + var height = (int)Math.Ceiling(root.ActualHeight * dpi.DpiScaleY); + if (width <= 0 || height <= 0) return; + var bitmap = new RenderTargetBitmap(width, height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32); + bitmap.Render(window.FlowDirection == FlowDirection.RightToLeft ? Mirrored(root) : root); + var encoder = new PngBitmapEncoder(); + encoder.Frames.Add(BitmapFrame.Create(bitmap)); + using var stream = File.Create(path); + encoder.Save(stream); + } + + /// + /// A right-to-left window is mirrored by a transform on the window itself, which rendering its content alone + /// would leave out: draw the content through that mirror. + /// + private static DrawingVisual Mirrored(FrameworkElement root) + { + var size = new Rect(0, 0, root.ActualWidth, root.ActualHeight); + var visual = new DrawingVisual(); + using var dc = visual.RenderOpen(); + dc.PushTransform(new MatrixTransform(-1, 0, 0, 1, size.Width, 0)); + dc.DrawRectangle(new VisualBrush(root) { Stretch = Stretch.Fill, ViewboxUnits = BrushMappingMode.Absolute, Viewbox = size }, null, size); + return visual; + } +} diff --git a/src/Titano.Setup/Views/SetupViewModel.cs b/src/Titano.Setup/Views/SetupViewModel.cs index 3a68e5aa..8cc1b642 100644 --- a/src/Titano.Setup/Views/SetupViewModel.cs +++ b/src/Titano.Setup/Views/SetupViewModel.cs @@ -11,6 +11,9 @@ using Titano.Ui.Mvvm; namespace Titano.Setup.Views; +/// A line of the "Remove my data" dry run: a file or folder name (or "3 more items") and its size. +internal sealed record DataPlanRow(string Name, string Size, bool IsFileName); + /// What the setup screen currently shows. internal enum SetupStage { @@ -28,6 +31,10 @@ internal enum SetupStage internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo { private const string FallbackProduct = "Titano"; + + /// Largest entries listed in the data plan; the rest are summed in one line. + private const int PlanRows = 6; + private readonly SetupArguments _arguments; private readonly PayloadReader? _payload; private readonly InstallEngine? _engine; @@ -42,6 +49,8 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo private bool _startMenu; private bool _launchAfter; private bool _removeUserData; + private UserDataPlan? _dataPlan; + private bool _measuring; private bool _closeConfirmed; private double _progress; private bool _indeterminate; @@ -197,6 +206,7 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo if (!Set(ref _directory, value ?? string.Empty)) return; ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(nameof(Directory))); OnPropertyChanged(nameof(DirectoryToolTip)); + OnPropertyChanged(nameof(InstallToolTip)); } } @@ -206,6 +216,9 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo ? Loc.L("Tooltips.Setup.Locked") : IsDirectoryValid ? Loc.L("Tooltips.Setup.Folder") : Loc.L("Tooltips.Setup.FolderInvalid"); + /// Browse is disabled when upgrading; its tooltip then says why (DESIGN §4). + public string BrowseToolTip => CanChangeLocation ? Loc.L("Tooltips.Setup.Browse") : Loc.L("Tooltips.Setup.Locked"); + public string JustMeToolTip => CanChangeLocation ? Loc.L("Tooltips.Setup.JustMe") : Loc.L("Tooltips.Setup.Locked"); public string AllUsersToolTip => CanChangeLocation ? Loc.L("Tooltips.Setup.AllUsers") : Loc.L("Tooltips.Setup.Locked"); @@ -232,16 +245,46 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo public bool HasLaunchOption => _engine?.LaunchTarget(SelectedComponents) is not null; public string InstallText => CanChangeLocation ? Loc.L("Setup.Action.Install") : Loc.L("Setup.Action.Update"); - public string InstallToolTip => CanChangeLocation ? Loc.L("Tooltips.Setup.Install") : Loc.L("Tooltips.Setup.Update"); - private bool CanStart => IsOptions && (IsUninstall || (IsInstall && IsDirectoryValid && Components.Any(c => c.IsSelected))); + /// What Install does, or why it is disabled: no program selected, or a folder it cannot use. + public string InstallToolTip => !Components.Any(c => c.IsSelected) ? Loc.L("Tooltips.Setup.NoComponent") + : !IsDirectoryValid ? Loc.L("Tooltips.Setup.FolderInvalid") + : CanChangeLocation ? Loc.L("Tooltips.Setup.Install") : Loc.L("Tooltips.Setup.Update"); + + /// Removing user data waits for its plan, so the user has seen what goes before choosing Uninstall. + private bool CanStart => IsOptions && (IsUninstall ? !_removeUserData || _dataPlan is not null : IsInstall && IsDirectoryValid && Components.Any(c => c.IsSelected)); // ---- Uninstall options ---- + /// Checking it measures the user data folder; the plan is shown before Uninstall can run. public bool RemoveUserData { get => _removeUserData; - set => Set(ref _removeUserData, value); + set + { + if (!Set(ref _removeUserData, value)) return; + OnPropertyChanged(nameof(IsDataPlanVisible)); + CommandManager.InvalidateRequerySuggested(); + if (value && _dataPlan is null) _ = MeasureUserDataAsync(); + } + } + + public bool IsDataPlanVisible => _removeUserData && _dataPlan is not null; + + /// "Deletes 3.4 GB" over the plan's lines. + public string DataPlanText => _dataPlan is null ? string.Empty : Loc.L("Setup.Uninstall.Plan", ByteSize.Format(_dataPlan.TotalBytes)); + + /// The largest entries of the user data folder, then one line for the rest. + public IReadOnlyList DataPlanRows + { + get + { + if (_dataPlan is null) return []; + var rows = _dataPlan.Entries.Take(PlanRows).Select(e => new DataPlanRow(e.Name, ByteSize.Format(e.Bytes), IsFileName: true)).ToList(); + var rest = _dataPlan.Entries.Skip(PlanRows).ToList(); + if (rest.Count > 0) rows.Add(new DataPlanRow(Loc.Plural("Setup.Uninstall.More", rest.Count), ByteSize.Format(rest.Sum(e => e.Bytes)), IsFileName: false)); + return rows; + } } // ---- Confirm, progress, outcome ---- @@ -294,6 +337,12 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo public bool CanRetry => IsFailed && _failure is not (SetupExitCode.PayloadInvalid or SetupExitCode.NotInstalled or SetupExitCode.InvalidArguments); + /// Done or failed: Close is offered (and Esc closes). + public bool IsFinished => IsDone || IsFailed; + + /// Close is the default action when there is nothing to launch or retry. + public bool IsCloseDefault => IsFinished && !CanLaunch && !CanRetry; + public ICommand PrimaryCommand { get; } public ICommand BrowseCommand { get; } public ICommand CloseProgramsCommand { get; } @@ -313,6 +362,23 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo if (_arguments.Elevated && IsInstall && CanStart) Start(InstallAsync); } + /// + /// For --capture only: shows with sample progress and outcome (a program to + /// launch, a full disk) and, when given, a data plan with "Remove my data" checked. Nothing runs. + /// + internal void Preview(SetupStage stage, UserDataPlan? dataPlan = null) + { + _runningPrograms = "Titano Uploader"; + _progress = 0.46; + _indeterminate = false; + _progressFile = @"Titano\Titano.Core.dll"; + _launchProgram = IsInstall ? "Titano.exe" : null; + _failure = SetupExitCode.DiskFull; + _dataPlan = dataPlan; + _removeUserData = dataPlan is not null; + Stage = stage; + } + public override void Dispose() { foreach (var c in Components) c.Dispose(); @@ -498,9 +564,33 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo Stage = SetupStage.Failed; } + private async Task MeasureUserDataAsync() + { + if (_measuring) return; + _measuring = true; + try + { + _dataPlan = await Task.Run(() => UserDataPlan.Measure(SetupPaths.UserData)); + } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException) + { + Log.Warning("setup", $"User data '{SetupPaths.UserData}' not measured", ex); + _dataPlan = new UserDataPlan([]); + } + finally + { + _measuring = false; + } + OnPropertyChanged(nameof(IsDataPlanVisible)); + OnPropertyChanged(nameof(DataPlanText)); + OnPropertyChanged(nameof(DataPlanRows)); + CommandManager.InvalidateRequerySuggested(); + } + private void OnComponentsChanged() { OnPropertyChanged(nameof(RequiredSpaceText)); + OnPropertyChanged(nameof(InstallToolTip)); OnPropertyChanged(nameof(HasDesktopOption)); OnPropertyChanged(nameof(HasStartMenuOption)); OnPropertyChanged(nameof(HasLaunchOption)); diff --git a/src/Titano.Setup/Views/SetupWindow.xaml b/src/Titano.Setup/Views/SetupWindow.xaml index 9b4495b6..e7a794fb 100644 --- a/src/Titano.Setup/Views/SetupWindow.xaml +++ b/src/Titano.Setup/Views/SetupWindow.xaml @@ -18,7 +18,8 @@ - + + @@ -43,7 +44,7 @@ - + @@ -58,13 +59,18 @@ ToolTipService.ShowOnDisabled="True" ToolTip="{Binding AllUsersToolTip}" /> + - - @@ -196,7 +250,7 @@ -