fix(setup): handle install-folder services, startup entries, shared shortcuts and data
- 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
This commit is contained in:
32 files changed
+1175
-88
No files matched your search
@@ -0,0 +1,60 @@
|
||||
using System.IO;
|
||||
|
||||
namespace Titano.Setup.Engine;
|
||||
|
||||
/// <summary>The program a command line registered with Windows starts: a service's image path, a Run value.</summary>
|
||||
internal static class CommandProgram
|
||||
{
|
||||
/// <summary>
|
||||
/// The first token, quoted or up to <c>.exe</c>, with environment variables expanded; for the <c>dotnet</c> host,
|
||||
/// the assembly it runs. Null when the line names no full path.
|
||||
/// </summary>
|
||||
public static string? Of(string commandLine)
|
||||
{
|
||||
var line = Environment.ExpandEnvironmentVariables(commandLine).Trim();
|
||||
var first = NextToken(ref line);
|
||||
if (first is null) return null;
|
||||
if (Path.GetFileNameWithoutExtension(first).Equals("dotnet", StringComparison.OrdinalIgnoreCase)) first = NextToken(ref line);
|
||||
return first is not null && Path.IsPathFullyQualified(first) ? first : null;
|
||||
}
|
||||
|
||||
/// <summary>True when <paramref name="commandLine"/> starts a program inside <paramref name="directory"/>.</summary>
|
||||
public static bool IsInside(string commandLine, string directory) => Of(commandLine) is { } program && IsPathInside(program, directory);
|
||||
|
||||
/// <summary><see cref="SetupPaths.IsSameOrInside"/> that answers false for a path Windows cannot normalise.</summary>
|
||||
public static bool IsPathInside(string path, string directory)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SetupPaths.IsSameOrInside(path, directory);
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or NotSupportedException or PathTooLongException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Takes the next token of a command line: quoted, or up to <c>.exe</c> followed by a space, or up to the next space.</summary>
|
||||
private static string? NextToken(ref string line)
|
||||
{
|
||||
line = line.TrimStart();
|
||||
if (line.Length == 0) return null;
|
||||
string token;
|
||||
if (line[0] == '"')
|
||||
{
|
||||
var close = line.IndexOf('"', 1);
|
||||
token = close < 0 ? line[1..] : line[1..close];
|
||||
line = close < 0 ? string.Empty : line[(close + 1)..];
|
||||
}
|
||||
else
|
||||
{
|
||||
// An unquoted path with spaces ("C:\Program Files\Titano\Titano.Server.exe --service") ends at its extension.
|
||||
var exe = line.IndexOf(".exe", StringComparison.OrdinalIgnoreCase);
|
||||
var space = line.IndexOf(' ');
|
||||
var end = exe >= 0 && (exe + 4 == line.Length || line[exe + 4] == ' ') ? exe + 4 : space >= 0 ? space : line.Length;
|
||||
token = line[..end];
|
||||
line = line[end..];
|
||||
}
|
||||
return token.Length == 0 ? null : token;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user