Skip to content

Commit

Permalink
vpforum relations updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xantari committed Jan 10, 2021
1 parent 45b9d7d commit 0eaaa88
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 33 deletions.
7 changes: 4 additions & 3 deletions PinCab.Configurator/DatabaseBrowserForm.Designer.cs

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

28 changes: 23 additions & 5 deletions PinCab.Configurator/DatabaseBrowserForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,21 @@ private List<DatabaseBrowserEntry> GetEntriesByFilterCriteria()
var tags = GetAllSelectedTags();
if (tags != null && tags.Count > 0)
{
list = list.Where(c => c.Tags.Any(g => tags.Contains(g)));
list = list.Where(c => c.Tags.Any(g => tags.Contains(g))
|| c.RelatedEntries.Any(d => d.Tags.Any(k => tags.Contains(k)))
);
}
return list.ToList();
}

private void RebindGridUsingFilter()
{
vpinDatabaseSettingBindingSource.DataSource = GetEntriesByFilterCriteria().ToSortableBindingList();
var list = GetEntriesByFilterCriteria();
vpinDatabaseSettingBindingSource.DataSource = list.ToSortableBindingList();
var tags = _dbManager.GetAllTags(list.ToList(), false).OrderBy(c => c).ToList();
tags.Insert(0, "(Select Tag)");
cmbTags.DataSource = tags;
UpdateToolstripStatus();
}

private void contextMenuStripGridActions_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
Expand Down Expand Up @@ -263,7 +270,7 @@ private void backgroundWorkerProgressBar_RunWorkerCompleted(object sender, RunWo
private void UpdateToolstripStatus()
{
var entriesInGrid = vpinDatabaseSettingBindingSource.DataSource as SortableBindingList<DatabaseBrowserEntry>;
toolStripStatusLabel.Text = "Total Database Entries: " + entriesInGrid.Count.ToString();
toolStripStatusLabel.Text = $"Total Database Entries: {_dbManager.Entries.Count} Filtered: {entriesInGrid.Count}";
}

private void backgroundWorkerProgressBar_DoWork(object sender, DoWorkEventArgs e)
Expand Down Expand Up @@ -339,8 +346,8 @@ private ToolResult LoadTags()
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
//var tagsByCritera = GetEntriesByFilterCriteria(); //vs: _dbManager.Entries (all entries)
//var list =
var tags = _dbManager.GetAllTags(_dbManager.Entries).OrderBy(c => c).ToList();
var list = vpinDatabaseSettingBindingSource.DataSource as SortableBindingList<DatabaseBrowserEntry>;
var tags = _dbManager.GetAllTags(list.ToList()).OrderBy(c => c).ToList();
tags.Insert(0, "(Select Tag)");
var toolResult = new ToolResult();
toolResult.ToolName = DatabaseManager.ToolName;
Expand Down Expand Up @@ -474,6 +481,8 @@ private void goToUrlToolStripMenuItem_Click(object sender, EventArgs e)

private void dataGridViewEntryList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex == -1 || e.ColumnIndex == -1)
return;
var row = GetActiveRowEntry();
if (row != null)
{
Expand All @@ -483,5 +492,14 @@ private void dataGridViewEntryList_CellDoubleClick(object sender, DataGridViewCe
}
}
}

private void dataGridViewEntryList_RowContextMenuStripNeeded(object sender, DataGridViewRowContextMenuStripNeededEventArgs e)
{
var row = GetActiveRowEntry();
if (!row.IpdbId.HasValue)
contextMenuStripGridActions.Items["IpdbInfoToolStripMenuItem"].Enabled = false;
else
contextMenuStripGridActions.Items["IpdbInfoToolStripMenuItem"].Enabled = true;
}
}
}
18 changes: 17 additions & 1 deletion PinCab.Utils/Models/DatabaseBrowserEntry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using PinCab.Utils.Extensions;
using Newtonsoft.Json;
using PinCab.Utils.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -24,6 +25,21 @@ public DatabaseBrowserEntry()
public string Version { get; set; }
public DateTime LastUpdated { get; set; }

