From b943fee50da7f7d65a2e8ba667adf3dcb5633108 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 22 Jun 2016 21:44:58 -0700 Subject: [PATCH] [SimpleSort] Make the user experience better --- SimpleSort/SimpleSort.cs | 42 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/SimpleSort/SimpleSort.cs b/SimpleSort/SimpleSort.cs index fb543918..acd428ed 100644 --- a/SimpleSort/SimpleSort.cs +++ b/SimpleSort/SimpleSort.cs @@ -281,15 +281,14 @@ namespace SabreTools Output.CleanDirectory(_tempdir); } - // Then, loop through and check each of the inputs - _logger.User("Starting to loop through inputs"); + // Create a list of just files from inputs + List files = new List(); foreach (string input in _inputs) { if (File.Exists(input)) { _logger.Log("File found: '" + input + "'"); - success &= RebuildToOutputHelper(input); - Output.CleanDirectory(_tempdir); + files.Add(Path.GetFullPath(input)); } else if (Directory.Exists(input)) { @@ -297,8 +296,7 @@ namespace SabreTools foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) { _logger.Log("File found: '" + file + "'"); - success &= RebuildToOutputHelper(file); - Output.CleanDirectory(_tempdir); + files.Add(Path.GetFullPath(file)); } } else @@ -307,6 +305,14 @@ namespace SabreTools } } + // Then, loop through and check each of the inputs + _logger.User("Starting to loop through inputs\n"); + for (int i = 0; i < files.Count; i++) + { + success &= RebuildToOutputHelper(files[i], i, files.Count); + Output.CleanDirectory(_tempdir); + } + // Now one final delete of the temp directory while (Directory.Exists(_tempdir)) { @@ -330,16 +336,18 @@ namespace SabreTools /// /// Process an individual file against the DAT /// - /// The name of the input file + /// Name of the input file + /// Index of the current file + /// Total number of files /// True if this is in a recurse step and the file should be deleted, false otherwise (default) /// True if it was processed properly, false otherwise - private bool RebuildToOutputHelper(string input, bool recurse = false) + private bool RebuildToOutputHelper(string input, int index, int total, bool recurse = false) { bool success = true; // Get the full path of the input for movement purposes - input = Path.GetFullPath(input); - _logger.User("Beginning processing of '" + input + "'"); + string statement = "\r" + (100 * index / total) + "% - Processing '" + input + "'"; + _logger.LogExact(statement.PadRight(79, ' ')); // Get if the file should be scanned internally and externally bool shouldExternalScan = true; @@ -397,7 +405,7 @@ namespace SabreTools Directory.CreateDirectory(gamedir); } - _logger.User("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); + _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); try { File.Copy(input, Path.Combine(gamedir, Path.GetFileName(found.Name))); @@ -444,7 +452,7 @@ namespace SabreTools Directory.CreateDirectory(gamedir); } - _logger.User("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); + _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); try { File.Copy(newinput, Path.Combine(gamedir, Path.GetFileName(found.Name))); @@ -469,7 +477,7 @@ namespace SabreTools Directory.CreateDirectory(gamedir); } - _logger.User("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + newfound.Name + "'"); + _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + newfound.Name + "'"); try { File.Copy(input, Path.Combine(gamedir, Path.GetFileName(newfound.Name))); @@ -518,7 +526,7 @@ namespace SabreTools if (_toFolder) { // Copy file to output directory - _logger.User("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); + _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); string outfile = ArchiveTools.ExtractSingleItemFromArchive(input, rom.Name, _tempdir, _logger); if (File.Exists(outfile)) { @@ -538,7 +546,7 @@ namespace SabreTools else { // Copy file between archives - _logger.User("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); + _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); if (Build.MonoEnvironment) { @@ -585,10 +593,10 @@ namespace SabreTools // If no errors were encountered, we loop through the temp directory if (!encounteredErrors) { - _logger.User("Archive found! Successfully extracted"); + _logger.Log("Archive found! Successfully extracted"); foreach (string file in Directory.EnumerateFiles(_tempdir, "*", SearchOption.AllDirectories)) { - success &= RebuildToOutputHelper(file, true); + success &= RebuildToOutputHelper(file, index, total, true); } } }