Add a Windows desktop installer for PC-based OmniNX installs.
This lets mass deployments and modchip setups apply the same install/update flow from a PC, with generated deletion lists kept in sync with the payload headers.
This commit is contained in:
21 files changed
+2312
No files matched your search
@@ -0,0 +1,118 @@
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public sealed class BackupService
|
||||
{
|
||||
private const string TempBackup = @"temp_backup";
|
||||
private const string DbiConfig = @"switch\DBI\dbi.config";
|
||||
private const string ProdKeys = @"switch\prod.keys";
|
||||
private const string CyberFoilDir = @"switch\CyberFoil";
|
||||
private const string CheckpointDir = @"switch\Checkpoint";
|
||||
|
||||
private const string HorizonOcConfig = @"config\horizon-oc\config.ini";
|
||||
private const string HorizonOcBackupDir = @".omninx_oc_update";
|
||||
|
||||
public void BackupUserData(string driveRoot, IProgress<string>? progress = null)
|
||||
{
|
||||
var backupRoot = PathUtils.ToDrivePath(driveRoot, TempBackup);
|
||||
PathUtils.EnsureDirectory(backupRoot);
|
||||
progress?.Report("Backing up CyberFoil, Checkpoint, DBI (dbi.config), prod.keys...");
|
||||
|
||||
CopyIfExists(PathUtils.ToDrivePath(driveRoot, DbiConfig),
|
||||
Path.Combine(backupRoot, "dbi.config"));
|
||||
|
||||
CopyIfExists(PathUtils.ToDrivePath(driveRoot, ProdKeys),
|
||||
Path.Combine(backupRoot, "prod.keys"));
|
||||
|
||||
var cyberfoil = PathUtils.ToDrivePath(driveRoot, CyberFoilDir);
|
||||
if (Directory.Exists(cyberfoil))
|
||||
{
|
||||
var dst = Path.Combine(backupRoot, "CyberFoil");
|
||||
PathUtils.EnsureDirectory(dst);
|
||||
CopyIfExists(Path.Combine(cyberfoil, "cyberfoil.nro"), Path.Combine(dst, "cyberfoil.nro"));
|
||||
CopyIfExists(Path.Combine(cyberfoil, "config.json"), Path.Combine(dst, "config.json"));
|
||||
var remotes = Path.Combine(cyberfoil, "remotes");
|
||||
if (Directory.Exists(remotes))
|
||||
PathUtils.CopyDirectory(remotes, Path.Combine(dst, "remotes"));
|
||||
}
|
||||
|
||||
var checkpoint = PathUtils.ToDrivePath(driveRoot, CheckpointDir);
|
||||
if (Directory.Exists(checkpoint))
|
||||
PathUtils.CopyDirectory(checkpoint, Path.Combine(backupRoot, "Checkpoint"));
|
||||
}
|
||||
|
||||
public void RestoreUserData(string driveRoot, IProgress<string>? progress = null)
|
||||
{
|
||||
var backupRoot = PathUtils.ToDrivePath(driveRoot, TempBackup);
|
||||
if (!Directory.Exists(backupRoot))
|
||||
return;
|
||||
|
||||
progress?.Report("Restoring CyberFoil, Checkpoint, DBI (dbi.config), prod.keys...");
|
||||
PathUtils.EnsureDirectory(PathUtils.ToDrivePath(driveRoot, @"switch"));
|
||||
|
||||
CopyIfExists(Path.Combine(backupRoot, "dbi.config"),
|
||||
PathUtils.ToDrivePath(driveRoot, DbiConfig));
|
||||
|
||||
CopyIfExists(Path.Combine(backupRoot, "prod.keys"),
|
||||
PathUtils.ToDrivePath(driveRoot, ProdKeys));
|
||||
|
||||
var cyberBackup = Path.Combine(backupRoot, "CyberFoil");
|
||||
if (Directory.Exists(cyberBackup))
|
||||
{
|
||||
var dst = PathUtils.ToDrivePath(driveRoot, CyberFoilDir);
|
||||
PathUtils.EnsureDirectory(dst);
|
||||
CopyIfExists(Path.Combine(cyberBackup, "cyberfoil.nro"), Path.Combine(dst, "cyberfoil.nro"));
|
||||
CopyIfExists(Path.Combine(cyberBackup, "config.json"), Path.Combine(dst, "config.json"));
|
||||
var remotes = Path.Combine(cyberBackup, "remotes");
|
||||
if (Directory.Exists(remotes))
|
||||
PathUtils.CopyDirectory(remotes, Path.Combine(dst, "remotes"));
|
||||
}
|
||||
|
||||
var checkpointBackup = Path.Combine(backupRoot, "Checkpoint");
|
||||
if (Directory.Exists(checkpointBackup))
|
||||
PathUtils.CopyDirectory(checkpointBackup, PathUtils.ToDrivePath(driveRoot, @"switch"));
|
||||
}
|
||||
|
||||
public void CleanupBackup(string driveRoot)
|
||||
{
|
||||
var backupRoot = PathUtils.ToDrivePath(driveRoot, TempBackup);
|
||||
if (Directory.Exists(backupRoot))
|
||||
PathUtils.DeletePath(backupRoot);
|
||||
}
|
||||
|
||||
public void BackupHorizonOcConfig(string driveRoot, IProgress<string>? progress = null)
|
||||
{
|
||||
var src = PathUtils.ToDrivePath(driveRoot, HorizonOcConfig);
|
||||
if (!File.Exists(src))
|
||||
return;
|
||||
|
||||
progress?.Report("HorizonOC: backing up config.ini...");
|
||||
var dstDir = PathUtils.ToDrivePath(driveRoot, HorizonOcBackupDir);
|
||||
PathUtils.EnsureDirectory(dstDir);
|
||||
PathUtils.CopyFile(src, Path.Combine(dstDir, "config.ini"));
|
||||
}
|
||||
|
||||
public void RestoreHorizonOcConfig(string driveRoot, IProgress<string>? progress = null)
|
||||
{
|
||||
var src = Path.Combine(PathUtils.ToDrivePath(driveRoot, HorizonOcBackupDir), "config.ini");
|
||||
if (!File.Exists(src))
|
||||
return;
|
||||
|
||||
progress?.Report("HorizonOC: restoring config.ini...");
|
||||
PathUtils.EnsureDirectory(PathUtils.ToDrivePath(driveRoot, @"config\horizon-oc"));
|
||||
PathUtils.CopyFile(src, PathUtils.ToDrivePath(driveRoot, HorizonOcConfig));
|
||||
}
|
||||
|
||||
public void CleanupHorizonOcBackup(string driveRoot)
|
||||
{
|
||||
var dir = PathUtils.ToDrivePath(driveRoot, HorizonOcBackupDir);
|
||||
if (Directory.Exists(dir))
|
||||
PathUtils.DeletePath(dir);
|
||||
}
|
||||
|
||||
private static void CopyIfExists(string src, string dst)
|
||||
{
|
||||
if (!File.Exists(src))
|
||||
return;
|
||||
PathUtils.CopyFile(src, dst);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public sealed class ConfigIniService
|
||||
{
|
||||
private const string ConfigIniRelative = @"config\omninx\config.ini";
|
||||
private const string LegacyRamConfigRelative = @"config\omninx\ram_config.ini";
|
||||
|
||||
public bool TryReadBool(string driveRoot, string section, string key, out bool value)
|
||||
{
|
||||
value = false;
|
||||
var path = PathUtils.ToDrivePath(driveRoot, ConfigIniRelative);
|
||||
if (!File.Exists(path))
|
||||
return false;
|
||||
|
||||
var inSection = false;
|
||||
foreach (var rawLine in File.ReadLines(path))
|
||||
{
|
||||
var line = rawLine.Trim();
|
||||
if (line.Length == 0)
|
||||
continue;
|
||||
|
||||
if (line.StartsWith('[') && line.EndsWith(']'))
|
||||
{
|
||||
inSection = line[1..^1].Equals(section, StringComparison.Ordinal);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inSection)
|
||||
continue;
|
||||
|
||||
var eq = line.IndexOf('=');
|
||||
if (eq <= 0)
|
||||
continue;
|
||||
|
||||
var k = line[..eq].Trim();
|
||||
if (!k.Equals(key, StringComparison.Ordinal))
|
||||
continue;
|
||||
|
||||
var val = line[(eq + 1)..].Trim();
|
||||
if (val == "1")
|
||||
{
|
||||
value = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (val == "0")
|
||||
{
|
||||
value = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void MigrateLegacyRamConfig(string driveRoot)
|
||||
{
|
||||
var legacy = PathUtils.ToDrivePath(driveRoot, LegacyRamConfigRelative);
|
||||
if (!File.Exists(legacy))
|
||||
return;
|
||||
|
||||
if (TryReadLegacyBool(legacy, "Ram", "8gb", out var use8Gb))
|
||||
{
|
||||
var havePro = TryReadBool(driveRoot, "HekateAms", "pro", out var usePro);
|
||||
WriteExtras(driveRoot, needRam: true, use8Gb, needHekateAms: havePro, havePro ? usePro : false);
|
||||
}
|
||||
|
||||
PathUtils.DeletePath(legacy);
|
||||
}
|
||||
|
||||
public void WriteExtras(string driveRoot, bool needRam, bool use8Gb, bool needHekateAms, bool usePro)
|
||||
{
|
||||
var path = PathUtils.ToDrivePath(driveRoot, ConfigIniRelative);
|
||||
PathUtils.EnsureDirectory(Path.GetDirectoryName(path)!);
|
||||
|
||||
using var writer = new StreamWriter(path, append: false);
|
||||
if (needRam)
|
||||
{
|
||||
writer.WriteLine("[Ram]");
|
||||
writer.WriteLine($"8gb={(use8Gb ? 1 : 0)}");
|
||||
writer.WriteLine();
|
||||
}
|
||||
|
||||
if (needHekateAms)
|
||||
{
|
||||
writer.WriteLine("[HekateAms]");
|
||||
writer.WriteLine($"pro={(usePro ? 1 : 0)}");
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryReadLegacyBool(string path, string section, string key, out bool value)
|
||||
{
|
||||
value = false;
|
||||
var inSection = false;
|
||||
foreach (var rawLine in File.ReadLines(path))
|
||||
{
|
||||
var line = rawLine.Trim();
|
||||
if (line.StartsWith('[') && line.EndsWith(']'))
|
||||
{
|
||||
inSection = line[1..^1].Equals(section, StringComparison.Ordinal);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inSection)
|
||||
continue;
|
||||
|
||||
var eq = line.IndexOf('=');
|
||||
if (eq <= 0)
|
||||
continue;
|
||||
|
||||
if (!line[..eq].Trim().Equals(key, StringComparison.Ordinal))
|
||||
continue;
|
||||
|
||||
var val = line[(eq + 1)..].Trim();
|
||||
if (val == "1")
|
||||
{
|
||||
value = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (val == "0")
|
||||
{
|
||||
value = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
using CleanLists = OmniNX.DesktopInstaller.Data.DeletionLists.Clean;
|
||||
using UpdateLists = OmniNX.DesktopInstaller.Data.DeletionLists.Update;
|
||||
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public sealed class DeletionService
|
||||
{
|
||||
private readonly PreserveService _preserve = new();
|
||||
|
||||
public void RunCleanDeletion(string driveRoot, IProgress<string>? progress = null)
|
||||
{
|
||||
DeleteGroup(driveRoot, "atmosphere", CleanLists.clean_atmosphere_dirs_to_delete, progress);
|
||||
DeleteGroup(driveRoot, "bootloader", CleanLists.clean_bootloader_dirs_to_delete, progress);
|
||||
DeleteFiles(driveRoot, CleanLists.clean_bootloader_files_to_delete, progress);
|
||||
DeleteGroup(driveRoot, "config", CleanLists.clean_config_dirs_to_delete, progress);
|
||||
DeleteGroup(driveRoot, "switch", CleanLists.clean_switch_dirs_to_delete, progress);
|
||||
DeleteFiles(driveRoot, CleanLists.clean_root_files_to_delete, progress);
|
||||
DeleteGroup(driveRoot, "misc", CleanLists.clean_misc_dirs_to_delete, progress);
|
||||
DeleteFiles(driveRoot, CleanLists.clean_misc_files_to_delete, progress);
|
||||
DeleteFiles(driveRoot, CleanLists.old_version_files_to_delete, progress);
|
||||
PathUtils.EnsureDirectory(PathUtils.ToDrivePath(driveRoot, @"switch"));
|
||||
}
|
||||
|
||||
public void RunUpdateDeletion(string driveRoot, IProgress<string>? progress = null)
|
||||
{
|
||||
_preserve.Load(driveRoot, progress);
|
||||
|
||||
DeleteGroup(driveRoot, "atmosphere", UpdateLists.atmosphere_dirs_to_delete, progress, _preserve);
|
||||
DeleteGroup(driveRoot, "atmosphere/contents", UpdateLists.atmosphere_contents_dirs_to_delete, progress, _preserve);
|
||||
DeleteFiles(driveRoot, UpdateLists.atmosphere_files_to_delete, progress, _preserve);
|
||||
DeleteGroup(driveRoot, "bootloader", UpdateLists.bootloader_dirs_to_delete, progress, _preserve);
|
||||
DeleteFiles(driveRoot, UpdateLists.bootloader_files_to_delete, progress, _preserve);
|
||||
DeleteGroup(driveRoot, "config", UpdateLists.config_dirs_to_delete, progress, _preserve);
|
||||
DeleteGroup(driveRoot, "switch", UpdateLists.switch_dirs_to_delete, progress, _preserve);
|
||||
DeleteFiles(driveRoot, UpdateLists.switch_files_to_delete, progress, _preserve);
|
||||
DeleteFiles(driveRoot, UpdateLists.root_files_to_delete, progress, _preserve);
|
||||
DeleteGroup(driveRoot, "misc", UpdateLists.misc_dirs_to_delete, progress, _preserve);
|
||||
DeleteFiles(driveRoot, UpdateLists.misc_files_to_delete, progress, _preserve);
|
||||
|
||||
_preserve.Clear();
|
||||
}
|
||||
|
||||
public void RunPostRestoreCleanup(string driveRoot)
|
||||
{
|
||||
DeleteGroup(driveRoot, "switch (post-restore)", CleanLists.clean_post_restore_dirs_to_delete, null);
|
||||
}
|
||||
|
||||
private static void DeleteGroup(
|
||||
string driveRoot,
|
||||
string label,
|
||||
string[] paths,
|
||||
IProgress<string>? progress,
|
||||
PreserveService? preserve = null)
|
||||
{
|
||||
if (paths.Length == 0)
|
||||
return;
|
||||
|
||||
progress?.Report($"Deleting {label}...");
|
||||
foreach (var rel in paths)
|
||||
{
|
||||
var full = PathUtils.ToDrivePath(driveRoot, rel);
|
||||
if (!PathUtils.PathExists(full))
|
||||
continue;
|
||||
if (preserve?.IsBlocked(full, driveRoot) == true)
|
||||
{
|
||||
progress?.Report($" Skipped (preserve): {rel}");
|
||||
continue;
|
||||
}
|
||||
|
||||
progress?.Report($" Delete: {rel}");
|
||||
PathUtils.DeletePath(full);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DeleteFiles(
|
||||
string driveRoot,
|
||||
string[] paths,
|
||||
IProgress<string>? progress,
|
||||
PreserveService? preserve = null)
|
||||
{
|
||||
foreach (var rel in paths)
|
||||
{
|
||||
var full = PathUtils.ToDrivePath(driveRoot, rel);
|
||||
if (!File.Exists(full))
|
||||
continue;
|
||||
if (preserve?.IsBlocked(full, driveRoot) == true)
|
||||
{
|
||||
progress?.Report($" Skipped (preserve): {rel}");
|
||||
continue;
|
||||
}
|
||||
|
||||
progress?.Report($" Delete: {rel}");
|
||||
PathUtils.DeletePath(full);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class PreserveService
|
||||
{
|
||||
private readonly List<string> _paths = new();
|
||||
|
||||
public void Load(string driveRoot, IProgress<string>? progress = null)
|
||||
{
|
||||
_paths.Clear();
|
||||
var iniPath = PathUtils.ToDrivePath(driveRoot, @"config\omninx\preserve.ini");
|
||||
if (!File.Exists(iniPath))
|
||||
return;
|
||||
|
||||
var inSection = false;
|
||||
foreach (var rawLine in File.ReadLines(iniPath))
|
||||
{
|
||||
var line = rawLine.Trim();
|
||||
if (line.StartsWith('[') && line.EndsWith(']'))
|
||||
{
|
||||
inSection = line[1..^1].Equals("Preserve", StringComparison.Ordinal);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inSection || !line.Contains('='))
|
||||
continue;
|
||||
|
||||
var eq = line.IndexOf('=');
|
||||
var key = line[..eq].Trim().Trim('\'', '"');
|
||||
var val = line[(eq + 1)..].Trim();
|
||||
if (!IsTruthy(val))
|
||||
continue;
|
||||
|
||||
var normalized = NormalizePreservePath(key, driveRoot);
|
||||
if (normalized is null)
|
||||
continue;
|
||||
|
||||
if (!_paths.Contains(normalized, StringComparer.OrdinalIgnoreCase))
|
||||
_paths.Add(normalized);
|
||||
}
|
||||
|
||||
if (_paths.Count > 0)
|
||||
progress?.Report($"preserve.ini: {_paths.Count} path(s) excluded from update cleanup.");
|
||||
}
|
||||
|
||||
public bool IsBlocked(string deleteFullPath, string driveRoot)
|
||||
{
|
||||
if (_paths.Count == 0)
|
||||
return false;
|
||||
|
||||
var normalizedDelete = Path.GetFullPath(deleteFullPath).TrimEnd(Path.DirectorySeparatorChar);
|
||||
foreach (var preserve in _paths)
|
||||
{
|
||||
var normalizedPreserve = Path.GetFullPath(preserve).TrimEnd(Path.DirectorySeparatorChar);
|
||||
if (normalizedDelete.Equals(normalizedPreserve, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (IsPrefix(normalizedPreserve, normalizedDelete))
|
||||
return true;
|
||||
if (IsPrefix(normalizedDelete, normalizedPreserve))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Clear() => _paths.Clear();
|
||||
|
||||
private static string? NormalizePreservePath(string key, string driveRoot)
|
||||
{
|
||||
var path = key.Replace("sd:/", string.Empty).Replace("sd:\\", string.Empty)
|
||||
.Replace('/', Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar);
|
||||
if (path.Length < 2)
|
||||
return null;
|
||||
|
||||
return PathUtils.ToDrivePath(driveRoot, path);
|
||||
}
|
||||
|
||||
private static bool IsPrefix(string prefix, string path)
|
||||
{
|
||||
if (!path.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
return path.Length == prefix.Length ||
|
||||
path[prefix.Length] == Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
private static bool IsTruthy(string val)
|
||||
{
|
||||
if (string.IsNullOrEmpty(val))
|
||||
return false;
|
||||
var c = char.ToUpperInvariant(val[0]);
|
||||
return c is '1' or 'T' or 'Y';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public sealed class ExtrasService
|
||||
{
|
||||
private readonly ConfigIniService _config = new();
|
||||
|
||||
public (bool needRam, bool needHekateAms) DetectExtras(string driveRoot)
|
||||
{
|
||||
var extras = PathUtils.ToDrivePath(driveRoot, "extras");
|
||||
var needRam = File.Exists(Path.Combine(extras, "hekate_8gb.bin")) ||
|
||||
File.Exists(Path.Combine(extras, "hekate-pro_8gb.bin"));
|
||||
var needHekateAms = Directory.Exists(Path.Combine(extras, "hekate-ams-pro"));
|
||||
return (needRam, needHekateAms);
|
||||
}
|
||||
|
||||
public void ApplyExtras(
|
||||
string driveRoot,
|
||||
bool use8GbRam,
|
||||
bool useHekateAmsPro,
|
||||
IProgress<string>? progress = null)
|
||||
{
|
||||
_config.MigrateLegacyRamConfig(driveRoot);
|
||||
|
||||
var extras = PathUtils.ToDrivePath(driveRoot, "extras");
|
||||
if (!Directory.Exists(extras))
|
||||
return;
|
||||
|
||||
var (needRam, needHekateAms) = DetectExtras(driveRoot);
|
||||
if (!needRam && !needHekateAms)
|
||||
return;
|
||||
|
||||
progress?.Report("Saving RAM / Hekate-AMS selection to config.ini...");
|
||||
_config.WriteExtras(driveRoot, needRam, use8GbRam, needHekateAms, useHekateAmsPro);
|
||||
|
||||
if (useHekateAmsPro && needHekateAms)
|
||||
{
|
||||
progress?.Report("Installing Hekate-Pro / Atmosphere-Pro...");
|
||||
ApplyHekateAmsPro(extras, driveRoot, progress);
|
||||
}
|
||||
else if (needHekateAms)
|
||||
{
|
||||
progress?.Report("Keeping standard Hekate / Atmosphere.");
|
||||
}
|
||||
|
||||
if (needRam)
|
||||
{
|
||||
progress?.Report("Applying RAM payload setting...");
|
||||
Apply8GbPayload(extras, driveRoot, use8GbRam, useHekateAmsPro);
|
||||
}
|
||||
|
||||
progress?.Report("Removing extras/...");
|
||||
PathUtils.DeletePath(extras);
|
||||
}
|
||||
|
||||
private static void ApplyHekateAmsPro(string extrasDir, string driveRoot, IProgress<string>? progress)
|
||||
{
|
||||
var src = Path.Combine(extrasDir, "hekate-ams-pro");
|
||||
if (!Directory.Exists(src))
|
||||
return;
|
||||
|
||||
foreach (var entry in Directory.GetFileSystemEntries(src))
|
||||
{
|
||||
var name = Path.GetFileName(entry);
|
||||
var dst = Path.Combine(PathUtils.NormalizeDriveRoot(driveRoot), name);
|
||||
if (Directory.Exists(entry))
|
||||
PathUtils.CopyDirectory(entry, dst);
|
||||
else
|
||||
PathUtils.CopyFile(entry, dst);
|
||||
progress?.Report($" Copied: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void Apply8GbPayload(string extrasDir, string driveRoot, bool use8Gb, bool usePro)
|
||||
{
|
||||
var hekate8 = Path.Combine(extrasDir, "hekate_8gb.bin");
|
||||
var hekatePro8 = Path.Combine(extrasDir, "hekate-pro_8gb.bin");
|
||||
|
||||
if (!use8Gb)
|
||||
{
|
||||
if (File.Exists(hekate8)) File.Delete(hekate8);
|
||||
if (File.Exists(hekatePro8)) File.Delete(hekatePro8);
|
||||
return;
|
||||
}
|
||||
|
||||
var src = usePro ? hekatePro8 : hekate8;
|
||||
if (!File.Exists(src))
|
||||
return;
|
||||
|
||||
var payloadDst = PathUtils.ToDrivePath(driveRoot, "payload.bin");
|
||||
var updateDst = PathUtils.ToDrivePath(driveRoot, @"bootloader\update.bin");
|
||||
PathUtils.CopyFile(src, payloadDst);
|
||||
PathUtils.CopyFile(src, updateDst);
|
||||
|
||||
if (File.Exists(hekate8)) File.Delete(hekate8);
|
||||
if (File.Exists(hekatePro8)) File.Delete(hekatePro8);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
using System.Net.Http.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using OmniNX.DesktopInstaller.Models;
|
||||
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public sealed class GiteaClient
|
||||
{
|
||||
public const string DefaultBaseUrl = "https://git.niklascfw.de";
|
||||
private readonly HttpClient _http;
|
||||
private readonly string _baseUrl;
|
||||
|
||||
public GiteaClient(HttpClient? http = null, string? baseUrl = null)
|
||||
{
|
||||
_http = http ?? new HttpClient();
|
||||
_http.DefaultRequestHeaders.UserAgent.ParseAdd("OmniNX-Desktop-Installer/1.0");
|
||||
_baseUrl = (baseUrl ?? DefaultBaseUrl).TrimEnd('/');
|
||||
}
|
||||
|
||||
public async Task<ReleaseInfo> GetLatestReleaseAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var url = $"{_baseUrl}/api/v1/repos/OmniNX/OmniNX/releases/latest";
|
||||
var response = await _http.GetFromJsonAsync<GiteaReleaseDto>(url, cancellationToken)
|
||||
?? throw new InvalidOperationException("Empty release response from Gitea.");
|
||||
|
||||
return MapRelease(response);
|
||||
}
|
||||
|
||||
public async Task<string> DownloadAssetAsync(
|
||||
ReleaseAsset asset,
|
||||
string destinationPath,
|
||||
IProgress<(long downloaded, long total)>? progress = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
PathUtils.EnsureDirectory(Path.GetDirectoryName(destinationPath)!);
|
||||
|
||||
using var response = await _http.GetAsync(asset.DownloadUrl, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var total = response.Content.Headers.ContentLength ?? asset.Size;
|
||||
await using var input = await response.Content.ReadAsStreamAsync(cancellationToken);
|
||||
await using var output = File.Create(destinationPath);
|
||||
|
||||
var buffer = new byte[81920];
|
||||
long downloaded = 0;
|
||||
int read;
|
||||
while ((read = await input.ReadAsync(buffer, cancellationToken)) > 0)
|
||||
{
|
||||
await output.WriteAsync(buffer.AsMemory(0, read), cancellationToken);
|
||||
downloaded += read;
|
||||
progress?.Report((downloaded, total));
|
||||
}
|
||||
|
||||
return destinationPath;
|
||||
}
|
||||
|
||||
public ReleaseAsset? FindPackAsset(ReleaseInfo release, OmniNxVariant variant)
|
||||
{
|
||||
var prefix = VariantHelper.GetZipAssetPrefix(variant);
|
||||
return release.Assets.FirstOrDefault(a =>
|
||||
a.Name.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) &&
|
||||
a.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
private static ReleaseInfo MapRelease(GiteaReleaseDto dto) => new()
|
||||
{
|
||||
TagName = dto.TagName ?? string.Empty,
|
||||
Name = dto.Name ?? dto.TagName ?? string.Empty,
|
||||
Assets = dto.Assets?.Select(a => new ReleaseAsset
|
||||
{
|
||||
Name = a.Name ?? string.Empty,
|
||||
DownloadUrl = a.BrowserDownloadUrl ?? string.Empty,
|
||||
Size = a.Size,
|
||||
}).ToList() ?? [],
|
||||
};
|
||||
|
||||
private sealed class GiteaReleaseDto
|
||||
{
|
||||
[JsonPropertyName("tag_name")]
|
||||
public string? TagName { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("assets")]
|
||||
public List<GiteaAssetDto>? Assets { get; set; }
|
||||
}
|
||||
|
||||
private sealed class GiteaAssetDto
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("browser_download_url")]
|
||||
public string? BrowserDownloadUrl { get; set; }
|
||||
|
||||
[JsonPropertyName("size")]
|
||||
public long Size { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using OmniNX.DesktopInstaller.Models;
|
||||
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public sealed class InstallEngine
|
||||
{
|
||||
private readonly DeletionService _deletion = new();
|
||||
private readonly BackupService _backup = new();
|
||||
private readonly ExtrasService _extras = new();
|
||||
|
||||
public async Task RunAsync(
|
||||
InstallOptions options,
|
||||
IProgress<InstallProgressReport> progress,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var driveRoot = PathUtils.NormalizeDriveRoot(options.DriveRoot);
|
||||
var staging = options.StagingPath
|
||||
?? throw new InvalidOperationException("Staging path is required.");
|
||||
|
||||
if (!Directory.Exists(staging))
|
||||
throw new DirectoryNotFoundException($"Staging path not found: {staging}");
|
||||
|
||||
Report(progress, $"Install mode: {options.Mode}");
|
||||
Report(progress, $"Pack variant: {VariantHelper.GetDisplayName(options.Variant)}");
|
||||
|
||||
if (options.Mode == InstallMode.Update)
|
||||
{
|
||||
await RunUpdateAsync(driveRoot, staging, options, progress, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
await RunCleanAsync(driveRoot, staging, options, progress, cancellationToken);
|
||||
}
|
||||
|
||||
Report(progress, options.Mode == InstallMode.Update
|
||||
? "Update completed successfully."
|
||||
: "Installation completed successfully.");
|
||||
}
|
||||
|
||||
private async Task RunUpdateAsync(
|
||||
string driveRoot,
|
||||
string staging,
|
||||
InstallOptions options,
|
||||
IProgress<InstallProgressReport> progress,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (options.Variant == OmniNxVariant.Oc)
|
||||
{
|
||||
Report(progress, "HorizonOC: backing up config.ini...");
|
||||
_backup.BackupHorizonOcConfig(driveRoot, StringProgress(progress));
|
||||
}
|
||||
|
||||
Report(progress, "Step 1: Cleanup...");
|
||||
await Task.Run(() => _deletion.RunUpdateDeletion(driveRoot, StringProgress(progress)), cancellationToken);
|
||||
|
||||
Report(progress, "Step 2: Copying files...");
|
||||
await Task.Run(() => CopyPackFiles(staging, driveRoot, options.Variant, progress), cancellationToken);
|
||||
|
||||
Report(progress, "Applying RAM / Hekate-AMS extras...");
|
||||
await Task.Run(() => _extras.ApplyExtras(driveRoot, options.Use8GbRam, options.UseHekateAmsPro,
|
||||
StringProgress(progress)), cancellationToken);
|
||||
|
||||
if (options.Variant == OmniNxVariant.Oc)
|
||||
{
|
||||
Report(progress, "HorizonOC: restoring config.ini...");
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_backup.RestoreHorizonOcConfig(driveRoot, StringProgress(progress));
|
||||
_backup.CleanupHorizonOcBackup(driveRoot);
|
||||
}, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task RunCleanAsync(
|
||||
string driveRoot,
|
||||
string staging,
|
||||
InstallOptions options,
|
||||
IProgress<InstallProgressReport> progress,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
Report(progress, "Step 1: Backing up user data...");
|
||||
await Task.Run(() => _backup.BackupUserData(driveRoot, StringProgress(progress)), cancellationToken);
|
||||
|
||||
Report(progress, "Step 2: Cleaning old installation...");
|
||||
await Task.Run(() => _deletion.RunCleanDeletion(driveRoot, StringProgress(progress)), cancellationToken);
|
||||
|
||||
Report(progress, "Step 3: Restoring user data...");
|
||||
await Task.Run(() =>
|
||||
{
|
||||
_backup.RestoreUserData(driveRoot, StringProgress(progress));
|
||||
_deletion.RunPostRestoreCleanup(driveRoot);
|
||||
_backup.CleanupBackup(driveRoot);
|
||||
}, cancellationToken);
|
||||
|
||||
Report(progress, "Step 4: Copying files...");
|
||||
await Task.Run(() => CopyPackFiles(staging, driveRoot, options.Variant, progress), cancellationToken);
|
||||
|
||||
Report(progress, "Applying RAM / Hekate-AMS extras...");
|
||||
await Task.Run(() => _extras.ApplyExtras(driveRoot, options.Use8GbRam, options.UseHekateAmsPro,
|
||||
StringProgress(progress)), cancellationToken);
|
||||
}
|
||||
|
||||
private static void CopyPackFiles(
|
||||
string staging,
|
||||
string driveRoot,
|
||||
OmniNxVariant variant,
|
||||
IProgress<InstallProgressReport> progress)
|
||||
{
|
||||
CopyFolderIfExists(staging, driveRoot, "atmosphere", progress);
|
||||
CopyFolderIfExists(staging, driveRoot, "bootloader", progress);
|
||||
CopyFolderIfExists(staging, driveRoot, "config", progress);
|
||||
CopyFolderIfExists(staging, driveRoot, "switch", progress);
|
||||
CopyFolderIfExists(staging, driveRoot, "themes", progress);
|
||||
CopyFolderIfExists(staging, driveRoot, "warmboot_mariko", progress);
|
||||
|
||||
if (variant == OmniNxVariant.Oc)
|
||||
CopyFolderIfExists(staging, driveRoot, "SaltySD", progress);
|
||||
|
||||
CopyFolderIfExists(staging, driveRoot, "extras", progress);
|
||||
CopyRootFiles(staging, driveRoot, progress);
|
||||
}
|
||||
|
||||
private static void CopyFolderIfExists(
|
||||
string staging,
|
||||
string driveRoot,
|
||||
string folder,
|
||||
IProgress<InstallProgressReport> progress)
|
||||
{
|
||||
var src = Path.Combine(staging, folder);
|
||||
if (!Directory.Exists(src))
|
||||
return;
|
||||
|
||||
var dst = Path.Combine(PathUtils.NormalizeDriveRoot(driveRoot), folder);
|
||||
Report(progress, $"Copying {folder}/...");
|
||||
PathUtils.CopyDirectory(src, dst, new Progress<(int current, int total, string file)>(copyProgress =>
|
||||
{
|
||||
var (current, total, file) = copyProgress;
|
||||
var pct = total > 0 ? current * 100 / total : 0;
|
||||
progress.Report(new InstallProgressReport
|
||||
{
|
||||
Message = $" {folder}/ {file}",
|
||||
Percent = pct,
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private static void CopyRootFiles(
|
||||
string staging,
|
||||
string driveRoot,
|
||||
IProgress<InstallProgressReport> progress)
|
||||
{
|
||||
Report(progress, "Copying root files...");
|
||||
var skipDirs = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"atmosphere", "bootloader", "config", "switch", "themes",
|
||||
"warmboot_mariko", "SaltySD", "extras",
|
||||
};
|
||||
|
||||
foreach (var file in Directory.GetFiles(staging))
|
||||
{
|
||||
var name = Path.GetFileName(file);
|
||||
if (name.StartsWith('.'))
|
||||
continue;
|
||||
|
||||
var dst = Path.Combine(PathUtils.NormalizeDriveRoot(driveRoot), name);
|
||||
PathUtils.CopyFile(file, dst);
|
||||
Report(progress, $" {name}");
|
||||
}
|
||||
|
||||
foreach (var dir in Directory.GetDirectories(staging))
|
||||
{
|
||||
var name = Path.GetFileName(dir);
|
||||
if (skipDirs.Contains(name))
|
||||
continue;
|
||||
Report(progress, $"Skipping unexpected directory at pack root: {name}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void Report(IProgress<InstallProgressReport> progress, string message, bool isError = false)
|
||||
{
|
||||
progress.Report(new InstallProgressReport { Message = message, IsError = isError });
|
||||
}
|
||||
|
||||
private static IProgress<string> StringProgress(IProgress<InstallProgressReport> progress) =>
|
||||
new Progress<string>(msg => Report(progress, msg));
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
using OmniNX.DesktopInstaller.Models;
|
||||
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public static class VariantHelper
|
||||
{
|
||||
public static string GetDisplayName(OmniNxVariant variant) => variant switch
|
||||
{
|
||||
OmniNxVariant.Light => "Light",
|
||||
OmniNxVariant.Standard => "Standard",
|
||||
OmniNxVariant.Oc => "OC",
|
||||
_ => "None",
|
||||
};
|
||||
|
||||
public static string GetStagingFolderName(OmniNxVariant variant) => variant switch
|
||||
{
|
||||
OmniNxVariant.Light => "OmniNX Light",
|
||||
OmniNxVariant.Standard => "OmniNX Standard",
|
||||
OmniNxVariant.Oc => "OmniNX OC",
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
public static string GetZipAssetPrefix(OmniNxVariant variant) => variant switch
|
||||
{
|
||||
OmniNxVariant.Light => "OmniNX-Light",
|
||||
OmniNxVariant.Standard => "OmniNX-Standard",
|
||||
OmniNxVariant.Oc => "OmniNX-OC",
|
||||
_ => string.Empty,
|
||||
};
|
||||
|
||||
public static OmniNxVariant ParsePackName(string? value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return OmniNxVariant.None;
|
||||
|
||||
return value.Trim() switch
|
||||
{
|
||||
"Light" => OmniNxVariant.Light,
|
||||
"Standard" => OmniNxVariant.Standard,
|
||||
"OC" => OmniNxVariant.Oc,
|
||||
_ => OmniNxVariant.None,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static class PathUtils
|
||||
{
|
||||
public static string NormalizeDriveRoot(string driveRoot)
|
||||
{
|
||||
var root = driveRoot.Trim();
|
||||
if (!root.EndsWith(Path.DirectorySeparatorChar))
|
||||
root += Path.DirectorySeparatorChar;
|
||||
return root;
|
||||
}
|
||||
|
||||
public static string ToDrivePath(string driveRoot, string sdRelative)
|
||||
{
|
||||
var rel = sdRelative.Replace("sd:/", string.Empty).Replace("sd:\\", string.Empty)
|
||||
.Replace('/', Path.DirectorySeparatorChar);
|
||||
return Path.Combine(NormalizeDriveRoot(driveRoot), rel);
|
||||
}
|
||||
|
||||
public static string RelativeFromDrive(string driveRoot, string fullPath)
|
||||
{
|
||||
var root = NormalizeDriveRoot(driveRoot);
|
||||
if (fullPath.StartsWith(root, StringComparison.OrdinalIgnoreCase))
|
||||
return fullPath[root.Length..];
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
public static bool PathExists(string path)
|
||||
{
|
||||
return Directory.Exists(path) || File.Exists(path);
|
||||
}
|
||||
|
||||
public static void EnsureDirectory(string path)
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
}
|
||||
|
||||
public static void CopyFile(string src, string dst, bool overwrite = true)
|
||||
{
|
||||
var dir = Path.GetDirectoryName(dst);
|
||||
if (!string.IsNullOrEmpty(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
File.Copy(src, dst, overwrite);
|
||||
}
|
||||
|
||||
public static void CopyDirectory(string src, string dst, IProgress<(int current, int total, string file)>? progress = null)
|
||||
{
|
||||
if (!Directory.Exists(src))
|
||||
return;
|
||||
|
||||
var files = Directory.GetFiles(src, "*", SearchOption.AllDirectories);
|
||||
var total = files.Length;
|
||||
var current = 0;
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
var rel = Path.GetRelativePath(src, file);
|
||||
var target = Path.Combine(dst, rel);
|
||||
CopyFile(file, target);
|
||||
current++;
|
||||
progress?.Report((current, total, rel));
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeletePath(string path)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.SetAttributes(path, FileAttributes.Normal);
|
||||
File.Delete(path);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Directory.Exists(path))
|
||||
Directory.Delete(path, recursive: true);
|
||||
}
|
||||
|
||||
public static int CountItemsRecursive(string path)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
return 1;
|
||||
if (!Directory.Exists(path))
|
||||
return 0;
|
||||
|
||||
var count = 1;
|
||||
foreach (var entry in Directory.EnumerateFileSystemEntries(path, "*", SearchOption.AllDirectories))
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using OmniNX.DesktopInstaller.Models;
|
||||
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public sealed class VersionDetectService
|
||||
{
|
||||
private const string ManifestRelative = @"config\omninx\manifest.ini";
|
||||
|
||||
public OmniNxStatus DetectInstallation(string driveRoot)
|
||||
{
|
||||
var manifest = PathUtils.ToDrivePath(driveRoot, ManifestRelative);
|
||||
if (!File.Exists(manifest))
|
||||
return new OmniNxStatus { IsInstalled = false, Variant = OmniNxVariant.None };
|
||||
|
||||
var variant = OmniNxVariant.None;
|
||||
var version = string.Empty;
|
||||
var inSection = false;
|
||||
|
||||
foreach (var rawLine in File.ReadLines(manifest))
|
||||
{
|
||||
var line = rawLine.Trim();
|
||||
if (line.StartsWith('[') && line.EndsWith(']'))
|
||||
{
|
||||
inSection = line[1..^1].Equals("OmniNX", StringComparison.Ordinal);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inSection || !line.Contains('='))
|
||||
continue;
|
||||
|
||||
var eq = line.IndexOf('=');
|
||||
var key = line[..eq].Trim();
|
||||
var val = line[(eq + 1)..].Trim();
|
||||
|
||||
if (key.Equals("current_pack", StringComparison.Ordinal))
|
||||
variant = VariantHelper.ParsePackName(val);
|
||||
else if (key.Equals("version", StringComparison.Ordinal))
|
||||
version = val;
|
||||
}
|
||||
|
||||
return new OmniNxStatus
|
||||
{
|
||||
IsInstalled = variant != OmniNxVariant.None,
|
||||
Variant = variant,
|
||||
Version = version,
|
||||
};
|
||||
}
|
||||
|
||||
public InstallMode DetermineMode(OmniNxStatus status, bool forceClean)
|
||||
{
|
||||
if (forceClean)
|
||||
return InstallMode.Clean;
|
||||
return status.IsInstalled ? InstallMode.Update : InstallMode.Clean;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DriveService
|
||||
{
|
||||
public sealed record DriveItem(DriveInfo Drive)
|
||||
{
|
||||
public override string ToString() => FormatDriveLabel(Drive);
|
||||
}
|
||||
|
||||
public static IReadOnlyList<DriveItem> GetCandidateDrives()
|
||||
{
|
||||
return DriveInfo.GetDrives()
|
||||
.Where(d => d.IsReady && d.DriveType == DriveType.Removable)
|
||||
.OrderBy(d => d.Name)
|
||||
.Select(d => new DriveItem(d))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public static string FormatDriveLabel(DriveInfo drive)
|
||||
{
|
||||
var label = string.IsNullOrWhiteSpace(drive.VolumeLabel) ? "No Label" : drive.VolumeLabel;
|
||||
var sizeGb = drive.TotalSize / (1024.0 * 1024 * 1024);
|
||||
return $"{drive.Name} [{label}] ({sizeGb:F1} GB, {drive.DriveFormat})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.IO.Compression;
|
||||
using OmniNX.DesktopInstaller.Models;
|
||||
|
||||
namespace OmniNX.DesktopInstaller.Services;
|
||||
|
||||
public static class ZipExtractor
|
||||
{
|
||||
public static string ExtractPack(string zipPath, string extractRoot, IProgress<string>? progress = null)
|
||||
{
|
||||
PathUtils.EnsureDirectory(extractRoot);
|
||||
var targetDir = Path.Combine(extractRoot, Path.GetFileNameWithoutExtension(zipPath));
|
||||
if (Directory.Exists(targetDir))
|
||||
Directory.Delete(targetDir, recursive: true);
|
||||
|
||||
progress?.Report($"Extracting {Path.GetFileName(zipPath)}...");
|
||||
ZipFile.ExtractToDirectory(zipPath, targetDir, overwriteFiles: true);
|
||||
return ResolveStagingPath(targetDir);
|
||||
}
|
||||
|
||||
public static string ResolveStagingPath(string extractRoot)
|
||||
{
|
||||
foreach (var variant in new[] { OmniNxVariant.Standard, OmniNxVariant.Light, OmniNxVariant.Oc })
|
||||
{
|
||||
var candidate = Path.Combine(extractRoot, VariantHelper.GetStagingFolderName(variant));
|
||||
if (Directory.Exists(candidate))
|
||||
return candidate;
|
||||
}
|
||||
|
||||
if (Directory.Exists(Path.Combine(extractRoot, "atmosphere")) ||
|
||||
Directory.Exists(Path.Combine(extractRoot, "bootloader")))
|
||||
return extractRoot;
|
||||
|
||||
var subdirs = Directory.GetDirectories(extractRoot);
|
||||
if (subdirs.Length == 1)
|
||||
return ResolveStagingPath(subdirs[0]);
|
||||
|
||||
throw new InvalidOperationException(
|
||||
"Could not locate OmniNX pack root in extracted archive. Expected 'OmniNX Light', 'OmniNX Standard', or 'OmniNX OC' folder.");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user