Files
AlayaCore/AlayaCore/Installation/InstallEnvironment.cs
2026-04-04 20:51:53 +01:00

70 lines
2.5 KiB
C#

using System;
using System.Runtime.InteropServices;
using AlayaCore.Models.Manifests;
namespace AlayaCore.Installation
{
public sealed class InstallEnvironment
{
public OSPlatform OsPlatform { get; }
public bool JavaInstalled { get; }
public string? JavaVersion { get; }
public string? JavaPath { get; }
public bool MinecraftInstalled { get; }
public string? MinecraftVersion { get; }
public bool NeoforgedInstalled { get; }
public string? NeoforgedVersion { get; }
public InstalledModsManifestModel InstalledModsManifest { get; }
public InstallEnvironment(OSPlatform osPlatform,
bool javaInstalled,
string? javaPath,
string? javaVersion,
bool minecraftInstalled,
string? minecraftVersion,
bool neoforgedInstalled,
string? neoforgedVersion,
InstalledModsManifestModel installedModsManifest)
{
if (javaInstalled && string.IsNullOrWhiteSpace(javaPath))
{
throw new ArgumentException(
"Java path must be provided when Java is marked as installed.",
nameof(javaPath));
}
if (!javaInstalled && !string.IsNullOrWhiteSpace(javaPath))
{
throw new ArgumentException(
"Java path must be null when Java is not installed.",
nameof(javaPath));
}
OsPlatform = osPlatform;
JavaInstalled = javaInstalled;
JavaPath = javaInstalled ? javaPath : null;
JavaVersion = javaInstalled ? javaVersion : null;
MinecraftInstalled = minecraftInstalled;
MinecraftVersion = minecraftVersion;
NeoforgedInstalled = neoforgedInstalled;
NeoforgedVersion = neoforgedVersion;
InstalledModsManifest = installedModsManifest ?? throw new ArgumentNullException(nameof(installedModsManifest));
}
public static InstallEnvironment Empty()
{
return new InstallEnvironment(
osPlatform: System.Runtime.InteropServices.OSPlatform.Windows,
javaInstalled: false,
javaPath: null,
javaVersion: null,
minecraftInstalled: false,
minecraftVersion: null,
neoforgedInstalled: false,
neoforgedVersion: null,
installedModsManifest: InstalledModsManifestModel.Empty());
}
}
}