[JsonIgnore]
public Uri Uri
{
get
{
Uri uriResult;
bool result = Uri.TryCreate(Url, UriKind.Absolute, out uriResult)
&& (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
if (result)
return uriResult;
else
return null;
}
}

public string TypeString
{
get
Expand Down
83 changes: 59 additions & 24 deletions PinCab.Utils/Utils/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public ToolResult RefreshAllDatabases()
result.Result = true;
_settingManager.SaveSettings(_settings);
}
else
else
{
result.Result = false; //We didn't re-download anything
}
Expand Down Expand Up @@ -245,15 +245,15 @@ public List<DatabaseBrowserEntry> GetAllEntries(bool forceReload)
//Write the preprocessed database so next load is faster
SaveDatabaseCache(entries, preprocessedDatabasePath);
}
else
else
{
_reportProgress?.Invoke(10);
entries = JsonConvert.DeserializeObject<List<DatabaseBrowserEntry>>(File.ReadAllText(preprocessedDatabasePath));
Entries = entries;
Log.Information("{toolname}: Loaded preprocessed database.", ToolName, preprocessedDatabasePath);
_reportProgress?.Invoke(100);
}

return entries;
}

Expand Down Expand Up @@ -367,45 +367,71 @@ private List<DatabaseBrowserEntry> GetVpForumsEntries()
foreach (var item in VpforumDatabase.BackglassFiles)
{
var entry = GetBackglassEntry(item, DatabaseType.VPForums);
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Url == entry.Url));
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Uri?.PathAndQuery.ToLower() == entry.Uri?.PathAndQuery.ToLower())); //Ignore differences in http:// vs https:// in URL and only look at the path string
if (relatedGame != null) //Create the reverse link to the game
{
entry.RelatedEntries.Add(relatedGame);
entry.IpdbId = relatedGame.IpdbId;
entry.Tags.AddRange(GetIpdbTags(relatedGame));
//Could add all the related game tags here too, but maybe a bit too busy?
entry.Tags = entry.Tags.NormalizeTagList();
}
entries.Add(entry);
}

foreach (var item in VpforumDatabase.MediaPackFiles)
{
var entry = GetMediaPackEntry(item, DatabaseType.VPForums);
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Url == entry.Url));
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Uri?.PathAndQuery.ToLower() == entry.Uri?.PathAndQuery.ToLower())); //Ignore differences in http:// vs https:// in URL and only look at the path string
if (relatedGame != null) //Create the reverse link to the game
{
entry.RelatedEntries.Add(relatedGame);
entry.IpdbId = relatedGame.IpdbId;
entry.Tags.AddRange(GetIpdbTags(relatedGame));
entry.Tags = entry.Tags.NormalizeTagList();
}
entries.Add(entry);
}

foreach (var item in VpforumDatabase.RomFiles)
{
var entry = GetRomEntry(item, DatabaseType.VPForums);
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Url == entry.Url));
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Uri?.PathAndQuery.ToLower() == entry.Uri?.PathAndQuery.ToLower())); //Ignore differences in http:// vs https:// in URL and only look at the path string
if (relatedGame != null) //Create the reverse link to the game
{
entry.RelatedEntries.Add(relatedGame);
entry.IpdbId = relatedGame.IpdbId;
entry.Tags.AddRange(GetIpdbTags(relatedGame));
entry.Tags = entry.Tags.NormalizeTagList();
}
entries.Add(entry);
}

foreach (var item in VpforumDatabase.TopperFiles)
{
var entry = GetTopperEntry(item, DatabaseType.VPForums);
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Url == entry.Url));
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Uri?.PathAndQuery.ToLower() == entry.Uri?.PathAndQuery.ToLower())); //Ignore differences in http:// vs https:// in URL and only look at the path string
if (relatedGame != null) //Create the reverse link to the game
{
entry.RelatedEntries.Add(relatedGame);
entry.IpdbId = relatedGame.IpdbId;
entry.Tags.AddRange(GetIpdbTags(relatedGame));
entry.Tags = entry.Tags.NormalizeTagList();
}
entries.Add(entry);
}

