-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
29 changed files
with
1,360 additions
and
1,199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using System.Text.RegularExpressions; | ||
|
||
namespace SuchByte.MacroDeck.DataTypes.Core; | ||
|
||
public partial struct Version | ||
{ | ||
public int Major { get; set; } | ||
public int Minor { get; set; } | ||
public int Patch { get; set; } | ||
public int? BetaNo { get; set; } | ||
|
||
public Version(int major, int minor, int patch, int? betaNo = null) | ||
{ | ||
Major = major; | ||
Minor = minor; | ||
Patch = patch; | ||
BetaNo = betaNo; | ||
} | ||
|
||
public bool IsBetaVersion => BetaNo.HasValue; | ||
|
||
public string VersionName => BetaNo.HasValue | ||
? $"{Major}.{Minor}.{Patch}-b{BetaNo}" | ||
: $"{Major}.{Minor}.{Patch}"; | ||
|
||
public override string ToString() | ||
{ | ||
return VersionName; | ||
} | ||
|
||
public static bool TryParse(string versionString, out Version result) | ||
{ | ||
try | ||
{ | ||
result = Parse(versionString); | ||
return true; | ||
} | ||
catch | ||
{ | ||
result = default; | ||
return false; | ||
} | ||
} | ||
|
||
public static Version Parse(string? versionString) | ||
{ | ||
if (string.IsNullOrWhiteSpace(versionString)) | ||
{ | ||
throw new FormatException("Version string was empty"); | ||
} | ||
|
||
var match = VersionRegex().Match(versionString); | ||
if (!match.Success) | ||
{ | ||
throw new FormatException("Invalid version string"); | ||
} | ||
|
||
var major = int.Parse(match.Groups["major"].Value); | ||
var minor = int.Parse(match.Groups["minor"].Value); | ||
var patch = int.Parse(match.Groups["patch"].Value); | ||
|
||
int? previewNo = null; | ||
if (match.Groups["beta"].Success) | ||
{ | ||
previewNo = int.Parse(match.Groups["beta"].Value); | ||
} | ||
|
||
return new Version(major, minor, patch, previewNo); | ||
} | ||
|
||
[GeneratedRegex("^(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)(-b(?<beta>\\d+))?$")] | ||
private static partial Regex VersionRegex(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace SuchByte.MacroDeck.DataTypes.FileDownloader; | ||
|
||
public class DownloadProgressInfo | ||
{ | ||
public int Percentage { get; set; } = 0; | ||
public long TotalBytes { get; set; } = 0; | ||
public long DownloadedBytes { get; set; } = 0; | ||
public double DownloadSpeed { get; set; } = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace SuchByte.MacroDeck.DataTypes.Updater; | ||
|
||
public class UpdateApiCheckResult | ||
{ | ||
public bool? NewerVersionAvailable { get; set; } | ||
public UpdateApiVersionInfo? Version { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SuchByte.MacroDeck.DataTypes.Updater; | ||
|
||
public class UpdateApiVersionFileInfo | ||
{ | ||
public string? DownloadUrl { get; set; } | ||
public string? FileHash { get; set; } | ||
public long FileSize { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using SuchByte.MacroDeck.Enums; | ||
|
||
namespace SuchByte.MacroDeck.DataTypes.Updater; | ||
|
||
public class UpdateApiVersionInfo | ||
{ | ||
public string? Version { get; set; } | ||
public bool? IsBeta { get; set; } | ||
public string? ChangeNotesUrl { get; set; } | ||
public Dictionary<PlatformIdentifier, UpdateApiVersionFileInfo>? Platforms { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace SuchByte.MacroDeck.DataTypes.Updater; | ||
|
||
public class UpdateServiceProgress | ||
{ | ||
public int Percentage { get; set; } = 0; | ||
public long TotalBytes { get; set; } = 0; | ||
public long DownloadedBytes { get; set; } = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace SuchByte.MacroDeck.Enums; | ||
|
||
public enum PlatformIdentifier | ||
{ | ||
WinX64 = 1000, | ||
MacX64 = 2000, | ||
MacArm64 = 2100, | ||
LinuxX64 = 3000, | ||
LinuxArm64 = 3100, | ||
LinuxArm32 = 3110 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SuchByte.MacroDeck.Extension; | ||
|
||
public static class DoubleExtensions | ||
{ | ||
public static double ConvertBytesToMegabytes(this double bytes) | ||
{ | ||
return bytes / 1024.0f / 1024.0f; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace SuchByte.MacroDeck.Extension; | ||
|
||
public static class LongExtensions | ||
{ | ||
public static double ConvertBytesToMegabytes(this long bytes) | ||
{ | ||
return bytes / 1024f / 1024f; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System.IO; | ||
using System.Security.Cryptography; | ||
using System; | ||
|
||
namespace SuchByte.MacroDeck.Extension; | ||
|
||
public static class StreamExtensions | ||
{ | ||
public static async ValueTask<string> CalculateSha256Hash(this Stream stream) | ||
{ | ||
stream.Position = 0; | ||
|
||
var bufferedStream = new BufferedStream(stream); | ||
using var sha256 = SHA256.Create(); | ||
|
||
var buffer = new byte[8192]; | ||
int bytesRead; | ||
while ((bytesRead = await bufferedStream.ReadAsync(buffer)) > 0) | ||
{ | ||
sha256.TransformBlock(buffer, 0, bytesRead, buffer, 0); | ||
} | ||
sha256.TransformFinalBlock(buffer, 0, 0); | ||
|
||
if (sha256.Hash == null) | ||
{ | ||
throw new InvalidOperationException("Hash was null"); | ||
} | ||
|
||
stream.Position = 0; | ||
return BitConverter.ToString(sha256.Hash).Replace("-", "").ToLower(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Security.Cryptography; | ||
|
||
namespace SuchByte.MacroDeck.Extension; | ||
|
||
public static class StringExtensions | ||
{ | ||
public static bool EqualsCryptographically(this string? str1, string? str2) | ||
{ | ||
if (str1 == null || str2 == null) | ||
{ | ||
return false; | ||
} | ||
|
||
var hash1 = SHA256.HashData(Encoding.UTF8.GetBytes(str1)); | ||
var hash2 = SHA256.HashData(Encoding.UTF8.GetBytes(str2)); | ||
|
||
if (hash1.Length != hash2.Length) | ||
{ | ||
return false; | ||
} | ||
|
||
return !hash1.Where((t, i) => t != hash2[i]).Any(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.