diff --git a/SabreTools.Helper/Objects/Dat/DatFile.cs b/SabreTools.Helper/Objects/Dat/DatFile.cs index d5d6b421..7a3a0b11 100644 --- a/SabreTools.Helper/Objects/Dat/DatFile.cs +++ b/SabreTools.Helper/Objects/Dat/DatFile.cs @@ -2096,7 +2096,7 @@ namespace SabreTools.Helper int parentcount = parent.Count; if (parentcount == 0) { - logger.Log("Empty parent: " + String.Join("\\", parent)); + logger.Verbose("Empty parent: " + String.Join("\\", parent)); empty = true; } @@ -2522,13 +2522,13 @@ namespace SabreTools.Helper } if (subreader.GetAttribute("flags") == "baddump" || subreader.GetAttribute("status") == "baddump") { - logger.Log("Bad dump detected: " + + logger.Verbose("Bad dump detected: " + (subreader.GetAttribute("name") != null && subreader.GetAttribute("name") != "" ? "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); its = ItemStatus.BadDump; } if (subreader.GetAttribute("flags") == "itemStatus" || subreader.GetAttribute("status") == "itemStatus") { - logger.Log("Nodump detected: " + + logger.Verbose("Nodump detected: " + (subreader.GetAttribute("name") != null && subreader.GetAttribute("name") != "" ? "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); its = ItemStatus.Nodump; } @@ -2677,12 +2677,12 @@ namespace SabreTools.Helper its = ItemStatus.Good; break; case "baddump": - logger.Log("Bad dump detected: " + (xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != "" ? + logger.Verbose("Bad dump detected: " + (xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != "" ? "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); its = ItemStatus.BadDump; break; case "itemStatus": - logger.Log("Nodump detected: " + (xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != "" ? + logger.Verbose("Nodump detected: " + (xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != "" ? "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); its = ItemStatus.Nodump; break; @@ -3090,7 +3090,7 @@ namespace SabreTools.Helper && ((Rom)rom).MD5 == "null" && ((Rom)rom).SHA1 == "null") { - logger.Log("Empty folder found: " + rom.MachineName); + logger.Verbose("Empty folder found: " + rom.MachineName); // If we're in a mode that doesn't allow for actual empty folders, add the blank info if (outputFormat != OutputFormat.SabreDat && outputFormat != OutputFormat.MissFile) @@ -3123,7 +3123,7 @@ namespace SabreTools.Helper // Write the file footer out WriteFooter(sw, outputFormat, depth, logger); - logger.Log("File written!" + Environment.NewLine); + logger.Verbose("File written!" + Environment.NewLine); sw.Dispose(); fs.Dispose(); } @@ -3946,7 +3946,7 @@ namespace SabreTools.Helper } // Process the input folder - logger.Log("Folder found: " + basePath); + logger.Verbose("Folder found: " + basePath); // Process the files in all subfolders List files = Directory.EnumerateFiles(basePath, "*", SearchOption.AllDirectories).ToList(); @@ -4007,7 +4007,7 @@ namespace SabreTools.Helper romname = romname.Substring(0, romname.Length - 1); } - logger.Log("Adding blank empty folder: " + gamename); + logger.Verbose("Adding blank empty folder: " + gamename); Files["null"].Add(new Rom(romname, gamename)); } }); @@ -4134,7 +4134,7 @@ namespace SabreTools.Helper // If the file was an archive and was extracted successfully, check it if (!encounteredErrors) { - logger.Log(Path.GetFileName(item) + " treated like an archive"); + logger.Verbose(Path.GetFileName(item) + " treated like an archive"); List extracted = Directory.EnumerateFiles(tempSubDir, "*", SearchOption.AllDirectories).ToList(); Parallel.ForEach(extracted, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, @@ -4184,7 +4184,7 @@ namespace SabreTools.Helper /// Parent game to be used private void DFDProcessFile(string item, string parent, string basePath, bool noMD5, bool noSHA1, bool addDate, Logger logger) { - logger.Log(Path.GetFileName(item) + " treated like a file"); + logger.Verbose(Path.GetFileName(item) + " treated like a file"); Rom rom = FileTools.GetSingleFileInfo(item, noMD5: noMD5, noSHA1: noSHA1, date: addDate); DFDProcessFileHelper(item, rom, basePath, parent, logger); @@ -5078,7 +5078,7 @@ namespace SabreTools.Helper /// Now process each of the input files foreach (string filename in newinputs) { - logger.Log("Beginning stat collection for '" + filename + "'"); + logger.Verbose("Beginning stat collection for '" + filename + "'"); List games = new List(); DatFile datdata = new DatFile(); datdata.Parse(filename, 0, 0, logger); diff --git a/SabreTools.Helper/Objects/Logger.cs b/SabreTools.Helper/Objects/Logger.cs index b87bd1fe..5672c042 100644 --- a/SabreTools.Helper/Objects/Logger.cs +++ b/SabreTools.Helper/Objects/Logger.cs @@ -117,13 +117,14 @@ namespace SabreTools.Helper /// /// String to be written log /// Severity of the information being logged + /// True if the level and datetime should be prepended to each statement, false otherwise /// True if the output could be written, false otherwise - public bool Log(string output, LogLevel loglevel = LogLevel.VERBOSE) + private bool Log(string output, LogLevel loglevel, bool appendPrefix) { // USER and ERROR writes to console if (loglevel == LogLevel.USER || loglevel == LogLevel.ERROR) { - Console.WriteLine((loglevel == LogLevel.ERROR ? loglevel.ToString() + " " : "") + output); + Console.WriteLine((loglevel == LogLevel.ERROR && appendPrefix ? loglevel.ToString() + " " : "") + output); } // If we're writing to file, use the existing stream @@ -131,7 +132,7 @@ namespace SabreTools.Helper { try { - _log.WriteLine(loglevel.ToString() + " - " + DateTime.Now + " - " + output); + _log.WriteLine((appendPrefix ? loglevel.ToString() + " - " + DateTime.Now + " - " : "" ) + output); _log.Flush(); } catch @@ -151,7 +152,7 @@ namespace SabreTools.Helper /// Line number to write out to /// Column number to write out to /// True if the output could be written, false otherwise - public bool Log(string output, int line, int column) + public bool WriteExact(string output, int line, int column) { // Set the cursor position (if not being redirected) if (!Console.IsOutputRedirected) @@ -181,34 +182,48 @@ namespace SabreTools.Helper return true; } + /// + /// Write the given string as a verbose message to the log output + /// + /// String to be written log + /// True if the level and datetime should be prepended to each statement (default), false otherwise + /// True if the output could be written, false otherwises + public bool Verbose(string output, bool appendPrefix = true) + { + return Log(output, LogLevel.VERBOSE, appendPrefix); + } + /// /// Write the given string as a user message to the log output /// /// String to be written log + /// True if the level and datetime should be prepended to each statement (default), false otherwise /// True if the output could be written, false otherwise - public bool User(string output) + public bool User(string output, bool appendPrefix = true) { - return Log(output, LogLevel.USER); + return Log(output, LogLevel.USER, appendPrefix); } /// /// Write the given string as a warning to the log output /// /// String to be written log + /// True if the level and datetime should be prepended to each statement (default), false otherwise /// True if the output could be written, false otherwise - public bool Warning(string output) + public bool Warning(string output, bool appendPrefix = true) { - return Log(output, LogLevel.WARNING); + return Log(output, LogLevel.WARNING, appendPrefix); } /// /// Writes the given string as an error in the log /// /// String to be written log + /// True if the level and datetime should be prepended to each statement (default), false otherwise /// True if the output could be written, false otherwise - public bool Error(string output) + public bool Error(string output, bool appendPrefix = true) { - return Log(output, LogLevel.ERROR); + return Log(output, LogLevel.ERROR, appendPrefix); } /// diff --git a/SabreTools.Helper/Objects/SimpleSort.cs b/SabreTools.Helper/Objects/SimpleSort.cs index fa2b9641..4ed42e7f 100644 --- a/SabreTools.Helper/Objects/SimpleSort.cs +++ b/SabreTools.Helper/Objects/SimpleSort.cs @@ -125,7 +125,7 @@ namespace SabreTools.Helper List files = new List(); foreach (string file in Directory.EnumerateFiles(_outDir, "*", SearchOption.AllDirectories)) { - _logger.Log("File found: '" + file + "'"); + _logger.Verbose("File found: '" + file + "'"); files.Add(Path.GetFullPath(file)); } @@ -212,15 +212,15 @@ namespace SabreTools.Helper { if (File.Exists(input)) { - _logger.Log("File found: '" + input + "'"); + _logger.Verbose("File found: '" + input + "'"); files.Add(Path.GetFullPath(input)); } else if (Directory.Exists(input)) { - _logger.Log("Directory found: '" + input + "'"); + _logger.Verbose("Directory found: '" + input + "'"); foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) { - _logger.Log("File found: '" + file + "'"); + _logger.Verbose("File found: '" + file + "'"); files.Add(Path.GetFullPath(file)); } } @@ -304,7 +304,7 @@ namespace SabreTools.Helper { if (File.Exists(input)) { - _logger.Log("File found: '" + input + "'"); + _logger.Verbose("File found: '" + input + "'"); lock (files) { files.Add(Path.GetFullPath(input)); @@ -312,14 +312,14 @@ namespace SabreTools.Helper } else if (Directory.Exists(input)) { - _logger.Log("Directory found: '" + input + "'"); + _logger.Verbose("Directory found: '" + input + "'"); List infiles = Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories).ToList(); Parallel.ForEach(infiles, new ParallelOptions { MaxDegreeOfParallelism = _maxDegreeOfParallelism }, file => { - _logger.Log("File found: '" + input + "'"); + _logger.Verbose("File found: '" + input + "'"); lock (files) { files.Add(Path.GetFullPath(file)); @@ -361,9 +361,9 @@ namespace SabreTools.Helper // If external scanning is enabled, use that method instead if (_quickScan) { - _logger.Log("Beginning quick scan of contents from '" + file + "'"); + _logger.Verbose("Beginning quick scan of contents from '" + file + "'"); List internalRomData = ArchiveTools.GetArchiveFileInfo(file, _logger); - _logger.Log(internalRomData.Count + " entries found in '" + file + "'"); + _logger.Verbose(internalRomData.Count + " entries found in '" + file + "'"); // Now add all of the roms to the DAT for (int i = 0; i < internalRomData.Count; i++) @@ -533,7 +533,7 @@ namespace SabreTools.Helper string percentage = (index == 0 ? "0.00" : Math.Round((100 * ((double)index / total)), 2, MidpointRounding.AwayFromZero).ToString()); string statement = percentage + "% - " + input; _logger.ClearBeneath(_cursorTop + 1); - _logger.Log(statement, _cursorTop, 0); + _logger.WriteExact(statement, _cursorTop, 0); // Get if the file should be scanned internally and externally bool shouldExternalScan, shouldInternalScan; @@ -552,10 +552,10 @@ namespace SabreTools.Helper // Try to find the matches to the file that was found List foundroms = rom.GetDuplicates(_datdata, _logger); - _logger.Log("File '" + input + "' had " + foundroms.Count + " matches in the DAT!"); + _logger.Verbose("File '" + input + "' had " + foundroms.Count + " matches in the DAT!"); foreach (Rom found in foundroms) { - _logger.Log("Matched name: " + found.Name); + _logger.Verbose("Matched name: " + found.Name); // Add rom to the matched list string key = found.Size + "-" + found.CRC; @@ -579,7 +579,7 @@ namespace SabreTools.Helper Directory.CreateDirectory(gamedir); } - _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.SHA1 : found.Name) + "'"); + _logger.Verbose("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.SHA1 : found.Name) + "'"); try { File.Copy(input, Path.Combine(gamedir, Path.GetFileName(found.Name))); @@ -622,7 +622,7 @@ namespace SabreTools.Helper // Try to find the matches to the file that was found List founddroms = drom.GetDuplicates(_datdata, _logger); - _logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!"); + _logger.Verbose("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!"); foreach (Rom found in founddroms) { // Add rom to the matched list @@ -639,7 +639,7 @@ namespace SabreTools.Helper } // First output the headerless rom - _logger.Log("Matched name: " + found.Name); + _logger.Verbose("Matched name: " + found.Name); if (_toFolder) { @@ -650,7 +650,7 @@ namespace SabreTools.Helper Directory.CreateDirectory(gamedir); } - _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.SHA1 : found.Name) + "'"); + _logger.Verbose("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.SHA1 : found.Name) + "'"); try { File.Copy(newinput, Path.Combine(gamedir, Path.GetFileName(found.Name))); @@ -703,7 +703,7 @@ namespace SabreTools.Helper Directory.CreateDirectory(gamedir); } - _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + newfound.Name + "'"); + _logger.Verbose("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + newfound.Name + "'"); try { File.Copy(input, Path.Combine(gamedir, Path.GetFileName(newfound.Name))); @@ -712,7 +712,7 @@ namespace SabreTools.Helper } else { - _logger.Log("Matched name: " + newfound.Name); + _logger.Verbose("Matched name: " + newfound.Name); if (_torrentX == true) { ArchiveTools.WriteTorrentZip(input, _outDir, newfound, _logger); @@ -746,9 +746,9 @@ namespace SabreTools.Helper // If external scanning is enabled, use that method instead if (_quickScan) { - _logger.Log("Beginning quick scan of contents from '" + input + "'"); + _logger.Verbose("Beginning quick scan of contents from '" + input + "'"); List internalRomData = ArchiveTools.GetArchiveFileInfo(input, _logger); - _logger.Log(internalRomData.Count + " entries found in '" + input + "'"); + _logger.Verbose(internalRomData.Count + " entries found in '" + input + "'"); // If the list is populated, then the file was a filled archive if (internalRomData.Count > 0) @@ -757,7 +757,7 @@ namespace SabreTools.Helper { // Try to find the matches to the file that was found List foundroms = rom.GetDuplicates(_datdata, _logger); - _logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!"); + _logger.Verbose("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!"); foreach (Rom found in foundroms) { // Add rom to the matched list @@ -776,7 +776,7 @@ namespace SabreTools.Helper if (_toFolder) { // Copy file to output directory - _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); + _logger.Verbose("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'"); string outfile = ArchiveTools.ExtractSingleItemFromArchive(input, rom.Name, _tempDir, _logger); if (File.Exists(outfile)) { @@ -796,7 +796,7 @@ namespace SabreTools.Helper else { // Copy file between archives - _logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.SHA1 : found.Name) + "'"); + _logger.Verbose("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_torrentX == false ? found.SHA1 : found.Name) + "'"); if (Build.MonoEnvironment || _torrentX == false) { @@ -853,7 +853,7 @@ namespace SabreTools.Helper // If no errors were encountered, we loop through the temp directory if (!encounteredErrors) { - _logger.Log("Archive found! Successfully extracted"); + _logger.Verbose("Archive found! Successfully extracted"); foreach (string file in Directory.EnumerateFiles(_tempDir, "*", SearchOption.AllDirectories)) { success &= RebuildToOutputHelper(file, index, total, true); @@ -1047,7 +1047,7 @@ namespace SabreTools.Helper // If no errors were encountered, we loop through the temp directory if (!encounteredErrors) { - _logger.Log("Archive found! Successfully extracted"); + _logger.Verbose("Archive found! Successfully extracted"); foreach (string file in Directory.EnumerateFiles(_tempDir, "*", SearchOption.AllDirectories)) { _logger.User("Processing extracted file " + file); diff --git a/SabreTools.Helper/Skippers/Skippers.cs b/SabreTools.Helper/Skippers/Skippers.cs index 85575454..61d3d509 100644 --- a/SabreTools.Helper/Skippers/Skippers.cs +++ b/SabreTools.Helper/Skippers/Skippers.cs @@ -323,7 +323,7 @@ namespace SabreTools.Helper SkipperRule skipperRule = new SkipperRule(); // Loop through and find a Skipper that has the right name - logger.Log("Beginning search for matching header skip rules"); + logger.Verbose("Beginning search for matching header skip rules"); foreach (Skipper skipper in List) { if (String.IsNullOrEmpty(skipperName) || (!String.IsNullOrEmpty(skipper.Name) && skipperName.ToLowerInvariant() == skipper.Name.ToLowerInvariant())) @@ -483,7 +483,7 @@ namespace SabreTools.Helper // If we have a blank rule, inform the user if (skipperRule.Tests == null) { - logger.Log("No matching rule found!"); + logger.Verbose("No matching rule found!"); } return skipperRule; diff --git a/SabreTools.Helper/Tools/ArchiveTools.cs b/SabreTools.Helper/Tools/ArchiveTools.cs index 1e64bc78..a70c26cc 100644 --- a/SabreTools.Helper/Tools/ArchiveTools.cs +++ b/SabreTools.Helper/Tools/ArchiveTools.cs @@ -92,7 +92,7 @@ namespace SabreTools.Helper { if (at == ArchiveType.SevenZip && sevenzip != ArchiveScanLevel.External) { - logger.Log("Found archive of type: " + at); + logger.Verbose("Found archive of type: " + at); // Create the temp directory Directory.CreateDirectory(tempDir); @@ -109,7 +109,7 @@ namespace SabreTools.Helper } else if (at == ArchiveType.GZip && gz != ArchiveScanLevel.External) { - logger.Log("Found archive of type: " + at); + logger.Verbose("Found archive of type: " + at); // Create the temp directory Directory.CreateDirectory(tempDir); @@ -128,7 +128,7 @@ namespace SabreTools.Helper else if ((at == ArchiveType.Zip && zip != ArchiveScanLevel.External) || (at == ArchiveType.Rar && rar != ArchiveScanLevel.External)) { - logger.Log("Found archive of type: " + at); + logger.Verbose("Found archive of type: " + at); // Create the temp directory Directory.CreateDirectory(tempDir); @@ -194,7 +194,7 @@ namespace SabreTools.Helper reader = ReaderFactory.Open(File.OpenRead(input)); while (reader.MoveToNextEntry()) { - logger.Log("Current entry name: '" + reader.Entry.Key + "'"); + logger.Verbose("Current entry name: '" + reader.Entry.Key + "'"); if (reader.Entry != null && reader.Entry.Key.Contains(entryname)) { outfile = Path.GetFullPath(Path.Combine(tempDir, reader.Entry.Key)); @@ -272,7 +272,7 @@ namespace SabreTools.Helper IReader reader = null; try { - logger.Log("Found archive of type: " + at); + logger.Verbose("Found archive of type: " + at); long size = 0; string crc = ""; @@ -296,7 +296,7 @@ namespace SabreTools.Helper { if (reader.Entry != null && !reader.Entry.IsDirectory) { - logger.Log("Entry found: '" + reader.Entry.Key + "': " + logger.Verbose("Entry found: '" + reader.Entry.Key + "': " + (size == 0 ? reader.Entry.Size : size) + ", " + (crc == "" ? reader.Entry.Crc.ToString("X").ToLowerInvariant() : crc)); diff --git a/SabreTools.Helper/Tools/DatabaseTools.cs b/SabreTools.Helper/Tools/DatabaseTools.cs index a3083ac9..cfa8f670 100644 --- a/SabreTools.Helper/Tools/DatabaseTools.cs +++ b/SabreTools.Helper/Tools/DatabaseTools.cs @@ -36,7 +36,7 @@ namespace SabreTools.Helper "'" + header + "', " + "'" + source + "')"; slc = new SqliteCommand(query, dbc); - logger.Log("Result of inserting header: " + slc.ExecuteNonQuery()); + logger.Verbose("Result of inserting header: " + slc.ExecuteNonQuery()); } // Dispose of database objects diff --git a/SabreTools.Helper/Tools/FileTools.cs b/SabreTools.Helper/Tools/FileTools.cs index 9a743a36..1a720c19 100644 --- a/SabreTools.Helper/Tools/FileTools.cs +++ b/SabreTools.Helper/Tools/FileTools.cs @@ -28,7 +28,7 @@ namespace SabreTools.Helper } // Read the input file, if possible - logger.Log("Attempting to read file: \"" + filename + "\""); + logger.Verbose("Attempting to read file: \"" + filename + "\""); // Check if file exists if (!File.Exists(filename)) @@ -100,7 +100,7 @@ namespace SabreTools.Helper /// The XmlTextReader representing the (possibly converted) file, null otherwise public static XmlTextReader GetXmlTextReader(string filename, Logger logger) { - logger.Log("Attempting to read file: \"" + filename + "\""); + logger.Verbose("Attempting to read file: \"" + filename + "\""); // Check if file exists if (!File.Exists(filename)) @@ -282,7 +282,7 @@ namespace SabreTools.Helper int sub = 0; while (sldr.Read()) { - logger.Log("Found match with rom type " + sldr.GetString(1)); + logger.Verbose("Found match with rom type " + sldr.GetString(1)); header = sldr.GetString(0); logger.User("Creating reheadered file: " +