foreach (var item in VpforumDatabase.WheelArtFiles)
{
var entry = GetWheelEntry(item, DatabaseType.VPForums);
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Url == entry.Url));
var relatedGame = entries.FirstOrDefault(c => c.Type == DatabaseEntryType.Table && c.RelatedEntries.Any(g => g.Uri?.PathAndQuery.ToLower() == entry.Uri?.PathAndQuery.ToLower())); //Ignore differences in http:// vs https:// in URL and only look at the path string
if (relatedGame != null) //Create the reverse link to the game
{
entry.RelatedEntries.Add(relatedGame);
entry.IpdbId = relatedGame.IpdbId;
entry.Tags.AddRange(GetIpdbTags(relatedGame));
entry.Tags = entry.Tags.NormalizeTagList();
}
entries.Add(entry);
}

Expand Down Expand Up @@ -524,7 +550,7 @@ private string NormalizeTag(string tag)
|| t == "vpx 10.6" || t == "vp10" || t.Contains("vpx")
)
t = "VPX";
else if (t == "vtp 9.9.5" || t == "vp92" || t == "vp915" || t== "vpinmame 9 recreations" || t == "vpinmame 9.x recreations"
else if (t == "vtp 9.9.5" || t == "vp92" || t == "vp915" || t == "vpinmame 9 recreations" || t == "vpinmame 9.x recreations"
|| t == "vp9 fs cabinet b2s table." || t == "vp9" || t == "vp 9" || t == "vp 9.x" || t == "visual pinball 9"
|| t == "bs70 vp 9.x cabinet fs b2s" || t == "bs80 vp 9.x cabinet fs b2s" || t == "vp9.2"
)
Expand All @@ -541,10 +567,11 @@ private string NormalizeTag(string tag)
}


public HashSet<string> GetAllTags(List<DatabaseBrowserEntry> entries)
public HashSet<string> GetAllTags(List<DatabaseBrowserEntry> entries, bool reportProgress = true)
{
var tags = new HashSet<string>();
_reportProgress?.Invoke(50);
if (reportProgress)
_reportProgress?.Invoke(50);
if (Entries == null)
{
Log.Warning("{tool}: Database not loaded yet. Load database using GetAllEntries()", ToolName);
Expand All @@ -556,7 +583,8 @@ public HashSet<string> GetAllTags(List<DatabaseBrowserEntry> entries)
foreach (var itm in entryTags)
tags.Add(itm);
}
_reportProgress?.Invoke(100);
if (reportProgress)
_reportProgress?.Invoke(100);
return tags;
}

Expand Down Expand Up @@ -616,18 +644,8 @@ private DatabaseBrowserEntry GetVpGameEntry(VpGame file, DatabaseType dbType)
entry.Description += "\r\n\r\n" + file.Features;
entry.Tags.AddRange(file.FeatureFlags.ConvertFeatureFlagsToTags());

List<string> TagsByIpdbNumber = new List<string>();
if (entry.IpdbId.HasValue)
{
var ipdbTags = GetTagsByIpdbNumber(entry.IpdbId.Value);
foreach (var tag in ipdbTags)
{
var t = NormalizeTag(tag);
if (!string.IsNullOrEmpty(t))
entry.Tags.Add(t);
}
}

List<string> TagsByIpdbNumber = GetIpdbTags(entry);
entry.Tags.AddRange(TagsByIpdbNumber);
entry.Tags = entry.Tags.NormalizeTagList();

//Get related media
Expand Down Expand Up @@ -733,6 +751,23 @@ private DatabaseBrowserEntry GetVpGameEntry(VpGame file, DatabaseType dbType)
return entry;
}

private List<string> GetIpdbTags(DatabaseBrowserEntry entry)
{
var list = new List<string>();
if (entry.IpdbId.HasValue)
{
var ipdbTags = GetTagsByIpdbNumber(entry.IpdbId.Value);
foreach (var tag in ipdbTags)
{
var t = NormalizeTag(tag);
if (!string.IsNullOrEmpty(t))
list.Add(t);
}
}

return list.NormalizeTagList();
}

private DatabaseBrowserEntry GetWheelEntry(WheelArtFile file, DatabaseType dbType)
{
if (file != null)
Expand Down

0 comments on commit 0eaaa88

Please sign in to comment.