mirror of
https://github.com/bloxstraplabs/bloxstrap.git
synced 2025-04-21 10:01:27 -07:00
Minor restructuring
This commit is contained in:
parent
28bcf57dff
commit
e7fd0b9642
@ -15,9 +15,9 @@ using Microsoft.Win32;
|
|||||||
|
|
||||||
using Bloxstrap.Extensions;
|
using Bloxstrap.Extensions;
|
||||||
using Bloxstrap.Models;
|
using Bloxstrap.Models;
|
||||||
using Bloxstrap.Singletons;
|
|
||||||
using Bloxstrap.UI.BootstrapperDialogs;
|
using Bloxstrap.UI.BootstrapperDialogs;
|
||||||
using Bloxstrap.UI.Menu.Views;
|
using Bloxstrap.UI.Menu.Views;
|
||||||
|
using Bloxstrap.Utility;
|
||||||
|
|
||||||
namespace Bloxstrap
|
namespace Bloxstrap
|
||||||
{
|
{
|
||||||
|
@ -256,7 +256,7 @@ namespace Bloxstrap
|
|||||||
|
|
||||||
if (_launchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch)
|
if (_launchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch)
|
||||||
{
|
{
|
||||||
Utilities.OpenWebsite("https://www.roblox.com/games");
|
Utilities.ShellExecute("https://www.roblox.com/games");
|
||||||
Dialog?.CloseBootstrapper();
|
Dialog?.CloseBootstrapper();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -562,7 +562,7 @@ namespace Bloxstrap
|
|||||||
private async Task CheckForUpdates()
|
private async Task CheckForUpdates()
|
||||||
{
|
{
|
||||||
// don't update if there's another instance running (likely running in the background)
|
// don't update if there's another instance running (likely running in the background)
|
||||||
if (Utilities.GetProcessCount(App.ProjectName) > 1)
|
if (Process.GetProcessesByName(App.ProjectName).Count() > 1)
|
||||||
{
|
{
|
||||||
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] More than one Bloxstrap instance running, aborting update check");
|
App.Logger.WriteLine($"[Bootstrapper::CheckForUpdates] More than one Bloxstrap instance running, aborting update check");
|
||||||
return;
|
return;
|
||||||
@ -616,7 +616,7 @@ namespace Bloxstrap
|
|||||||
private void Uninstall()
|
private void Uninstall()
|
||||||
{
|
{
|
||||||
// prompt to shutdown roblox if its currently running
|
// prompt to shutdown roblox if its currently running
|
||||||
if (Utilities.CheckIfRobloxRunning())
|
if (Process.GetProcessesByName(App.RobloxAppName).Any())
|
||||||
{
|
{
|
||||||
App.Logger.WriteLine($"[Bootstrapper::Uninstall] Prompting to shut down all open Roblox instances");
|
App.Logger.WriteLine($"[Bootstrapper::Uninstall] Prompting to shut down all open Roblox instances");
|
||||||
|
|
||||||
@ -1004,7 +1004,7 @@ namespace Bloxstrap
|
|||||||
|
|
||||||
if (File.Exists(fileVersionFolder))
|
if (File.Exists(fileVersionFolder))
|
||||||
{
|
{
|
||||||
if (Utilities.MD5File(fileModFolder) == Utilities.MD5File(fileVersionFolder))
|
if (Utility.MD5Hash.FromFile(fileModFolder) == Utility.MD5Hash.FromFile(fileVersionFolder))
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1072,7 +1072,7 @@ namespace Bloxstrap
|
|||||||
await File.WriteAllBytesAsync(modFolderLocation, binaryData);
|
await File.WriteAllBytesAsync(modFolderLocation, binaryData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (File.Exists(modFolderLocation) && Utilities.MD5File(modFolderLocation) == Utilities.MD5Data(binaryData))
|
else if (File.Exists(modFolderLocation) && Utility.MD5Hash.FromFile(modFolderLocation) == Utility.MD5Hash.FromBytes(binaryData))
|
||||||
{
|
{
|
||||||
File.Delete(modFolderLocation);
|
File.Delete(modFolderLocation);
|
||||||
}
|
}
|
||||||
@ -1091,7 +1091,8 @@ namespace Bloxstrap
|
|||||||
{
|
{
|
||||||
FileInfo file = new(packageLocation);
|
FileInfo file = new(packageLocation);
|
||||||
|
|
||||||
string calculatedMD5 = Utilities.MD5File(packageLocation);
|
string calculatedMD5 = Utility.MD5Hash.FromFile(packageLocation);
|
||||||
|
|
||||||
if (calculatedMD5 != package.Signature)
|
if (calculatedMD5 != package.Signature)
|
||||||
{
|
{
|
||||||
App.Logger.WriteLine($"[Bootstrapper::DownloadPackage] {package.Name} is corrupted ({calculatedMD5} != {package.Signature})! Deleting and re-downloading...");
|
App.Logger.WriteLine($"[Bootstrapper::DownloadPackage] {package.Name} is corrupted ({calculatedMD5} != {package.Signature})! Deleting and re-downloading...");
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
using Newtonsoft.Json.Linq;
|
using System.Collections.Generic;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Bloxstrap.Singletons
|
namespace Bloxstrap
|
||||||
{
|
{
|
||||||
public class FastFlagManager : JsonManager<Dictionary<string, object>>
|
public class FastFlagManager : JsonManager<Dictionary<string, object>>
|
||||||
{
|
{
|
@ -2,7 +2,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace Bloxstrap.Singletons
|
namespace Bloxstrap
|
||||||
{
|
{
|
||||||
public class JsonManager<T> where T : new()
|
public class JsonManager<T> where T : new()
|
||||||
{
|
{
|
@ -5,7 +5,7 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace Bloxstrap.Singletons
|
namespace Bloxstrap
|
||||||
{
|
{
|
||||||
// https://stackoverflow.com/a/53873141/11852173
|
// https://stackoverflow.com/a/53873141/11852173
|
||||||
// TODO - this kind of sucks
|
// TODO - this kind of sucks
|
@ -1,7 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
using Bloxstrap.Extensions;
|
using Bloxstrap.Extensions;
|
||||||
|
using Bloxstrap.Utility;
|
||||||
|
|
||||||
namespace Bloxstrap.UI.BootstrapperDialogs.WinForms
|
namespace Bloxstrap.UI.BootstrapperDialogs.WinForms
|
||||||
{
|
{
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
using System.ComponentModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
|
||||||
using Bloxstrap.Singletons;
|
|
||||||
using System.ComponentModel;
|
|
||||||
|
|
||||||
namespace Bloxstrap.UI.Menu.ViewModels
|
namespace Bloxstrap.UI.Menu.ViewModels
|
||||||
{
|
{
|
||||||
public class FastFlagsViewModel : INotifyPropertyChanged
|
public class FastFlagsViewModel : INotifyPropertyChanged
|
||||||
@ -17,7 +14,7 @@ namespace Bloxstrap.UI.Menu.ViewModels
|
|||||||
|
|
||||||
public ICommand OpenClientSettingsCommand => new RelayCommand(OpenClientSettings);
|
public ICommand OpenClientSettingsCommand => new RelayCommand(OpenClientSettings);
|
||||||
|
|
||||||
private void OpenClientSettings() => Utilities.OpenWebsite(Path.Combine(Directories.Modifications, "ClientSettings\\ClientAppSettings.json"));
|
private void OpenClientSettings() => Utilities.ShellExecute(Path.Combine(Directories.Modifications, "ClientSettings\\ClientAppSettings.json"));
|
||||||
|
|
||||||
public int FramerateLimit
|
public int FramerateLimit
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ namespace Bloxstrap.UI.Menu.ViewModels
|
|||||||
if (location is null)
|
if (location is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Utilities.OpenWebsite(location);
|
Utilities.ShellExecute(location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ namespace Bloxstrap
|
|||||||
|
|
||||||
if (isAutoUpgrade)
|
if (isAutoUpgrade)
|
||||||
{
|
{
|
||||||
EventHandler ReleaseNotesLauncher = new((_, _) => Utilities.OpenWebsite($"https://github.com/{App.ProjectRepository}/releases/tag/v{currentVersionInfo.ProductVersion}"));
|
EventHandler ReleaseNotesLauncher = new((_, _) => Utilities.ShellExecute($"https://github.com/{App.ProjectRepository}/releases/tag/v{currentVersionInfo.ProductVersion}"));
|
||||||
|
|
||||||
App.Notification.BalloonTipTitle = $"Bloxstrap has been upgraded to v{currentVersionInfo.ProductVersion}";
|
App.Notification.BalloonTipTitle = $"Bloxstrap has been upgraded to v{currentVersionInfo.ProductVersion}";
|
||||||
App.Notification.BalloonTipText = "Click here to see what's new in this version";
|
App.Notification.BalloonTipText = "Click here to see what's new in this version";
|
||||||
|
@ -10,11 +10,6 @@ namespace Bloxstrap
|
|||||||
{
|
{
|
||||||
static class Utilities
|
static class Utilities
|
||||||
{
|
{
|
||||||
public static bool IsDirectoryEmpty(string path)
|
|
||||||
{
|
|
||||||
return !Directory.EnumerateFileSystemEntries(path).Any();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long GetFreeDiskSpace(string path)
|
public static long GetFreeDiskSpace(string path)
|
||||||
{
|
{
|
||||||
foreach (DriveInfo drive in DriveInfo.GetDrives())
|
foreach (DriveInfo drive in DriveInfo.GetDrives())
|
||||||
@ -26,24 +21,7 @@ namespace Bloxstrap
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetProcessCount(string processName, bool log = true)
|
public static void ShellExecute(string website) => Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true });
|
||||||
{
|
|
||||||
if (log)
|
|
||||||
App.Logger.WriteLine($"[Utilities::CheckIfProcessRunning] Checking if '{processName}' is running...");
|
|
||||||
|
|
||||||
Process[] processes = Process.GetProcessesByName(processName);
|
|
||||||
|
|
||||||
if (log)
|
|
||||||
App.Logger.WriteLine($"[Utilities::CheckIfProcessRunning] Found {processes.Length} process(es) running for '{processName}'");
|
|
||||||
|
|
||||||
return processes.Length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool CheckIfProcessRunning(string processName, bool log = true) => GetProcessCount(processName, log) >= 1;
|
|
||||||
|
|
||||||
public static bool CheckIfRobloxRunning(bool log = true) => CheckIfProcessRunning("RobloxPlayerBeta", log);
|
|
||||||
|
|
||||||
public static void OpenWebsite(string website) => Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true });
|
|
||||||
|
|
||||||
public static async Task<T?> GetJson<T>(string url)
|
public static async Task<T?> GetJson<T>(string url)
|
||||||
{
|
{
|
||||||
@ -61,41 +39,5 @@ namespace Bloxstrap
|
|||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string MD5File(string filename)
|
|
||||||
{
|
|
||||||
using (MD5 md5 = MD5.Create())
|
|
||||||
{
|
|
||||||
using (FileStream stream = File.OpenRead(filename))
|
|
||||||
{
|
|
||||||
byte[] hash = md5.ComputeHash(stream);
|
|
||||||
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string MD5Data(byte[] data)
|
|
||||||
{
|
|
||||||
using (MD5 md5 = MD5.Create())
|
|
||||||
{
|
|
||||||
byte[] hash = md5.ComputeHash(data);
|
|
||||||
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// quick and hacky way of getting a value from any key/value pair formatted list
|
|
||||||
// (command line args, uri params, etc)
|
|
||||||
public static string? GetKeyValue(string subject, string key, char delimiter)
|
|
||||||
{
|
|
||||||
if (subject.LastIndexOf(key) == -1)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
string substr = subject.Substring(subject.LastIndexOf(key) + key.Length);
|
|
||||||
|
|
||||||
if (!substr.Contains(delimiter))
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return substr.Split(delimiter)[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
Bloxstrap/Utility/MD5Hash.cs
Normal file
34
Bloxstrap/Utility/MD5Hash.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Bloxstrap.Utility
|
||||||
|
{
|
||||||
|
public static class MD5Hash
|
||||||
|
{
|
||||||
|
public static string FromFile(string filename)
|
||||||
|
{
|
||||||
|
using (MD5 md5 = MD5.Create())
|
||||||
|
{
|
||||||
|
using (FileStream stream = File.OpenRead(filename))
|
||||||
|
{
|
||||||
|
byte[] hash = md5.ComputeHash(stream);
|
||||||
|
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string FromBytes(byte[] data)
|
||||||
|
{
|
||||||
|
using (MD5 md5 = MD5.Create())
|
||||||
|
{
|
||||||
|
byte[] hash = md5.ComputeHash(data);
|
||||||
|
return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Bloxstrap
|
namespace Bloxstrap.Utility
|
||||||
{
|
{
|
||||||
static class NativeMethods
|
static class NativeMethods
|
||||||
{
|
{
|
@ -2,18 +2,15 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace Bloxstrap
|
namespace Bloxstrap.Utility
|
||||||
{
|
{
|
||||||
public static class WindowScaling
|
public static class WindowScaling
|
||||||
{
|
{
|
||||||
public static double GetFactor()
|
public static double ScaleFactor => Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth;
|
||||||
{
|
|
||||||
return Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int GetScaledNumber(int number)
|
public static int GetScaledNumber(int number)
|
||||||
{
|
{
|
||||||
return (int)Math.Ceiling(number * GetFactor());
|
return (int)Math.Ceiling(number * ScaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static System.Drawing.Size GetScaledSize(System.Drawing.Size size)
|
public static System.Drawing.Size GetScaledSize(System.Drawing.Size size)
|
Loading…
Reference in New Issue
Block a user