Skip to content

Commit

Permalink
fixed related entry loading, null loading, switched to hashsets (shou…
Browse files Browse the repository at this point in the history
…ld be faster)
  • Loading branch information
xantari committed Mar 25, 2021
1 parent 037d0af commit 9b4ff87
Show file tree
Hide file tree
Showing 8 changed files with 926 additions and 164 deletions.
321 changes: 170 additions & 151 deletions PinCab.Configurator/DatabaseBrowserForm.Designer.cs

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions PinCab.Configurator/DatabaseBrowserForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ private void txtSearch_TextChanged(object sender, EventArgs e)

private List<DatabaseBrowserEntry> GetEntriesByFilterCriteria()
{
string searchTerm = txtSearch.Text.ToLower();
IEnumerable<DatabaseBrowserEntry> list;
list = _dbManager.Entries.Where(p => (p.Title.FuzzyMatch(txtSearch.Text) > .5)
|| p.Title.ToLower().Contains(txtSearch.Text.ToLower())); //Search by text
list = _dbManager.Entries.Where(p => //(p.Title.FuzzyMatch(txtSearch.Text) > .1)
p.Title.ToLower().Contains(searchTerm)
|| p.Description.ToLower().Contains(searchTerm)
); //Search by text

list = list.Where(p => p.LastUpdated <= dateTimePickerEnd.Value.EndOfDay()
&& p.LastUpdated >= dateTimePickerBegin.Value.BeginningOfDay());
Expand Down Expand Up @@ -671,5 +674,16 @@ private void chkFuzzyMatch_CheckedChanged(object sender, EventArgs e)
if (!_loading)
RebindGridUsingFilter();
}

private void editToolStripMenuItem_Click(object sender, EventArgs e)
{
//Get the source database entry

//Load the form

//Upon Successful response update the entry

//Save the pre-processed database again
}
}
}
482 changes: 482 additions & 0 deletions PinCab.Configurator/EditDatabaseEntryForm.Designer.cs

Large diffs are not rendered by default.

100 changes: 100 additions & 0 deletions PinCab.Configurator/EditDatabaseEntryForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using PinCab.Utils;
using PinCab.Utils.Extensions;
using PinCab.Utils.Models;
using PinCab.Utils.Utils;
using PinCab.Utils.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PinCab.Configurator
{
public partial class EditDatabaseEntryForm : Form
{
private FrontEndGameViewModel _setting { get; set; }
//private string originalFileName { get; set; }
private FrontEndManager _manager { get; set; }
private string _databaseFile { get; set; }
private IpdbBrowserForm _ipdbForm = null;
private bool isNewEntry = false;
public EditDatabaseEntryForm(FrontEndGameViewModel setting, string databaseFile, FrontEndManager manager, IpdbBrowserForm ipdbForm)
{
InitializeComponent();
}

private void LoadForm()
{
txtManufacturer.Text = _setting.Manufacturer;
txtTheme.Text = _setting.Theme;
txtAuthor.Text = _setting.Author;
txtVersion.Text = _setting.Version;
txtIpdb.Text = _setting.IPDBNumber;
txtAdded.Text = _setting.DateAdded.ToString();
txtGameUrl.Text = _setting.TableFileUrl;
}

private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}

private void btnSave_Click(object sender, EventArgs e)
{
//var result = GetSettingFromControls();
//if (string.IsNullOrEmpty(result.Description))
//{
// MessageBox.Show("Description is a required field");
// return;
//}
//if (string.IsNullOrEmpty(result.FileName))
//{
// MessageBox.Show("File Name is a required field");
// return;
//}

//_manager.SaveGame(result, null);
//DialogResult = DialogResult.OK;
//Close();
}

private void btnIpdbUrl_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtIpdb.Text))
System.Diagnostics.Process.Start("https://www.ipdb.org/machine.cgi?id=" + txtIpdb.Text);
}

private void btnFillFromIpdb_Click(object sender, EventArgs e)
{
//_ipdbForm.SearchText(txtTableName.Text);
//if (isNewEntry)
// _ipdbForm.chkOverrideDisplayName.Checked = true;
//var result = _ipdbForm.ShowDialog(this);
//if (result == DialogResult.OK)
//{
// //Fill the data
// var ipdbEntry = _ipdbForm.GetActiveRowEntry();
// if (_ipdbForm.chkOverrideDisplayName.Checked)
// txtDisplayName.Text = ipdbEntry.Title;
// txtManufacturer.Text = ipdbEntry.ManufacturerShortName;
// txtYear.Text = ipdbEntry.DateOfManufacture?.Year.ToString();
// txtTheme.Text = ipdbEntry.Theme;
// txtIpdb.Text = ipdbEntry.IpdbId.ToString();
// txtType.Text = ipdbEntry.TypeShortName;
// txtPlayers.Text = ipdbEntry.Players.ToString();
//}
}

