bloxstrap/Bloxstrap/Helpers/Integrations/RbxFpsUnlocker.cs
pizzaboxer 92b159d682 Updates and bugfixes for v1.3.0
- Features
    - Added integration with rbxfpsunlocker
    - Added support for user-applicable mods
    - Added ability to disable auto-update checking

 - Misc
    - Removed Bloxstrap branding from Discord Rich Presence
    - Mod presets for old death sound and mouse cursor are now statically stored as base64 strings, eliminating reliance on the website and the old cursors still existing

 - Bugfixes
    - Fixed vista bootstrapper style not hiding properly and improper behavior when closed
    - Fixed forms not being brought to the front when shown

 - Code
    - Reconsolidated Bootstrapper to a single file, using regions instead of partials
2022-08-21 22:41:16 +01:00

96 lines
3.3 KiB
C#

using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net.Http;
using Newtonsoft.Json.Linq;
namespace Bloxstrap.Helpers.Integrations
{
internal class RbxFpsUnlocker
{
public const string ProjectRepository = "axstin/rbxfpsunlocker";
// default settings but with QuickStart set to true and CheckForUpdates set to false
private static readonly string Settings =
"UnlockClient=true\n" +
"UnlockStudio=false\n" +
"FPSCapValues=[30.000000, 60.000000, 75.000000, 120.000000, 144.000000, 165.000000, 240.000000, 360.000000]\n" +
"FPSCapSelection=0\n" +
"FPSCap=0.000000\n" +
"CheckForUpdates=false\n" +
"NonBlockingErrors=true\n" +
"SilentErrors=false\n" +
"QuickStart=true\n";
public static async Task CheckInstall()
{
if (Program.BaseDirectory is null)
return;
string folderLocation = Path.Combine(Program.BaseDirectory, "Integrations", "rbxfpsunlocker");
string fileLocation = Path.Combine(folderLocation, "rbxfpsunlocker.exe");
string settingsLocation = Path.Combine(folderLocation, "settings");
if (!Program.Settings.RFUEnabled)
{
if (Directory.Exists(folderLocation))
{
Directory.Delete(folderLocation, true);
}
return;
}
DateTime lastReleasePublish;
string downloadUrl;
try
{
JObject releaseInfo = await Utilities.GetJson($"https://api.github.com/repos/{ProjectRepository}/releases/latest");
// so... rbxfpsunlocker does not actually have any version info for the executable
// meaning the best way we can check for a new version is comparing time last download to time last release published
lastReleasePublish = DateTime.Parse(releaseInfo["created_at"].Value<string>());
downloadUrl = releaseInfo["assets"][0]["browser_download_url"].Value<string>();
}
catch (Exception ex)
{
Debug.WriteLine($"Failed to fetch latest version info! ({ex.Message})");
return;
}
Directory.CreateDirectory(folderLocation);
if (File.Exists(fileLocation))
{
DateTime lastDownload = File.GetCreationTimeUtc(fileLocation);
// no new release published, return
if (lastDownload > lastReleasePublish)
return;
File.Delete(fileLocation);
}
Debug.WriteLine("Installing/Updating rbxfpsunlocker...");
using (HttpClient client = new())
{
byte[] bytes = await client.GetByteArrayAsync(downloadUrl);
using (MemoryStream zipStream = new MemoryStream(bytes))
{
ZipArchive zip = new ZipArchive(zipStream);
zip.ExtractToDirectory(folderLocation, true);
}
}
if (!File.Exists(settingsLocation))
{
await File.WriteAllTextAsync(settingsLocation, Settings);
}
}
}
}