feat(setup): add one-screen installer, uninstaller and silent mode

Titano.Setup reads the TPK1 payload from its own executable and installs per
user (%LOCALAPPDATA%\Programs) or for all users (Program Files, relaunched
elevated through ShellExecuteEx "runas"). Extraction is hash-verified into a
staging folder and committed with rollback; upgrades replace files in place,
remove obsolete ones and never touch %LOCALAPPDATA%\Titano.

- Components, scope, folder (IFileOpenDialog picker), desktop and Start menu
  shortcuts (IShellLinkW), start-after-install, language picker
- Add/Remove Programs entry, .titano file type, install log
- /uninstall [/S] removes only logged files, shortcuts and registry entries;
  user data only when "Remove my data" is ticked; the uninstaller deletes
  itself through a temporary helper copy
- Silent switches /S /DIR= /COMPONENTS= /ALLUSERS /NODESKTOP /NOSTARTMENU
  /LAUNCH /LANG= with documented exit codes; running programs are asked to
  close, never killed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 10:16:20 +00:00
1 parent 5b5f38c91d
commit c97b4fb82c
25 files changed
+2183 -11

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
using System.Runtime.InteropServices;
namespace Titano.Setup.Interop;
/// <summary>Win32 entry points used by setup (shell notification, delayed delete, process image path).</summary>
internal static partial class NativeMethods
{
public const int ERROR_CANCELLED = 1223;
public const int HRESULT_ERROR_CANCELLED = unchecked((int)0x800704C7);
private const int SHCNE_ASSOCCHANGED = 0x08000000;
private const int SHCNF_IDLIST = 0x0000;
private const int MOVEFILE_DELAY_UNTIL_REBOOT = 0x4;
private const int PROCESS_QUERY_LIMITED_INFORMATION = 0x1000;
/// <summary>Tells Explorer that file associations changed so icons and "open with" refresh.</summary>
public static void NotifyAssociationsChanged() => SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);
/// <summary>Asks Windows to delete a file or empty folder at the next restart (needs administrator rights).</summary>
public static bool DeleteAtReboot(string path) => MoveFileExW(path, null, MOVEFILE_DELAY_UNTIL_REBOOT);
/// <summary>Full path of the executable of process <paramref name="processId"/>, or null when it cannot be queried.</summary>
public static unsafe string? ProcessImagePath(int processId)
{
var handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, false, processId);
if (handle == IntPtr.Zero) return null;
try
{
const int capacity = 1024;
var buffer = stackalloc char[capacity];
var length = capacity;
return QueryFullProcessImageNameW(handle, 0, buffer, ref length) ? new string(buffer, 0, length) : null;
}
finally
{
CloseHandle(handle);
}
}
[LibraryImport("shell32.dll")]
private static partial void SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
[LibraryImport("kernel32.dll", StringMarshalling = StringMarshalling.Utf16, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool MoveFileExW(string existingFileName, string? newFileName, int flags);
[LibraryImport("kernel32.dll", SetLastError = true)]
private static partial IntPtr OpenProcess(int desiredAccess, [MarshalAs(UnmanagedType.Bool)] bool inheritHandle, int processId);
[LibraryImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static unsafe partial bool QueryFullProcessImageNameW(IntPtr process, int flags, char* exeName, ref int size);
[LibraryImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool CloseHandle(IntPtr handle);
}