bloxstrap/Bloxstrap/Helpers/Utilities.cs
pizzaboxer bacb650ddc Features and bugfixes for v1.1.0
- Features
    - Add Discord Rich Presence support (the nuget package is like a year and a half out of date so submodule it is lol)
    - Add update checker
    - Add start menu folder creation

- Bugfixes
   - Fix "Directory is not empty" error when updating Roblox
   - Fix uninstalling sometimes not working properly

- Quality of Life
   - Split Bootstrapper class into partial files
   - Renamed TaskDialogStyle to VistaDialog for name simplification
2022-08-11 08:26:28 +01:00

49 lines
1.4 KiB
C#

using System.Security.Cryptography;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Bloxstrap.Helpers
{
public class Utilities
{
public static async Task<JObject> GetJson(string url)
{
using (HttpClient client = new())
{
client.DefaultRequestHeaders.Add("User-Agent", Program.ProjectRepository);
string jsonString = await client.GetStringAsync(url);
return (JObject)JsonConvert.DeserializeObject(jsonString);
}
}
public static string CalculateMD5(string filename)
{
using (MD5 md5 = MD5.Create())
{
using (FileStream stream = File.OpenRead(filename))
{
byte[] hash = md5.ComputeHash(stream);
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.IndexOf(delimiter) == -1)
return null;
return substr.Split(delimiter)[0];
}
}
}