Better progress indicator

This commit is contained in:
Matt Nadareski
2018-07-18 10:38:41 -07:00
parent 7338640635
commit a2e00e3945
3 changed files with 25 additions and 8 deletions

View File

@@ -54,6 +54,7 @@
<ItemGroup>
<Compile Include="CaseInsensitiveDictionary.cs" />
<Compile Include="EVORE.cs" />
<Compile Include="Progress.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ProtectionFind.cs" />
</ItemGroup>

16
BurnOutSharp/Progress.cs Normal file
View File

@@ -0,0 +1,16 @@
namespace BurnOutSharp
{
public class Progress
{
public string Filename { get; private set; }
public float Percentage { get; private set; }
public string Protection { get; private set; }
public Progress(string filename, float percentage, string protection)
{
this.Filename = filename;
this.Percentage = percentage;
this.Protection = protection;
}
}
}

View File

@@ -52,12 +52,12 @@ namespace BurnOutSharp
/// - The Bongle (http://web.archive.org/web/19990508193708/www.hideseek.com/products.htm)
/// - The Copy-Protected CD (http://web.archive.org/web/19990508193708/www.hideseek.com/products.htm)
/// </remarks>
public static Dictionary<string, string> Scan(string path, IProgress<float> progress = null)
public static Dictionary<string, string> Scan(string path, IProgress<Progress> progress = null)
{
var protections = new Dictionary<string, string>();
// Checkpoint
progress?.Report(0);
progress?.Report(new Progress(null, 0, null));
// Create mappings for checking against
var mappings = CreateFilenameProtectionMapping();
@@ -77,6 +77,9 @@ namespace BurnOutSharp
string protectionname = ScanInFile(path)?.Replace("" + (char)0x00, "");
if (!String.IsNullOrEmpty(protectionname))
protections[path] = protectionname;
// Checkpoint
progress?.Report(new Progress(path, 1, protectionname));
}
// If we have a directory
else if (Directory.Exists(path))
@@ -106,9 +109,6 @@ namespace BurnOutSharp
// Get the current file
string file = files[i];
// Checkpoint
progress?.Report(i / files.Length);
// If the file is in the list of known files, add that to the protections found
if (mappings.ContainsKey(Path.GetFileName(file)))
protections[file] = mappings[Path.GetFileName(file)];
@@ -121,6 +121,9 @@ namespace BurnOutSharp
string protectionname = ScanInFile(file)?.Replace("" + (char)0x00, "");
if (!String.IsNullOrEmpty(protectionname))
protections[file] = protectionname;
// Checkpoint
progress?.Report(new Progress(file, i / files.Length, protectionname));
}
}
@@ -130,9 +133,6 @@ namespace BurnOutSharp
protections = new Dictionary<string, string>();
}
// Checkpoint
progress?.Report(1);
return protections;
}