From e69264c69192cfac381b73933d1fbc2414b74634 Mon Sep 17 00:00:00 2001 From: DSPAUL <35136955+DSPAUL@users.noreply.github.com> Date: Sat, 9 Jul 2022 22:27:53 +0200 Subject: [PATCH 1/9] Download webdrivers to appdata removes needing to run as admin --- src/COMPASS.csproj | 2 +- src/Tools/CoverFetcher.cs | 48 ++++++++++++++++++++++----------- src/Tools/Utils.cs | 13 +++++++++ src/ViewModels/MainViewModel.cs | 11 ++++---- 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/COMPASS.csproj b/src/COMPASS.csproj index 4af74ee6..cbca661c 100644 --- a/src/COMPASS.csproj +++ b/src/COMPASS.csproj @@ -56,7 +56,7 @@ 6.0.0 - + diff --git a/src/Tools/CoverFetcher.cs b/src/Tools/CoverFetcher.cs index 97a18bf7..9fe72c87 100644 --- a/src/Tools/CoverFetcher.cs +++ b/src/Tools/CoverFetcher.cs @@ -146,34 +146,50 @@ public static bool GetCoverFromURL(Codex destfile, Enums.Sources source) //sites do not store cover as img, Use Selenium for screenshotting pages else if (source.HasFlag(Enums.Sources.GmBinder) || source.HasFlag(Enums.Sources.Homebrewery)) { - DriverService driverService; + var browser = (Enums.Browser)Properties.Settings.Default.SeleniumBrowser; + + string driverPath = browser switch + { + Enums.Browser.Chrome => Utils.FindFileDirectory("chromedriver.exe", Constants.WebDriverDirectoryPath), + Enums.Browser.Firefox => Utils.FindFileDirectory("geckodriver.exe", Constants.WebDriverDirectoryPath), + _ => Utils.FindFileDirectory("msedgedriver.exe", Constants.WebDriverDirectoryPath) + }; + + DriverService driverService = browser switch + { + Enums.Browser.Chrome => ChromeDriverService.CreateDefaultService(driverPath), + Enums.Browser.Firefox => FirefoxDriverService.CreateDefaultService(driverPath), + _ => EdgeDriverService.CreateDefaultService(driverPath) + }; + + driverService.HideCommandPromptWindow = true; + + List DriverArguments = new() + { + "--headless", + "--window-size=3000,3000", + "--width=3000", + "--height=3000" + }; + WebDriver driver; - switch (Properties.Settings.Default.SeleniumBrowser) + switch (browser) { - case (int)Enums.Browser.Chrome: - driverService = ChromeDriverService.CreateDefaultService(); - driverService.HideCommandPromptWindow = true; + case Enums.Browser.Chrome: ChromeOptions CO = new(); - CO.AddArgument("--window-size=2500,2000"); - CO.AddArgument("--headless"); + CO.AddArguments(DriverArguments); driver = new ChromeDriver((ChromeDriverService)driverService, CO); break; - case (int)Enums.Browser.Firefox: - driverService = FirefoxDriverService.CreateDefaultService(); - driverService.HideCommandPromptWindow = true; + case Enums.Browser.Firefox: FirefoxOptions FO = new(); - FO.AddArgument("--window-size=2500,2000"); - FO.AddArgument("--headless"); + FO.AddArguments(DriverArguments); driver = new FirefoxDriver((FirefoxDriverService)driverService, FO); break; default: - driverService = EdgeDriverService.CreateDefaultService(); - driverService.HideCommandPromptWindow = true; EdgeOptions EO = new(); - EO.AddArgument("--window-size=2500,2000"); - EO.AddArgument("--headless"); + EO.AddArguments(DriverArguments); driver = new EdgeDriver((EdgeDriverService)driverService, EO); break; } diff --git a/src/Tools/Utils.cs b/src/Tools/Utils.cs index 52fb09fd..8faffdf1 100644 --- a/src/Tools/Utils.cs +++ b/src/Tools/Utils.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.IO; using System.Linq; using System.Net.Http; using System.Net.NetworkInformation; @@ -92,5 +93,17 @@ public static bool IsInstalled(string name) } return false; } + + public static string FindFileDirectory(string fileName) + { + return FindFileDirectory(fileName, Directory.GetCurrentDirectory()); + } + public static string FindFileDirectory(string fileName, string rootDirectory) + { + string filePath = Directory.GetFiles(rootDirectory, fileName, SearchOption.AllDirectories)[0]; + string parentDirectory = Path.GetDirectoryName(filePath); + return parentDirectory; + } + } } diff --git a/src/ViewModels/MainViewModel.cs b/src/ViewModels/MainViewModel.cs index 79bb9783..11fe3e08 100644 --- a/src/ViewModels/MainViewModel.cs +++ b/src/ViewModels/MainViewModel.cs @@ -116,8 +116,7 @@ private void InitCollection() //Get latest version of relevant Webdriver for selenium private void InitWebdriver() { - //DriverManager DM = new(Constants.WebDriverDirectoryPath); - DriverManager DM = new(); + DriverManager DM = new(Constants.WebDriverDirectoryPath); if (Utils.IsInstalled("chrome.exe")) { Properties.Settings.Default.SeleniumBrowser = (int)Browser.Chrome; @@ -127,7 +126,7 @@ private void InitWebdriver() } catch (Exception ex) { - Logger.log.Error(ex.InnerException); + Logger.log.Error(ex.Message); } } else if (Utils.IsInstalled("firefox.exe")) @@ -139,7 +138,7 @@ private void InitWebdriver() } catch (Exception ex) { - Logger.log.Error(ex.InnerException); + Logger.log.Error(ex.Message); } } @@ -148,11 +147,11 @@ private void InitWebdriver() Properties.Settings.Default.SeleniumBrowser = (int)Browser.Edge; try { - DM.SetUpDriver(new EdgeConfig()); + DM.SetUpDriver(new EdgeConfig(), WebDriverManager.Helpers.VersionResolveStrategy.MatchingBrowser); } catch (Exception ex) { - Logger.log.Error(ex.InnerException); + Logger.log.Error(ex.Message); } } } From 5684fa2c74ee33ee9c9b50a779a18a374885fec8 Mon Sep 17 00:00:00 2001 From: DSPAUL <35136955+DSPAUL@users.noreply.github.com> Date: Sat, 9 Jul 2022 22:36:15 +0200 Subject: [PATCH 2/9] Fix resizing bug --- src/Windows/ImportURLWindow.xaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Windows/ImportURLWindow.xaml b/src/Windows/ImportURLWindow.xaml index 3a308602..e710d92c 100644 --- a/src/Windows/ImportURLWindow.xaml +++ b/src/Windows/ImportURLWindow.xaml @@ -5,10 +5,11 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:Tools ="clr-namespace:COMPASS.Tools" xmlns:local="clr-namespace:COMPASS.Windows" - xmlns:viewmodels="clr-namespace:COMPASS.ViewModels" d:DataContext="{d:DesignInstance Type=viewmodels:ImportViewModel}" + xmlns:viewmodels="clr-namespace:COMPASS.ViewModels" + d:DataContext="{d:DesignInstance Type=viewmodels:ImportViewModel}" mc:Ignorable="d" Foreground="{StaticResource TextColor}" WindowStyle="ToolWindow" - Background="{StaticResource WindowBackground}" SizeToContent="Height" - Title="Import URL" Height="170" Width="600" WindowStartupLocation="CenterScreen"> + Background="{StaticResource WindowBackground}" + Title="Import URL" Height="190" Width="600" WindowStartupLocation="CenterScreen"> From 240612faf70efddcbc69cd21a4714163a37e30f0 Mon Sep 17 00:00:00 2001 From: DSPAUL <35136955+DSPAUL@users.noreply.github.com> Date: Sat, 9 Jul 2022 22:44:14 +0200 Subject: [PATCH 3/9] ignore vscode --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ca497ed6..ff478d85 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ # Visual Studio 2015/2017 cache/options directory .vs/ +.vscode/ # Build results [Dd]ebug/ From 6e1863f5f2845efb290012413cf4dad717c19747 Mon Sep 17 00:00:00 2001 From: DSPAUL <35136955+DSPAUL@users.noreply.github.com> Date: Thu, 14 Jul 2022 00:12:02 +0200 Subject: [PATCH 4/9] persist layout options of home and tile layout --- src/App.config | 9 +++++ src/Properties/Settings.Designer.cs | 36 +++++++++++++++++++ src/Properties/Settings.settings | 9 +++++ src/ViewModels/Layouts/HomeLayoutViewModel.cs | 8 ++--- src/ViewModels/Layouts/TileLayoutViewModel.cs | 4 ++- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/src/App.config b/src/App.config index 5f220604..a44eef60 100644 --- a/src/App.config +++ b/src/App.config @@ -77,6 +77,15 @@ True + + False + + + 156 + + + 156 + diff --git a/src/Properties/Settings.Designer.cs b/src/Properties/Settings.Designer.cs index 2fe6d0f5..81efcc12 100644 --- a/src/Properties/Settings.Designer.cs +++ b/src/Properties/Settings.Designer.cs @@ -298,5 +298,41 @@ public bool justUpdated { this["justUpdated"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool HomeShowTitle { + get { + return ((bool)(this["HomeShowTitle"])); + } + set { + this["HomeShowTitle"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("156")] + public double HomeCoverSize { + get { + return ((double)(this["HomeCoverSize"])); + } + set { + this["HomeCoverSize"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("156")] + public double TileCoverSize { + get { + return ((double)(this["TileCoverSize"])); + } + set { + this["TileCoverSize"] = value; + } + } } } diff --git a/src/Properties/Settings.settings b/src/Properties/Settings.settings index 092702d5..b0e93a0c 100644 --- a/src/Properties/Settings.settings +++ b/src/Properties/Settings.settings @@ -71,5 +71,14 @@ True + + False + + + 156 + + + 156 + \ No newline at end of file diff --git a/src/ViewModels/Layouts/HomeLayoutViewModel.cs b/src/ViewModels/Layouts/HomeLayoutViewModel.cs index b9ae5f6a..ee45468d 100644 --- a/src/ViewModels/Layouts/HomeLayoutViewModel.cs +++ b/src/ViewModels/Layouts/HomeLayoutViewModel.cs @@ -11,10 +11,9 @@ public HomeLayoutViewModel():base() ViewOptions.Add(new MyMenuItem("Cover Size", value => TileWidth = (double)value) { Prop = TileWidth }); ViewOptions.Add(new MyMenuItem("Show Title", value => ShowTitle = (bool)value) { Prop = ShowTitle }); - ViewOptions.Add(SortOptionsMenuItem); } - private double _width = 156; + private double _width = Properties.Settings.Default.HomeCoverSize; public double TileWidth { get { return _width; } @@ -22,6 +21,7 @@ public double TileWidth { SetProperty(ref _width, value); RaisePropertyChanged(nameof(TileHeight)); + Properties.Settings.Default.HomeCoverSize = value; } } @@ -30,14 +30,14 @@ public double TileHeight get { return (int)(_width * 4 / 3); } } - private bool _showtitle = Properties.Settings.Default.TileShowTitle; + private bool _showtitle = Properties.Settings.Default.HomeShowTitle; public bool ShowTitle { get { return _showtitle; } set { SetProperty(ref _showtitle, value); - Properties.Settings.Default.TileShowTitle = value; + Properties.Settings.Default.HomeShowTitle = value; } } } diff --git a/src/ViewModels/Layouts/TileLayoutViewModel.cs b/src/ViewModels/Layouts/TileLayoutViewModel.cs index 3b7115e2..14bc0bfe 100644 --- a/src/ViewModels/Layouts/TileLayoutViewModel.cs +++ b/src/ViewModels/Layouts/TileLayoutViewModel.cs @@ -11,9 +11,10 @@ public TileLayoutViewModel() : base() ViewOptions.Add(new MyMenuItem("Cover Size", value => TileWidth = (double)value) { Prop = TileWidth }); ViewOptions.Add(new MyMenuItem("Show Title", value => ShowTitle = (bool)value) { Prop = ShowTitle }); + ViewOptions.Add(SortOptionsMenuItem); } #region Properties - private double _width = 156; + private double _width = Properties.Settings.Default.TileCoverSize; public double TileWidth { get { return _width; } @@ -21,6 +22,7 @@ public double TileWidth { SetProperty(ref _width, value); RaisePropertyChanged(nameof(TileHeight)); + Properties.Settings.Default.TileCoverSize = value; } } From cf805cf5e6f73e20dcb7394cac52cabd61b688fa Mon Sep 17 00:00:00 2001 From: DSPAUL <35136955+DSPAUL@users.noreply.github.com> Date: Sat, 16 Jul 2022 17:30:14 +0200 Subject: [PATCH 5/9] Add BlackPearl, version bump autoupdater --- src/COMPASS.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/COMPASS.csproj b/src/COMPASS.csproj index cbca661c..3c289c1b 100644 --- a/src/COMPASS.csproj +++ b/src/COMPASS.csproj @@ -25,7 +25,8 @@ - + + From 9fd8949b42b7b8ba5ba068ce402a14084e2350de Mon Sep 17 00:00:00 2001 From: DSPAUL <35136955+DSPAUL@users.noreply.github.com> Date: Sat, 16 Jul 2022 17:40:50 +0200 Subject: [PATCH 6/9] Add support for multiple authors --- src/Models/Codex.cs | 38 +++++++++++++++----- src/Models/CodexCollection.cs | 12 ++++++- src/Resources/CommonResources.xaml | 40 ++++++++++++++++++++- src/Tools/CreatableLookupContract.cs | 34 ++++++++++++++++++ src/ViewModels/CodexBulkEditViewModel.cs | 29 ++++++++++++---- src/ViewModels/CodexEditViewModel.cs | 6 ++-- src/ViewModels/CodexViewModel.cs | 2 +- src/ViewModels/CollectionViewModel.cs | 3 +- src/ViewModels/ImportViewModel.cs | 8 ++--- src/ViewModels/Layouts/LayoutViewModel.cs | 25 +++++++------- src/Views/CardLayout.xaml | 42 +++++++++++------------ src/Views/ListLayout.xaml | 6 ++-- src/Views/TileLayout.xaml | 2 +- src/Windows/FileBulkEditWindow.xaml | 14 +++++--- src/Windows/FileBulkEditWindow.xaml.cs | 16 --------- src/Windows/FilePropWindow.xaml | 21 +++++++----- src/Windows/FilePropWindow.xaml.cs | 18 ++-------- 17 files changed, 211 insertions(+), 105 deletions(-) create mode 100644 src/Tools/CreatableLookupContract.cs diff --git a/src/Models/Codex.cs b/src/Models/Codex.cs index e873fba8..ce4f6c2f 100644 --- a/src/Models/Codex.cs +++ b/src/Models/Codex.cs @@ -4,27 +4,32 @@ using System.Collections.ObjectModel; using System.IO; using System.Xml.Serialization; +using System.Linq; namespace COMPASS.Models { public class Codex : ObservableObject, IHasID { //empty constructor for serialization - public Codex() { } + public Codex() + { + Authors.CollectionChanged += (e, v) => RaisePropertyChanged(nameof(AuthorsAsString)); + } - public Codex(CodexCollection cc) + public Codex(CodexCollection cc):this() { Tags = new(); ID = Utils.GetAvailableID(cc.AllCodices); CoverArt = CodexCollection.CollectionsPath + cc.DirectoryName + @"\CoverArt\" + ID.ToString() + ".png"; Thumbnail = CodexCollection.CollectionsPath + cc.DirectoryName + @"\Thumbnails\" + ID.ToString() + ".png"; + } public void Copy(Codex c) { Title = c.Title; Path = c.Path; - Author = c.Author; + Authors = new(c.Authors); Publisher = c.Publisher; Version = c.Version; SourceURL = c.SourceURL; @@ -69,11 +74,28 @@ public string Title set { SetProperty(ref _title, value); } } - private string _author; - public string Author - { - get { return _author; } - set { SetProperty(ref _author, value); } + private ObservableCollection _authors = new(); + public ObservableCollection Authors + { + get { return _authors; } + set + { + SetProperty(ref _authors, value); + RaisePropertyChanged(nameof(AuthorsAsString)); + } + } + + public string AuthorsAsString { + get + { + string str = Authors.Count switch + { + 1 => Authors[0], + > 1 => String.Join(", ", Authors.OrderBy(a=>a)), + _ => "" + }; + return str; + } } private string _publisher; diff --git a/src/Models/CodexCollection.cs b/src/Models/CodexCollection.cs index 79a0619b..219edbe5 100644 --- a/src/Models/CodexCollection.cs +++ b/src/Models/CodexCollection.cs @@ -91,10 +91,11 @@ private void LoadCodices() AllCodices = serializer.Deserialize(Reader) as List; } + foreach (Codex f in AllCodices) { //Populate Author and Publisher List - if (!String.IsNullOrEmpty(f.Author) && !AuthorList.Contains(f.Author)) AuthorList.Add(f.Author); + AddAuthors(f); if (!String.IsNullOrEmpty(f.Publisher) && !PublisherList.Contains(f.Publisher)) PublisherList.Add(f.Publisher); //reconstruct tags from ID's @@ -173,5 +174,14 @@ public void RenameCollection(string NewCollectionName) Directory.Move(CollectionsPath + DirectoryName, CollectionsPath + NewCollectionName); DirectoryName = NewCollectionName; } + + public void AddAuthors(Codex codex) + { + foreach (var author in codex.Authors) + { + if (!String.IsNullOrEmpty(author) && !AuthorList.Contains(author)) + AuthorList.Add(author); + } + } } } diff --git a/src/Resources/CommonResources.xaml b/src/Resources/CommonResources.xaml index 23ed1d2d..0a10793c 100644 --- a/src/Resources/CommonResources.xaml +++ b/src/Resources/CommonResources.xaml @@ -2,7 +2,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:Converters ="clr-namespace:COMPASS.Tools.Converters" - xmlns:Tools="clr-namespace:COMPASS.Tools"> + xmlns:Tools="clr-namespace:COMPASS.Tools" + xmlns:BlackPearl="clr-namespace:BlackPearl.Controls.CoreLibrary;assembly=BlackPearl.Controls.CoreLibrary" + xmlns:docs="clr-namespace:System.Windows.Documents;assembly=PresentationFramework"> @@ -511,6 +513,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + - + - - - - diff --git a/src/Windows/FilePropWindow.xaml b/src/Windows/FilePropWindow.xaml index 4872e8c2..7c025cc2 100644 --- a/src/Windows/FilePropWindow.xaml +++ b/src/Windows/FilePropWindow.xaml @@ -12,7 +12,7 @@ xmlns:BlackPearl="clr-namespace:BlackPearl.Controls.CoreLibrary;assembly=BlackPearl.Controls.CoreLibrary" d:DataContext="{d:DesignInstance Type=viewmodels:CodexEditViewModel}" mc:Ignorable="d" - Title="File Properties" Height="450" Width="1100" FontSize="16" + Title="File Properties" Height="500" Width="1200" FontSize="16" WindowStyle="ToolWindow" WindowStartupLocation="CenterScreen" Foreground="{StaticResource TextColor}" Background="{StaticResource WindowBackground}" MouseDown="MainGrid_MouseDown"> @@ -21,6 +21,7 @@ + @@ -81,7 +82,7 @@ - + @@ -92,6 +93,22 @@ + + + + + + @@ -104,7 +121,10 @@ - + + +