Skip to content

Commit 7338640

Browse files
committed
Add optional progress indicator callback
1 parent 99d4ade commit 7338640

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

BurnOutSharp/ProtectionFind.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public static class ProtectionFind
3333
/// Scan a path to find any known copy protection(s)
3434
/// </summary>
3535
/// <param name="path">Path to scan for protection(s)</param>
36+
/// <param name="progress">Optional progress indicator that will return a float in the range from 0 to 1</param>
3637
/// <returns>Dictionary of filename to protection mappings, if possible</returns>
3738
/// <remarks>
3839
/// TODO: Sector scanning?
@@ -51,10 +52,13 @@ public static class ProtectionFind
5152
/// - The Bongle (http://web.archive.org/web/19990508193708/www.hideseek.com/products.htm)
5253
/// - The Copy-Protected CD (http://web.archive.org/web/19990508193708/www.hideseek.com/products.htm)
5354
/// </remarks>
54-
public static Dictionary<string, string> Scan(string path)
55+
public static Dictionary<string, string> Scan(string path, IProgress<float> progress = null)
5556
{
5657
var protections = new Dictionary<string, string>();
5758

59+
// Checkpoint
60+
progress?.Report(0);
61+
5862
// Create mappings for checking against
5963
var mappings = CreateFilenameProtectionMapping();
6064

@@ -97,8 +101,14 @@ public static Dictionary<string, string> Scan(string path)
97101
protections[path] = "Zzxzz";
98102

99103
// Loop through all files and scan them
100-
foreach (string file in files)
104+
for (int i = 0; i < files.Length; i++)
101105
{
106+
// Get the current file
107+
string file = files[i];
108+
109+
// Checkpoint
110+
progress?.Report(i / files.Length);
111+
102112
// If the file is in the list of known files, add that to the protections found
103113
if (mappings.ContainsKey(Path.GetFileName(file)))
104114
protections[file] = mappings[Path.GetFileName(file)];
@@ -120,6 +130,9 @@ public static Dictionary<string, string> Scan(string path)
120130
protections = new Dictionary<string, string>();
121131
}
122132

133+
// Checkpoint
134+
progress?.Report(1);
135+
123136
return protections;
124137
}
125138

0 commit comments

Comments
 (0)