mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-22 20:13:06 +00: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:
parent
da8ba46d22
commit
d8c2cdb8e3
5 changed files with 7 additions and 7 deletions
|
@ -164,7 +164,7 @@ namespace PKHeX.Core
|
|||
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 @@ namespace PKHeX.Core
|
|||
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 @@ namespace PKHeX.Core
|
|||
/// <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 @@ namespace PKHeX.WinForms
|
|||
{
|
||||
// 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 @@ namespace PKHeX.WinForms
|
|||
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 @@ namespace PKHeX.WinForms
|
|||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue