mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 07:28:45 -07:00
7d1ac82cf8
Set DORKNET_LOCAL_MANIFEST and/or DORKNET_LOCAL_RELEASES to point
the launcher at on-disk artifacts instead of the public repo:
- DORKNET_LOCAL_MANIFEST: full path to a versions.json file.
VersionsManifest.FetchAsync reads it from disk and skips the
GitHub round-trip.
- DORKNET_LOCAL_RELEASES: path to a directory laid out as
{root}/{version_key}/server/ + .../patcher/. EnsureServerAsync /
EnsurePatcherAsync return those paths in-place — no download,
no copy, no marker files.
Both are silent no-ops when unset / missing on disk, so it's safe
to leave them set permanently in a dev profile. When at least one
is active, the Settings view surfaces a "Dev overrides active"
panel listing the paths so it's obvious the launcher isn't using
the public manifest.
Lets contributors iterate on per-version branch changes against
the launcher UI without needing to tag a public Release.
91 lines
3.3 KiB
C#
91 lines
3.3 KiB
C#
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace DorkNet.Launcher.Backend;
|
|
|
|
/// <summary>Fetches the canonical branch-to-build mapping from
|
|
/// <c>versions.json</c> on the public DorkNet repo's <c>main</c>
|
|
/// branch. Falls back to the locally-cached copy when offline, so the
|
|
/// launcher opens even with no internet (host mode just can't fetch
|
|
/// new server builds).
|
|
///
|
|
/// <para>Source URL is hardcoded — it's the entire point of the
|
|
/// launcher knowing where to look. To run against a fork's manifest,
|
|
/// edit <see cref="ManifestUrl"/>.</para></summary>
|
|
public sealed class VersionsManifest
|
|
{
|
|
public const string ManifestUrl =
|
|
"https://raw.githubusercontent.com/DorkSquadRR/DorkNet/main/versions.json";
|
|
|
|
private static readonly HttpClient Http = new()
|
|
{
|
|
Timeout = TimeSpan.FromSeconds(15),
|
|
};
|
|
|
|
[JsonPropertyName("$schema_version")] public int SchemaVersion { get; set; }
|
|
[JsonPropertyName("branches")] public List<VersionEntry> Branches { get; set; } = new();
|
|
|
|
public async Task<VersionsManifest?> FetchAsync(CancellationToken ct = default)
|
|
{
|
|
// Dev-time override: read manifest from a local file instead of
|
|
// GitHub. Used for testing branch changes before they're public.
|
|
var localPath = LocalOverrides.GetLocalManifestPath();
|
|
if (localPath is not null)
|
|
{
|
|
try
|
|
{
|
|
var json = await File.ReadAllTextAsync(localPath, ct);
|
|
return JsonSerializer.Deserialize<VersionsManifest>(json);
|
|
}
|
|
catch
|
|
{
|
|
// Bad local file — fall through to the network so the
|
|
// user gets a real error instead of silent emptiness.
|
|
}
|
|
}
|
|
|
|
try
|
|
{
|
|
var m = await Http.GetFromJsonAsync<VersionsManifest>(ManifestUrl, ct);
|
|
if (m is not null)
|
|
{
|
|
File.WriteAllText(AppPaths.ManifestCacheFile,
|
|
JsonSerializer.Serialize(m));
|
|
}
|
|
return m;
|
|
}
|
|
catch
|
|
{
|
|
// Offline / 404 / parse failure — fall back to last-seen
|
|
// cache. Returns null only when there's no cache either
|
|
// (first launch + no internet — the launcher reports the
|
|
// failure to the user in that case).
|
|
return LoadCached();
|
|
}
|
|
}
|
|
|
|
public static VersionsManifest? LoadCached()
|
|
{
|
|
if (!File.Exists(AppPaths.ManifestCacheFile)) return null;
|
|
try
|
|
{
|
|
var json = File.ReadAllText(AppPaths.ManifestCacheFile);
|
|
return JsonSerializer.Deserialize<VersionsManifest>(json);
|
|
}
|
|
catch { return null; }
|
|
}
|
|
}
|
|
|
|
public sealed class VersionEntry
|
|
{
|
|
[JsonPropertyName("branch")] public string Branch { get; set; } = "";
|
|
[JsonPropertyName("client_build")] public string ClientBuild { get; set; } = "";
|
|
[JsonPropertyName("alt_builds")] public List<string> AltBuilds { get; set; } = new();
|
|
[JsonPropertyName("version_key")] public string VersionKey { get; set; } = "";
|
|
[JsonPropertyName("release_tag_prefix")] public string ReleaseTagPrefix { get; set; } = "";
|
|
[JsonPropertyName("supported")] public bool Supported { get; set; }
|
|
}
|