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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user