diff --git a/RombaSharp/Partials/RombaSharp_Helpers.cs b/RombaSharp/Partials/RombaSharp_Helpers.cs index ede46f75..5b23b70e 100644 --- a/RombaSharp/Partials/RombaSharp_Helpers.cs +++ b/RombaSharp/Partials/RombaSharp_Helpers.cs @@ -87,7 +87,7 @@ namespace SabreTools dbc.Open(); StreamWriter sw = new StreamWriter(File.Open("export.csv", FileMode.Create, FileAccess.Write)); - sw.WriteLine("\"ID\",\"Size\",\"CRC\",\"MD5\",\"SHA-1\",\"In Depot\",\"DAT Hash""); + sw.WriteLine("\"ID\",\"Size\",\"CRC\",\"MD5\",\"SHA-1\",\"In Depot\",\"DAT Hash\""); string query = "SELECT dats.id, size, crc, md5, sha1, indepot, hash FROM data JOIN dats ON data.id=dats.id"; SqliteCommand slc = new SqliteCommand(query, dbc); @@ -97,13 +97,13 @@ namespace SabreTools { while (sldr.Read()) { - string line = """ + sldr.GetInt32(0) + "\"," - + """ + sldr.GetInt64(1) + "\"," - + """ + sldr.GetString(2) + "\"," - + """ + sldr.GetString(3) + "\"," - + """ + sldr.GetString(4) + "\"," - + """ + sldr.GetInt32(5) + "\"," - + """ + sldr.GetString(6) + """; + string line = "\"" + sldr.GetInt32(0) + "\"," + + "\"" + sldr.GetInt64(1) + "\"," + + "\"" + sldr.GetString(2) + "\"," + + "\"" + sldr.GetString(3) + "\"," + + "\"" + sldr.GetString(4) + "\"," + + "\"" + sldr.GetInt32(5) + "\"," + + "\"" + sldr.GetString(6) + "\""; sw.WriteLine(line); } } @@ -459,7 +459,7 @@ namespace SabreTools foreach (string dathash in unneeded) { - query = "DELETE FROM dats WHERE hash="" + dathash + """; + query = "DELETE FROM dats WHERE hash=\"" + dathash + "\""; slc = new SqliteCommand(query, dbc); slc.ExecuteNonQuery(); slc.Dispose(); @@ -502,23 +502,23 @@ namespace SabreTools if (!String.IsNullOrEmpty(rom.CRC)) { - crcquery += " ("" + rom.CRC + "\"),"; + crcquery += " (\"" + rom.CRC + "\"),"; } if (!String.IsNullOrEmpty(rom.MD5)) { - md5query += " ("" + rom.MD5 + "\"),"; + md5query += " (\"" + rom.MD5 + "\"),"; } if (!String.IsNullOrEmpty(rom.SHA1)) { - sha1query += " ("" + rom.SHA1 + "\"),"; + sha1query += " (\"" + rom.SHA1 + "\"),"; if (!String.IsNullOrEmpty(rom.CRC)) { - crcsha1query += " ("" + rom.CRC + "\", "" + rom.SHA1 + "\"),"; + crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; } if (!String.IsNullOrEmpty(rom.MD5)) { - md5sha1query += " ("" + rom.MD5 + "\", "" + rom.SHA1 + "\"),"; + md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),"; } } } @@ -528,15 +528,15 @@ namespace SabreTools if (!String.IsNullOrEmpty(disk.MD5)) { - md5query += " ("" + disk.MD5 + "\"),"; + md5query += " (\"" + disk.MD5 + "\"),"; } if (!String.IsNullOrEmpty(disk.SHA1)) { - sha1query += " ("" + disk.SHA1 + "\"),"; + sha1query += " (\"" + disk.SHA1 + "\"),"; if (!String.IsNullOrEmpty(disk.MD5)) { - md5sha1query += " ("" + disk.MD5 + "\", "" + disk.SHA1 + "\"),"; + md5sha1query += " (\"" + disk.MD5 + "\", \"" + disk.SHA1 + "\"),"; } } } @@ -571,7 +571,7 @@ namespace SabreTools } } - string datquery = "INSERT OR IGNORE INTO dat (hash) VALUES ("" + dat.SHA1 + "\")"; + string datquery = "INSERT OR IGNORE INTO dat (hash) VALUES (\"" + dat.SHA1 + "\")"; slc = new SqliteCommand(datquery, dbc); slc.ExecuteNonQuery(); slc.Dispose(); @@ -603,7 +603,7 @@ namespace SabreTools // If we have it, then check for all hashes that are in that depot List hashes = new List(); - string query = "SELECT sha1 FROM sha1 WHERE depot="" + depotname + """; + string query = "SELECT sha1 FROM sha1 WHERE depot=\"" + depotname + "\""; SqliteCommand slc = new SqliteCommand(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); if (sldr.HasRows) @@ -643,23 +643,23 @@ namespace SabreTools { if (!String.IsNullOrEmpty(rom.CRC)) { - crcquery += " ("" + rom.CRC + "\"),"; + crcquery += " (\"" + rom.CRC + "\"),"; } if (!String.IsNullOrEmpty(rom.MD5)) { - md5query += " ("" + rom.MD5 + "\"),"; + md5query += " (\"" + rom.MD5 + "\"),"; } if (!String.IsNullOrEmpty(rom.SHA1)) { - sha1query += " ("" + rom.SHA1 + "\", "" + depotname + "\"),"; + sha1query += " (\"" + rom.SHA1 + "\", \"" + depotname + "\"),"; if (!String.IsNullOrEmpty(rom.CRC)) { - crcsha1query += " ("" + rom.CRC + "\", "" + rom.SHA1 + "\"),"; + crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; } if (!String.IsNullOrEmpty(rom.MD5)) { - md5sha1query += " ("" + rom.MD5 + "\", "" + rom.SHA1 + "\"),"; + md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),"; } } } @@ -703,7 +703,7 @@ JOIN crc ON crcsha1.crc=crc.crc JOIN md5 ON md5sha1.md5=md5.md5 -WHERE sha1.sha1 IN (String.Empty" + String.Join("\","", hashes) + "\")"; +WHERE sha1.sha1 IN (String.Empty" + String.Join("\",\"", hashes) + "\")"; slc = new SqliteCommand(query, dbc); slc.ExecuteNonQuery(); diff --git a/RombaSharp/Partials/RombaSharp_Inits.cs b/RombaSharp/Partials/RombaSharp_Inits.cs index fa185e8f..15d5e99d 100644 --- a/RombaSharp/Partials/RombaSharp_Inits.cs +++ b/RombaSharp/Partials/RombaSharp_Inits.cs @@ -73,9 +73,9 @@ namespace SabreTools if (onlyNeeded) { string query = "SELECT * FROM crcsha1 JOIN md5sha1 ON crcsha1.sha1=md5sha1.sha1" - + " WHERE crcsha1.crc="" + rom.CRC + """ - + " OR md5sha1.md5="" + rom.MD5 + """ - + " OR md5sha1.sha1="" + rom.SHA1 + """; + + " WHERE crcsha1.crc=\"" + rom.CRC + "\"" + + " OR md5sha1.md5=\"" + rom.MD5 + "\"" + + " OR md5sha1.sha1=\"" + rom.SHA1 + "\""; SqliteCommand slc = new SqliteCommand(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); @@ -84,23 +84,23 @@ namespace SabreTools // Add to the queries if (!String.IsNullOrEmpty(rom.CRC)) { - crcquery += " ("" + rom.CRC + "\"),"; + crcquery += " (\"" + rom.CRC + "\"),"; } if (!String.IsNullOrEmpty(rom.MD5)) { - md5query += " ("" + rom.MD5 + "\"),"; + md5query += " (\"" + rom.MD5 + "\"),"; } if (!String.IsNullOrEmpty(rom.SHA1)) { - sha1query += " ("" + rom.SHA1 + "\", "" + _depots.Keys.ToList()[0] + "\"),"; + sha1query += " (\"" + rom.SHA1 + "\", \"" + _depots.Keys.ToList()[0] + "\"),"; if (!String.IsNullOrEmpty(rom.CRC)) { - crcsha1query += " ("" + rom.CRC + "\", "" + rom.SHA1 + "\"),"; + crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; } if (!String.IsNullOrEmpty(rom.MD5)) { - md5sha1query += " ("" + rom.MD5 + "\", "" + rom.SHA1 + "\"),"; + md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),"; } } @@ -114,23 +114,23 @@ namespace SabreTools // Add to the queries if (!String.IsNullOrEmpty(rom.CRC)) { - crcquery += " ("" + rom.CRC + "\"),"; + crcquery += " (\"" + rom.CRC + "\"),"; } if (!String.IsNullOrEmpty(rom.MD5)) { - md5query += " ("" + rom.MD5 + "\"),"; + md5query += " (\"" + rom.MD5 + "\"),"; } if (!String.IsNullOrEmpty(rom.SHA1)) { - sha1query += " ("" + rom.SHA1 + "\", "" + _depots.Keys.ToList()[0] + "\"),"; + sha1query += " (\"" + rom.SHA1 + "\", \"" + _depots.Keys.ToList()[0] + "\"),"; if (!String.IsNullOrEmpty(rom.CRC)) { - crcsha1query += " ("" + rom.CRC + "\", "" + rom.SHA1 + "\"),"; + crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; } if (!String.IsNullOrEmpty(rom.MD5)) { - md5sha1query += " ("" + rom.MD5 + "\", "" + rom.SHA1 + "\"),"; + md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),"; } } @@ -320,7 +320,7 @@ namespace SabreTools // Now, search for each of them and return true or false for each foreach (string input in crc) { - string query = "SELECT * FROM crc WHERE crc="" + input + """; + string query = "SELECT * FROM crc WHERE crc=\"" + input + "\""; SqliteCommand slc = new SqliteCommand(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); if (sldr.HasRows) @@ -337,7 +337,7 @@ namespace SabreTools } foreach (string input in md5) { - string query = "SELECT * FROM md5 WHERE md5="" + input + """; + string query = "SELECT * FROM md5 WHERE md5=\"" + input + "\""; SqliteCommand slc = new SqliteCommand(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); if (sldr.HasRows) @@ -354,7 +354,7 @@ namespace SabreTools } foreach (string input in sha1) { - string query = "SELECT * FROM sha1 WHERE sha1="" + input + """; + string query = "SELECT * FROM sha1 WHERE sha1=\"" + input + "\""; SqliteCommand slc = new SqliteCommand(query, dbc); SqliteDataReader sldr = slc.ExecuteReader(); if (sldr.HasRows) diff --git a/RombaSharp/Properties/AssemblyInfo.cs b/RombaSharp/Properties/AssemblyInfo.cs index f73d8200..77f5f3c0 100644 --- a/RombaSharp/Properties/AssemblyInfo.cs +++ b/RombaSharp/Properties/AssemblyInfo.cs @@ -6,13 +6,13 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("RombaSharp")] -[assembly: AssemblyDescription(String.Empty)] -[assembly: AssemblyConfiguration(String.Empty)] -[assembly: AssemblyCompany(String.Empty)] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] [assembly: AssemblyProduct("RombaSharp")] [assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark(String.Empty)] -[assembly: AssemblyCulture(String.Empty)] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from diff --git a/RombaSharp/RombaSharp.cs b/RombaSharp/RombaSharp.cs index ff465194..e0a7d04c 100644 --- a/RombaSharp/RombaSharp.cs +++ b/RombaSharp/RombaSharp.cs @@ -178,7 +178,7 @@ namespace SabreTools outdat = args[i]; break; default: - string temparg = args[i].Replace(""", String.Empty).Replace("file://", String.Empty); + string temparg = args[i].Replace("\"", String.Empty).Replace("file://", String.Empty); if (temparg.StartsWith("-") && temparg.Contains("=")) { diff --git a/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs b/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs index 6908f489..d3451cb9 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.ConvertUpdate.cs @@ -478,7 +478,7 @@ namespace SabreTools.Helper.Dats if (File.Exists(inputFileName)) { DatFile innerDatdata = new DatFile(this); - logger.User("Processing "" + Path.GetFileName(inputFileName) + """); + logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\""); innerDatdata.Parse(inputFileName, 0, 0, filter, splitType, trim, single, root, logger, true, clean, softlist, keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); @@ -497,7 +497,7 @@ namespace SabreTools.Helper.Dats new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, file => { - logger.User("Processing "" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + """); + logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\""); DatFile innerDatdata = new DatFile(this); innerDatdata.Parse(file, 0, 0, filter, splitType, trim, single, root, logger, true, clean, softlist, diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs b/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs index 2d2eec9d..7cd76ce8 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Parsers.cs @@ -369,7 +369,7 @@ namespace SabreTools.Helper.Dats // If we have a sample, treat it special if (temptype == ItemType.Sample) { - line = line.Trim().Remove(0, 6).Trim().Replace(""", String.Empty); // Remove "sample" from the input string + line = line.Trim().Remove(0, 6).Trim().Replace("\"", String.Empty); // Remove "sample" from the input string item.Name = line; // Now process and add the sample @@ -421,7 +421,7 @@ namespace SabreTools.Helper.Dats else if (gc[i] == "date") { i++; - ((Rom)item).Date = gc[i].Replace(""", String.Empty) + " " + gc[i + 1].Replace(""", String.Empty); + ((Rom)item).Date = gc[i].Replace("\"", String.Empty) + " " + gc[i + 1].Replace("\"", String.Empty); i += 3; } @@ -429,7 +429,7 @@ namespace SabreTools.Helper.Dats else if (gc[i] == "crc") { i++; - ((Rom)item).CRC = gc[i].Replace(""", String.Empty).ToLowerInvariant(); + ((Rom)item).CRC = gc[i].Replace("\"", String.Empty).ToLowerInvariant(); } } @@ -443,11 +443,11 @@ namespace SabreTools.Helper.Dats for (int i = 0; i < gc.Length; i++) { // Look at the current item and use it if possible - string quoteless = gc[i].Replace(""", String.Empty); + string quoteless = gc[i].Replace("\"", String.Empty); switch (quoteless) { //If the item is empty, we automatically skip it because it's a fluke - case String.Empty: + case "": continue; // Special cases for standalone item statuses @@ -495,14 +495,14 @@ namespace SabreTools.Helper.Dats // Regular attributes case "name": i++; - quoteless = gc[i].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty); item.Name = quoteless; break; case "size": if (item.Type == ItemType.Rom) { i++; - quoteless = gc[i].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty); long size = -1; if (Int64.TryParse(quoteless, out size)) { @@ -515,7 +515,7 @@ namespace SabreTools.Helper.Dats if (item.Type == ItemType.Rom) { i++; - quoteless = gc[i].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty); ((Rom)item).CRC = quoteless.ToLowerInvariant(); } break; @@ -523,13 +523,13 @@ namespace SabreTools.Helper.Dats if (item.Type == ItemType.Rom) { i++; - quoteless = gc[i].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty); ((Rom)item).MD5 = quoteless.ToLowerInvariant(); } else if (item.Type == ItemType.Disk) { i++; - quoteless = gc[i].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty); ((Disk)item).MD5 = quoteless.ToLowerInvariant(); } break; @@ -537,20 +537,20 @@ namespace SabreTools.Helper.Dats if (item.Type == ItemType.Rom) { i++; - quoteless = gc[i].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty); ((Rom)item).SHA1 = quoteless.ToLowerInvariant(); } else if (item.Type == ItemType.Disk) { i++; - quoteless = gc[i].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty); ((Disk)item).SHA1 = quoteless.ToLowerInvariant(); } break; case "status": case "flags": i++; - quoteless = gc[i].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty); if (quoteless.ToLowerInvariant() == "good") { if (item.Type == ItemType.Rom) @@ -600,7 +600,7 @@ namespace SabreTools.Helper.Dats if (item.Type == ItemType.Rom) { i++; - quoteless = gc[i].Replace(""", String.Empty) + " " + gc[i + 1].Replace(""", String.Empty); + quoteless = gc[i].Replace("\"", String.Empty) + " " + gc[i + 1].Replace("\"", String.Empty); ((Rom)item).Date = quoteless; } i++; @@ -620,7 +620,7 @@ namespace SabreTools.Helper.Dats if (blockname != "header") { - string itemval = gc[2].Value.Replace(""", String.Empty); + string itemval = gc[2].Value.Replace("\"", String.Empty); switch (gc[1].Value) { case "name": @@ -648,7 +648,7 @@ namespace SabreTools.Helper.Dats } else { - string itemval = gc[2].Value.Replace(""", String.Empty); + string itemval = gc[2].Value.Replace("\"", String.Empty); if (line.Trim().StartsWith("Name:")) { @@ -1418,7 +1418,7 @@ namespace SabreTools.Helper.Dats machine.Description = subreader.ReadElementContentAsString(); if (!softlist && temptype == "software") { - machine.Name = machine.Description.Replace('/', '_').Replace(""", "''"); + machine.Name = machine.Description.Replace('/', '_').Replace("\"", "''"); } break; case "year": @@ -1580,13 +1580,13 @@ namespace SabreTools.Helper.Dats if (subreader.GetAttribute("flags") == "baddump" || subreader.GetAttribute("status") == "baddump") { logger.Verbose("Bad dump detected: " + - (subreader.GetAttribute("name") != null && subreader.GetAttribute("name") != String.Empty ? """ + xtr.GetAttribute("name") + """ : "ROM NAME NOT FOUND")); + (subreader.GetAttribute("name") != null && subreader.GetAttribute("name") != String.Empty ? "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); its = ItemStatus.BadDump; } if (subreader.GetAttribute("flags") == "nodump" || subreader.GetAttribute("status") == "nodump") { logger.Verbose("Nodump detected: " + - (subreader.GetAttribute("name") != null && subreader.GetAttribute("name") != String.Empty ? """ + xtr.GetAttribute("name") + """ : "ROM NAME NOT FOUND")); + (subreader.GetAttribute("name") != null && subreader.GetAttribute("name") != String.Empty ? "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); its = ItemStatus.Nodump; } if (subreader.GetAttribute("flags") == "verified" || subreader.GetAttribute("status") == "verified") @@ -1765,12 +1765,12 @@ namespace SabreTools.Helper.Dats break; case "baddump": logger.Verbose("Bad dump detected: " + (xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != String.Empty ? - """ + xtr.GetAttribute("name") + """ : "ROM NAME NOT FOUND")); + "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); its = ItemStatus.BadDump; break; case "nodump": logger.Verbose("Nodump detected: " + (xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != String.Empty ? - """ + xtr.GetAttribute("name") + """ : "ROM NAME NOT FOUND")); + "\"" + xtr.GetAttribute("name") + "\"" : "ROM NAME NOT FOUND")); its = ItemStatus.Nodump; break; case "verified": @@ -2304,7 +2304,7 @@ namespace SabreTools.Helper.Dats // If the file has no size and it's not the above case, skip and log else if (itemRom.ItemStatus != ItemStatus.Nodump && (itemRom.Size == 0 || itemRom.Size == -1)) { - logger.Verbose("Incomplete entry for "" + itemRom.Name + "\" will be output as nodump"); + logger.Verbose("Incomplete entry for \"" + itemRom.Name + "\" will be output as nodump"); itemRom.ItemStatus = ItemStatus.Nodump; } // If the file has a size but aboslutely no hashes, skip and log @@ -2314,7 +2314,7 @@ namespace SabreTools.Helper.Dats && String.IsNullOrEmpty(itemRom.MD5) && String.IsNullOrEmpty(itemRom.SHA1)) { - logger.Verbose("Incomplete entry for "" + itemRom.Name + "\" will be output as nodump"); + logger.Verbose("Incomplete entry for \"" + itemRom.Name + "\" will be output as nodump"); itemRom.ItemStatus = ItemStatus.Nodump; } @@ -2333,7 +2333,7 @@ namespace SabreTools.Helper.Dats && String.IsNullOrEmpty(itemDisk.MD5) && String.IsNullOrEmpty(itemDisk.SHA1)) { - logger.Verbose("Incomplete entry for "" + itemDisk.Name + "\" will be output as nodump"); + logger.Verbose("Incomplete entry for \"" + itemDisk.Name + "\" will be output as nodump"); itemDisk.ItemStatus = ItemStatus.Nodump; } diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Statistics.cs b/SabreTools.Helper/Dats/Partials/DatFile.Statistics.cs index 49a88bb8..007407b1 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Statistics.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Statistics.cs @@ -158,22 +158,22 @@ namespace SabreTools.Helper.Dats } if (outputs.ContainsKey(StatDatFormat.CSV)) { - line = """ + FileName + "\"," - + """ + TotalSize + "\"," - + """ + (game == -1 ? Count : game) + "\"," - + """ + RomCount + "\"," - + """ + DiskCount + "\"," - + """ + CRCCount + "\"," - + """ + MD5Count + "\"," - + """ + SHA1Count + """; + line = "\"" + FileName + "\"," + + "\"" + TotalSize + "\"," + + "\"" + (game == -1 ? Count : game) + "\"," + + "\"" + RomCount + "\"," + + "\"" + DiskCount + "\"," + + "\"" + CRCCount + "\"," + + "\"" + MD5Count + "\"," + + "\"" + SHA1Count + "\""; if (baddumpCol) { - line += ","" + BaddumpCount + """; + line += ",\"" + BaddumpCount + "\""; } if (nodumpCol) { - line += ","" + NodumpCount + """; + line += ",\"" + NodumpCount + "\""; } line += "\n"; @@ -206,22 +206,22 @@ namespace SabreTools.Helper.Dats } if (outputs.ContainsKey(StatDatFormat.TSV)) { - line = """ + FileName + "\"\t" - + """ + TotalSize + "\"\t" - + """ + (game == -1 ? Count : game) + "\"\t" - + """ + RomCount + "\"\t" - + """ + DiskCount + "\"\t" - + """ + CRCCount + "\"\t" - + """ + MD5Count + "\"\t" - + """ + SHA1Count + """; + line = "\"" + FileName + "\"\t" + + "\"" + TotalSize + "\"\t" + + "\"" + (game == -1 ? Count : game) + "\"\t" + + "\"" + RomCount + "\"\t" + + "\"" + DiskCount + "\"\t" + + "\"" + CRCCount + "\"\t" + + "\"" + MD5Count + "\"\t" + + "\"" + SHA1Count + "\""; if (baddumpCol) { - line += "\t"" + BaddumpCount + """; + line += "\t\"" + BaddumpCount + "\""; } if (nodumpCol) { - line += "\t"" + NodumpCount + """; + line += "\t\"" + NodumpCount + "\""; } line += "\n"; @@ -530,8 +530,8 @@ Please check the log folder if the stats scrolled offscreen", false); } if (outputs.ContainsKey(StatDatFormat.CSV)) { - outputs[StatDatFormat.CSV].Write("\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1"" - + (baddumpCol ? ",\"BadDumps"" : String.Empty) + (nodumpCol ? ",\"Nodumps"" : String.Empty) + "\n"); + outputs[StatDatFormat.CSV].Write("\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1\"" + + (baddumpCol ? ",\"BadDumps\"" : String.Empty) + (nodumpCol ? ",\"Nodumps\"" : String.Empty) + "\n"); } if (outputs.ContainsKey(StatDatFormat.HTML)) { @@ -558,8 +558,8 @@ Please check the log folder if the stats scrolled offscreen", false); } if (outputs.ContainsKey(StatDatFormat.TSV)) { - outputs[StatDatFormat.TSV].Write("\"File Name\"\t\"Total Size\"\t\"Games\"\t\"Roms\"\t\"Disks\"\t\"# with CRC\"\t\"# with MD5\"\t\"# with SHA-1"" - + (baddumpCol ? "\t\"BadDumps"" : String.Empty) + (nodumpCol ? "\t\"Nodumps"" : String.Empty) + "\n"); + outputs[StatDatFormat.TSV].Write("\"File Name\"\t\"Total Size\"\t\"Games\"\t\"Roms\"\t\"Disks\"\t\"# with CRC\"\t\"# with MD5\"\t\"# with SHA-1\"" + + (baddumpCol ? "\t\"BadDumps\"" : String.Empty) + (nodumpCol ? "\t\"Nodumps\"" : String.Empty) + "\n"); } // Now write the mid header for those who need it @@ -614,7 +614,7 @@ Please check the log folder if the stats scrolled offscreen", false); } if (outputs.ContainsKey(StatDatFormat.HTML)) { - outputs[StatDatFormat.HTML].Write(" -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ namespace SabreTools.Helper.Resources { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - public class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SabreTools.Helper.Resources.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - public static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - - /// - /// Looks up a localized string similar to This is the default help output. - /// - public static string Default_Desc { - get { - return ResourceManager.GetString("Default_Desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Remove and restore rom headers. - /// - public static string Headerer_Desc { - get { - return ResourceManager.GetString("Headerer_Desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Headerer. - /// - public static string Headerer_Name { - get { - return ResourceManager.GetString("Headerer_Name", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to C# port of the Romba rom management tool. - /// - public static string RombaSharp_Desc { - get { - return ResourceManager.GetString("RombaSharp_Desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to RombaSharp. - /// - public static string RombaSharp_Name { - get { - return ResourceManager.GetString("RombaSharp_Name", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Import, generate, manipulate DAT files. - /// - public static string SabreTools_Desc { - get { - return ResourceManager.GetString("SabreTools_Desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to SabreTools. - /// - public static string SabreTools_Name { - get { - return ResourceManager.GetString("SabreTools_Name", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Basic rebuild using a DAT. - /// - public static string SimpleSort_Desc { - get { - return ResourceManager.GetString("SimpleSort_Desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to SimpleSort. - /// - public static string SimpleSort_Name { - get { - return ResourceManager.GetString("SimpleSort_Name", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Convert files to TGZ output. - /// - public static string TGZTest_Desc { - get { - return ResourceManager.GetString("TGZTest_Desc", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to TGZConvert. - /// - public static string TGZTest_Name { - get { - return ResourceManager.GetString("TGZTest_Name", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to Usage. - /// - public static string Usage { - get { - return ResourceManager.GetString("Usage", resourceCulture); - } - } - } + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SabreTools.Helper.Resources.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to This is the default help output. + /// + public static string Default_Desc { + get { + return ResourceManager.GetString("Default_Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Remove and restore rom headers. + /// + public static string Headerer_Desc { + get { + return ResourceManager.GetString("Headerer_Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Headerer. + /// + public static string Headerer_Name { + get { + return ResourceManager.GetString("Headerer_Name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to C# port of the Romba rom management tool. + /// + public static string RombaSharp_Desc { + get { + return ResourceManager.GetString("RombaSharp_Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to RombaSharp. + /// + public static string RombaSharp_Name { + get { + return ResourceManager.GetString("RombaSharp_Name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Import, generate, manipulate DAT files. + /// + public static string SabreTools_Desc { + get { + return ResourceManager.GetString("SabreTools_Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to SabreTools. + /// + public static string SabreTools_Name { + get { + return ResourceManager.GetString("SabreTools_Name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Basic rebuild using a DAT. + /// + public static string SimpleSort_Desc { + get { + return ResourceManager.GetString("SimpleSort_Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to SimpleSort. + /// + public static string SimpleSort_Name { + get { + return ResourceManager.GetString("SimpleSort_Name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Convert files to TGZ output. + /// + public static string TGZTest_Desc { + get { + return ResourceManager.GetString("TGZTest_Desc", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to TGZConvert. + /// + public static string TGZTest_Name { + get { + return ResourceManager.GetString("TGZTest_Name", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Usage. + /// + public static string Usage { + get { + return ResourceManager.GetString("Usage", resourceCulture); + } + } + } } diff --git a/SabreTools.Helper/Resources/Resources.de-DE.resx b/SabreTools.Helper/Resources/Resources.de-DE.resx index c333b7cc..7446e8b4 100644 --- a/SabreTools.Helper/Resources/Resources.de-DE.resx +++ b/SabreTools.Helper/Resources/Resources.de-DE.resx @@ -59,7 +59,7 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - + diff --git a/SabreTools.Helper/Resources/Resources.es-ES.resx b/SabreTools.Helper/Resources/Resources.es-ES.resx index db79e4b5..4b6d5e3a 100644 --- a/SabreTools.Helper/Resources/Resources.es-ES.resx +++ b/SabreTools.Helper/Resources/Resources.es-ES.resx @@ -59,7 +59,7 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - + diff --git a/SabreTools.Helper/Resources/Resources.fr-FR.resx b/SabreTools.Helper/Resources/Resources.fr-FR.resx index eb1999fe..dee186d4 100644 --- a/SabreTools.Helper/Resources/Resources.fr-FR.resx +++ b/SabreTools.Helper/Resources/Resources.fr-FR.resx @@ -59,7 +59,7 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - + diff --git a/SabreTools.Helper/Resources/Resources.resx b/SabreTools.Helper/Resources/Resources.resx index 9f37e96e..c1c30dfa 100644 --- a/SabreTools.Helper/Resources/Resources.resx +++ b/SabreTools.Helper/Resources/Resources.resx @@ -59,7 +59,7 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - + diff --git a/SabreTools.Helper/Tools/ArchiveTools.cs b/SabreTools.Helper/Tools/ArchiveTools.cs index f38bbc2b..ee77cd57 100644 --- a/SabreTools.Helper/Tools/ArchiveTools.cs +++ b/SabreTools.Helper/Tools/ArchiveTools.cs @@ -1102,6 +1102,13 @@ namespace SabreTools.Helper.Tools public static bool WriteTAR(List inputFiles, string outDir, List roms, Logger logger, bool date = false) { bool success = false; + string tempFile = Path.GetTempFileName(); + + // If either list of roms is null or empty, return + if (inputFiles == null || roms == null || inputFiles.Count == 0 || roms.Count == 0) + { + return success; + } // If the number of inputs is less than the number of available roms, return if (inputFiles.Count < roms.Count) @@ -1122,8 +1129,8 @@ namespace SabreTools.Helper.Tools string archiveFileName = Path.Combine(outDir, Style.RemovePathUnsafeCharacters(roms[0].Machine.Name) + (roms[0].Machine.Name.EndsWith(".tar") ? String.Empty : ".tar")); // Set internal variables - Stream tarstream = new MemoryStream(); - TarArchive tarchive = TarArchive.Create(); + TarArchive oldTarFile = TarArchive.Create(); + TarArchive tarFile = TarArchive.Create(); try { @@ -1133,42 +1140,120 @@ namespace SabreTools.Helper.Tools Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName)); } - // We can only overwrite at this point, sorry - tarstream = File.Open(archiveFileName, FileMode.Create, FileAccess.Write); - - // Map all inputs to index - Dictionary inputIndexMap = new Dictionary(); - for (int i = 0; i < inputFiles.Count; i++) + // If the archive doesn't exist, create it and put the single file + if (!File.Exists(archiveFileName)) { - inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), i); + // Map all inputs to index + Dictionary inputIndexMap = new Dictionary(); + for (int i = 0; i < inputFiles.Count; i++) + { + inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), i); + } + + // Sort the keys in TZIP order + List keys = inputIndexMap.Keys.ToList(); + keys.Sort(ZipFile.TorrentZipStringCompare); + + // Now add all of the files in order + foreach (string key in keys) + { + // Get the index mapped to the key + int index = inputIndexMap[key]; + + // Copy the input stream to the output + tarFile.AddEntry(roms[index].Name, inputFiles[index]); + } } - // Sort the keys in TZIP order - List keys = inputIndexMap.Keys.ToList(); - keys.Sort(ZipFile.TorrentZipStringCompare); - - // Now add each of the files - foreach (string key in keys) + // Otherwise, sort the input files and write out in the correct order + else { - int index = inputIndexMap[key]; - tarchive.AddEntry(key, inputFiles[index]); + // Open the old archive for reading + oldTarFile = TarArchive.Open(archiveFileName); + + // Get a list of all current entries + List entries = oldTarFile.Entries.Select(i => i.Key).ToList(); + + // Map all inputs to index + Dictionary inputIndexMap = new Dictionary(); + for (int i = 0; i < inputFiles.Count; i++) + { + // If the old one contains the new file, then just skip out + if (entries.Contains(roms[i].Name.Replace('\\', '/'))) + { + continue; + } + + inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), -(i + 1)); + } + + // Then add all of the old entries to it too + for (int i = 0; i < entries.Count; i++) + { + inputIndexMap.Add(entries[i], i); + } + + // If the number of entries is the same as the old archive, skip out + if (inputIndexMap.Keys.Count <= entries.Count) + { + success = true; + return success; + } + + // Get the order for the entries with the new file + List keys = inputIndexMap.Keys.ToList(); + keys.Sort(ZipFile.TorrentZipStringCompare); + + // Copy over all files to the new archive + foreach (string key in keys) + { + // Get the index mapped to the key + int index = inputIndexMap[key]; + + // If we have the input file, add it now + if (index < 0) + { + // Copy the input file to the output + tarFile.AddEntry(roms[-index - 1].Name, inputFiles[-index - 1]); + } + + // Otherwise, copy the file from the old archive + else + { + // Get the stream from the original archive + MemoryStream readStream = new MemoryStream(); + oldTarFile.Entries.Where(e => e.Key == key).ToList()[0].WriteTo(readStream); + + // Copy the input stream to the output + tarFile.AddEntry(key, readStream); + } + } } - tarchive.SaveTo(tarstream, new WriterOptions(CompressionType.None)); + // Close the output tar file + tarFile.SaveTo(tempFile, new WriterOptions(CompressionType.None)); + success = true; } catch (Exception ex) { + Console.WriteLine(ex); success = false; - logger.Error(ex.ToString()); } finally { - tarstream?.Dispose(); - tarchive?.Dispose(); + tarFile.Dispose(); + oldTarFile.Dispose(); } - return success; + // If the old file exists, delete it and replace + if (File.Exists(archiveFileName)) + { + File.Delete(archiveFileName); + } + File.Move(tempFile, archiveFileName); + + return true; } /// diff --git a/SabreTools.Helper/Tools/FileTools.cs b/SabreTools.Helper/Tools/FileTools.cs index 6ee430a3..fa4db639 100644 --- a/SabreTools.Helper/Tools/FileTools.cs +++ b/SabreTools.Helper/Tools/FileTools.cs @@ -79,7 +79,7 @@ namespace SabreTools.Helper.Tools } // Read the input file, if possible - logger.Verbose("Attempting to read file to get format: "" + filename + """); + logger.Verbose("Attempting to read file to get format: \"" + filename + "\""); // Check if file exists if (!File.Exists(filename)) @@ -437,7 +437,7 @@ namespace SabreTools.Helper.Tools /// The XmlTextReader representing the (possibly converted) file, null otherwise public static XmlReader GetXmlTextReader(string filename, Logger logger) { - logger.Verbose("Attempting to read file: "" + filename + """); + logger.Verbose("Attempting to read file: \"" + filename + "\""); // Check if file exists if (!File.Exists(filename)) diff --git a/SabreTools/Properties/AssemblyInfo.cs b/SabreTools/Properties/AssemblyInfo.cs index fbaf0bde..89cd2b66 100644 --- a/SabreTools/Properties/AssemblyInfo.cs +++ b/SabreTools/Properties/AssemblyInfo.cs @@ -7,12 +7,12 @@ using System.Runtime.InteropServices; // associated with an assembly. [assembly: AssemblyTitle("SabreTools")] [assembly: AssemblyDescription("DAT manipulation toolset")] -[assembly: AssemblyConfiguration(String.Empty)] -[assembly: AssemblyCompany(String.Empty)] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] [assembly: AssemblyProduct("SabreTools")] [assembly: AssemblyCopyright("Copyright © 2016")] -[assembly: AssemblyTrademark(String.Empty)] -[assembly: AssemblyCulture(String.Empty)] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from