add registry saving and launching
This commit is contained in:
		
							parent
							
								
									b8c915a37d
								
							
						
					
					
						commit
						e9924bded2
					
				@ -2,6 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public interface IAppData
 | 
					public interface IAppData
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    string Name { get; }
 | 
					    string ExecutableName { get; }
 | 
				
			||||||
 | 
					    string PackageName { get; }
 | 
				
			||||||
    Dictionary<string, string> PackageFiles { get; }
 | 
					    Dictionary<string, string> PackageFiles { get; }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -2,7 +2,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class StudioData : IAppData
 | 
					public class StudioData : IAppData
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public string Name => "WindowsStudio64";
 | 
					    public string ExecutableName => "RobloxStudioBeta.exe";
 | 
				
			||||||
 | 
					    public string PackageName => "WindowsStudio64";
 | 
				
			||||||
    public Dictionary<string, string> PackageFiles { get; } = new()
 | 
					    public Dictionary<string, string> PackageFiles { get; } = new()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ["RobloxStudio.zip"]                    = "",
 | 
					        ["RobloxStudio.zip"]                    = "",
 | 
				
			||||||
 | 
				
			|||||||
@ -2,4 +2,5 @@
 | 
				
			|||||||
using RobloxLegacy.AppData;
 | 
					using RobloxLegacy.AppData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
using var manager = new VersionManager(new StudioData());
 | 
					using var manager = new VersionManager(new StudioData());
 | 
				
			||||||
await manager.InstallPackage();
 | 
					await manager.InstallPackage(); // update studio if needed
 | 
				
			||||||
 | 
					manager.LaunchApp();
 | 
				
			||||||
@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <PropertyGroup>
 | 
					    <PropertyGroup>
 | 
				
			||||||
        <OutputType>Exe</OutputType>
 | 
					        <OutputType>Exe</OutputType>
 | 
				
			||||||
        <TargetFramework>net8.0</TargetFramework>
 | 
					        <TargetFramework>net8.0-windows</TargetFramework>
 | 
				
			||||||
        <ImplicitUsings>enable</ImplicitUsings>
 | 
					        <ImplicitUsings>enable</ImplicitUsings>
 | 
				
			||||||
        <Nullable>enable</Nullable>
 | 
					        <Nullable>enable</Nullable>
 | 
				
			||||||
    </PropertyGroup>
 | 
					    </PropertyGroup>
 | 
				
			||||||
 | 
				
			|||||||
@ -1,4 +1,5 @@
 | 
				
			|||||||
using Newtonsoft.Json;
 | 
					using System.Diagnostics;
 | 
				
			||||||
 | 
					using Newtonsoft.Json;
 | 
				
			||||||
using RobloxLegacy.AppData;
 | 
					using RobloxLegacy.AppData;
 | 
				
			||||||
using RobloxLegacy.Utilities;
 | 
					using RobloxLegacy.Utilities;
 | 
				
			||||||
using ICSharpCode.SharpZipLib.Zip;
 | 
					using ICSharpCode.SharpZipLib.Zip;
 | 
				
			||||||
@ -18,12 +19,15 @@ 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 string? _currentVersion;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    private readonly string _tempPath = Path.Combine(Path.GetTempPath(), $"RobloxLegacy.{Guid.NewGuid().ToString()}");
 | 
					    private readonly string _tempPath = Path.Combine(Path.GetTempPath(), $"RobloxLegacy.{Guid.NewGuid().ToString()}");
 | 
				
			||||||
    private readonly IAppData _appData;
 | 
					    private readonly IAppData _appData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public VersionManager(IAppData appData)
 | 
					    public VersionManager(IAppData appData)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Directory.CreateDirectory(_tempPath);
 | 
					        Directory.CreateDirectory(_tempPath);
 | 
				
			||||||
 | 
					        _currentVersion = Registry.GetVersion(appData.PackageName);
 | 
				
			||||||
        _appData = appData;
 | 
					        _appData = appData;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -32,12 +36,12 @@ public class VersionManager : IDisposable
 | 
				
			|||||||
        var localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
 | 
					        var localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
 | 
				
			||||||
        return Path.Combine(localAppDataPath, "Roblox", "Versions", version);
 | 
					        return Path.Combine(localAppDataPath, "Roblox", "Versions", version);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    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.PackageName}/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;
 | 
				
			||||||
        var version = await response.Content.ReadAsAsync<VersionData>();
 | 
					        var version = await response.Content.ReadAsAsync<VersionData>();
 | 
				
			||||||
        return version;
 | 
					        return version;
 | 
				
			||||||
@ -53,10 +57,13 @@ public class VersionManager : IDisposable
 | 
				
			|||||||
    public async Task InstallPackage()
 | 
					    public async Task InstallPackage()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        var version = await GetLatestVersion();
 | 
					        var version = await GetLatestVersion();
 | 
				
			||||||
        if(version == null)
 | 
					
 | 
				
			||||||
 | 
					        if (version == null)
 | 
				
			||||||
            throw new Exception("No version data found");
 | 
					            throw new Exception("No version data found");
 | 
				
			||||||
        
 | 
					        if (version.UploadHash == _currentVersion)
 | 
				
			||||||
        Logger.Info($"Installing {_appData.Name} version {version.Version}");
 | 
					            return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Logger.Info($"Installing {_appData.PackageName} version {version.Version}");
 | 
				
			||||||
        foreach (var file in _appData.PackageFiles)
 | 
					        foreach (var file in _appData.PackageFiles)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
@ -74,8 +81,27 @@ public class VersionManager : IDisposable
 | 
				
			|||||||
                Logger.Error($"Failed to download {file.Key}");
 | 
					                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()
 | 
					    public void Dispose()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Directory.Delete(_tempPath, true);
 | 
					        Directory.Delete(_tempPath, true);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user