40 lines
1.8 KiB
C#
40 lines
1.8 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Launcher.Next.Application;
|
|
|
|
public sealed record LegacyProbeOverride(
|
|
int SchemaVersion,
|
|
string Mode,
|
|
string SettingsXml,
|
|
string DownloadListXml,
|
|
string CompatibilityOverlay,
|
|
string SelectedPattern,
|
|
string EvidenceOutputRoot);
|
|
|
|
public static class LegacyProbeOverrideParser
|
|
{
|
|
private static readonly JsonSerializerOptions Options = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
UnmappedMemberHandling = JsonUnmappedMemberHandling.Disallow
|
|
};
|
|
|
|
public static LegacyProbeOverride Parse(string json)
|
|
{
|
|
try
|
|
{
|
|
var value = JsonSerializer.Deserialize<LegacyProbeOverride>(json, Options)
|
|
?? throw new InvalidOperationException("LEGACY_PROBE_OVERRIDE_MISSING");
|
|
if (value.SchemaVersion != 1) throw new InvalidOperationException("LEGACY_PROBE_OVERRIDE_SCHEMA_UNSUPPORTED");
|
|
if (!string.Equals(value.Mode, "LegacyConfigurationProbe", StringComparison.Ordinal)) throw new InvalidOperationException("LEGACY_PROBE_MODE_REQUIRED");
|
|
if (new[] { value.SettingsXml, value.DownloadListXml, value.CompatibilityOverlay, value.SelectedPattern, value.EvidenceOutputRoot }.Any(string.IsNullOrWhiteSpace))
|
|
throw new InvalidOperationException("LEGACY_PROBE_INPUT_MISSING");
|
|
if (new[] { value.SettingsXml, value.DownloadListXml, value.CompatibilityOverlay, value.EvidenceOutputRoot }.Any(x => Uri.TryCreate(x, UriKind.Absolute, out var uri) && !uri.IsFile || x.Contains('*') || x.Contains('?')))
|
|
throw new InvalidOperationException("LEGACY_PROBE_INPUT_PATH_INVALID");
|
|
return value;
|
|
}
|
|
catch (JsonException) { throw new InvalidOperationException("LEGACY_PROBE_OVERRIDE_UNKNOWN_FIELD"); }
|
|
}
|
|
}
|