71 lines
2.1 KiB
C#
71 lines
2.1 KiB
C#
using Serilog;
|
|
using Spectre.Console;
|
|
using System.IO.Compression;
|
|
using System.Text.RegularExpressions;
|
|
using System.Security.Cryptography;
|
|
namespace EdgeInstaller;
|
|
|
|
public static partial class EdgeInstall
|
|
{
|
|
private static string GetPackagesString(string filepath)
|
|
{
|
|
using (var CompressedStream = File.Open(filepath, FileMode.Open))
|
|
using (var decompressor = new GZipStream(CompressedStream, CompressionMode.Decompress))
|
|
using (var streamReader = new StreamReader(decompressor))
|
|
{
|
|
return streamReader.ReadToEnd();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* HACK: Spectre.Console uses fixed regex to detect terminal capabilites
|
|
* This function tests for known working terminals that are currently not
|
|
* detected by AnsiDetector
|
|
*/
|
|
private static void BUGFIX_ansiDetection()
|
|
{
|
|
Regex[] regexes = {
|
|
new("foot")
|
|
};
|
|
AnsiConsole.Profile.Capabilities.Ansi = true;
|
|
AnsiConsole.Profile.Capabilities.Legacy = false;
|
|
}
|
|
|
|
static bool ValidateChecksum(FileInfo file, string checksum)
|
|
{
|
|
using (FileStream fs = file.Open(FileMode.Open))
|
|
{
|
|
return ValidateChecksum(fs, checksum);
|
|
}
|
|
}
|
|
|
|
static bool ValidateChecksum(Stream stream, string checksum)
|
|
{
|
|
stream.Position = 0;
|
|
using (SHA256 mySHA256 = SHA256.Create())
|
|
{
|
|
byte[] hashValue = mySHA256.ComputeHash(stream);
|
|
if (hashValue is null)
|
|
{
|
|
throw new NullReferenceException("Hash be null??");
|
|
}
|
|
Log.Debug("Computed hash = {hash}", hashValue);
|
|
byte[] storedHash = Convert.FromHexString(checksum);
|
|
Log.Debug("Stored Hash = {hash}", storedHash);
|
|
|
|
Log.Debug("Compare result = {result}", hashValue.SequenceEqual(storedHash));
|
|
return (storedHash.SequenceEqual(hashValue));
|
|
}
|
|
}
|
|
|
|
|
|
static Version GetCurrentVersion()
|
|
{
|
|
// To get the current version we need to execute the installed microsoft edge.
|
|
// Before doing this we need to make sure we can execute microsoft edge.
|
|
|
|
|
|
return new("0.0.0.0-0");
|
|
}
|
|
}
|