Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 117 additions & 6 deletions SiteLink.API/Packages/PackageManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
Expand All @@ -20,12 +21,25 @@ public static async Task<PackageReleaseIndex> GetIndexAsync(
CancellationToken cancellationToken = default)
{
(string owner, string name) = ParseRepository(repository);
string url = $"https://{owner.ToLowerInvariant()}.github.io/{name}/releases.json";
using HttpResponseMessage response = await Http.GetAsync(url, cancellationToken);
response.EnsureSuccessStatusCode();
string json = await response.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<PackageReleaseIndex>(json)
?? throw new InvalidDataException($"Release index '{url}' was empty.");

try
{
string url = $"https://{owner.ToLowerInvariant()}.github.io/{name}/releases.json";
using HttpResponseMessage response = await Http.GetAsync(url, cancellationToken);
if (response.IsSuccessStatusCode)
{
string json = await response.Content.ReadAsStringAsync();
PackageReleaseIndex index = JsonConvert.DeserializeObject<PackageReleaseIndex>(json);
if (index != null && index.Versions != null && index.Versions.Count > 0)
return index;
}
}
catch
{
// Fall back to GitHub REST API if releases.json is missing or invalid
}

return await GetIndexFromGitHubApiAsync(owner, name, cancellationToken);
}

public static PackageManifest GetLatest(
Expand Down Expand Up @@ -174,6 +188,103 @@ public static (string Owner, string Repository) ParseRepository(string repositor
private static Version ParseVersion(string value) =>
Version.TryParse(value?.TrimStart('v', 'V'), out Version version) ? version : null;

private static async Task<PackageReleaseIndex> GetIndexFromGitHubApiAsync(
string owner,
string name,
CancellationToken cancellationToken)
{
string url = $"https://api.github.com/repos/{owner}/{name}/releases";
using HttpResponseMessage response = await Http.GetAsync(url, cancellationToken);
response.EnsureSuccessStatusCode();

string json = await response.Content.ReadAsStringAsync();
JArray releases = JArray.Parse(json);

PackageReleaseIndex index = new()
{
DisplayName = name,
OwnerName = owner,
RepositoryName = name
};

foreach (JObject release in releases.Children<JObject>())
{
if (release["draft"]?.Value<bool>() == true)
continue;

string tagName = release["tag_name"]?.ToString();
if (string.IsNullOrWhiteSpace(tagName))
continue;

string versionStr = tagName.TrimStart('v', 'V');
PackageManifest manifest = new()
{
DisplayName = name,
OwnerName = owner,
RepositoryName = name,
Version = versionStr,
PackageType = "core"
};

if (release["assets"] is JArray assets)
{
foreach (JObject asset in assets.Children<JObject>())
{
string fileName = asset["name"]?.ToString();
string downloadUrl = asset["browser_download_url"]?.ToString();
long size = asset["size"]?.Value<long>() ?? 0;

if (string.IsNullOrWhiteSpace(fileName) || string.IsNullOrWhiteSpace(downloadUrl))
continue;

string platform;
if (fileName.Equals("SiteLink.exe", StringComparison.OrdinalIgnoreCase) ||
fileName.EndsWith(".exe", StringComparison.OrdinalIgnoreCase) ||
fileName.Contains("win", StringComparison.OrdinalIgnoreCase))
{
platform = "windows";
}
else if (fileName.Equals("SiteLink", StringComparison.OrdinalIgnoreCase) ||
fileName.Contains("linux", StringComparison.OrdinalIgnoreCase))
{
platform = "linux";
}
else if (fileName.Contains("mac", StringComparison.OrdinalIgnoreCase) ||
fileName.Contains("osx", StringComparison.OrdinalIgnoreCase))
{
platform = "macos";
}
else
{
platform = "any";
}

manifest.Platforms[platform] = new PackageAsset
{
Platform = platform,
FileName = fileName,
FileUrl = downloadUrl,
Size = size
};
}
}

if (index.DisplayName == name && release["name"] != null)
{
string relName = release["name"].ToString();
if (!string.IsNullOrWhiteSpace(relName))
index.DisplayName = relName;
}

index.Versions[versionStr] = manifest;
}

if (index.Versions.Count == 0)
throw new InvalidOperationException($"No valid releases found in GitHub repository '{owner}/{name}'.");

return index;
}

private static HttpClient CreateHttpClient()
{
HttpClient client = new();
Expand Down
4 changes: 2 additions & 2 deletions SiteLink.API/SiteLinkAPI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SiteLink.API;
using SiteLink.API;

[assembly: AssemblyProduct("SiteLinkAPI")]
[assembly: AssemblyCopyright("Killers0992 @ 2026")]
Expand All @@ -12,7 +12,7 @@ public class SiteLinkAPI
static Version _apiVersion;

public const string GameVersionText = "14.2.7";
public const string ApiVersionText = "2.1.2";
public const string ApiVersionText = "2.1.3";

public static int ThresholdBytes => 65535 * (NetConstants.MaxPacketSize - 6);

Expand Down
4 changes: 2 additions & 2 deletions SiteLink/Services/BuildInformation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SiteLink.Services;
namespace SiteLink.Services;

public class BuildInformation
{
public const string VersionText = "1.0.1";
public static string VersionText => SiteLink.API.SiteLinkAPI.ApiVersionText;
}
4 changes: 2 additions & 2 deletions SiteLink/SiteLink.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -8,7 +8,7 @@
<Product>SiteLink</Product>
<Description>Multi-server proxy for SCP: Secret Laboratory.</Description>
<Authors>Killers0992</Authors>
<Version>2.1.2</Version>
<Version>2.1.3</Version>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>

Expand Down