add registry saving and launching
This commit is contained in:
		
							parent
							
								
									b8c915a37d
								
							
						
					
					
						commit
						e9924bded2
					
				@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
public interface IAppData
 | 
			
		||||
{
 | 
			
		||||
    string Name { get; }
 | 
			
		||||
    string ExecutableName { get; }
 | 
			
		||||
    string PackageName { get; }
 | 
			
		||||
    Dictionary<string, string> PackageFiles { get; }
 | 
			
		||||
}
 | 
			
		||||
@ -2,7 +2,8 @@
 | 
			
		||||
 | 
			
		||||
public class StudioData : IAppData
 | 
			
		||||
{
 | 
			
		||||
    public string Name => "WindowsStudio64";
 | 
			
		||||
    public string ExecutableName => "RobloxStudioBeta.exe";
 | 
			
		||||
    public string PackageName => "WindowsStudio64";
 | 
			
		||||
    public Dictionary<string, string> PackageFiles { get; } = new()
 | 
			
		||||
    {
 | 
			
		||||
        ["RobloxStudio.zip"]                    = "",
 | 
			
		||||
 | 
			
		||||
@ -2,4 +2,5 @@
 | 
			
		||||
using RobloxLegacy.AppData;
 | 
			
		||||
 | 
			
		||||
using var manager = new VersionManager(new StudioData());
 | 
			
		||||
await manager.InstallPackage();
 | 
			
		||||
await manager.InstallPackage(); // update studio if needed
 | 
			
		||||
manager.LaunchApp();
 | 
			
		||||
@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
    <PropertyGroup>
 | 
			
		||||
        <OutputType>Exe</OutputType>
 | 
			
		||||
        <TargetFramework>net8.0</TargetFramework>
 | 
			
		||||
        <TargetFramework>net8.0-windows</TargetFramework>
 | 
			
		||||
        <ImplicitUsings>enable</ImplicitUsings>
 | 
			
		||||
        <Nullable>enable</Nullable>
 | 
			
		||||
    </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
@ -1,4 +1,5 @@
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using Newtonsoft.Json;
 | 
			
		||||
using RobloxLegacy.AppData;
 | 
			
		||||
using RobloxLegacy.Utilities;
 | 
			
		||||
using ICSharpCode.SharpZipLib.Zip;
 | 
			
		||||
@ -18,12 +19,15 @@ public class VersionManager : IDisposable
 | 
			
		||||
{
 | 
			
		||||
    private static readonly HttpClient Client = new();
 | 
			
		||||
    private const string CdnUrl = "https://setup.rbxcdn.com";
 | 
			
		||||
    private string? _currentVersion;
 | 
			
		||||
    
 | 
			
		||||
    private readonly string _tempPath = Path.Combine(Path.GetTempPath(), $"RobloxLegacy.{Guid.NewGuid().ToString()}");
 | 
			
		||||
    private readonly IAppData _appData;
 | 
			
		||||
 | 
			
		||||
    public VersionManager(IAppData appData)
 | 
			
		||||
    {
 | 
			
		||||
        Directory.CreateDirectory(_tempPath);
 | 
			
		||||
        _currentVersion = Registry.GetVersion(appData.PackageName);
 | 
			
		||||
        _appData = appData;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -35,7 +39,7 @@ public class VersionManager : IDisposable
 | 
			
		||||
 | 
			
		||||
    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.PackageName}/channel/LIVE";
 | 
			
		||||
        var response = await Client.GetAsync(url);
 | 
			
		||||
        if (!response.IsSuccessStatusCode) // just to be safe
 | 
			
		||||
            return null;
 | 
			
		||||
@ -53,10 +57,13 @@ public class VersionManager : IDisposable
 | 
			
		||||
    public async Task InstallPackage()
 | 
			
		||||
    {
 | 
			
		||||
        var version = await GetLatestVersion();
 | 
			
		||||
 | 
			
		||||
        if (version == null)
 | 
			
		||||
            throw new Exception("No version data found");
 | 
			
		||||
        if (version.UploadHash == _currentVersion)
 | 
			
		||||
            return;
 | 
			
		||||
 | 
			
		||||
        Logger.Info($"Installing {_appData.Name} version {version.Version}");
 | 
			
		||||
        Logger.Info($"Installing {_appData.PackageName} version {version.Version}");
 | 
			
		||||
        foreach (var file in _appData.PackageFiles)
 | 
			
		||||
        {
 | 
			
		||||
            try
 | 
			
		||||
@ -74,6 +81,25 @@ public class VersionManager : IDisposable
 | 
			
		||||
                Logger.Error($"Failed to download {file.Key}");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        _currentVersion = version.UploadHash;
 | 
			
		||||
        Registry.SaveVersion(_appData.PackageName, version.UploadHash);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void LaunchApp()
 | 
			
		||||
    {
 | 
			
		||||
        Logger.Info($"Launching {_appData.PackageName}...");
 | 
			
		||||
        if(string.IsNullOrEmpty(_currentVersion))
 | 
			
		||||
            throw new Exception("No version data found");
 | 
			
		||||
        
 | 
			
		||||
        var startInfo = new ProcessStartInfo()
 | 
			
		||||
        {
 | 
			
		||||
            FileName = _appData.ExecutableName,
 | 
			
		||||
            WorkingDirectory = GetVersionPath(_currentVersion),
 | 
			
		||||
            UseShellExecute = true
 | 
			
		||||
        };
 | 
			
		||||
        
 | 
			
		||||
        Process.Start(startInfo);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void Dispose()
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user