feat(setup): --capture renders every setup stage, uninstall plan and Arabic layout
The installer had no screenshot mode, so CI could not review its stages. Titano.Setup.exe --capture <dir> builds a small sample installer in a temporary folder and renders install options, programs running, installing, installed, failed and uninstall with the "Remove my data" plan, in the dark and light themes and in Arabic (mirrored). Nothing is installed, removed or registered. Also: uploader smoke tests (names, focusable rows, no premature errors, right-to-left islands), and watch chips cap the path itself because the button template measures content without a width limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
6 files changed
+415
-6
No files matched your search
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// <c>Titano.Setup.exe --capture <dir></c>: 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.
|
||||
/// </summary>
|
||||
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),
|
||||
];
|
||||
|
||||
/// <summary>What a user data folder typically holds; eight entries, so the plan also shows its "more" line.</summary>
|
||||
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),
|
||||
]);
|
||||
|
||||
/// <summary>Returns the process exit code: 0 when every screen was written.</summary>
|
||||
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<AppTheme> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>One window per model; each screen puts the model in its stage and is saved as <c><file>.png</c>.</summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Three components of random (incompressible) bytes, with the shortcuts the real installer carries.</summary>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -361,6 +361,23 @@ internal sealed class SetupViewModel : LocalizedViewModel, INotifyDataErrorInfo
|
||||
if (_arguments.Elevated && IsInstall && CanStart) Start(InstallAsync);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For <c>--capture</c> only: shows <paramref name="stage"/> 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.
|
||||
/// </summary>
|
||||
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();
|
||||
|
||||
Reference in new issue
Block a user