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.
80 lines
2.5 KiB
C#
80 lines
2.5 KiB
C#
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})";
|
|
}
|
|
}
|