- Windows services whose program lies in the install folder (Titano.Server --install-service) are found in the registry and, through the Service Control Manager, stopped before files are replaced (they join the "programs running" prompt), started again after an upgrade that stopped them, deleted when an upgrade drops their program and on uninstall. An unelevated setup runs that step in an elevated copy (/SERVICES=...). - The Server component installs for all users only (manifest allUsersOnly): choosing it moves a new install to Program Files and disables "Just me" with the reason; a per-user install cannot take it. - Uninstall removes every HKCU Run value that starts a program in the folder (the Uploader's "Start with Windows"). - A shortcut that already starts an existing program elsewhere is neither retargeted nor logged, and a logged shortcut is deleted only while it still starts a program of this folder, so the two products no longer remove each other's "Titano Uploader" shortcuts. - "Remove my data" lists and deletes only the data of this product's programs that no other installed Titano product uses (the desktop app and the Uploader share %LOCALAPPDATA%\Titano and its logs folder). - The .titano file type is named in setup's language (Setup.FileType.*). Setup tests run in Titano.App.Tests on Windows CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
103 lines
4.5 KiB
C#
103 lines
4.5 KiB
C#
using System.IO;
|
|
using Titano.Setup.Engine;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.App.Tests.Setup;
|
|
|
|
/// <summary>
|
|
/// "Remove my data" covers only the programs being removed (SRS-05): the desktop app and the Uploader share
|
|
/// %LOCALAPPDATA%\Titano and its logs folder, and uninstalling one product never deletes what another still uses.
|
|
/// </summary>
|
|
public sealed class UserDataPlanTests(TestContext context)
|
|
{
|
|
[Test]
|
|
public void TheDesktopAppsPlanLeavesTheUploadersFiles()
|
|
{
|
|
var folder = SampleFolder();
|
|
var plan = UserDataPlan.Measure(folder, Owners(UserDataOwners.Titano));
|
|
|
|
Assert.SequenceEqual(
|
|
["backups", "cache", "logs" + Path.DirectorySeparatorChar + "titano-20261012.log", "settings.json", "titano.db"],
|
|
plan.Entries.Select(e => e.Name).Order(StringComparer.Ordinal));
|
|
Assert.Equal(4000L + 3000 + 300 + 20 + 100, plan.TotalBytes);
|
|
|
|
plan.Remove();
|
|
Assert.SequenceEqual(
|
|
["logs" + Path.DirectorySeparatorChar + "uploader-20261012.log", "uploader-queue.json", "uploader.json"],
|
|
Directory.EnumerateFiles(folder, "*", SearchOption.AllDirectories).Select(f => Path.GetRelativePath(folder, f)).Order(StringComparer.Ordinal));
|
|
Assert.False(Directory.Exists(Path.Combine(folder, "cache")));
|
|
}
|
|
|
|
[Test]
|
|
public void TheUploadersPlanLeavesTheDesktopAppsFilesAndEmptiedFoldersGo()
|
|
{
|
|
var folder = SampleFolder();
|
|
var plan = UserDataPlan.Measure(folder, Owners(UserDataOwners.Uploader));
|
|
|
|
Assert.SequenceEqual(
|
|
["logs" + Path.DirectorySeparatorChar + "uploader-20261012.log", "uploader-queue.json", "uploader.json"],
|
|
plan.Entries.Select(e => e.Name).Order(StringComparer.Ordinal));
|
|
|
|
plan.Remove();
|
|
Assert.True(File.Exists(Path.Combine(folder, "titano.db")));
|
|
Assert.True(File.Exists(Path.Combine(folder, "logs", "titano-20261012.log")));
|
|
Assert.FileMissing(Path.Combine(folder, "uploader.json"));
|
|
Assert.FileMissing(Path.Combine(folder, "logs", "uploader-20261012.log"));
|
|
|
|
// Once the desktop app's data goes too, nothing is left of the folder.
|
|
UserDataPlan.Measure(folder, Owners(UserDataOwners.Titano)).Remove();
|
|
Assert.False(Directory.Exists(folder));
|
|
}
|
|
|
|
[Test]
|
|
public void BothProgramsDataIsTheWholeFolderAndNoOwnerIsAnEmptyPlan()
|
|
{
|
|
var folder = SampleFolder();
|
|
var whole = UserDataPlan.Measure(folder, UserDataOwners.All);
|
|
Assert.SequenceEqual(
|
|
["backups", "cache", "logs", "settings.json", "titano.db", "uploader-queue.json", "uploader.json"],
|
|
whole.Entries.Select(e => e.Name).Order(StringComparer.Ordinal));
|
|
Assert.Empty(UserDataPlan.Measure(folder, Owners()).Entries);
|
|
|
|
whole.Remove();
|
|
Assert.False(Directory.Exists(folder));
|
|
}
|
|
|
|
[Test]
|
|
public void AProductRemovesTheDataOfItsProgramsThatNoOtherInstalledProductHas()
|
|
{
|
|
string[] titano = ["Titano", "Uploader", "Server"];
|
|
string[] uploader = ["Uploader"];
|
|
|
|
Assert.SequenceEqual(["Titano", "Uploader"], UserDataOwners.Removable(titano, []).Order(StringComparer.Ordinal));
|
|
Assert.SequenceEqual(["Titano"], UserDataOwners.Removable(titano, [uploader]).Order(StringComparer.Ordinal));
|
|
Assert.Empty(UserDataOwners.Removable(uploader, [titano]));
|
|
Assert.SequenceEqual(["Uploader"], UserDataOwners.Removable(uploader, [["titano"]]));
|
|
// Titano Server keeps its data elsewhere: a Server-only product removes nothing here.
|
|
Assert.Empty(UserDataOwners.Removable(["Server"], []));
|
|
}
|
|
|
|
private static HashSet<string> Owners(params string[] owners) => new(owners, StringComparer.OrdinalIgnoreCase);
|
|
|
|
private string SampleFolder()
|
|
{
|
|
var folder = Path.Combine(context.CreateTempDirectory("userdata"), "Titano");
|
|
Write(folder, "titano.db", 4000);
|
|
Write(folder, "settings.json", 20);
|
|
Write(folder, Path.Combine("cache", "proxies", "a.jpg"), 3000);
|
|
Write(folder, Path.Combine("backups", "titano-1.db"), 100);
|
|
Write(folder, Path.Combine("logs", "titano-20261012.log"), 300);
|
|
Write(folder, Path.Combine("logs", "uploader-20261012.log"), 200);
|
|
Write(folder, "uploader.json", 10);
|
|
Write(folder, "uploader-queue.json", 50);
|
|
return folder;
|
|
}
|
|
|
|
private static void Write(string folder, string relative, int bytes)
|
|
{
|
|
var path = Path.Combine(folder, relative);
|
|
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
|
File.WriteAllBytes(path, new byte[bytes]);
|
|
}
|
|
}
|