mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-14 16:27:21 +00:00
Merge pull request #679 from kwsch/r/better-database-init
More database speed improvements
This commit is contained in:
commit
dcb3745cc1
1 changed files with 8 additions and 12 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
@ -81,27 +82,22 @@ namespace PKHeX
|
||||||
p.ContextMenuStrip = mnu;
|
p.ContextMenuStrip = mnu;
|
||||||
|
|
||||||
// Load Data
|
// Load Data
|
||||||
RawDB = new List<PKM>();
|
var dbTemp = new ConcurrentBag<PKM>();
|
||||||
var files = Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories);
|
var files = Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories);
|
||||||
Parallel.ForEach(files, file =>
|
Parallel.ForEach(files, file =>
|
||||||
{
|
{
|
||||||
FileInfo fi = new FileInfo(file);
|
FileInfo fi = new FileInfo(file);
|
||||||
if (!fi.Extension.Contains(".pk") || !PKX.getIsPKM(fi.Length)) return;
|
if (!fi.Extension.Contains(".pk") || !PKX.getIsPKM(fi.Length)) return;
|
||||||
var pk = PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file);
|
var pk = PKMConverter.getPKMfromBytes(File.ReadAllBytes(file), file);
|
||||||
if (pk == null)
|
if (pk != null)
|
||||||
return;
|
dbTemp.Add(pk);
|
||||||
lock (RawDB)
|
|
||||||
RawDB.Add(pk);
|
|
||||||
});
|
});
|
||||||
RawDB = new List<PKM>(RawDB.Where(pk => pk != null).OrderBy(pk => pk.Identifier));
|
|
||||||
|
|
||||||
// Fetch from save file
|
|
||||||
foreach (var pkm in Main.SAV.BoxData.Where(pk => pk.Species != 0))
|
|
||||||
RawDB.Add(pkm);
|
|
||||||
|
|
||||||
// Prepare Database
|
// Prepare Database
|
||||||
RawDB = new List<PKM>(RawDB.Where(pk => pk.ChecksumValid && pk.Species != 0 && pk.Sanity == 0));
|
RawDB = new List<PKM>(dbTemp.OrderBy(pk => pk.Identifier)
|
||||||
RawDB = new List<PKM>(RawDB.Distinct());
|
.Concat(Main.SAV.BoxData.Where(pk => pk.Species != 0)) // Fetch from save file
|
||||||
|
.Where(pk => pk.ChecksumValid && pk.Species != 0 && pk.Sanity == 0)
|
||||||
|
.Distinct());
|
||||||
setResults(RawDB);
|
setResults(RawDB);
|
||||||
|
|
||||||
Menu_SearchSettings.DropDown.Closing += (sender, e) =>
|
Menu_SearchSettings.DropDown.Closing += (sender, e) =>
|
||||||
|
|
Loading…
Reference in a new issue