From b8c915a37d84c44c5bb78e559603e9177984a8cd Mon Sep 17 00:00:00 2001 From: murdle Date: Thu, 1 May 2025 15:45:01 -0700 Subject: [PATCH] downloading now works --- RobloxLegacy/Program.cs | 6 ++-- RobloxLegacy/RobloxLegacy.csproj | 1 + RobloxLegacy/Utilities/Logger.cs | 9 ++++-- RobloxLegacy/VersionManager.cs | 54 +++++++++++++++++++++++--------- 4 files changed, 52 insertions(+), 18 deletions(-) diff --git a/RobloxLegacy/Program.cs b/RobloxLegacy/Program.cs index f4a2413..31f6682 100644 --- a/RobloxLegacy/Program.cs +++ b/RobloxLegacy/Program.cs @@ -1,3 +1,5 @@ -// See https://aka.ms/new-console-template for more information +using RobloxLegacy; +using RobloxLegacy.AppData; -Console.WriteLine("hi"); \ No newline at end of file +using var manager = new VersionManager(new StudioData()); +await manager.InstallPackage(); \ No newline at end of file diff --git a/RobloxLegacy/RobloxLegacy.csproj b/RobloxLegacy/RobloxLegacy.csproj index 0a2f3d3..7fad543 100644 --- a/RobloxLegacy/RobloxLegacy.csproj +++ b/RobloxLegacy/RobloxLegacy.csproj @@ -9,6 +9,7 @@ + diff --git a/RobloxLegacy/Utilities/Logger.cs b/RobloxLegacy/Utilities/Logger.cs index 3b297f0..08503f0 100644 --- a/RobloxLegacy/Utilities/Logger.cs +++ b/RobloxLegacy/Utilities/Logger.cs @@ -2,8 +2,13 @@ public static class Logger { - public static void Log(string msg) + public static void Info(string msg) { - Console.Write($"[+] {msg}"); + Console.Write($"[+] {msg}\n", ConsoleColor.Gray); + } + + public static void Error(string msg) + { + Console.Write($"[!] {msg}\n", ConsoleColor.Red); } } \ No newline at end of file diff --git a/RobloxLegacy/VersionManager.cs b/RobloxLegacy/VersionManager.cs index 46773ef..286e32a 100644 --- a/RobloxLegacy/VersionManager.cs +++ b/RobloxLegacy/VersionManager.cs @@ -1,23 +1,31 @@ -using System.Text.Json.Serialization; -using System.IO.Compression; +using Newtonsoft.Json; using RobloxLegacy.AppData; using RobloxLegacy.Utilities; +using ICSharpCode.SharpZipLib.Zip; namespace RobloxLegacy; -public abstract class VersionData +public class VersionData { - [JsonPropertyName("version")] + [JsonProperty("version")] public required string Version { get; set; } - [JsonPropertyName("clientVersionUpload")] + [JsonProperty("clientVersionUpload")] public required string UploadHash { get; set; } } -public class VersionManager(IAppData appData) +public class VersionManager : IDisposable { private static readonly HttpClient Client = new(); private const string CdnUrl = "https://setup.rbxcdn.com"; + private readonly string _tempPath = Path.Combine(Path.GetTempPath(), $"RobloxLegacy.{Guid.NewGuid().ToString()}"); + private readonly IAppData _appData; + + public VersionManager(IAppData appData) + { + Directory.CreateDirectory(_tempPath); + _appData = appData; + } private static string GetVersionPath(string version) { @@ -27,7 +35,7 @@ public class VersionManager(IAppData appData) private async Task GetLatestVersion() { - var url = $"https://clientsettings.roblox.com/v2/client-version/{appData.Name}/channel/LIVE"; + var url = $"https://clientsettings.roblox.com/v2/client-version/{_appData.Name}/channel/LIVE"; var response = await Client.GetAsync(url); if(!response.IsSuccessStatusCode) // just to be safe return null; @@ -35,10 +43,11 @@ public class VersionManager(IAppData appData) return version; } - private static void ExtractBundle(string version, string folder, Stream file) + private static void ExtractBundle(string version, string folder, string tempFile) { + var fastZip = new FastZip(); var extractPath = Path.Combine(GetVersionPath(version), folder); - ZipFile.ExtractToDirectory(file, extractPath); + fastZip.ExtractZip(tempFile, extractPath, null); } public async Task InstallPackage() @@ -47,12 +56,29 @@ public class VersionManager(IAppData appData) if(version == null) throw new Exception("No version data found"); - Logger.Log($"Installing {appData.Name} version {version.Version}"); - foreach (var file in appData.PackageFiles) + Logger.Info($"Installing {_appData.Name} version {version.Version}"); + foreach (var file in _appData.PackageFiles) { - var fileName = $"{version.UploadHash}-{file.Key}"; - var fileStream = await Client.GetStreamAsync($"{CdnUrl}/{fileName}"); - ExtractBundle(version.UploadHash, file.Value, fileStream); + try + { + var fileName = $"{version.UploadHash}-{file.Key}"; + var fileBytes = await Client.GetByteArrayAsync($"{CdnUrl}/{fileName}"); + + var zipPath = Path.Combine(_tempPath, fileName); + await File.WriteAllBytesAsync(zipPath, fileBytes); + + ExtractBundle(version.UploadHash, file.Value, zipPath); + } + catch (HttpRequestException) + { + Logger.Error($"Failed to download {file.Key}"); + } } } + + public void Dispose() + { + Directory.Delete(_tempPath, true); + GC.SuppressFinalize(this); + } } \ No newline at end of file