From 46530a9fca6949e69f7ec238d12be379ab580367 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 5 Aug 2020 21:54:00 -0700 Subject: [PATCH 1/5] Add Avalonia, remove NET462 --- DICUI.Avalonia/App.axaml | 8 + DICUI.Avalonia/App.axaml.cs | 24 + .../ComboBoxItems/CategoryComboBoxItem.cs | 29 + .../ComboBoxItems/KnownSystemComboBoxItem.cs | 35 + .../ComboBoxItems/LanguageComboBoxItem.cs | 29 + .../ComboBoxItems/MediaTypeComboBoxItem.cs | 20 + .../ComboBoxItems/RegionComboBoxItem.cs | 30 + DICUI.Avalonia/Constants.cs | 55 ++ DICUI.Avalonia/DICUI.Avalonia.csproj | 29 + DICUI.Avalonia/DiscInformationWindow.axaml | 120 +++ DICUI.Avalonia/DiscInformationWindow.axaml.cs | 264 ++++++ DICUI.Avalonia/EnumDescriptionConverter.cs | 32 + DICUI.Avalonia/LogWindow.axaml | 40 + DICUI.Avalonia/LogWindow.axaml.cs | 82 ++ DICUI.Avalonia/MainWindow.axaml | 109 +++ DICUI.Avalonia/MainWindow.axaml.cs | 824 ++++++++++++++++++ DICUI.Avalonia/MessageBox.axaml | 17 + DICUI.Avalonia/MessageBox.axaml.cs | 83 ++ DICUI.Avalonia/OptionsWindow.axaml | 162 ++++ DICUI.Avalonia/OptionsWindow.axaml.cs | 142 +++ DICUI.Avalonia/Program.cs | 22 + DICUI.Avalonia/UIOptions.cs | 122 +++ DICUI.Avalonia/ViewModels.cs | 233 +++++ DICUI.Avalonia/nuget.config | 11 + DICUI.Check/DICUI.Check.csproj | 2 +- DICUI.Library/DICUI.Library.csproj | 2 +- DICUI.Library/Utilities/Validators.cs | 36 +- DICUI.Test/DICUI.Test.csproj | 2 +- DICUI.sln | 14 +- DICUI/DICUI.csproj | 2 +- 30 files changed, 2554 insertions(+), 26 deletions(-) create mode 100644 DICUI.Avalonia/App.axaml create mode 100644 DICUI.Avalonia/App.axaml.cs create mode 100644 DICUI.Avalonia/ComboBoxItems/CategoryComboBoxItem.cs create mode 100644 DICUI.Avalonia/ComboBoxItems/KnownSystemComboBoxItem.cs create mode 100644 DICUI.Avalonia/ComboBoxItems/LanguageComboBoxItem.cs create mode 100644 DICUI.Avalonia/ComboBoxItems/MediaTypeComboBoxItem.cs create mode 100644 DICUI.Avalonia/ComboBoxItems/RegionComboBoxItem.cs create mode 100644 DICUI.Avalonia/Constants.cs create mode 100644 DICUI.Avalonia/DICUI.Avalonia.csproj create mode 100644 DICUI.Avalonia/DiscInformationWindow.axaml create mode 100644 DICUI.Avalonia/DiscInformationWindow.axaml.cs create mode 100644 DICUI.Avalonia/EnumDescriptionConverter.cs create mode 100644 DICUI.Avalonia/LogWindow.axaml create mode 100644 DICUI.Avalonia/LogWindow.axaml.cs create mode 100644 DICUI.Avalonia/MainWindow.axaml create mode 100644 DICUI.Avalonia/MainWindow.axaml.cs create mode 100644 DICUI.Avalonia/MessageBox.axaml create mode 100644 DICUI.Avalonia/MessageBox.axaml.cs create mode 100644 DICUI.Avalonia/OptionsWindow.axaml create mode 100644 DICUI.Avalonia/OptionsWindow.axaml.cs create mode 100644 DICUI.Avalonia/Program.cs create mode 100644 DICUI.Avalonia/UIOptions.cs create mode 100644 DICUI.Avalonia/ViewModels.cs create mode 100644 DICUI.Avalonia/nuget.config diff --git a/DICUI.Avalonia/App.axaml b/DICUI.Avalonia/App.axaml new file mode 100644 index 00000000..c1a2b88f --- /dev/null +++ b/DICUI.Avalonia/App.axaml @@ -0,0 +1,8 @@ + + + + + + diff --git a/DICUI.Avalonia/App.axaml.cs b/DICUI.Avalonia/App.axaml.cs new file mode 100644 index 00000000..40ee8f77 --- /dev/null +++ b/DICUI.Avalonia/App.axaml.cs @@ -0,0 +1,24 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; + +namespace DICUI.Avalonia +{ + public class App : Application + { + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow(); + } + + base.OnFrameworkInitializationCompleted(); + } + } +} diff --git a/DICUI.Avalonia/ComboBoxItems/CategoryComboBoxItem.cs b/DICUI.Avalonia/ComboBoxItems/CategoryComboBoxItem.cs new file mode 100644 index 00000000..2eb67000 --- /dev/null +++ b/DICUI.Avalonia/ComboBoxItems/CategoryComboBoxItem.cs @@ -0,0 +1,29 @@ +using DICUI.Utilities; +using DICUI.Web; + +namespace DICUI.Avalonia +{ + /// + /// Represents a single item in the Category combo box + /// + public class CategoryComboBoxItem + { + private object data; + + public CategoryComboBoxItem(DiscCategory? category) => data = category; + + public static implicit operator DiscCategory? (CategoryComboBoxItem item) => item.data as DiscCategory?; + + public string Name + { + get { return (data as DiscCategory?).LongName(); } + } + + public bool IsChecked { get; set; } + + public DiscCategory? Value + { + get { return data as DiscCategory?; } + } + } +} diff --git a/DICUI.Avalonia/ComboBoxItems/KnownSystemComboBoxItem.cs b/DICUI.Avalonia/ComboBoxItems/KnownSystemComboBoxItem.cs new file mode 100644 index 00000000..0f9160b3 --- /dev/null +++ b/DICUI.Avalonia/ComboBoxItems/KnownSystemComboBoxItem.cs @@ -0,0 +1,35 @@ +using Avalonia.Media; +using DICUI.Data; +using DICUI.Utilities; + +namespace DICUI.Avalonia +{ + /// + /// Represents a single item in the System combo box + /// + public class KnownSystemComboBoxItem + { + private object data; + + public KnownSystemComboBoxItem(KnownSystem? system) => data = system; + public KnownSystemComboBoxItem(KnownSystemCategory? category) => data = category; + + public ISolidColorBrush Foreground { get => IsHeader() ? Brushes.Gray : Brushes.Black; } + + public bool IsHeader() => data is KnownSystemCategory?; + public bool IsSystem() => data is KnownSystem?; + + public static implicit operator KnownSystem? (KnownSystemComboBoxItem item) => item.data as KnownSystem?; + + public string Name + { + get + { + if (IsHeader()) + return "---------- " + (data as KnownSystemCategory?).LongName() + " ----------"; + else + return (data as KnownSystem?).LongName(); + } + } + } +} diff --git a/DICUI.Avalonia/ComboBoxItems/LanguageComboBoxItem.cs b/DICUI.Avalonia/ComboBoxItems/LanguageComboBoxItem.cs new file mode 100644 index 00000000..7216b1fc --- /dev/null +++ b/DICUI.Avalonia/ComboBoxItems/LanguageComboBoxItem.cs @@ -0,0 +1,29 @@ +using DICUI.Utilities; +using DICUI.Web; + +namespace DICUI.Avalonia +{ + /// + /// Represents a single item in the Language combo box + /// + public class LanguageComboBoxItem + { + private object data; + + public LanguageComboBoxItem(Language? region) => data = region; + + public static implicit operator Language? (LanguageComboBoxItem item) => item.data as Language?; + + public string Name + { + get { return (data as Language?).LongName(); } + } + + public bool IsChecked { get; set; } + + public Language? Value + { + get { return data as Language?; } + } + } +} diff --git a/DICUI.Avalonia/ComboBoxItems/MediaTypeComboBoxItem.cs b/DICUI.Avalonia/ComboBoxItems/MediaTypeComboBoxItem.cs new file mode 100644 index 00000000..4dbc4abc --- /dev/null +++ b/DICUI.Avalonia/ComboBoxItems/MediaTypeComboBoxItem.cs @@ -0,0 +1,20 @@ +using DICUI.Data; +using DICUI.Utilities; + +namespace DICUI.Avalonia +{ + /// + /// Represents a single item in the MediaType combo box + /// + public class MediaTypeComboBoxItem + { + private MediaType? data; + + public MediaTypeComboBoxItem(MediaType? mediaType) => data = mediaType; + + public static implicit operator MediaType? (MediaTypeComboBoxItem item) => item.data; + + public string Name { get { return data.LongName(); } + } + } +} diff --git a/DICUI.Avalonia/ComboBoxItems/RegionComboBoxItem.cs b/DICUI.Avalonia/ComboBoxItems/RegionComboBoxItem.cs new file mode 100644 index 00000000..2309b43a --- /dev/null +++ b/DICUI.Avalonia/ComboBoxItems/RegionComboBoxItem.cs @@ -0,0 +1,30 @@ +using DICUI.Utilities; +using DICUI.Web; + +namespace DICUI.Avalonia +{ + /// + /// Represents a single item in the Region combo box + /// + public class RegionComboBoxItem + { + private object data; + + public RegionComboBoxItem(Region? region) => data = region; + + public static implicit operator Region? (RegionComboBoxItem item) => item.data as Region?; + + public string Name + { + get + { + return (data as Region?).LongName(); + } + } + + public Region? Value + { + get { return data as Region?; } + } + } +} diff --git a/DICUI.Avalonia/Constants.cs b/DICUI.Avalonia/Constants.cs new file mode 100644 index 00000000..600af0c7 --- /dev/null +++ b/DICUI.Avalonia/Constants.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using DICUI.Data; + +namespace DICUI.Avalonia +{ + /// + /// Variables for UI elements + /// + public static class Constants + { + public const string StartDumping = "Start Dumping"; + public const string StopDumping = "Stop Dumping"; + + public const int LogWindowMarginFromMainWindow = 40; + + // Private lists of known drive speed ranges + private static IReadOnlyList cd { get; } = new List { 1, 2, 3, 4, 6, 8, 12, 16, 20, 24, 32, 40, 44, 48, 52, 56, 72 }; + private static IReadOnlyList dvd { get; } = cd.Where(s => s <= 24).ToList(); + private static IReadOnlyList bd { get; } = cd.Where(s => s <= 16).ToList(); + private static IReadOnlyList unknown { get; } = cd; // TODO: All or {1}? Maybe null? + + /// + /// Get list of all drive speeds for a given MediaType + /// + /// MediaType? that represents the current item + /// Read-only list of drive speeds + public static IReadOnlyList GetSpeedsForMediaType(MediaType? type) + { + switch (type) + { + case MediaType.CDROM: + case MediaType.GDROM: + return cd; + case MediaType.DVD: + case MediaType.HDDVD: + case MediaType.NintendoGameCubeGameDisc: + case MediaType.NintendoWiiOpticalDisc: + return dvd; + case MediaType.BluRay: + return bd; + default: + return unknown; + } + } + + // Create collections for UI based on known drive speeds + public static List SpeedsForCDAsCollection { get; } = GetDoubleCollectionFromIntList(cd); + public static List SpeedsForDVDAsCollection { get; } = GetDoubleCollectionFromIntList(dvd); + public static List SpeedsForBDAsCollection { get; } = GetDoubleCollectionFromIntList(bd); + private static List GetDoubleCollectionFromIntList(IReadOnlyList list) + => new List(list.Select(i => Convert.ToDouble(i)).ToList()); + } +} diff --git a/DICUI.Avalonia/DICUI.Avalonia.csproj b/DICUI.Avalonia/DICUI.Avalonia.csproj new file mode 100644 index 00000000..4f9bf7b8 --- /dev/null +++ b/DICUI.Avalonia/DICUI.Avalonia.csproj @@ -0,0 +1,29 @@ + + + WinExe + net472;net48;netcoreapp3.1 + + + + + + + + + + + + + DiscInformationWindow.axaml + + + LogWindow.axaml + + + MainWindow.axaml + + + OptionsWindow.axaml + + + diff --git a/DICUI.Avalonia/DiscInformationWindow.axaml b/DICUI.Avalonia/DiscInformationWindow.axaml new file mode 100644 index 00000000..e35fe1fc --- /dev/null +++ b/DICUI.Avalonia/DiscInformationWindow.axaml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +