mirror of
https://github.com/claunia/cuetools.net.git
synced 2025-12-16 18:14:25 +00:00
Some refactoring in CUETools
This commit is contained in:
@@ -2630,407 +2630,4 @@ namespace JDP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSystemTreeNodeLocalDBEntry : CUEControls.FileSystemTreeNode
|
||||
{
|
||||
private string m_input_path;
|
||||
|
||||
public bool ShowArtist { get; set; }
|
||||
public bool ShowYear { get; set; }
|
||||
public CUEToolsLocalDBEntry Item { get; private set; }
|
||||
public override string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_input_path ?? Item.Path;
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
if (m_input_path != null && File.Exists(m_input_path))
|
||||
return icon_mgr.GetDisplayName(new FileInfo(m_input_path));
|
||||
return
|
||||
(string.IsNullOrEmpty(Item.Metadata.Artist) || !ShowArtist ? "" : Item.Metadata.Artist + " - ")
|
||||
+ Item.Metadata.Title
|
||||
+ (string.IsNullOrEmpty(Item.Metadata.Year) || !ShowYear ? "" : " (" + Item.Metadata.Year + ")")
|
||||
+ (string.IsNullOrEmpty(Item.Metadata.DiscNumberAndTotal) ? "" : " [" + Item.Metadata.DiscNumberAndTotal + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public override int DisplayIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
return icon_mgr.GetIconIndex(m_input_path ?? (Item.AudioPaths == null || Item.AudioPaths.Count == 0 ? "*.wav" : Item.AudioPaths[0]));
|
||||
}
|
||||
}
|
||||
|
||||
public FileSystemTreeNodeLocalDBEntry(CUEControls.IIconManager icon_mgr, CUEToolsLocalDBEntry item, bool showArtist, bool showYear, string inputPath)
|
||||
: base(icon_mgr, inputPath == null && item.InputPaths != null && item.InputPaths.Count > 1)
|
||||
{
|
||||
this.Item = item;
|
||||
this.m_input_path = inputPath;
|
||||
this.ShowArtist = showArtist;
|
||||
this.ShowYear = showYear;
|
||||
this.SelectedImageIndex = this.ImageIndex = this.DisplayIcon;
|
||||
this.Text = this.DisplayName;
|
||||
//// Choose state from m_state_image_list
|
||||
//if (item.InputPaths.Find(path => Path.GetExtension(path).ToLower() == ".cue") != null)
|
||||
// album.StateImageKey = "cue";
|
||||
//else
|
||||
// album.StateImageKey = "blank";
|
||||
}
|
||||
|
||||
public override void DoExpand()
|
||||
{
|
||||
if (Item.InputPaths != null)
|
||||
foreach (var path in Item.InputPaths)
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBEntry(icon_mgr, Item, ShowArtist, ShowYear, path));
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class FileSystemTreeNodeLocalDBFolder : CUEControls.FileSystemTreeNode
|
||||
{
|
||||
public List<CUEToolsLocalDBEntry> Group { get; protected set; }
|
||||
|
||||
public FileSystemTreeNodeLocalDBFolder(CUEControls.IIconManager icon_mgr)
|
||||
: base(icon_mgr, true)
|
||||
{
|
||||
}
|
||||
|
||||
public void Purge(List<CUEToolsLocalDBEntry> entries)
|
||||
{
|
||||
foreach (TreeNode child in this.Nodes)
|
||||
{
|
||||
if (child is FileSystemTreeNodeLocalDBFolder)
|
||||
(child as FileSystemTreeNodeLocalDBFolder).Purge(entries);
|
||||
if ((child is FileSystemTreeNodeLocalDBEntry && entries.Contains((child as FileSystemTreeNodeLocalDBEntry).Item))
|
||||
|| (child is FileSystemTreeNodeLocalDBGroup && (child as FileSystemTreeNodeLocalDBGroup).Group.Count == 0))
|
||||
child.Remove();
|
||||
}
|
||||
|
||||
this.Group.RemoveAll(item => entries.Contains(item));
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSystemTreeNodeLocalDBCollision : FileSystemTreeNodeLocalDBFolder
|
||||
{
|
||||
public enum GroupType
|
||||
{
|
||||
Unverified = 0,
|
||||
Different = 1,
|
||||
Offsetted = 2,
|
||||
Equal = 3,
|
||||
Single = 4
|
||||
}
|
||||
|
||||
public bool ShowArtist { get; set; }
|
||||
public bool ShowYear { get; set; }
|
||||
public override string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
var artistItem = Group.Find(i => !string.IsNullOrEmpty(i.Metadata.Artist) && ShowArtist);
|
||||
var titleItem = Group.Find(i => !string.IsNullOrEmpty(i.Metadata.Title));
|
||||
var yearItem = Group.Find(i => !string.IsNullOrEmpty(i.Metadata.Year) && ShowYear);
|
||||
var discItem = Group.Find(i => !string.IsNullOrEmpty(i.Metadata.DiscNumberAndTotal));
|
||||
return
|
||||
(artistItem == null ? "" : artistItem.Metadata.Artist + " - ")
|
||||
+ (titleItem == null ? "" : titleItem.Metadata.Title)
|
||||
+ (yearItem == null ? "" : " (" + yearItem.Metadata.Year + ")")
|
||||
+ (discItem == null ? "" : " [" + discItem.Metadata.DiscNumberAndTotal + "]");
|
||||
}
|
||||
}
|
||||
|
||||
public override int DisplayIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
return icon_mgr.GetIconIndex(GroupTypeToIconTag(GetGroupType(Group)));
|
||||
}
|
||||
}
|
||||
|
||||
public FileSystemTreeNodeLocalDBCollision(CUEControls.IIconManager icon_mgr, List<CUEToolsLocalDBEntry> group, bool showArtist, bool showYear)
|
||||
: base(icon_mgr)
|
||||
{
|
||||
this.Group = group;
|
||||
this.ShowArtist = showArtist;
|
||||
this.ShowYear = showYear;
|
||||
this.SelectedImageIndex = this.ImageIndex = this.DisplayIcon;
|
||||
this.Text = this.DisplayName;
|
||||
}
|
||||
|
||||
internal static string GroupTypeToIconTag(GroupType type)
|
||||
{
|
||||
return type == GroupType.Equal ? ".#picture"
|
||||
: type == GroupType.Offsetted ? ".#pictures"
|
||||
: type == GroupType.Different ? ".#images"
|
||||
: type == GroupType.Unverified ? ".#images_question"
|
||||
: ".#puzzle";
|
||||
}
|
||||
|
||||
internal static string GroupTypeToDescription(GroupType type)
|
||||
{
|
||||
return type == GroupType.Equal ? "Identical clones"
|
||||
: type == GroupType.Offsetted ? "Offsetted clones"
|
||||
: type == GroupType.Different ? "Mismatching clones"
|
||||
: type == GroupType.Unverified ? "Not yet verified clones"
|
||||
: "Unique";
|
||||
}
|
||||
|
||||
internal static GroupType GetGroupType(List<CUEToolsLocalDBEntry> group)
|
||||
{
|
||||
if (group.Count < 2)
|
||||
return GroupType.Single;
|
||||
if (!group.TrueForAll(i => i.OffsetSafeCRC != null))
|
||||
return GroupType.Unverified;
|
||||
if (!group.TrueForAll(i => i.OffsetSafeCRC.DifferByOffset(group[0].OffsetSafeCRC)))
|
||||
return GroupType.Different;
|
||||
if (!group.TrueForAll(i => i.OffsetSafeCRC == group[0].OffsetSafeCRC))
|
||||
return GroupType.Offsetted;
|
||||
return GroupType.Equal;
|
||||
}
|
||||
|
||||
public override void DoExpand()
|
||||
{
|
||||
foreach (var item in Group)
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBEntry(icon_mgr, item, ShowArtist, ShowYear, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSystemTreeNodeLocalDBGroup : FileSystemTreeNodeLocalDBFolder
|
||||
{
|
||||
private int m_icon;
|
||||
private string m_name;
|
||||
public bool ShowArtist { get; set; }
|
||||
public bool ShowYear { get; set; }
|
||||
public override string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
}
|
||||
|
||||
public override int DisplayIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
}
|
||||
|
||||
public FileSystemTreeNodeLocalDBGroup(CUEControls.IIconManager icon_mgr, List<CUEToolsLocalDBEntry> group, bool showArtist, bool showYear, int icon, string name)
|
||||
: base(icon_mgr)
|
||||
{
|
||||
this.Group = group;
|
||||
this.m_icon = icon;
|
||||
this.m_name = name;
|
||||
this.ShowArtist = showArtist;
|
||||
this.ShowYear = showYear;
|
||||
this.SelectedImageIndex = this.ImageIndex = this.DisplayIcon;
|
||||
this.Text = this.DisplayName;
|
||||
}
|
||||
|
||||
private static int Compare(List<CUEToolsLocalDBEntry> a, List<CUEToolsLocalDBEntry> b)
|
||||
{
|
||||
int diff = FileSystemTreeNodeLocalDBCollision.GetGroupType(a) - FileSystemTreeNodeLocalDBCollision.GetGroupType(b);
|
||||
return diff != 0 ? diff :
|
||||
String.Compare(
|
||||
a[0].Metadata.Artist + " - " + a[0].Metadata.Title + " - " + a[0].Metadata.DiscNumberAndTotal,
|
||||
b[0].Metadata.Artist + " - " + b[0].Metadata.Title + " - " + b[0].Metadata.DiscNumberAndTotal);
|
||||
}
|
||||
|
||||
public override void DoExpand()
|
||||
{
|
||||
var byDiscId = CUEToolsLocalDB.Group(Group, i => i.DiscID, (a, b) => Compare(a,b));
|
||||
foreach (var group in byDiscId)
|
||||
{
|
||||
if (group.Count > 1)
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBCollision(icon_mgr, group, ShowArtist, ShowYear));
|
||||
else
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBEntry(icon_mgr, group[0], ShowArtist, ShowYear, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSystemTreeNodeLocalDBCategory : FileSystemTreeNodeLocalDBFolder
|
||||
{
|
||||
private Converter<CUEToolsLocalDBEntry, string> m_converter_key;
|
||||
private Converter<CUEToolsLocalDBEntry, string> m_converter_name;
|
||||
private Converter<CUEToolsLocalDBEntry, int> m_converter_icon;
|
||||
private int m_icon;
|
||||
private string m_name;
|
||||
public bool ShowArtist { get; set; }
|
||||
public bool ShowYear { get; set; }
|
||||
public override string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
}
|
||||
|
||||
public override int DisplayIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_icon;
|
||||
}
|
||||
}
|
||||
|
||||
public FileSystemTreeNodeLocalDBCategory(CUEControls.IIconManager icon_mgr, List<CUEToolsLocalDBEntry> group, bool showArtist, bool showYear, int icon, string name, Converter<CUEToolsLocalDBEntry, string> converter_key, Converter<CUEToolsLocalDBEntry, string> converter_name, Converter<CUEToolsLocalDBEntry, int> converter_icon)
|
||||
: base(icon_mgr)
|
||||
{
|
||||
this.Group = group;
|
||||
this.m_converter_key = converter_key;
|
||||
this.m_converter_name = converter_name ?? converter_key;
|
||||
this.m_converter_icon = converter_icon ?? (i => m_icon);
|
||||
this.m_icon = icon;
|
||||
this.m_name = name;
|
||||
this.ShowArtist = showArtist;
|
||||
this.ShowYear = showYear;
|
||||
this.SelectedImageIndex = this.ImageIndex = this.DisplayIcon;
|
||||
this.Text = this.DisplayName;
|
||||
}
|
||||
|
||||
public override void DoExpand()
|
||||
{
|
||||
foreach (var group in CUEToolsLocalDB.Group(Group, m_converter_key, null))
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBGroup(icon_mgr, group, ShowArtist, ShowYear, m_converter_icon(group[0]), m_converter_name(group[0])));
|
||||
}
|
||||
}
|
||||
|
||||
public class FileSystemTreeNodeLocalDB : FileSystemTreeNodeLocalDBFolder
|
||||
{
|
||||
public override string Path
|
||||
{
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public override string DisplayName
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Local DB";
|
||||
}
|
||||
}
|
||||
|
||||
public override int DisplayIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
return icon_mgr.GetIconIndex(".#puzzle");
|
||||
}
|
||||
}
|
||||
|
||||
public FileSystemTreeNodeLocalDB(CUEControls.IIconManager icon_mgr, List<CUEToolsLocalDBEntry> group)
|
||||
: base(icon_mgr)
|
||||
{
|
||||
this.Group = group;
|
||||
this.SelectedImageIndex = this.ImageIndex = this.DisplayIcon;
|
||||
this.Text = this.DisplayName;
|
||||
}
|
||||
|
||||
public override void DoExpand()
|
||||
{
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBCategory(
|
||||
icon_mgr, this.Group, true, true, icon_mgr.GetIconIndex(".#puzzle"), "By Uniqueness",
|
||||
i => ((int)FileSystemTreeNodeLocalDBCollision.GetGroupType(this.Group.FindAll(j => j.DiscID == i.DiscID))).ToString(),
|
||||
i => FileSystemTreeNodeLocalDBCollision.GroupTypeToDescription(FileSystemTreeNodeLocalDBCollision.GetGroupType(this.Group.FindAll(j => j.DiscID == i.DiscID))),
|
||||
i => icon_mgr.GetIconIndex(FileSystemTreeNodeLocalDBCollision.GroupTypeToIconTag(FileSystemTreeNodeLocalDBCollision.GetGroupType(this.Group.FindAll(j => j.DiscID == i.DiscID)))))); //converter_icon
|
||||
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBCategory(
|
||||
icon_mgr, this.Group, true, true, icon_mgr.GetIconIndex(".flac"), "By Format",
|
||||
i => i.AudioPaths == null || i.AudioPaths.Count == 0 ? null : System.IO.Path.GetExtension(i.AudioPaths[0]).ToLower(),
|
||||
null,
|
||||
i => icon_mgr.GetIconIndex(i.AudioPaths[0])));
|
||||
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBCategory(
|
||||
icon_mgr, this.Group, false, true, icon_mgr.GetIconIndex(".#users"), "By Artist",
|
||||
i => i.Metadata.Artist, null, null));
|
||||
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBCategory(
|
||||
icon_mgr, this.Group, true, false, icon_mgr.GetIconIndex(".#calendar"), "By Release Date",
|
||||
i => i.Metadata.Year, null, null));
|
||||
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBCategory(
|
||||
icon_mgr, this.Group, true, true, icon_mgr.GetIconIndex(".#alarm_clock"), "By Verification Date",
|
||||
i =>
|
||||
i.VerificationDate == DateTime.MinValue ? "0" :
|
||||
i.VerificationDate.AddHours(1) > DateTime.Now ? "1" :
|
||||
i.VerificationDate.AddDays(1) > DateTime.Now ? "2" :
|
||||
i.VerificationDate.AddDays(7) > DateTime.Now ? "3" :
|
||||
i.VerificationDate.AddDays(31) > DateTime.Now ? "4" :
|
||||
i.VerificationDate.AddDays(365) > DateTime.Now ? "5" :
|
||||
"6",
|
||||
i =>
|
||||
i.VerificationDate == DateTime.MinValue ? "never" :
|
||||
i.VerificationDate.AddHours(1) > DateTime.Now ? "this hour" :
|
||||
i.VerificationDate.AddDays(1) > DateTime.Now ? "this day" :
|
||||
i.VerificationDate.AddDays(7) > DateTime.Now ? "this week" :
|
||||
i.VerificationDate.AddDays(31) > DateTime.Now ? "this month" :
|
||||
i.VerificationDate.AddDays(365) > DateTime.Now ? "this year" :
|
||||
"more than a year ago",
|
||||
null));
|
||||
|
||||
this.Nodes.Add(new FileSystemTreeNodeLocalDBCategory(
|
||||
icon_mgr, this.Group, true, true, icon_mgr.GetIconIndex(".#ar"), "By AccurateRip Confidence",
|
||||
i =>
|
||||
i.VerificationDate == DateTime.MinValue ? "00" :
|
||||
i.ARConfidence == 0 ? "01" :
|
||||
i.ARConfidence == 1 ? "02" :
|
||||
i.ARConfidence == 2 ? "03" :
|
||||
i.ARConfidence == 3 ? "04" :
|
||||
i.ARConfidence < 5 ? "05" :
|
||||
i.ARConfidence < 10 ? "06" :
|
||||
i.ARConfidence < 20 ? "07" :
|
||||
i.ARConfidence < 50 ? "08" :
|
||||
i.ARConfidence < 100 ? "09" :
|
||||
"10",
|
||||
i =>
|
||||
i.VerificationDate == DateTime.MinValue ? "?" :
|
||||
i.ARConfidence == 0 ? "0" :
|
||||
i.ARConfidence == 1 ? "1" :
|
||||
i.ARConfidence == 2 ? "2" :
|
||||
i.ARConfidence == 3 ? "3" :
|
||||
i.ARConfidence < 5 ? "< 5" :
|
||||
i.ARConfidence < 10 ? "< 10" :
|
||||
i.ARConfidence < 20 ? "< 20" :
|
||||
i.ARConfidence < 50 ? "< 50" :
|
||||
i.ARConfidence < 100 ? "< 100" :
|
||||
">=100",
|
||||
null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user