edge-install/Program.HelperFunctions.cs
Robert Morrison 60e06b2144
Another bad commit
Lots of changes here...

- Removed code using RecursivExtractor due to bad usage of /tmp
  Note: the code that used RecursiveExtractor may not have been in the
  previous commit
- Created _functioning_ implementation of DebUnpacker
- Restructured Project layout.

TODO:
- Possibly rewrite how the DebUnpacker works to have the file contents
  part of an entry.
- Further restructuring and refactoring to make the code a little
  neater.
- Add code for the final unpack steps Un-XZ -> untar -> write to disk
- Add code to install
- Add code for modified post-install pre-remove etc..
  This is kinda needed to ensure proper system integration of new
  packages.
2023-06-08 04:36:31 +01:00

68 lines
2.0 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()
{
return new("0.0.0.0-0");
}
}