Skip to content

Commit a2e00e3

Browse files
committed
Better progress indicator
1 parent 7338640 commit a2e00e3

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

BurnOutSharp/BurnOutSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<ItemGroup>
5555
<Compile Include="CaseInsensitiveDictionary.cs" />
5656
<Compile Include="EVORE.cs" />
57+
<Compile Include="Progress.cs" />
5758
<Compile Include="Properties\AssemblyInfo.cs" />
5859
<Compile Include="ProtectionFind.cs" />
5960
</ItemGroup>

BurnOutSharp/Progress.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace BurnOutSharp
2+
{
3+
public class Progress
4+
{
5+
public string Filename { get; private set; }
6+
public float Percentage { get; private set; }
7+
public string Protection { get; private set; }
8+
9+
public Progress(string filename, float percentage, string protection)
10+
{
11+
this.Filename = filename;
12+
this.Percentage = percentage;
13+
this.Protection = protection;
14+
}
15+
}
16+
}

BurnOutSharp/ProtectionFind.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public static class ProtectionFind
5252
/// - The Bongle (http://web.archive.org/web/19990508193708/www.hideseek.com/products.htm)
5353
/// - The Copy-Protected CD (http://web.archive.org/web/19990508193708/www.hideseek.com/products.htm)
5454
/// </remarks>
55-
public static Dictionary<string, string> Scan(string path, IProgress<float> progress = null)
55+
public static Dictionary<string, string> Scan(string path, IProgress<Progress> progress = null)
5656
{
5757
var protections = new Dictionary<string, string>();
5858

5959
// Checkpoint
60-
progress?.Report(0);
60+
progress?.Report(new Progress(null, 0, null));
6161

6262
// Create mappings for checking against
6363
var mappings = CreateFilenameProtectionMapping();
@@ -77,6 +77,9 @@ public static Dictionary<string, string> Scan(string path, IProgress<float> prog
7777
string protectionname = ScanInFile(path)?.Replace("" + (char)0x00, "");
7878
if (!String.IsNullOrEmpty(protectionname))
7979
protections[path] = protectionname;
80+
81+
// Checkpoint
82+
progress?.Report(new Progress(path, 1, protectionname));
8083
}
8184
// If we have a directory
8285
else if (Directory.Exists(path))
@@ -106,9 +109,6 @@ public static Dictionary<string, string> Scan(string path, IProgress<float> prog
106109
// Get the current file
107110
string file = files[i];
108111

109-
// Checkpoint
110-
progress?.Report(i / files.Length);
111-
112112
// If the file is in the list of known files, add that to the protections found
113113
if (mappings.ContainsKey(Path.GetFileName(file)))
114114
protections[file] = mappings[Path.GetFileName(file)];
@@ -121,6 +121,9 @@ public static Dictionary<string, string> Scan(string path, IProgress<float> prog
121121
string protectionname = ScanInFile(file)?.Replace("" + (char)0x00, "");
122122
if (!String.IsNullOrEmpty(protectionname))
123123
protections[file] = protectionname;
124+
125+
// Checkpoint
126+
progress?.Report(new Progress(file, i / files.Length, protectionname));
124127
}
125128
}
126129

@@ -130,9 +133,6 @@ public static Dictionary<string, string> Scan(string path, IProgress<float> prog
130133
protections = new Dictionary<string, string>();
131134
}
132135

133-
// Checkpoint
134-
progress?.Report(1);
135-
136136
return protections;
137137
}
138138

0 commit comments

Comments
 (0)