From 0cd9dfdd41d011c1c3fa4d11fc899a3086d2a5c6 Mon Sep 17 00:00:00 2001 From: maforget <11904426+maforget@users.noreply.github.com> Date: Thu, 11 Apr 2024 00:53:16 -0400 Subject: [PATCH] Added the Actual File Format and restored original FIle Format implentation. Actual File Format doesn't have a smart list entry (macther) because of performance consideration. --- ComicRack.Engine/ComicBook.cs | 27 +++++++++++++++++-- ComicRack.Engine/ComicRack.Engine.csproj | 2 ++ .../IO/Provider/ImageProviderFactory.cs | 10 ++++--- .../IO/Provider/ProviderFactory.cs | 17 +++++++++--- .../ComicBookActualFileFormatComparer.cs | 12 +++++++++ .../Group/ComicBookGroupActualFileFormat.cs | 12 +++++++++ ComicRack/Changes.txt | 3 ++- ComicRack/Dialogs/ComicBookDialog.Designer.cs | 4 +-- ComicRack/Dialogs/ComicBookDialog.cs | 7 ++--- ComicRack/Views/ComicBrowserControl.cs | 1 + 10 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 ComicRack.Engine/Metadata/ComicBook/Comparer/ComicBookActualFileFormatComparer.cs create mode 100644 ComicRack.Engine/Metadata/ComicBook/Group/ComicBookGroupActualFileFormat.cs diff --git a/ComicRack.Engine/ComicBook.cs b/ComicRack.Engine/ComicBook.cs index 5304665..96cefdb 100644 --- a/ComicRack.Engine/ComicBook.cs +++ b/ComicRack.Engine/ComicBook.cs @@ -175,6 +175,8 @@ public ParseFilePathEventArgs(string path) private volatile string fileFormat; + private volatile string actualFileFormat; + private volatile string fileDirectory; private static readonly Calendar weekCalendar; @@ -544,7 +546,7 @@ public string FilePath { string text = FilePath; filePath = value; - fileName = (fileNameWithExtension = (fileFormat = (fileDirectory = null))); + fileName = fileNameWithExtension = actualFileFormat = fileFormat = fileDirectory = null; proposed = null; FireBookChanged("FilePath", text, filePath); if (!string.IsNullOrEmpty(text)) @@ -878,6 +880,27 @@ public string FileFormat } } + [Browsable(true)] + public string ActualFileFormat + { + get + { + if (actualFileFormat != null) + { + return actualFileFormat; + } + try + { + actualFileFormat = Providers.Readers.GetSourceFormatName(filePath, true); + } + catch (Exception) + { + actualFileFormat = string.Empty; + } + return actualFileFormat; + } + } + [Browsable(true)] public string FileDirectory { @@ -977,7 +1000,7 @@ public string InfoText StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("{0}\n", FileName); stringBuilder.AppendFormat("{0} ({1})\n\n", FileSizeAsText, PagesAsText); - stringBuilder.AppendFormat("{0}\n", FileFormat); + stringBuilder.AppendFormat("{0}\n", ActualFileFormat); stringBuilder.AppendFormat("{0}\n\n", FileDirectory); stringBuilder.Append(StringUtility.Format(lastTimeOpenedAtText.Value, OpenedTimeAsText)); stringBuilder.AppendLine(); diff --git a/ComicRack.Engine/ComicRack.Engine.csproj b/ComicRack.Engine/ComicRack.Engine.csproj index b438ffd..813bcc0 100644 --- a/ComicRack.Engine/ComicRack.Engine.csproj +++ b/ComicRack.Engine/ComicRack.Engine.csproj @@ -66,6 +66,8 @@ + + diff --git a/ComicRack.Engine/IO/Provider/ImageProviderFactory.cs b/ComicRack.Engine/IO/Provider/ImageProviderFactory.cs index f0c687c..f914f95 100644 --- a/ComicRack.Engine/IO/Provider/ImageProviderFactory.cs +++ b/ComicRack.Engine/IO/Provider/ImageProviderFactory.cs @@ -1,3 +1,4 @@ +using System.CodeDom; using System.Linq; namespace cYo.Projects.ComicRack.Engine.IO.Provider @@ -31,9 +32,10 @@ public override ImageProvider CreateSourceProvider(string source) return null; } - public override FileFormat GetSourceFormat(string source) - { + protected override FileFormat GetActualSourceFormat(string source) + { + //returns the actual file format based on the actual providers used. return CreateSourceProvider(source).DefaultFileFormat; - } - } + } + } } diff --git a/ComicRack.Engine/IO/Provider/ProviderFactory.cs b/ComicRack.Engine/IO/Provider/ProviderFactory.cs index 777b70d..71f44e8 100644 --- a/ComicRack.Engine/IO/Provider/ProviderFactory.cs +++ b/ComicRack.Engine/IO/Provider/ProviderFactory.cs @@ -10,7 +10,7 @@ namespace cYo.Projects.ComicRack.Engine.IO.Provider { - public class ProviderFactory where T : class + public class ProviderFactory where T : class { private readonly ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim(); @@ -107,14 +107,23 @@ public IEnumerable GetSourceFormats(string source) return GetSourceProviderInfos(source).SelectMany((ProviderInfo pi) => pi.Formats); } - public virtual FileFormat GetSourceFormat(string source) + protected virtual FileFormat GetActualSourceFormat(string source) + { + //Just returns the source format based on the extension + return GetSourceFormat(source); + } + + public FileFormat GetSourceFormat(string source, bool actualFormat = false) { + if(actualFormat) + return GetActualSourceFormat(source); + return GetSourceFormats(source).FirstOrDefault((FileFormat ff) => ff.Supports(source)); } - public string GetSourceFormatName(string source) + public string GetSourceFormatName(string source, bool actualFormat = false) { - FileFormat sourceFormat = GetSourceFormat(source); + FileFormat sourceFormat = GetSourceFormat(source, actualFormat); if (sourceFormat != null && !string.IsNullOrEmpty(sourceFormat.Name)) { return sourceFormat.Name; diff --git a/ComicRack.Engine/Metadata/ComicBook/Comparer/ComicBookActualFileFormatComparer.cs b/ComicRack.Engine/Metadata/ComicBook/Comparer/ComicBookActualFileFormatComparer.cs new file mode 100644 index 0000000..d31a873 --- /dev/null +++ b/ComicRack.Engine/Metadata/ComicBook/Comparer/ComicBookActualFileFormatComparer.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; + +namespace cYo.Projects.ComicRack.Engine +{ + public class ComicBookActualFileFormatComparer : Comparer + { + public override int Compare(ComicBook x, ComicBook y) + { + return string.Compare(x.ActualFileFormat, y.ActualFileFormat); + } + } +} diff --git a/ComicRack.Engine/Metadata/ComicBook/Group/ComicBookGroupActualFileFormat.cs b/ComicRack.Engine/Metadata/ComicBook/Group/ComicBookGroupActualFileFormat.cs new file mode 100644 index 0000000..2efb80f --- /dev/null +++ b/ComicRack.Engine/Metadata/ComicBook/Group/ComicBookGroupActualFileFormat.cs @@ -0,0 +1,12 @@ +using cYo.Common.ComponentModel; + +namespace cYo.Projects.ComicRack.Engine +{ + public class ComicBookGroupActualFileFormat : ComicBookStringGrouper + { + public override IGroupInfo GetGroup(ComicBook item) + { + return new GroupInfo(string.IsNullOrEmpty(item.ActualFileFormat) ? GroupInfo.Unspecified : item.ActualFileFormat); + } + } +} diff --git a/ComicRack/Changes.txt b/ComicRack/Changes.txt index 2a46689..9ba4e6c 100644 --- a/ComicRack/Changes.txt +++ b/ComicRack/Changes.txt @@ -6,12 +6,14 @@ Community Edition Build 0.9.180: * NEW: Added the Git version to the Splash Screen, to more easily identify bugs in specific releases. * NEW: Added the "-local" command line switch, to have the program load in portable mode. * NEW: Added links to The Organizer guide to the online manual help system +* NEW: Added "Actual File Format" field that will be the actual file format of the archive and not simply based on the extension. * NEW: Unknown elements that may have been added by other software to the ComicInfo.xml will be kept, these will also be saved in the database. * NEW: Articles in IgnoredArticles can now terminate with an apostrophe (Like L'). * NEW: Added French articles (Le, La, Les, L') as default in IgnoredArticles. * NEW: Remember the Location & Size of Script Output Console by the Workspace system. Since the Workspace system is configured via the Main window, the console will load at the default location but be restored once the Main window is loaded. * NEW: Quick Search (using Mode All) will now search Scan Information & Custom Fields. * NEW: Added the Web field to smart list, so no more need to use expressions. (Again backup your DB, this could result in a corrupted database if going back to an older version) +* NEW: Added an "Is Missing" smart list entry. (Again backup your DB, this could result in a corrupted database if going back to an older version) * CHANGE: Updated to .NET Framework v4.8. * CHANGE: Updated the Splash Screen and Renamed the Program to Community Edition, this means that a new config folder will be used %appdata%\cYo\ComicRack Community Edition. @@ -29,7 +31,6 @@ Community Edition Build 0.9.180: * CHANGE: Updated the default help system to the online manual (from Wayback Machine). * CHANGE: Updated manual links & chapter links. * CHANGE: Updated Help localize ComicRack links (we still need access to the Localizer program). -* CHANGE: File Format will be the actual file format of the archive and not simply based on the extension. * CHANGE: The default docking mode is now Fill, instead of Bottom. * CHANGE: Improved performances while handling Tar files (by Apiweb). * CHANGE: Removed the Crash submission dialog because it depended on the cyolito.com website. diff --git a/ComicRack/Dialogs/ComicBookDialog.Designer.cs b/ComicRack/Dialogs/ComicBookDialog.Designer.cs index 3fd834c..b8aaf6d 100644 --- a/ComicRack/Dialogs/ComicBookDialog.Designer.cs +++ b/ComicRack/Dialogs/ComicBookDialog.Designer.cs @@ -464,9 +464,9 @@ private void InitializeComponent() // lblType // this.lblType.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.lblType.Location = new System.Drawing.Point(93, 285); + this.lblType.Location = new System.Drawing.Point(93, 272); this.lblType.Name = "lblType"; - this.lblType.Size = new System.Drawing.Size(145, 20); + this.lblType.Size = new System.Drawing.Size(160, 41); this.lblType.TabIndex = 2; this.lblType.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // diff --git a/ComicRack/Dialogs/ComicBookDialog.cs b/ComicRack/Dialogs/ComicBookDialog.cs index 42b66b4..87919cc 100644 --- a/ComicRack/Dialogs/ComicBookDialog.cs +++ b/ComicRack/Dialogs/ComicBookDialog.cs @@ -297,11 +297,12 @@ private void SetDataToEditor(ComicBook comic) { string text = comic.PagesAsText; if (comic.LastPageRead > 0) - { text = comic.LastPageRead + 1 + "/" + text; - } + + string fileFormat = comic.ActualFileFormat != comic.FileFormat ? $"{comic.ActualFileFormat} (Actual){Environment.NewLine}{comic.FileFormat}" : comic.FileFormat; + EditControlUtility.SetLabel(lblPages, text); - EditControlUtility.SetLabel(lblType, $"{comic.FileFormat}/{comic.FileSizeAsText}"); + EditControlUtility.SetLabel(lblType, $"{fileFormat}/{comic.FileSizeAsText}"); EditControlUtility.SetLabel(lblPath, comic.FilePath); EditControlUtility.SetText(txRating, comic.Rating); EditControlUtility.SetText(txCommunityRating, comic.CommunityRating); diff --git a/ComicRack/Views/ComicBrowserControl.cs b/ComicRack/Views/ComicBrowserControl.cs index 4ceab2c..e57126e 100644 --- a/ComicRack/Views/ComicBrowserControl.cs +++ b/ComicRack/Views/ComicBrowserControl.cs @@ -782,6 +782,7 @@ public ComicBrowserControl() itemView.Columns.Add(new ItemViewColumn(211, "Series: Book added", 50, new ComicListField("SeriesStatLastAddedTime", "Last time a book was added to the Series", null, StringTrimming.Word, typeof(DateTime)), new CoverViewItemStatsComparer(), new CoverViewItemStatsGrouper(), visible: false, StringAlignment.Far, strings)); itemView.Columns.Add(new ItemViewColumn(212, "Series: Opened", 50, new ComicListField("SeriesStatLastOpenedTime", "Last time a book was opened from the Series", null, StringTrimming.Word, typeof(DateTime)), new CoverViewItemStatsComparer(), new CoverViewItemStatsGrouper(), visible: false, StringAlignment.Far, strings)); itemView.Columns.Add(new ItemViewColumn(213, "Series: Book released", 50, new ComicListField("SeriesStatLastReleasedTime", "Last time a book of this Series was released", null, StringTrimming.Word, typeof(DateTime)), new CoverViewItemStatsComparer(), new CoverViewItemStatsGrouper(), visible: false, StringAlignment.Far, strings)); + itemView.Columns.Add(new ItemViewColumn(214, "Actual File Format", 40, new ComicListField("ActualFileFormat", "Actual File format of the Book (based on the header)"), new CoverViewItemBookComparer(), new CoverViewItemBookGrouper(), visible: false)); SetVirtualTagColumns(); SubView.TranslateColumns(itemView.Columns); foreach (ItemViewColumn column in itemView.Columns)