Minor restructuring

This commit is contained in:
pizzaboxer 2023-06-26 22:33:15 +01:00
parent 28bcf57dff
commit e7fd0b9642
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
15 changed files with 256 additions and 285 deletions

View File

@ -15,9 +15,9 @@ using Microsoft.Win32;
using Bloxstrap.Extensions;
using Bloxstrap.Models;
using Bloxstrap.Singletons;
using Bloxstrap.UI.BootstrapperDialogs;
using Bloxstrap.UI.Menu.Views;
using Bloxstrap.Utility;
namespace Bloxstrap
{

View File

@ -256,7 +256,7 @@ namespace Bloxstrap
if (_launchCommandLine == "--app" && App.Settings.Prop.UseDisableAppPatch)
{
Utilities.OpenWebsite("https://www.roblox.com/games");
Utilities.ShellExecute("https://www.roblox.com/games");
Dialog?.CloseBootstrapper();
return;
}
@ -562,7 +562,7 @@ namespace Bloxstrap
private async Task CheckForUpdates()
{
// 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");
return;
@ -616,7 +616,7 @@ namespace Bloxstrap
private void Uninstall()
{
// 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");
@ -1004,7 +1004,7 @@ namespace Bloxstrap
if (File.Exists(fileVersionFolder))
{
if (Utilities.MD5File(fileModFolder) == Utilities.MD5File(fileVersionFolder))
if (Utility.MD5Hash.FromFile(fileModFolder) == Utility.MD5Hash.FromFile(fileVersionFolder))
continue;
}
@ -1072,7 +1072,7 @@ namespace Bloxstrap
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);
}
@ -1091,7 +1091,8 @@ namespace Bloxstrap
{
FileInfo file = new(packageLocation);
string calculatedMD5 = Utilities.MD5File(packageLocation);
string calculatedMD5 = Utility.MD5Hash.FromFile(packageLocation);
if (calculatedMD5 != package.Signature)
{
App.Logger.WriteLine($"[Bootstrapper::DownloadPackage] {package.Name} is corrupted ({calculatedMD5} != {package.Signature})! Deleting and re-downloading...");

View File

@ -1,10 +1,8 @@
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
namespace Bloxstrap.Singletons
namespace Bloxstrap
{
public class FastFlagManager : JsonManager<Dictionary<string, object>>
{

View File

@ -2,7 +2,7 @@
using System.IO;
using System.Text.Json;
namespace Bloxstrap.Singletons
namespace Bloxstrap
{
public class JsonManager<T> where T : new()
{

View File

@ -5,7 +5,7 @@ using System.IO;
using System.Text;
using System.Threading;
namespace Bloxstrap.Singletons
namespace Bloxstrap
{
// https://stackoverflow.com/a/53873141/11852173
// TODO - this kind of sucks

View File

@ -1,7 +1,9 @@
using System;
using System.Windows;
using System.Windows.Forms;
using Bloxstrap.Extensions;
using Bloxstrap.Utility;
namespace Bloxstrap.UI.BootstrapperDialogs.WinForms
{

View File

@ -1,13 +1,10 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
using Bloxstrap.Singletons;
using System.ComponentModel;
namespace Bloxstrap.UI.Menu.ViewModels
{
public class FastFlagsViewModel : INotifyPropertyChanged
@ -17,7 +14,7 @@ namespace Bloxstrap.UI.Menu.ViewModels
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
{

View File

@ -14,7 +14,7 @@ namespace Bloxstrap.UI.Menu.ViewModels
if (location is null)
return;
Utilities.OpenWebsite(location);
Utilities.ShellExecute(location);
}
}
}

View File

@ -78,7 +78,7 @@ namespace Bloxstrap
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.BalloonTipText = "Click here to see what's new in this version";

View File

@ -10,11 +10,6 @@ namespace Bloxstrap
{
static class Utilities
{
public static bool IsDirectoryEmpty(string path)
{
return !Directory.EnumerateFileSystemEntries(path).Any();
}
public static long GetFreeDiskSpace(string path)
{
foreach (DriveInfo drive in DriveInfo.GetDrives())
@ -26,24 +21,7 @@ namespace Bloxstrap
return -1;
}
public static int GetProcessCount(string processName, bool log = 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 void ShellExecute(string website) => Process.Start(new ProcessStartInfo { FileName = website, UseShellExecute = true });
public static async Task<T?> GetJson<T>(string url)
{
@ -61,41 +39,5 @@ namespace Bloxstrap
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];
}
}
}

View 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();
}
}
}
}

View File

@ -5,7 +5,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Bloxstrap
namespace Bloxstrap.Utility
{
static class NativeMethods
{

View File

@ -2,18 +2,15 @@
using System.Windows;
using System.Windows.Forms;
namespace Bloxstrap
namespace Bloxstrap.Utility
{
public static class WindowScaling
{
public static double GetFactor()
{
return Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth;
}
public static double ScaleFactor => Screen.PrimaryScreen.Bounds.Width / SystemParameters.PrimaryScreenWidth;
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)