Services, sign-in entries and shortcuts are matched against the full paths of the files the install log or the payload lists, never against everything under the install folder: an install into a shared folder such as D:\Apps or /DIR="C:\Program Files" no longer stops, starts or deletes other vendors' services or removes their Run values. The elevated step now takes the names the unelevated setup found (/SERVICES=... /NAMES=...) and reads each service again, acting only when it still starts a program of the folder's log or of its own payload (or, for Prune, a program of the folder that is gone). Programs are asked to close before any service is touched. On uninstall the services are deleted only once the programs have closed, just before the files go; a failed install or uninstall starts again the services it stopped, and after an upgrade setup starts exactly the services it stopped, whatever their start type. The Server component installs only for all users in a folder inside Program Files. In the window a custom folder outside it is invalid while the Server is selected, with a tooltip saying why; silent mode refuses it. An upgrade of an installation elsewhere cannot add the Server, and one it carried is dropped with its service. Sign-in entries use StartupCommand (the same file as on fix/shell-notify) and are removed by SetupRegistry.DeleteStartupEntries only when the client's or the Uploader's value starts a program the install log lists; an upgrade that drops a program removes its entry too. StartupEntries is gone. A shortcut that starts another product's existing copy is still left alone but now logged; uninstalling the product it starts hands it to another product of the same scope that lists it and has the same program, so the Uploader that stays keeps its shortcuts. Another registered Titano installation whose folder or log cannot be read now counts as using every program's data, so "Remove my data" never offers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
115 lines
5.3 KiB
C#
115 lines
5.3 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"], []));
|
|
}
|
|
|
|
[Test]
|
|
public void AnInstallationThatCannotBeReadNowKeepsEveryProgramsData()
|
|
{
|
|
string[] titano = ["Titano", "Uploader", "Server"];
|
|
var uploader = new InstallLog { Product = "Titano Uploader", Version = "1.0.0", Components = ["Uploader"] };
|
|
|
|
Assert.SequenceEqual(["Titano"], UserDataOwners.RemovableBeside(titano, [new OtherInstall(@"D:\Titano Uploader", uploader)]).Order(StringComparer.Ordinal));
|
|
// Its drive is offline, its folder is gone or its log is damaged: it may still use the desktop app's index.
|
|
Assert.Empty(UserDataOwners.RemovableBeside(titano, [new OtherInstall(@"E:\Titano Uploader", null)]));
|
|
Assert.Empty(UserDataOwners.RemovableBeside(titano, [new OtherInstall(null, null)]));
|
|
}
|
|
|
|
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]);
|
|
}
|
|
}
|