downloading now works
This commit is contained in:
		
							parent
							
								
									e220c2e20d
								
							
						
					
					
						commit
						b8c915a37d
					
				@ -1,3 +1,5 @@
 | 
				
			|||||||
// See https://aka.ms/new-console-template for more information
 | 
					using RobloxLegacy;
 | 
				
			||||||
 | 
					using RobloxLegacy.AppData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Console.WriteLine("hi");
 | 
					using var manager = new VersionManager(new StudioData());
 | 
				
			||||||
 | 
					await manager.InstallPackage();
 | 
				
			||||||
@ -9,6 +9,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <ItemGroup>
 | 
					    <ItemGroup>
 | 
				
			||||||
      <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
 | 
					      <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
 | 
				
			||||||
 | 
					      <PackageReference Include="SharpZipLib" Version="1.4.2" />
 | 
				
			||||||
    </ItemGroup>
 | 
					    </ItemGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</Project>
 | 
					</Project>
 | 
				
			||||||
 | 
				
			|||||||
@ -2,8 +2,13 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public static class Logger
 | 
					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);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1,23 +1,31 @@
 | 
				
			|||||||
using System.Text.Json.Serialization;
 | 
					using Newtonsoft.Json;
 | 
				
			||||||
using System.IO.Compression;
 | 
					 | 
				
			||||||
using RobloxLegacy.AppData;
 | 
					using RobloxLegacy.AppData;
 | 
				
			||||||
using RobloxLegacy.Utilities;
 | 
					using RobloxLegacy.Utilities;
 | 
				
			||||||
 | 
					using ICSharpCode.SharpZipLib.Zip;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace RobloxLegacy;
 | 
					namespace RobloxLegacy;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public abstract class VersionData
 | 
					public class VersionData
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    [JsonPropertyName("version")]
 | 
					    [JsonProperty("version")]
 | 
				
			||||||
    public required string Version { get; set; }
 | 
					    public required string Version { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [JsonPropertyName("clientVersionUpload")]
 | 
					    [JsonProperty("clientVersionUpload")]
 | 
				
			||||||
    public required string UploadHash { get; set; }
 | 
					    public required string UploadHash { get; set; }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class VersionManager(IAppData appData)
 | 
					public class VersionManager : IDisposable
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private static readonly HttpClient Client = new();
 | 
					    private static readonly HttpClient Client = new();
 | 
				
			||||||
    private const string CdnUrl = "https://setup.rbxcdn.com";
 | 
					    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)
 | 
					    private static string GetVersionPath(string version)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -27,7 +35,7 @@ public class VersionManager(IAppData appData)
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    private async Task<VersionData?> GetLatestVersion()
 | 
					    private async Task<VersionData?> 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);
 | 
					        var response = await Client.GetAsync(url);
 | 
				
			||||||
        if(!response.IsSuccessStatusCode) // just to be safe
 | 
					        if(!response.IsSuccessStatusCode) // just to be safe
 | 
				
			||||||
            return null;
 | 
					            return null;
 | 
				
			||||||
@ -35,10 +43,11 @@ public class VersionManager(IAppData appData)
 | 
				
			|||||||
        return version;
 | 
					        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);
 | 
					        var extractPath = Path.Combine(GetVersionPath(version), folder);
 | 
				
			||||||
        ZipFile.ExtractToDirectory(file, extractPath);
 | 
					        fastZip.ExtractZip(tempFile, extractPath, null);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public async Task InstallPackage()
 | 
					    public async Task InstallPackage()
 | 
				
			||||||
@ -47,12 +56,29 @@ public class VersionManager(IAppData appData)
 | 
				
			|||||||
        if(version == null)
 | 
					        if(version == null)
 | 
				
			||||||
            throw new Exception("No version data found");
 | 
					            throw new Exception("No version data found");
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
        Logger.Log($"Installing {appData.Name} version {version.Version}");
 | 
					        Logger.Info($"Installing {_appData.Name} version {version.Version}");
 | 
				
			||||||
        foreach (var file in appData.PackageFiles)
 | 
					        foreach (var file in _appData.PackageFiles)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var fileName = $"{version.UploadHash}-{file.Key}";
 | 
					            try
 | 
				
			||||||
            var fileStream = await Client.GetStreamAsync($"{CdnUrl}/{fileName}");
 | 
					            {
 | 
				
			||||||
            ExtractBundle(version.UploadHash, file.Value, fileStream);
 | 
					                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);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user