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