mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Traverse] Add edc's traverse code (not hooked up)
This commit is contained in:
72
SabreTools.Helper/External/Traverse.cs
vendored
Normal file
72
SabreTools.Helper/External/Traverse.cs
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
#if MONO
|
||||||
|
using System.IO;
|
||||||
|
#else
|
||||||
|
using Alphaleonis.Win32.Filesystem;
|
||||||
|
|
||||||
|
using IOException = System.IO.IOException;
|
||||||
|
using SearchOption = System.IO.SearchOption;
|
||||||
|
#endif
|
||||||
|
using SabreTools.Helper.Data;
|
||||||
|
|
||||||
|
namespace SabreTools.Helper.External
|
||||||
|
{
|
||||||
|
public class Traverse
|
||||||
|
{
|
||||||
|
/// Original version: Microsoft (example code), updated by edc
|
||||||
|
public void TraverseTreeParallelForEach(string root, Action<FileInfo> action)
|
||||||
|
{
|
||||||
|
List<string> dirs = new List<string>();
|
||||||
|
|
||||||
|
if (!Directory.Exists(root))
|
||||||
|
{
|
||||||
|
throw new ArgumentException();
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs.Add(root);
|
||||||
|
|
||||||
|
List<string> subdirs = new List<string>();
|
||||||
|
|
||||||
|
while (dirs.Count > 0 || subdirs.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (string dir in subdirs)
|
||||||
|
{
|
||||||
|
dirs.Add(dir);
|
||||||
|
}
|
||||||
|
subdirs.Clear();
|
||||||
|
|
||||||
|
Parallel.ForEach(dirs,
|
||||||
|
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||||
|
currentDir =>
|
||||||
|
{
|
||||||
|
string[] subDirs = Directory.GetDirectories(currentDir);
|
||||||
|
|
||||||
|
lock (subdirs)
|
||||||
|
{
|
||||||
|
foreach (string str in subDirs)
|
||||||
|
{
|
||||||
|
subdirs.Add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var dir = new DirectoryInfo(currentDir);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FileInfo[] files = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly);
|
||||||
|
Parallel.ForEach(files,
|
||||||
|
new ParallelOptions() { MaxDegreeOfParallelism = Globals.MaxDegreeOfParallelism },
|
||||||
|
info =>
|
||||||
|
{
|
||||||
|
action(info);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
});
|
||||||
|
dirs.Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -124,6 +124,7 @@
|
|||||||
<Compile Include="External\NaturalSort\NaturalComparer.cs" />
|
<Compile Include="External\NaturalSort\NaturalComparer.cs" />
|
||||||
<Compile Include="External\NaturalSort\NaturalReversedComparer.cs" />
|
<Compile Include="External\NaturalSort\NaturalReversedComparer.cs" />
|
||||||
<Compile Include="External\OptimizedCRC.cs" />
|
<Compile Include="External\OptimizedCRC.cs" />
|
||||||
|
<Compile Include="External\Traverse.cs" />
|
||||||
<Compile Include="External\xxHash.cs" />
|
<Compile Include="External\xxHash.cs" />
|
||||||
<Compile Include="External\Zlib\CRC32.cs" />
|
<Compile Include="External\Zlib\CRC32.cs" />
|
||||||
<Compile Include="External\Zlib\Deflate.cs" />
|
<Compile Include="External\Zlib\Deflate.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user