Refactor SetReleaseIdentifier()
This commit is contained in:
parent
1e6e28cd57
commit
6ebbfb8e59
@ -247,7 +247,15 @@ namespace AaxDecrypter
|
|||||||
public override bool CanWrite => false;
|
public override bool CanWrite => false;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public override long Length => ContentLength;
|
public override long Length
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_backgroundDownloadTask is null)
|
||||||
|
throw new InvalidOperationException($"Background downloader must first be started by calling {nameof(BeginDownloadingAsync)}");
|
||||||
|
return ContentLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public override long Position { get => _readFile.Position; set => Seek(value, SeekOrigin.Begin); }
|
public override long Position { get => _readFile.Position; set => Seek(value, SeekOrigin.Begin); }
|
||||||
@ -267,6 +275,9 @@ namespace AaxDecrypter
|
|||||||
|
|
||||||
public override int Read(byte[] buffer, int offset, int count)
|
public override int Read(byte[] buffer, int offset, int count)
|
||||||
{
|
{
|
||||||
|
if (_backgroundDownloadTask is null)
|
||||||
|
throw new InvalidOperationException($"Background downloader must first be started by calling {nameof(BeginDownloadingAsync)}");
|
||||||
|
|
||||||
var toRead = Math.Min(count, Length - Position);
|
var toRead = Math.Min(count, Length - Position);
|
||||||
WaitToPosition(Position + toRead);
|
WaitToPosition(Position + toRead);
|
||||||
return IsCancelled ? 0 : _readFile.Read(buffer, offset, count);
|
return IsCancelled ? 0 : _readFile.Read(buffer, offset, count);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ using Dinah.Core;
|
|||||||
using Dinah.Core.IO;
|
using Dinah.Core.IO;
|
||||||
using Dinah.Core.Logging;
|
using Dinah.Core.Logging;
|
||||||
using LibationFileManager;
|
using LibationFileManager;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using System.Runtime.InteropServices;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
|
||||||
@ -18,16 +18,22 @@ namespace AppScaffolding
|
|||||||
public enum ReleaseIdentifier
|
public enum ReleaseIdentifier
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
WindowsClassic,
|
WindowsClassic = OS.Windows | Variety.Classic | Architecture.X64,
|
||||||
WindowsAvalonia,
|
WindowsAvalonia = OS.Windows | Variety.Chardonnay | Architecture.X64,
|
||||||
LinuxAvalonia,
|
LinuxAvalonia = OS.Linux | Variety.Chardonnay | Architecture.X64,
|
||||||
MacOSAvalonia,
|
MacOSAvalonia = OS.MacOS | Variety.Chardonnay | Architecture.X64,
|
||||||
LinuxAvalonia_Arm64,
|
LinuxAvalonia_Arm64 = OS.Linux | Variety.Chardonnay | Architecture.Arm64,
|
||||||
MacOSAvalonia_Arm64
|
MacOSAvalonia_Arm64 = OS.MacOS | Variety.Chardonnay | Architecture.Arm64
|
||||||
}
|
}
|
||||||
|
|
||||||
// I know I'm taking the wine metaphor a bit far by naming this "Variety", but I don't know what else to call it
|
// I know I'm taking the wine metaphor a bit far by naming this "Variety", but I don't know what else to call it
|
||||||
public enum VarietyType { None, Classic, Chardonnay }
|
[Flags]
|
||||||
|
public enum Variety
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Classic = 0x10000,
|
||||||
|
Chardonnay = 0x20000,
|
||||||
|
}
|
||||||
|
|
||||||
public static class LibationScaffolding
|
public static class LibationScaffolding
|
||||||
{
|
{
|
||||||
@ -35,13 +41,22 @@ namespace AppScaffolding
|
|||||||
public const string WebsiteUrl = "ht" + "tps://getlibation.com";
|
public const string WebsiteUrl = "ht" + "tps://getlibation.com";
|
||||||
public const string RepositoryLatestUrl = "ht" + "tps://github.com/rmcrackan/Libation/releases/latest";
|
public const string RepositoryLatestUrl = "ht" + "tps://github.com/rmcrackan/Libation/releases/latest";
|
||||||
public static ReleaseIdentifier ReleaseIdentifier { get; private set; }
|
public static ReleaseIdentifier ReleaseIdentifier { get; private set; }
|
||||||
public static VarietyType Variety
|
public static Variety Variety { get; private set; }
|
||||||
=> ReleaseIdentifier == ReleaseIdentifier.WindowsClassic ? VarietyType.Classic
|
|
||||||
: Enum.IsDefined(ReleaseIdentifier) ? VarietyType.Chardonnay
|
|
||||||
: VarietyType.None;
|
|
||||||
|
|
||||||
public static void SetReleaseIdentifier(ReleaseIdentifier releaseID)
|
public static void SetReleaseIdentifier(Variety varietyType)
|
||||||
=> ReleaseIdentifier = releaseID;
|
{
|
||||||
|
Variety = Enum.IsDefined(varietyType) ? varietyType : Variety.None;
|
||||||
|
|
||||||
|
var releaseID = (ReleaseIdentifier)((int)varietyType | (int)Configuration.OS | (int)RuntimeInformation.ProcessArchitecture);
|
||||||
|
|
||||||
|
if (Enum.IsDefined(releaseID))
|
||||||
|
ReleaseIdentifier = releaseID;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ReleaseIdentifier = ReleaseIdentifier.None;
|
||||||
|
Serilog.Log.Logger.Warning("Unknown release identifier @{DebugInfo}", new { Variety = varietyType, Configuration.OS, RuntimeInformation.ProcessArchitecture });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// AppScaffolding
|
// AppScaffolding
|
||||||
private static Assembly _executingAssembly;
|
private static Assembly _executingAssembly;
|
||||||
|
|||||||
@ -6,6 +6,7 @@ using System.Reflection;
|
|||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ApplicationServices;
|
using ApplicationServices;
|
||||||
|
using AppScaffolding;
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.ReactiveUI;
|
using Avalonia.ReactiveUI;
|
||||||
@ -42,7 +43,7 @@ namespace LibationAvalonia
|
|||||||
// //
|
// //
|
||||||
//***********************************************//
|
//***********************************************//
|
||||||
// Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration
|
// Migrations which must occur before configuration is loaded for the first time. Usually ones which alter the Configuration
|
||||||
var config = AppScaffolding.LibationScaffolding.RunPreConfigMigrations();
|
var config = LibationScaffolding.RunPreConfigMigrations();
|
||||||
|
|
||||||
App.SetupRequired = !config.LibationSettingsAreValid;
|
App.SetupRequired = !config.LibationSettingsAreValid;
|
||||||
|
|
||||||
@ -50,29 +51,10 @@ namespace LibationAvalonia
|
|||||||
var classicLifetimeTask = Task.Run(() => new ClassicDesktopStyleApplicationLifetime());
|
var classicLifetimeTask = Task.Run(() => new ClassicDesktopStyleApplicationLifetime());
|
||||||
var appBuilderTask = Task.Run(BuildAvaloniaApp);
|
var appBuilderTask = Task.Run(BuildAvaloniaApp);
|
||||||
|
|
||||||
if (Configuration.IsWindows)
|
LibationScaffolding.SetReleaseIdentifier(Variety.Chardonnay);
|
||||||
AppScaffolding.LibationScaffolding.SetReleaseIdentifier(AppScaffolding.ReleaseIdentifier.WindowsAvalonia);
|
|
||||||
else if (Configuration.IsLinux)
|
if (LibationScaffolding.ReleaseIdentifier is ReleaseIdentifier.None)
|
||||||
{
|
return;
|
||||||
var releaseID = RuntimeInformation.OSArchitecture switch
|
|
||||||
{
|
|
||||||
Architecture.X64 => AppScaffolding.ReleaseIdentifier.LinuxAvalonia,
|
|
||||||
Architecture.Arm64 => AppScaffolding.ReleaseIdentifier.LinuxAvalonia_Arm64,
|
|
||||||
_ => throw new PlatformNotSupportedException()
|
|
||||||
};
|
|
||||||
AppScaffolding.LibationScaffolding.SetReleaseIdentifier(releaseID);
|
|
||||||
}
|
|
||||||
else if (Configuration.IsMacOs)
|
|
||||||
{
|
|
||||||
var releaseID = RuntimeInformation.OSArchitecture switch
|
|
||||||
{
|
|
||||||
Architecture.X64 => AppScaffolding.ReleaseIdentifier.MacOSAvalonia,
|
|
||||||
Architecture.Arm64 => AppScaffolding.ReleaseIdentifier.MacOSAvalonia_Arm64,
|
|
||||||
_ => throw new PlatformNotSupportedException()
|
|
||||||
};
|
|
||||||
AppScaffolding.LibationScaffolding.SetReleaseIdentifier(releaseID);
|
|
||||||
}
|
|
||||||
else return;
|
|
||||||
|
|
||||||
|
|
||||||
if (!App.SetupRequired)
|
if (!App.SetupRequired)
|
||||||
@ -99,8 +81,8 @@ namespace LibationAvalonia
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// most migrations go in here
|
// most migrations go in here
|
||||||
AppScaffolding.LibationScaffolding.RunPostConfigMigrations(config);
|
LibationScaffolding.RunPostConfigMigrations(config);
|
||||||
AppScaffolding.LibationScaffolding.RunPostMigrationScaffolding(config);
|
LibationScaffolding.RunPostMigrationScaffolding(config);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,16 +6,25 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace LibationFileManager
|
namespace LibationFileManager
|
||||||
{
|
{
|
||||||
|
[Flags]
|
||||||
|
public enum OS
|
||||||
|
{
|
||||||
|
Unknown,
|
||||||
|
Windows = 0x100000,
|
||||||
|
Linux = 0x200000,
|
||||||
|
MacOS = 0x400000,
|
||||||
|
}
|
||||||
|
|
||||||
public partial class Configuration
|
public partial class Configuration
|
||||||
{
|
{
|
||||||
public static bool IsWindows { get; } = OperatingSystem.IsWindows();
|
public static bool IsWindows { get; } = OperatingSystem.IsWindows();
|
||||||
public static bool IsLinux { get; } = OperatingSystem.IsLinux();
|
public static bool IsLinux { get; } = OperatingSystem.IsLinux();
|
||||||
public static bool IsMacOs { get; } = OperatingSystem.IsMacOS();
|
public static bool IsMacOs { get; } = OperatingSystem.IsMacOS();
|
||||||
|
|
||||||
public static string OS { get; }
|
public static OS OS { get; }
|
||||||
= IsLinux ? "Linux"
|
= IsLinux ? OS.Linux
|
||||||
: IsMacOs ? "MacOS"
|
: IsMacOs ? OS.MacOS
|
||||||
: IsWindows ? "Windows"
|
: IsWindows ? OS.Windows
|
||||||
: "UNKNOWN_OS";
|
: OS.Unknown;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,7 +30,7 @@ namespace LibationWinForms
|
|||||||
|
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
|
|
||||||
AppScaffolding.LibationScaffolding.SetReleaseIdentifier(AppScaffolding.ReleaseIdentifier.WindowsClassic);
|
AppScaffolding.LibationScaffolding.SetReleaseIdentifier(AppScaffolding.Variety.Classic);
|
||||||
|
|
||||||
//***********************************************//
|
//***********************************************//
|
||||||
// //
|
// //
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user