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