mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Logging overhaul!
This change brings about a few changes: 1) A new LogLevel called "User" that is used for non-verbose, non-error output 2) Only User and Error are output to console now, not all of them 3) All programs have log to file enabled by default and all flags for enabling logging have been removed 4) Some former Verbose statements have been converted over to User because of the shift in usage.
This commit is contained in:
@@ -97,11 +97,11 @@ namespace SabreTools
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger logger = new Logger(false, "datfromdir.log");
|
Logger logger = new Logger(true, "datfromdir.log");
|
||||||
logger.Start();
|
logger.Start();
|
||||||
|
|
||||||
// First things first, take care of all of the arguments that this could have
|
// First things first, take care of all of the arguments that this could have
|
||||||
bool noMD5 = false, noSHA1 = false, forceunpack = false, archivesAsFiles = false, old = false, log = false, superDat = false, bare = false;
|
bool noMD5 = false, noSHA1 = false, forceunpack = false, archivesAsFiles = false, old = false, superDat = false, bare = false;
|
||||||
string name = "", desc = "", cat = "", version = "", author = "";
|
string name = "", desc = "", cat = "", version = "", author = "";
|
||||||
List<string> inputs = new List<string>();
|
List<string> inputs = new List<string>();
|
||||||
foreach (string arg in args)
|
foreach (string arg in args)
|
||||||
@@ -138,10 +138,6 @@ namespace SabreTools
|
|||||||
case "--old":
|
case "--old":
|
||||||
old = true;
|
old = true;
|
||||||
break;
|
break;
|
||||||
case "-l":
|
|
||||||
case "--log":
|
|
||||||
log = true;
|
|
||||||
break;
|
|
||||||
case "-sd":
|
case "-sd":
|
||||||
case "--superdat":
|
case "--superdat":
|
||||||
superDat = true;
|
superDat = true;
|
||||||
@@ -183,9 +179,6 @@ namespace SabreTools
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the new state for Logger
|
|
||||||
logger.ToFile = log;
|
|
||||||
|
|
||||||
// Output the title
|
// Output the title
|
||||||
Build.Start("DATFromDir");
|
Build.Start("DATFromDir");
|
||||||
|
|
||||||
@@ -365,7 +358,7 @@ namespace SabreTools
|
|||||||
_logger.Log(Path.GetFileName(item) + " treated like an archive");
|
_logger.Log(Path.GetFileName(item) + " treated like an archive");
|
||||||
foreach (string entry in Directory.EnumerateFiles(_tempDir, "*", SearchOption.AllDirectories))
|
foreach (string entry in Directory.EnumerateFiles(_tempDir, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
_logger.Log("\tFound file: " + entry);
|
_logger.Log("Found file: " + entry);
|
||||||
string fileCRC = String.Empty;
|
string fileCRC = String.Empty;
|
||||||
string fileMD5 = String.Empty;
|
string fileMD5 = String.Empty;
|
||||||
string fileSHA1 = String.Empty;
|
string fileSHA1 = String.Empty;
|
||||||
@@ -410,7 +403,7 @@ namespace SabreTools
|
|||||||
SHA1 = fileSHA1,
|
SHA1 = fileSHA1,
|
||||||
});
|
});
|
||||||
|
|
||||||
_logger.Log("File added" + Environment.NewLine);
|
_logger.User("File added: " + entry + Environment.NewLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, just get the info on the file itself
|
// Otherwise, just get the info on the file itself
|
||||||
@@ -474,7 +467,7 @@ namespace SabreTools
|
|||||||
SHA1 = fileSHA1,
|
SHA1 = fileSHA1,
|
||||||
});
|
});
|
||||||
|
|
||||||
_logger.Log("File added" + Environment.NewLine);
|
_logger.User("File added: " + actualitem + Environment.NewLine);
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace SabreTools
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// Perform initial setup and verification
|
// Perform initial setup and verification
|
||||||
logger = new Logger(false, "database.log");
|
logger = new Logger(true, "database.log");
|
||||||
logger.Start();
|
logger.Start();
|
||||||
DBTools.EnsureDatabase(_dbName, _connectionString);
|
DBTools.EnsureDatabase(_dbName, _connectionString);
|
||||||
Remapping.CreateRemappings();
|
Remapping.CreateRemappings();
|
||||||
@@ -44,7 +44,6 @@ namespace SabreTools
|
|||||||
// If there's no arguments, show the menu
|
// If there's no arguments, show the menu
|
||||||
if (args.Length == 0)
|
if (args.Length == 0)
|
||||||
{
|
{
|
||||||
logger.ToFile = true;
|
|
||||||
ShowMainMenu();
|
ShowMainMenu();
|
||||||
logger.Close();
|
logger.Close();
|
||||||
return;
|
return;
|
||||||
@@ -67,7 +66,6 @@ namespace SabreTools
|
|||||||
generate = false,
|
generate = false,
|
||||||
genall = false,
|
genall = false,
|
||||||
import = false,
|
import = false,
|
||||||
log = false,
|
|
||||||
listsrc = false,
|
listsrc = false,
|
||||||
listsys = false,
|
listsys = false,
|
||||||
merge = false,
|
merge = false,
|
||||||
@@ -163,10 +161,6 @@ namespace SabreTools
|
|||||||
case "--import":
|
case "--import":
|
||||||
import = true;
|
import = true;
|
||||||
break;
|
break;
|
||||||
case "-l":
|
|
||||||
case "--log":
|
|
||||||
log = true;
|
|
||||||
break;
|
|
||||||
case "-lso":
|
case "-lso":
|
||||||
case "--list-sources":
|
case "--list-sources":
|
||||||
listsrc = true;
|
listsrc = true;
|
||||||
@@ -321,9 +315,6 @@ namespace SabreTools
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the logger with the new value
|
|
||||||
logger.ToFile = log;
|
|
||||||
|
|
||||||
// Now take care of each mode in succesion
|
// Now take care of each mode in succesion
|
||||||
|
|
||||||
// Import a file or folder
|
// Import a file or folder
|
||||||
@@ -738,7 +729,7 @@ or 'b' to go back to the previous menu:
|
|||||||
private static void ConvertMissMenu()
|
private static void ConvertMissMenu()
|
||||||
{
|
{
|
||||||
string selection = "", input = "", prefix = "", postfix = "", addext = "", repext = "";
|
string selection = "", input = "", prefix = "", postfix = "", addext = "", repext = "";
|
||||||
bool usegame = true, quotes = false, gamename = false;
|
bool usegame = true, quotes = false, gamename = false, romba = false;
|
||||||
while (selection.ToLowerInvariant() != "b")
|
while (selection.ToLowerInvariant() != "b")
|
||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
@@ -749,13 +740,14 @@ Make a selection:
|
|||||||
|
|
||||||
1) File to convert" + (input != "" ? ":\n\t" + input : "") + @"
|
1) File to convert" + (input != "" ? ":\n\t" + input : "") + @"
|
||||||
2) " + (usegame ? "Output roms instead of games" : "Output games instead of roms") + @"
|
2) " + (usegame ? "Output roms instead of games" : "Output games instead of roms") + @"
|
||||||
3) Prefix to add to each line" + (prefix != "" ? ":\n\t" + prefix : "") + @"
|
3) " + (romba ? "Disable Romba-style output naming" : "Enable Romba-style output naming (overrides previous)") + @"
|
||||||
4) Postfix to add to each line" + (postfix != "" ? ":\n\t" + postfix : "") + @"
|
4) Prefix to add to each line" + (prefix != "" ? ":\n\t" + prefix : "") + @"
|
||||||
5) " + (quotes ? "Don't add quotes around each item" : "Add quotes around each item") + @"
|
5) Postfix to add to each line" + (postfix != "" ? ":\n\t" + postfix : "") + @"
|
||||||
6) Replace all extensions with another" + (repext != "" ? ":\t" + repext : "") + @"
|
6) " + (quotes ? "Don't add quotes around each item" : "Add quotes around each item") + @"
|
||||||
7) Add extensions to each item" + (addext != "" ? ":\n\t" + addext : "") + @"
|
7) Replace all extensions with another" + (repext != "" ? ":\t" + repext : "") + @"
|
||||||
" + (!usegame ? " 8) " + (gamename ? "Don't add game name before every item" : "Add game name before every item") + "\n" : "") +
|
8) Add extensions to each item" + (addext != "" ? ":\n\t" + addext : "") + @"
|
||||||
@" 9) Begin conversion
|
" + (!usegame ? " 9) " + (gamename ? "Don't add game name before every item" : "Add game name before every item") + "\n" : "") +
|
||||||
|
@" 10) Begin conversion
|
||||||
B) Go back to the previous menu
|
B) Go back to the previous menu
|
||||||
");
|
");
|
||||||
Console.Write("Enter selection: ");
|
Console.Write("Enter selection: ");
|
||||||
@@ -771,32 +763,35 @@ Make a selection:
|
|||||||
usegame = !usegame;
|
usegame = !usegame;
|
||||||
break;
|
break;
|
||||||
case "3":
|
case "3":
|
||||||
|
romba = !romba;
|
||||||
|
break;
|
||||||
|
case "4":
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.Write("Please enter the prefix: ");
|
Console.Write("Please enter the prefix: ");
|
||||||
prefix = Console.ReadLine();
|
prefix = Console.ReadLine();
|
||||||
break;
|
break;
|
||||||
case "4":
|
case "5":
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.Write("Please enter the postfix: ");
|
Console.Write("Please enter the postfix: ");
|
||||||
postfix = Console.ReadLine();
|
postfix = Console.ReadLine();
|
||||||
break;
|
break;
|
||||||
case "5":
|
case "6":
|
||||||
quotes = !quotes;
|
quotes = !quotes;
|
||||||
break;
|
break;
|
||||||
case "6":
|
case "7":
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.Write("Please enter the replacement extension: ");
|
Console.Write("Please enter the replacement extension: ");
|
||||||
repext = Console.ReadLine();
|
repext = Console.ReadLine();
|
||||||
break;
|
break;
|
||||||
case "7":
|
case "8":
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.Write("Please enter the additional extension: ");
|
Console.Write("Please enter the additional extension: ");
|
||||||
addext = Console.ReadLine();
|
addext = Console.ReadLine();
|
||||||
break;
|
break;
|
||||||
case "8":
|
case "9":
|
||||||
gamename = !gamename;
|
gamename = !gamename;
|
||||||
break;
|
break;
|
||||||
case "9":
|
case "10":
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
InitConvertMiss(input, usegame, prefix, postfix, quotes, repext, addext, gamename);
|
InitConvertMiss(input, usegame, prefix, postfix, quotes, repext, addext, gamename);
|
||||||
Console.Write("\nPress any key to continue...");
|
Console.Write("\nPress any key to continue...");
|
||||||
@@ -1100,20 +1095,20 @@ Make a selection:
|
|||||||
// Check to see if the second argument is a file that exists
|
// Check to see if the second argument is a file that exists
|
||||||
if (filename != "" && File.Exists(filename))
|
if (filename != "" && File.Exists(filename))
|
||||||
{
|
{
|
||||||
logger.Log("Beginning import of " + filename);
|
logger.User("Beginning import of " + filename);
|
||||||
Import imp = new Import(filename, _connectionString, logger);
|
Import imp = new Import(filename, _connectionString, logger);
|
||||||
bool success = imp.ImportData();
|
bool success = imp.ImportData();
|
||||||
logger.Log(filename + (success ? "" : " not") + " imported!");
|
logger.User(filename + (success ? "" : " not") + " imported!");
|
||||||
}
|
}
|
||||||
// Check to see if the second argument is a directory that exists
|
// Check to see if the second argument is a directory that exists
|
||||||
else if (filename != "" && Directory.Exists(filename))
|
else if (filename != "" && Directory.Exists(filename))
|
||||||
{
|
{
|
||||||
foreach (string file in Directory.GetFiles(filename, "*", SearchOption.AllDirectories))
|
foreach (string file in Directory.GetFiles(filename, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
logger.Log("Beginning import of " + file);
|
logger.User("Beginning import of " + file);
|
||||||
Import imp = new Import(file, _connectionString, logger);
|
Import imp = new Import(file, _connectionString, logger);
|
||||||
bool success = imp.ImportData();
|
bool success = imp.ImportData();
|
||||||
logger.Log(file + (success ? "" : " not") + " imported!");
|
logger.User(file + (success ? "" : " not") + " imported!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1239,7 +1234,7 @@ Make a selection:
|
|||||||
InitGenerate("", "", outdir, norename, old);
|
InitGenerate("", "", outdir, norename, old);
|
||||||
|
|
||||||
// Zip up all of the files that were generated
|
// Zip up all of the files that were generated
|
||||||
logger.Log("Creating zip archive");
|
logger.User("Creating zip archive");
|
||||||
ZipArchive zip = ZipFile.Open(actualdir + "dats-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip", ZipArchiveMode.Create);
|
ZipArchive zip = ZipFile.Open(actualdir + "dats-" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip", ZipArchiveMode.Create);
|
||||||
foreach (String filename in Directory.EnumerateFiles(outdir))
|
foreach (String filename in Directory.EnumerateFiles(outdir))
|
||||||
{
|
{
|
||||||
@@ -1252,7 +1247,7 @@ Make a selection:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
zip.Dispose();
|
zip.Dispose();
|
||||||
logger.Log("Zip archive created!");
|
logger.User("Zip archive created!");
|
||||||
|
|
||||||
// Remove all of the DATs from the folder
|
// Remove all of the DATs from the folder
|
||||||
Directory.Delete(outdir, true);
|
Directory.Delete(outdir, true);
|
||||||
@@ -1268,7 +1263,7 @@ Make a selection:
|
|||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
logger.Log("Converting " + filename);
|
logger.User("Converting " + filename);
|
||||||
XmlDocument doc = new XmlDocument();
|
XmlDocument doc = new XmlDocument();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -1279,7 +1274,7 @@ Make a selection:
|
|||||||
sw.Write(conv);
|
sw.Write(conv);
|
||||||
sw.Close();
|
sw.Close();
|
||||||
fs.Close();
|
fs.Close();
|
||||||
logger.Log("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.dat");
|
logger.User("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.dat");
|
||||||
}
|
}
|
||||||
catch (XmlException)
|
catch (XmlException)
|
||||||
{
|
{
|
||||||
@@ -1301,7 +1296,7 @@ Make a selection:
|
|||||||
{
|
{
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
{
|
{
|
||||||
logger.Log("Converting " + filename);
|
logger.User("Converting " + filename);
|
||||||
XElement conv = Converters.ClrMameProToXML(File.ReadAllLines(filename));
|
XElement conv = Converters.ClrMameProToXML(File.ReadAllLines(filename));
|
||||||
FileStream fs = File.OpenWrite(Path.GetFileNameWithoutExtension(filename) + ".new.xml");
|
FileStream fs = File.OpenWrite(Path.GetFileNameWithoutExtension(filename) + ".new.xml");
|
||||||
StreamWriter sw = new StreamWriter(fs);
|
StreamWriter sw = new StreamWriter(fs);
|
||||||
@@ -1310,7 +1305,7 @@ Make a selection:
|
|||||||
sw.Write(conv);
|
sw.Write(conv);
|
||||||
sw.Close();
|
sw.Close();
|
||||||
fs.Close();
|
fs.Close();
|
||||||
logger.Log("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.xml");
|
logger.User("Converted file: " + Path.GetFileNameWithoutExtension(filename) + ".new.xml");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1344,9 +1339,9 @@ Make a selection:
|
|||||||
string name = Path.GetFileNameWithoutExtension(input) + "-miss.txt";
|
string name = Path.GetFileNameWithoutExtension(input) + "-miss.txt";
|
||||||
|
|
||||||
// Read in the roms from the DAT and then write them to the file
|
// Read in the roms from the DAT and then write them to the file
|
||||||
logger.Log("Converting " + input);
|
logger.User("Converting " + input);
|
||||||
Output.WriteToText(name, Path.GetDirectoryName(input), RomManipulation.Parse(input, 0, 0, logger), logger, usegame, prefix, postfix, addext, repext, quotes, gamename);
|
Output.WriteToText(name, Path.GetDirectoryName(input), RomManipulation.Parse(input, 0, 0, logger), logger, usegame, prefix, postfix, addext, repext, quotes, gamename);
|
||||||
logger.Log(input + " converted to: " + name);
|
logger.User(input + " converted to: " + name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ namespace SabreTools
|
|||||||
Dictionary<string, List<RomData>> dict = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> dict = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string input in _inputs)
|
foreach (string input in _inputs)
|
||||||
{
|
{
|
||||||
_logger.Log("Adding DAT: " + input);
|
_logger.User("Adding DAT: " + input);
|
||||||
dict = RomManipulation.ParseDict(input, 0, 0, dict, _logger);
|
dict = RomManipulation.ParseDict(input, 0, 0, dict, _logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ namespace SabreTools
|
|||||||
name += " (merged)";
|
name += " (merged)";
|
||||||
|
|
||||||
// For good measure, get all sources
|
// For good measure, get all sources
|
||||||
Dictionary<int, string> sources = new Dictionary<int, string>();
|
Dictionary<int, string> sources = new Dictionary<int, string>();C:\Users\Matt\GitHub\DATabase\DATabaseTwo\Generate.cs
|
||||||
sources.Add(0, "Default");
|
sources.Add(0, "Default");
|
||||||
|
|
||||||
string squery = "SELECT id, name FROM source";
|
string squery = "SELECT id, name FROM source";
|
||||||
@@ -171,7 +171,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now process all of the roms
|
// Now process all of the roms
|
||||||
_logger.Log("Cleaning rom data");
|
_logger.User("Cleaning rom data");
|
||||||
List<string> keys = roms.Keys.ToList();
|
List<string> keys = roms.Keys.ToList();
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ namespace SabreTools
|
|||||||
/// <returns>True if the data could be inserted or updated correctly, false otherwise</returns>
|
/// <returns>True if the data could be inserted or updated correctly, false otherwise</returns>
|
||||||
public bool ImportData()
|
public bool ImportData()
|
||||||
{
|
{
|
||||||
_logger.Log("Beginning import/update process");
|
_logger.User("Beginning import/update process");
|
||||||
using (SqliteConnection dbc = new SqliteConnection(_connectionString))
|
using (SqliteConnection dbc = new SqliteConnection(_connectionString))
|
||||||
{
|
{
|
||||||
dbc.Open();
|
dbc.Open();
|
||||||
@@ -88,7 +88,7 @@ namespace SabreTools
|
|||||||
string system = _datroot + Path.DirectorySeparatorChar + sldr.GetString(1) + " - " + sldr.GetString(2);
|
string system = _datroot + Path.DirectorySeparatorChar + sldr.GetString(1) + " - " + sldr.GetString(2);
|
||||||
system = system.Trim();
|
system = system.Trim();
|
||||||
|
|
||||||
_logger.Log("System: " + system.Remove(0, 5));
|
_logger.User("System: " + system.Remove(0, 5));
|
||||||
|
|
||||||
// Audit all DATs in the folder
|
// Audit all DATs in the folder
|
||||||
foreach (string file in Directory.GetFiles(system, "*", SearchOption.AllDirectories))
|
foreach (string file in Directory.GetFiles(system, "*", SearchOption.AllDirectories))
|
||||||
@@ -246,7 +246,7 @@ VALUES (" + hashid + ", 'source', '" + sourceid + @"'),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Log("Import/update process complete!");
|
_logger.User("Import/update process complete!");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
// Perform initial setup and verification
|
// Perform initial setup and verification
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
logger = new Logger(false, "database.log");
|
logger = new Logger(true, "headerer.log");
|
||||||
logger.Start();
|
logger.Start();
|
||||||
DBTools.EnsureDatabase(_dbName, _connectionString);
|
DBTools.EnsureDatabase(_dbName, _connectionString);
|
||||||
Remapping.CreateHeaderSkips();
|
Remapping.CreateHeaderSkips();
|
||||||
@@ -194,7 +194,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Log("File has header: " + (type != HeaderType.None));
|
logger.User("File has header: " + (type != HeaderType.None));
|
||||||
|
|
||||||
if (type != HeaderType.None)
|
if (type != HeaderType.None)
|
||||||
{
|
{
|
||||||
@@ -212,13 +212,13 @@ namespace SabreTools
|
|||||||
hbin = hbin.Skip(hs).ToArray();
|
hbin = hbin.Skip(hs).ToArray();
|
||||||
|
|
||||||
// Write out the new file
|
// Write out the new file
|
||||||
logger.Log("Creating unheadered file: " + file + ".new");
|
logger.User("Creating unheadered file: " + file + ".new");
|
||||||
BinaryWriter bw = new BinaryWriter(File.OpenWrite(file + ".new"));
|
BinaryWriter bw = new BinaryWriter(File.OpenWrite(file + ".new"));
|
||||||
FileInfo fi = new FileInfo(file);
|
FileInfo fi = new FileInfo(file);
|
||||||
bw.Write(hbin);
|
bw.Write(hbin);
|
||||||
bw.Write(br.ReadBytes((int)fi.Length - hs));
|
bw.Write(br.ReadBytes((int)fi.Length - hs));
|
||||||
bw.Close();
|
bw.Close();
|
||||||
logger.Log("Unheadered file created!");
|
logger.User("Unheadered file created!");
|
||||||
|
|
||||||
// Now add the information to the database if it's not already there
|
// Now add the information to the database if it's not already there
|
||||||
SHA1 sha1 = SHA1.Create();
|
SHA1 sha1 = SHA1.Create();
|
||||||
@@ -287,7 +287,7 @@ namespace SabreTools
|
|||||||
logger.Log("Found match with rom type " + sldr.GetString(1));
|
logger.Log("Found match with rom type " + sldr.GetString(1));
|
||||||
header = sldr.GetString(0);
|
header = sldr.GetString(0);
|
||||||
|
|
||||||
logger.Log("Creating reheadered file: " + file + ".new" + sub);
|
logger.User("Creating reheadered file: " + file + ".new" + sub);
|
||||||
BinaryWriter bw = new BinaryWriter(File.OpenWrite(file + ".new" + sub));
|
BinaryWriter bw = new BinaryWriter(File.OpenWrite(file + ".new" + sub));
|
||||||
|
|
||||||
// Source: http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa
|
// Source: http://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa
|
||||||
@@ -297,7 +297,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
bw.Write(File.ReadAllBytes(file));
|
bw.Write(File.ReadAllBytes(file));
|
||||||
bw.Close();
|
bw.Close();
|
||||||
logger.Log("Reheadered file created!");
|
logger.User("Reheadered file created!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace SabreTools
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// Perform initial setup and verification
|
// Perform initial setup and verification
|
||||||
Logger logger = new Logger(false, "database.log");
|
Logger logger = new Logger(true, "offlinemerge.log");
|
||||||
logger.Start();
|
logger.Start();
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
|
||||||
@@ -143,13 +143,13 @@ namespace SabreTools
|
|||||||
if (_currentAllMerged != "" && _currentMissingMerged != "" && _currentNewMerged != "")
|
if (_currentAllMerged != "" && _currentMissingMerged != "" && _currentNewMerged != "")
|
||||||
{
|
{
|
||||||
// First get the combination Dictionary of currentAllMerged and currentNewMerged
|
// First get the combination Dictionary of currentAllMerged and currentNewMerged
|
||||||
_logger.Log("Adding Current and New Merged DATs to the dictionary");
|
_logger.User("Adding Current and New Merged DATs to the dictionary");
|
||||||
Dictionary<string, List<RomData>> completeDats = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> completeDats = new Dictionary<string, List<RomData>>();
|
||||||
completeDats = RomManipulation.ParseDict(_currentAllMerged, 0, 0, completeDats, _logger);
|
completeDats = RomManipulation.ParseDict(_currentAllMerged, 0, 0, completeDats, _logger);
|
||||||
completeDats = RomManipulation.ParseDict(_currentNewMerged, 0, 0, completeDats, _logger);
|
completeDats = RomManipulation.ParseDict(_currentNewMerged, 0, 0, completeDats, _logger);
|
||||||
|
|
||||||
// Now get Net New output dictionary [(currentNewMerged)-(currentAllMerged)]
|
// Now get Net New output dictionary [(currentNewMerged)-(currentAllMerged)]
|
||||||
_logger.Log("Creating and populating Net New dictionary");
|
_logger.User("Creating and populating Net New dictionary");
|
||||||
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> netNew = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in completeDats.Keys)
|
foreach (string key in completeDats.Keys)
|
||||||
{
|
{
|
||||||
@@ -173,7 +173,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now create the Unneeded dictionary [(currentAllMerged)-(currentNewMerged)]
|
// Now create the Unneeded dictionary [(currentAllMerged)-(currentNewMerged)]
|
||||||
_logger.Log("Creating and populating Uneeded dictionary");
|
_logger.User("Creating and populating Uneeded dictionary");
|
||||||
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> unneeded = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in completeDats.Keys)
|
foreach (string key in completeDats.Keys)
|
||||||
{
|
{
|
||||||
@@ -197,7 +197,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now create the New Missing dictionary [(Net New)+(currentMissingMerged-(Unneeded))]
|
// Now create the New Missing dictionary [(Net New)+(currentMissingMerged-(Unneeded))]
|
||||||
_logger.Log("Creating and populating New Missing dictionary");
|
_logger.User("Creating and populating New Missing dictionary");
|
||||||
Dictionary<string, List<RomData>> midMissing = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> midMissing = new Dictionary<string, List<RomData>>();
|
||||||
midMissing = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midMissing, _logger);
|
midMissing = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midMissing, _logger);
|
||||||
foreach (string key in unneeded.Keys)
|
foreach (string key in unneeded.Keys)
|
||||||
@@ -245,7 +245,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now create the Have dictionary [(currentNewMerged)-(c)]
|
// Now create the Have dictionary [(currentNewMerged)-(c)]
|
||||||
_logger.Log("Creating and populating Have dictionary");
|
_logger.User("Creating and populating Have dictionary");
|
||||||
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
||||||
foreach (string key in newMissing.Keys)
|
foreach (string key in newMissing.Keys)
|
||||||
{
|
{
|
||||||
@@ -308,7 +308,7 @@ namespace SabreTools
|
|||||||
// If we are supposed to replace everything in the output with default values, do so
|
// If we are supposed to replace everything in the output with default values, do so
|
||||||
if (_fake)
|
if (_fake)
|
||||||
{
|
{
|
||||||
_logger.Log("Replacing all hashes in Net New with 0-byte values");
|
_logger.User("Replacing all hashes in Net New with 0-byte values");
|
||||||
List<string> keys = netNew.Keys.ToList();
|
List<string> keys = netNew.Keys.ToList();
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
@@ -326,7 +326,7 @@ namespace SabreTools
|
|||||||
netNew[key] = temp;
|
netNew[key] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Log("Replacing all hashes in Unneeded with 0-byte values");
|
_logger.User("Replacing all hashes in Unneeded with 0-byte values");
|
||||||
keys = unneeded.Keys.ToList();
|
keys = unneeded.Keys.ToList();
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
@@ -344,7 +344,7 @@ namespace SabreTools
|
|||||||
unneeded[key] = temp;
|
unneeded[key] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Log("Replacing all hashes in New Missing with 0-byte values");
|
_logger.User("Replacing all hashes in New Missing with 0-byte values");
|
||||||
keys = newMissing.Keys.ToList();
|
keys = newMissing.Keys.ToList();
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
@@ -362,7 +362,7 @@ namespace SabreTools
|
|||||||
newMissing[key] = temp;
|
newMissing[key] = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.Log("Replacing all hashes in Have with 0-byte values");
|
_logger.User("Replacing all hashes in Have with 0-byte values");
|
||||||
keys = have.Keys.ToList();
|
keys = have.Keys.ToList();
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
@@ -394,7 +394,7 @@ namespace SabreTools
|
|||||||
else if (_currentAllMerged != "" && _currentMissingMerged != "")
|
else if (_currentAllMerged != "" && _currentMissingMerged != "")
|
||||||
{
|
{
|
||||||
// Now create the Have dictionary [(currentAllMerged)-(currentMissingMerged)]
|
// Now create the Have dictionary [(currentAllMerged)-(currentMissingMerged)]
|
||||||
_logger.Log("Creating and populating Have dictionary");
|
_logger.User("Creating and populating Have dictionary");
|
||||||
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
||||||
midHave = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midHave, _logger);
|
midHave = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midHave, _logger);
|
||||||
midHave = RomManipulation.ParseDict(_currentAllMerged, 0, 0, midHave, _logger);
|
midHave = RomManipulation.ParseDict(_currentAllMerged, 0, 0, midHave, _logger);
|
||||||
@@ -423,7 +423,7 @@ namespace SabreTools
|
|||||||
// If we are supposed to replace everything in the output with default values, do so
|
// If we are supposed to replace everything in the output with default values, do so
|
||||||
if (_fake)
|
if (_fake)
|
||||||
{
|
{
|
||||||
_logger.Log("Replacing all hashes in Have with 0-byte values");
|
_logger.User("Replacing all hashes in Have with 0-byte values");
|
||||||
List<string> keys = have.Keys.ToList();
|
List<string> keys = have.Keys.ToList();
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
@@ -451,7 +451,7 @@ namespace SabreTools
|
|||||||
else if (_currentNewMerged != "" && _currentMissingMerged != "")
|
else if (_currentNewMerged != "" && _currentMissingMerged != "")
|
||||||
{
|
{
|
||||||
// Now create the Have dictionary [(currentNewMerged)-(currentMissingMerged)]
|
// Now create the Have dictionary [(currentNewMerged)-(currentMissingMerged)]
|
||||||
_logger.Log("Creating and populating Have dictionary");
|
_logger.User("Creating and populating Have dictionary");
|
||||||
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
Dictionary<string, List<RomData>> midHave = new Dictionary<string, List<RomData>>();
|
||||||
midHave = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midHave, _logger);
|
midHave = RomManipulation.ParseDict(_currentMissingMerged, 0, 0, midHave, _logger);
|
||||||
midHave = RomManipulation.ParseDict(_currentNewMerged, 0, 0, midHave, _logger);
|
midHave = RomManipulation.ParseDict(_currentNewMerged, 0, 0, midHave, _logger);
|
||||||
@@ -480,7 +480,7 @@ namespace SabreTools
|
|||||||
// If we are supposed to replace everything in the output with default values, do so
|
// If we are supposed to replace everything in the output with default values, do so
|
||||||
if (_fake)
|
if (_fake)
|
||||||
{
|
{
|
||||||
_logger.Log("Replacing all hashes in Have with 0-byte values");
|
_logger.User("Replacing all hashes in Have with 0-byte values");
|
||||||
List<string> keys = have.Keys.ToList();
|
List<string> keys = have.Keys.ToList();
|
||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -114,7 +114,6 @@ Options:
|
|||||||
-nr, --no-rename Don't auto-rename games
|
-nr, --no-rename Don't auto-rename games
|
||||||
-o, --old Output DAT in CMP format instead of XML
|
-o, --old Output DAT in CMP format instead of XML
|
||||||
-i, --import Start tool in import mode
|
-i, --import Start tool in import mode
|
||||||
-l, --log Enable logging of program output
|
|
||||||
-lso, --list-sources List all sources (id <= name)
|
-lso, --list-sources List all sources (id <= name)
|
||||||
-lsy, --list-systems List all systems (id <= name)
|
-lsy, --list-systems List all systems (id <= name)
|
||||||
-m, --merge Merge one or more DATs
|
-m, --merge Merge one or more DATs
|
||||||
@@ -168,7 +167,6 @@ Options:
|
|||||||
-c=, --cat= Set the category of the DAT
|
-c=, --cat= Set the category of the DAT
|
||||||
-v=, --version= Set the version of the DAT
|
-v=, --version= Set the version of the DAT
|
||||||
-au=, --author= Set the author of the DAT
|
-au=, --author= Set the author of the DAT
|
||||||
-l, --log Enable log to file
|
|
||||||
-sd, --superdat Enable SuperDAT creation");
|
-sd, --superdat Enable SuperDAT creation");
|
||||||
break;
|
break;
|
||||||
case "OfflineMerge":
|
case "OfflineMerge":
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ namespace SabreTools.Helper
|
|||||||
public enum LogLevel
|
public enum LogLevel
|
||||||
{
|
{
|
||||||
VERBOSE = 0,
|
VERBOSE = 0,
|
||||||
|
USER,
|
||||||
WARNING,
|
WARNING,
|
||||||
ERROR,
|
ERROR,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,8 +106,11 @@ namespace SabreTools.Helper
|
|||||||
/// <returns>True if the output could be written, false otherwise</returns>
|
/// <returns>True if the output could be written, false otherwise</returns>
|
||||||
public bool Log(string output, LogLevel loglevel = LogLevel.VERBOSE)
|
public bool Log(string output, LogLevel loglevel = LogLevel.VERBOSE)
|
||||||
{
|
{
|
||||||
// Everything writes to console
|
// USER and ERROR writes to console
|
||||||
Console.WriteLine(loglevel.ToString() + " " + output);
|
if (loglevel == LogLevel.USER || loglevel == LogLevel.ERROR)
|
||||||
|
{
|
||||||
|
Console.WriteLine((loglevel == LogLevel.ERROR ? loglevel.ToString() + " " : "") + output);
|
||||||
|
}
|
||||||
|
|
||||||
// If we're writing to file, use the existing stream
|
// If we're writing to file, use the existing stream
|
||||||
if (_tofile)
|
if (_tofile)
|
||||||
@@ -127,6 +130,11 @@ namespace SabreTools.Helper
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool User(string output)
|
||||||
|
{
|
||||||
|
return Log(output, LogLevel.USER);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write the given string as a warning to the log output
|
/// Write the given string as a warning to the log output
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// (currently uses current time, change to "last updated time")
|
// (currently uses current time, change to "last updated time")
|
||||||
logger.Log("Opening file for writing: " + outDir + description + (old ? ".dat" : ".xml"));
|
logger.User("Opening file for writing: " + outDir + description + (old ? ".dat" : ".xml"));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -125,7 +125,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
sw.Write((old ? ")" : "\t</machine>\n</datafile>"));
|
sw.Write((old ? ")" : "\t</machine>\n</datafile>"));
|
||||||
logger.Log("File written!" + Environment.NewLine);
|
logger.User("File written!" + Environment.NewLine);
|
||||||
sw.Close();
|
sw.Close();
|
||||||
fs.Close();
|
fs.Close();
|
||||||
}
|
}
|
||||||
@@ -202,7 +202,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// (currently uses current time, change to "last updated time")
|
// (currently uses current time, change to "last updated time")
|
||||||
logger.Log("Opening file for writing: " + outDir + description + (old ? ".dat" : ".xml"));
|
logger.User("Opening file for writing: " + outDir + description + (old ? ".dat" : ".xml"));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -281,7 +281,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
sw.Write((old ? ")" : "\t</machine>\n</datafile>"));
|
sw.Write((old ? ")" : "\t</machine>\n</datafile>"));
|
||||||
logger.Log("File written!" + Environment.NewLine);
|
logger.User("File written!" + Environment.NewLine);
|
||||||
sw.Close();
|
sw.Close();
|
||||||
fs.Close();
|
fs.Close();
|
||||||
}
|
}
|
||||||
@@ -332,7 +332,7 @@ namespace SabreTools.Helper
|
|||||||
addext = (addext == "" || addext.StartsWith(".") ? addext : "." + addext);
|
addext = (addext == "" || addext.StartsWith(".") ? addext : "." + addext);
|
||||||
repext = (repext == "" || repext.StartsWith(".") ? repext : "." + repext);
|
repext = (repext == "" || repext.StartsWith(".") ? repext : "." + repext);
|
||||||
|
|
||||||
logger.Log("Opening file for writing: " + outdir + textfile);
|
logger.User("Opening file for writing: " + outdir + textfile);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -372,7 +372,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Log("File written!" + Environment.NewLine);
|
logger.User("File written!" + Environment.NewLine);
|
||||||
sw.Close();
|
sw.Close();
|
||||||
fs.Close();
|
fs.Close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Log("The total file size is: " + GetBytesReadable(size));
|
logger.User("The total file size is: " + GetBytesReadable(size));
|
||||||
logger.Close();
|
logger.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user