private void btnGameUrl_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtGameUrl.Text))
System.Diagnostics.Process.Start(txtGameUrl.Text);
}
}
}
123 changes: 123 additions & 0 deletions PinCab.Configurator/EditDatabaseEntryForm.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="colorDialogDmdColor.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
9 changes: 9 additions & 0 deletions PinCab.Configurator/Pincab.Configurator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@
<Compile Include="AboutBoxForm.Designer.cs">
<DependentUpon>AboutBoxForm.cs</DependentUpon>
</Compile>
<Compile Include="EditDatabaseEntryForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="EditDatabaseEntryForm.Designer.cs">
<DependentUpon>EditDatabaseEntryForm.cs</DependentUpon>
</Compile>
<Compile Include="RenameGameForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -247,6 +253,9 @@
<EmbeddedResource Include="AboutBoxForm.resx">
<DependentUpon>AboutBoxForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="EditDatabaseEntryForm.resx">
<DependentUpon>EditDatabaseEntryForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="RenameGameForm.resx">
<DependentUpon>RenameGameForm.cs</DependentUpon>
</EmbeddedResource>
Expand Down
8 changes: 4 additions & 4 deletions PinCab.Utils/Models/DatabaseBrowserEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class DatabaseBrowserEntry
{
public DatabaseBrowserEntry()
{
RelatedEntries = new List<DatabaseBrowserEntry>();
Tags = new List<string>();
RelatedEntries = new HashSet<DatabaseBrowserEntry>();
Tags = new HashSet<string>();
}
public int Id { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string ChangeLog { get; set; }
public string Authors { get; set; }
public List<string> Tags { get; set; }
public HashSet<string> Tags { get; set; }
public string Url { get; set; }
public int? IpdbId { get; set; }
public string Version { get; set; }
Expand Down Expand Up @@ -53,7 +53,7 @@ public string DatabaseTagsString
}
}

public List<DatabaseBrowserEntry> RelatedEntries { get; set; }
public HashSet<DatabaseBrowserEntry> RelatedEntries { get; set; }

public Uri GetUri()
{
Expand Down
29 changes: 22 additions & 7 deletions PinCab.Utils/Utils/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,30 @@ public List<DatabaseBrowserEntry> GetEntrysByDatabase(ContentDatabase database,
return null;
}

private List<DatabaseBrowserEntry> GetDatabaseBrowserEntries(ContentDatabase database)
private HashSet<DatabaseBrowserEntry> GetDatabaseBrowserEntries(ContentDatabase database)
{
List<DatabaseBrowserEntry> entries = new List<DatabaseBrowserEntry>();
HashSet<DatabaseBrowserEntry> entries = new HashSet<DatabaseBrowserEntry>();
foreach (var databaseEntry in Databases[database.Name].Entries)
{
var entry = GetDatabaseBrowserEntry(database, databaseEntry);
if (IsValidBrowserEntry(entry))
entries.Add(entry);
else
Log.Information("{tool}: Skipped adding {entry} because it didn't pass the data check.", ToolName, entry.Title);

//Add the related entries
foreach(var relatedEntry in databaseEntry.RelatedEntries)
{
var relatedContentEntry = Databases[database.Name].Entries.FirstOrDefault(c => c.Id == relatedEntry);
var newEntry = GetDatabaseBrowserEntry(database, relatedContentEntry);
if (IsValidBrowserEntry(newEntry))
{
entry.RelatedEntries.Add(newEntry);
entry.Tags.UnionWith(newEntry.Tags);
}
else
Log.Information("{tool}: Skipped related entry adding {entry} because it didn't pass the data check.", ToolName, relatedContentEntry.Title);
}
}

//Rescan the related entries and fill in missing tags that we were able to find for the URL in a different
Expand Down Expand Up @@ -311,7 +325,8 @@ public HashSet<string> GetAllTags(List<DatabaseBrowserEntry> entries, bool repor
{
var entryTags = GetTags(entry);
foreach (var itm in entryTags)
tags.Add(itm);
if (itm != null)
tags.Add(itm);
}
if (reportProgress)
_reportProgress?.Invoke(100);
Expand Down Expand Up @@ -352,7 +367,7 @@ private DatabaseBrowserEntry GetDatabaseBrowserEntry(ContentDatabase database, D
Type = file.MajorCategory,
Url = file.Url,
Version = file.Version,
Tags = file.Tags,
Tags = file.Tags.ToHashSet<string>(),
DatabaseName = database.Name,
LastUpdated = file.LastModifiedDateUtc.HasValue ? file.LastModifiedDateUtc.Value : new DateTime(1900, 1, 1),
};
Expand All @@ -372,11 +387,11 @@ private DatabaseBrowserEntry GetDatabaseBrowserEntry(ContentDatabase database, D
entry.Description += "\r\n\r\nFeatures:\r\n" + file.Features;

var tableInfoTags = file.ConvertTableInfoToTags();
entry.Tags.AddRange(tableInfoTags);
entry.Tags.UnionWith(tableInfoTags);

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

return entry;
}
Expand Down

0 comments on commit 9b4ff87

Please sign in to comment.