From e9924bded2fa150f985b067adb3fb67516b81c03 Mon Sep 17 00:00:00 2001 From: murdle Date: Thu, 1 May 2025 16:57:15 -0700 Subject: [PATCH] add registry saving and launching --- RobloxLegacy/AppData/IAppData.cs | 3 ++- RobloxLegacy/AppData/StudioData.cs | 3 ++- RobloxLegacy/Program.cs | 3 ++- RobloxLegacy/RobloxLegacy.csproj | 2 +- RobloxLegacy/VersionManager.cs | 42 ++++++++++++++++++++++++------ 5 files changed, 41 insertions(+), 12 deletions(-) diff --git a/RobloxLegacy/AppData/IAppData.cs b/RobloxLegacy/AppData/IAppData.cs index f97b578..2bee8c5 100644 --- a/RobloxLegacy/AppData/IAppData.cs +++ b/RobloxLegacy/AppData/IAppData.cs @@ -2,6 +2,7 @@ public interface IAppData { - string Name { get; } + string ExecutableName { get; } + string PackageName { get; } Dictionary PackageFiles { get; } } \ No newline at end of file diff --git a/RobloxLegacy/AppData/StudioData.cs b/RobloxLegacy/AppData/StudioData.cs index d41668c..aab88b6 100644 --- a/RobloxLegacy/AppData/StudioData.cs +++ b/RobloxLegacy/AppData/StudioData.cs @@ -2,7 +2,8 @@ public class StudioData : IAppData { - public string Name => "WindowsStudio64"; + public string ExecutableName => "RobloxStudioBeta.exe"; + public string PackageName => "WindowsStudio64"; public Dictionary PackageFiles { get; } = new() { ["RobloxStudio.zip"] = "", diff --git a/RobloxLegacy/Program.cs b/RobloxLegacy/Program.cs index 31f6682..d4d49a9 100644 --- a/RobloxLegacy/Program.cs +++ b/RobloxLegacy/Program.cs @@ -2,4 +2,5 @@ using RobloxLegacy.AppData; using var manager = new VersionManager(new StudioData()); -await manager.InstallPackage(); \ No newline at end of file +await manager.InstallPackage(); // update studio if needed +manager.LaunchApp(); \ No newline at end of file diff --git a/RobloxLegacy/RobloxLegacy.csproj b/RobloxLegacy/RobloxLegacy.csproj index 7fad543..043cdde 100644 --- a/RobloxLegacy/RobloxLegacy.csproj +++ b/RobloxLegacy/RobloxLegacy.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net8.0-windows enable enable diff --git a/RobloxLegacy/VersionManager.cs b/RobloxLegacy/VersionManager.cs index 286e32a..f11b32a 100644 --- a/RobloxLegacy/VersionManager.cs +++ b/RobloxLegacy/VersionManager.cs @@ -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; } @@ -32,12 +36,12 @@ public class VersionManager : IDisposable var localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); return Path.Combine(localAppDataPath, "Roblox", "Versions", version); } - + 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.PackageName}/channel/LIVE"; var response = await Client.GetAsync(url); - if(!response.IsSuccessStatusCode) // just to be safe + if (!response.IsSuccessStatusCode) // just to be safe return null; var version = await response.Content.ReadAsAsync(); return version; @@ -53,10 +57,13 @@ public class VersionManager : IDisposable public async Task InstallPackage() { var version = await GetLatestVersion(); - if(version == null) + + if (version == null) throw new Exception("No version data found"); - - Logger.Info($"Installing {_appData.Name} version {version.Version}"); + if (version.UploadHash == _currentVersion) + return; + + Logger.Info($"Installing {_appData.PackageName} version {version.Version}"); foreach (var file in _appData.PackageFiles) { try @@ -74,8 +81,27 @@ 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() { Directory.Delete(_tempPath, true);