// What differs between Windows and Linux, behind one face (DESIGN.md 8: "the Windows-only parts behind an IPlatform"; // research/02 section 11 lists each Windows mechanism and its Linux equivalent). Everything else in Triforce.Logic is // plain .NET and the same on both. // // TRIFORCE_TEST_ROOT= (old Setup.cs Install.TestRoot) keeps a whole install inside one folder on both systems: the // settings are \registry.txt, the shortcuts, the build's work folder, the default game folder, the emulators' saves // and Steam are folders inside it, and nothing outside it is written (TriforceContext.Allowed). A test run never reads or // writes the real registry, the real shortcuts, the real Steam or the real game. using System.Diagnostics; namespace Triforce.Logic; /// Where a shortcut to the launcher goes. public enum ShortcutPlace { /// Windows: the desktop's Triforce.lnk. Linux: ~/Desktop/triforce-launcher.desktop when there is a desktop folder. Desktop, /// Windows: Start menu\Programs\Triforce\Triforce.lnk. Linux: ~/.local/share/applications/triforce-launcher.desktop. StartMenu, } /// A shortcut's contents. public sealed record Shortcut(string Target, string Arguments, string WorkingDirectory, string Icon, string Description, string Name = "Triforce"); /// Something the App shows as a system notification (a build finished while the window was not in front, DESIGN 6). public sealed record LauncherNotification(string Title, string Text); /// A running program: its process id, name and, when it can be read, the full path of its executable. public sealed record RunningProcess(int Id, string Name, string? Exe); public interface IPlatform { bool IsWindows { get; } /// TRIFORCE_TEST_ROOT, as a full path, or null. string? TestRoot { get; } /// An environment variable as this context sees it (a test's own values first). string? Env(string name); /// The settings: HKCU\Software\Triforce (Windows), ~/.config/triforce/builder.ini (Linux), registry.txt (test run). ISettingsStore Settings { get; } // ---- paths ---- /// Windows %LOCALAPPDATA%\Programs\Triforce; Linux the self-update root ${XDG_DATA_HOME}/triforce/builder. string DefaultInstallDir { get; } /// make_game.py's work folder (its default --work): build_times.json, objcache, sa... (research/02 1.1, 12 section 2). string WorkFolder { get; } string DefaultGameFolder { get; } /// Where setup.log is written for an install folder (Windows: the folder itself; Linux ${XDG_STATE_HOME}/triforce). string LogFolder(string home); /// Where NVIDIA's DLSS SDK is fetched to: beside the tools, never inside them (an update replaces those whole). string NgxSdkFolder(string home); /// The save folder of a game folder: Windows <game>\user\save\<uid>; Linux ${XDG_DATA_HOME}/hookshot/save/<uid>. string SaveFolder(string game, string uid); /// The folders emulators keep their data in: (Roaming, Local) on Windows; (data, config) on Linux. (string Roaming, string Local) EmulatorDataRoots { get; } /// Steam folders to look in, in order (test run: <root>\Steam only). IReadOnlyList SteamRoots(); // ---- shortcuts and the shell ---- string ShortcutPath(ShortcutPlace place); void CreateShortcut(ShortcutPlace place, Shortcut shortcut); /// Removes the launcher's shortcuts (both places); quietly when one cannot be. void RemoveShortcuts(); /// Explorer / xdg-open on a folder. Not in a test run (nothing opens a window there). void OpenFolder(string folder); /// The App listens and shows it (a toast, a desktop notification). event EventHandler? NotificationRequested; void Notify(string title, string text); // ---- processes ---- /// Starts a program so that it and every program it starts can be stopped together (KillTree). Linux: setsid, its /// own process group; Windows: as is (taskkill /T walks the tree). Process StartTree(ProcessStartInfo info); /// Stops a program and its children, waiting up to 5 s: taskkill /PID n /T /F; kill(-pgid, SIGTERM) then SIGKILL. void KillTree(Process process); /// The running programs of these names (case-insensitive), with their executables where they can be read. IReadOnlyList FindProcesses(params string[] names); // ---- disks ---- /// Free bytes for this user on the disk of a folder (the nearest existing folder above it); null when unknown. long? FreeBytes(string folder); /// The disk as the player knows it: C:\ on Windows, the mount point on Linux. string Disk(string folder); /// Is this the error of a disk that filled while it was written to? (ERROR_DISK_FULL / ENOSPC) bool IsDiskFull(Exception? e); /// from over to in one step (MoveFileExW REPLACE_EXISTING|WRITE_THROUGH; rename(2)). void ReplaceFile(string from, string to); /// Does a file have a second name (a hard link)? Writing one writes the other. bool HasOtherName(string file); }