Skip to content

Commit

Permalink
definition load filter
Browse files Browse the repository at this point in the history
  • Loading branch information
barncastle committed Jul 13, 2018
1 parent 1965840 commit 0aec1fb
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 112 deletions.
210 changes: 112 additions & 98 deletions WDBXEditor/Forms/LoadDefinition.Designer.cs

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

37 changes: 23 additions & 14 deletions WDBXEditor/Forms/LoadDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private void lbDefinitions_MouseDoubleClick(object sender, MouseEventArgs e)
}
#endregion

private void LoadBuilds()
private void LoadBuilds(bool mostRecent = true)
{
if (Database.Definitions.Tables.Count == 0)
{
Expand All @@ -92,20 +92,24 @@ private void LoadBuilds()
}

//Get compatible builds only
bool db2 = Files.Any(x => Path.GetExtension(x).IndexOf("db2", IGNORECASE) >= 0);
bool adb = Files.Any(x => Path.GetExtension(x).IndexOf("adb", IGNORECASE) >= 0);
bool db2 = Files.Any(x => Path.GetExtension(x).IndexOf("db2", IGNORECASE) >= 0) || Files.Any(x => Path.GetExtension(x).IndexOf("adb", IGNORECASE) >= 0);

var files = Files.Select(x => Path.GetFileNameWithoutExtension(x).ToLower());
var datasource = Database.Definitions.Tables
.Where(x => files.Contains(x.Name.ToLower()))
.Select(x => new { Key = x.Build, Value = x.BuildText })
.Distinct()
.OrderBy(x => x.Key);
//Filter out non DB2/ADB clients
if (db2 || adb)
datasource = datasource.Where(x => x.Key > (int)ExpansionFinalBuild.WotLK).OrderBy(x => x.Key);

lbDefinitions.BeginUpdate();
var datasource = Database.Definitions.Tables
.Where(x => files.Contains(x.Name.ToLower()))
.Select(x => new { Key = x.Build, Value = x.BuildText })
.Distinct()
.Where(x => db2 ? x.Key > (int)ExpansionFinalBuild.WotLK : true); // filter out non DB2/ADB clients

// filter to the latest build for each version
if (mostRecent)
datasource = datasource.GroupBy(x => x.Value.Split('(').First()).Select(x => x.Aggregate((a, b) => a.Key > b.Key ? a : b));

// order
datasource = datasource.OrderBy(x => x.Key);


lbDefinitions.BeginUpdate();

if (datasource.Count() == 0)
{
Expand All @@ -126,5 +130,10 @@ private void SetFileText()
{
lblFiles.Text = Files.Count() == 1 ? "1 file" : Files.Count() + " files";
}
}

private void chkBuildFilter_CheckedChanged(object sender, EventArgs e)
{
LoadBuilds(!chkBuildFilter.Checked);
}
}
}

0 comments on commit 0aec1fb

Please sign in to comment.