Skip to content

Commit

Permalink
Added the Actual File Format and restored original FIle Format implen…
Browse files Browse the repository at this point in the history
…tation.

Actual File Format doesn't have a smart list entry (macther) because of performance consideration.
  • Loading branch information
maforget committed Apr 11, 2024
1 parent ef5783d commit 0cd9dfd
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 16 deletions.
27 changes: 25 additions & 2 deletions ComicRack.Engine/ComicBook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions ComicRack.Engine/ComicRack.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<Compile Include="IO\Provider\Pdfium.cs" />
<Compile Include="IO\Provider\Readers\Pdf\PdfiumReaderEngine.cs" />
<Compile Include="Metadata\ComicBook\Comparer\ComicBookAddedComparer.cs" />
<Compile Include="Metadata\ComicBook\Comparer\ComicBookActualFileFormatComparer.cs" />
<Compile Include="Metadata\ComicBook\Group\ComicBookGroupActualFileFormat.cs" />
<Compile Include="Metadata\ComicBook\Matcher\ComicBookAddedMatcher.cs" />
<Compile Include="Metadata\ComicBook\Comparer\ComicBookAgeRatingComparer.cs" />
<Compile Include="Metadata\ComicBook\Matcher\ComicBookAgeRatingMatcher.cs" />
Expand Down
10 changes: 6 additions & 4 deletions ComicRack.Engine/IO/Provider/ImageProviderFactory.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.CodeDom;
using System.Linq;

namespace cYo.Projects.ComicRack.Engine.IO.Provider
Expand Down Expand Up @@ -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;
}
}
}
}
}
17 changes: 13 additions & 4 deletions ComicRack.Engine/IO/Provider/ProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace cYo.Projects.ComicRack.Engine.IO.Provider
{
public class ProviderFactory<T> where T : class
public class ProviderFactory<T> where T : class
{
private readonly ReaderWriterLockSlim rwLock = new ReaderWriterLockSlim();

Expand Down Expand Up @@ -107,14 +107,23 @@ public IEnumerable<FileFormat> 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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;

namespace cYo.Projects.ComicRack.Engine
{
public class ComicBookActualFileFormatComparer : Comparer<ComicBook>
{
public override int Compare(ComicBook x, ComicBook y)
{
return string.Compare(x.ActualFileFormat, y.ActualFileFormat);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using cYo.Common.ComponentModel;

namespace cYo.Projects.ComicRack.Engine
{
public class ComicBookGroupActualFileFormat : ComicBookStringGrouper<ComicBookFileFormatMatcher>
{
public override IGroupInfo GetGroup(ComicBook item)
{
return new GroupInfo(string.IsNullOrEmpty(item.ActualFileFormat) ? GroupInfo.Unspecified : item.ActualFileFormat);
}
}
}
3 changes: 2 additions & 1 deletion ComicRack/Changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions ComicRack/Dialogs/ComicBookDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions ComicRack/Dialogs/ComicBookDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions ComicRack/Views/ComicBrowserControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComicBookSeriesStatsLastAddedTimeComparer>(), new CoverViewItemStatsGrouper<ComicBookStatsGroupLastAddedTime>(), 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<ComicBookSeriesStatsLastOpenedTimeComparer>(), new CoverViewItemStatsGrouper<ComicBookStatsGroupLastOpenedTime>(), 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<ComicBookSeriesStatsLastReleasedTimeComparer>(), new CoverViewItemStatsGrouper<ComicBookStatsGroupLastReleasedTime>(), 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<ComicBookActualFileFormatComparer>(), new CoverViewItemBookGrouper<ComicBookGroupActualFileFormat>(), visible: false));
SetVirtualTagColumns();
SubView.TranslateColumns(itemView.Columns);
foreach (ItemViewColumn column in itemView.Columns)
Expand Down

0 comments on commit 0cd9dfd

Please sign in to comment.