mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-10-01 07:26:42 -05:00
Use EnumerateFiles over GetFiles in some cases
https://msdn.microsoft.com/en-us/library/07wt70x2.aspx iterating as an ienumerable (ie not consuming the whole collection) can be more efficient by not waiting for the whole collection
This commit is contained in:
@@ -164,7 +164,7 @@ public static void RefreshMGDB(string localDbPath)
|
||||
var g7 = GetWC7DB(Util.GetBinaryResource("wc7.pkl"), Util.GetBinaryResource("wc7full.pkl"));
|
||||
|
||||
if (Directory.Exists(localDbPath))
|
||||
foreach (var file in Directory.GetFiles(localDbPath, "*", SearchOption.AllDirectories))
|
||||
foreach (var file in Directory.EnumerateFiles(localDbPath, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
var fi = new FileInfo(file);
|
||||
if (!MysteryGift.IsMysteryGift(fi.Length))
|
||||
|
||||
@@ -581,7 +581,7 @@ public static bool GetSavesFromFolder(string folderPath, bool deep, out IEnumera
|
||||
try
|
||||
{
|
||||
var searchOption = deep ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
||||
var files = Directory.GetFiles(folderPath, "*", searchOption);
|
||||
var files = Directory.EnumerateFiles(folderPath, "*", searchOption);
|
||||
result = files.Where(f => IsSizeValid((int)new FileInfo(f).Length));
|
||||
return true;
|
||||
}
|
||||
@@ -1015,7 +1015,7 @@ public static ushort[] AdvanceGCKeys(ushort[] oldKeys)
|
||||
/// <param name="input">Encrypted byte array of savedata to decrypt.</param>
|
||||
/// <param name="XORpads">Array of possible paths to check for xorpad compatibility.</param>
|
||||
/// <returns>Returns a <see cref="SaveFile"/> if decryption was successful, else null.</returns>
|
||||
public static SaveFile GetSAVfromXORpads(byte[] input, string[] XORpads)
|
||||
public static SaveFile GetSAVfromXORpads(byte[] input, IEnumerable<string> XORpads)
|
||||
{
|
||||
byte[] savID = new byte[0x10];
|
||||
Array.Copy(input, 0x10, savID, 0, 0x10);
|
||||
|
||||
@@ -651,13 +651,13 @@ private bool OpenXOR(byte[] input, string path)
|
||||
{
|
||||
// try to get a save file via xorpad in same folder
|
||||
var folder = new DirectoryInfo(path).Parent.FullName;
|
||||
string[] pads = Directory.GetFiles(folder);
|
||||
var pads = Directory.EnumerateFiles(folder);
|
||||
var s = SaveUtil.GetSAVfromXORpads(input, pads);
|
||||
|
||||
if (s == null) // failed to find xorpad in path folder
|
||||
{
|
||||
// try again
|
||||
pads = Directory.GetFiles(WorkingDirectory);
|
||||
pads = Directory.EnumerateFiles(WorkingDirectory);
|
||||
s = SaveUtil.GetSAVfromXORpads(input, pads);
|
||||
}
|
||||
|
||||
|
||||
@@ -329,7 +329,7 @@ private void GenerateDBReport(object sender, EventArgs e)
|
||||
private void LoadDatabase()
|
||||
{
|
||||
var dbTemp = new ConcurrentBag<PKM>();
|
||||
var files = Directory.GetFiles(DatabasePath, "*", SearchOption.AllDirectories);
|
||||
var files = Directory.EnumerateFiles(DatabasePath, "*", SearchOption.AllDirectories);
|
||||
Parallel.ForEach(files, file =>
|
||||
{
|
||||
FileInfo fi = new FileInfo(file);
|
||||
|
||||
@@ -102,7 +102,7 @@ public static bool LoadBoxes(this SaveFile SAV, string path, out string result,
|
||||
int maxCount = SAV.BoxCount*SAV.BoxSlotCount;
|
||||
int ctr = startCount;
|
||||
int pastctr = 0;
|
||||
string[] filepaths = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly);
|
||||
var filepaths = Directory.EnumerateFiles(path, "*.*", SearchOption.TopDirectoryOnly);
|
||||
|
||||
foreach (var file in filepaths)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user