Files
simplysanatori--KartFrame/Launcher/WiiCompiled.Setup.Windows/ShellIntegration.cs
T
heurazy 3e96d5c661 Integrate VR port features and Quest standalone support
Add migrated controls, onboarding, spatial menus, controller profiles and launcher packaging. Fix VR overlay rendering and tracking, add textured animated Touch Plus models, and disable frame interpolation on Quest.
2026-09-27 15:56:28 +02:00

95 lines
4.0 KiB
C#

using Microsoft.Win32;
namespace WiiCompiled.Setup.Windows;
internal static class ShellIntegration
{
private const string ShortcutFileName = "WiiCompiled OpenXR VR (base) (beta).lnk";
public static void RegisterUninstaller(string installDirectory, bool retroInstalled)
{
using var key = Registry.CurrentUser.CreateSubKey(ProductInfo.UninstallKey, writable: true)
?? throw new InvalidOperationException("Could not register the uninstaller.");
var cli = Path.Combine(installDirectory, ProductInfo.SetupCopyName);
key.SetValue("DisplayName", ProductInfo.Name);
key.SetValue("DisplayVersion", ProductInfo.Version);
key.SetValue("Publisher", "WiiCompiled");
key.SetValue("InstallLocation", installDirectory);
key.SetValue("DisplayIcon", cli);
key.SetValue("UninstallString", $"\"{cli}\" --uninstall --install-dir \"{installDirectory}\"");
key.SetValue("QuietUninstallString", $"\"{cli}\" --silent-uninstall --install-dir \"{installDirectory}\"");
key.SetValue("NoModify", 1, RegistryValueKind.DWord);
key.SetValue("NoRepair", 1, RegistryValueKind.DWord);
key.SetValue("EstimatedSize", EstimateSizeKb(installDirectory), RegistryValueKind.DWord);
key.SetValue("Comments", retroInstalled ? "Includes the Retro Rewind profile" : "WiiCompiled");
}
public static void UnregisterUninstaller() =>
Registry.CurrentUser.DeleteSubKeyTree(ProductInfo.UninstallKey, throwOnMissingSubKey: false);
/// <summary>Creates the desktop and Start Menu shortcuts that launch the base game.</summary>
public static void CreateShortcuts(string installDirectory)
{
var launcher = Path.Combine(installDirectory,"WheelWizard","WheelWizard.exe");
var hasLauncher=File.Exists(launcher);
var cli = hasLauncher ? launcher : Path.Combine(installDirectory, ProductInfo.SetupCopyName);
var shellType = Type.GetTypeFromProgID("WScript.Shell")
?? throw new InvalidOperationException("The Windows Script Host shell is unavailable.");
dynamic shell = Activator.CreateInstance(shellType)!;
foreach (var path in ShortcutPaths())
{
dynamic shortcut = shell.CreateShortcut(path);
shortcut.TargetPath = cli;
shortcut.Arguments = hasLauncher ? "" : "--launch-base";
shortcut.WorkingDirectory = installDirectory;
shortcut.IconLocation = cli + ",0";
shortcut.Description = "WiiCompiled VR: choose Mario Kart Wii or Retro Rewind";
shortcut.Save();
}
}
public static void RemoveShortcuts() => RemoveShortcuts(ShortcutPaths());
internal static void RemoveShortcuts(IEnumerable<string> shortcutPaths)
{
var failures = new List<Exception>();
foreach (var path in shortcutPaths)
DeleteFileBestEffort(path, failures);
if (failures.Count != 0)
throw new AggregateException("One or more WiiCompiled shortcuts could not be removed.", failures);
}
private static string[] ShortcutPaths() =>
[
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), ShortcutFileName),
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), "Programs", ShortcutFileName),
];
private static void DeleteFileBestEffort(string path, List<Exception> failures)
{
try
{
File.Delete(path);
}
catch (Exception ex)
{
failures.Add(new IOException($"Could not delete shortcut {path}: {ex.Message}", ex));
}
}
private static int EstimateSizeKb(string directory)
{
try
{
var bytes = Directory.EnumerateFiles(directory, "*", SearchOption.AllDirectories)
.Sum(path => new FileInfo(path).Length);
return (int)Math.Min(int.MaxValue, (bytes + 1023) / 1024);
}
catch
{
return 0;
}
}
}