Revert "[ALL] Fix String.Empty"

This reverts commit c02a115c98.
This commit is contained in:
Matt Nadareski
2017-01-27 16:53:23 -08:00
parent e3daf4ce69
commit c8142549bb
15 changed files with 294 additions and 379 deletions

View File

@@ -87,7 +87,7 @@ namespace SabreTools
dbc.Open(); dbc.Open();
StreamWriter sw = new StreamWriter(File.Open("export.csv", FileMode.Create, FileAccess.Write)); 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"; 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); SqliteCommand slc = new SqliteCommand(query, dbc);
@@ -97,13 +97,13 @@ namespace SabreTools
{ {
while (sldr.Read()) while (sldr.Read())
{ {
string line = "\"" + sldr.GetInt32(0) + "\"," string line = """ + sldr.GetInt32(0) + "\","
+ "\"" + sldr.GetInt64(1) + "\"," + """ + sldr.GetInt64(1) + "\","
+ "\"" + sldr.GetString(2) + "\"," + """ + sldr.GetString(2) + "\","
+ "\"" + sldr.GetString(3) + "\"," + """ + sldr.GetString(3) + "\","
+ "\"" + sldr.GetString(4) + "\"," + """ + sldr.GetString(4) + "\","
+ "\"" + sldr.GetInt32(5) + "\"," + """ + sldr.GetInt32(5) + "\","
+ "\"" + sldr.GetString(6) + "\""; + """ + sldr.GetString(6) + """;
sw.WriteLine(line); sw.WriteLine(line);
} }
} }
@@ -459,7 +459,7 @@ namespace SabreTools
foreach (string dathash in unneeded) 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 = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery(); slc.ExecuteNonQuery();
slc.Dispose(); slc.Dispose();
@@ -502,23 +502,23 @@ namespace SabreTools
if (!String.IsNullOrEmpty(rom.CRC)) if (!String.IsNullOrEmpty(rom.CRC))
{ {
crcquery += " (\"" + rom.CRC + "\"),"; crcquery += " ("" + rom.CRC + "\"),";
} }
if (!String.IsNullOrEmpty(rom.MD5)) if (!String.IsNullOrEmpty(rom.MD5))
{ {
md5query += " (\"" + rom.MD5 + "\"),"; md5query += " ("" + rom.MD5 + "\"),";
} }
if (!String.IsNullOrEmpty(rom.SHA1)) if (!String.IsNullOrEmpty(rom.SHA1))
{ {
sha1query += " (\"" + rom.SHA1 + "\"),"; sha1query += " ("" + rom.SHA1 + "\"),";
if (!String.IsNullOrEmpty(rom.CRC)) if (!String.IsNullOrEmpty(rom.CRC))
{ {
crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; crcsha1query += " ("" + rom.CRC + "\", "" + rom.SHA1 + "\"),";
} }
if (!String.IsNullOrEmpty(rom.MD5)) 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)) if (!String.IsNullOrEmpty(disk.MD5))
{ {
md5query += " (\"" + disk.MD5 + "\"),"; md5query += " ("" + disk.MD5 + "\"),";
} }
if (!String.IsNullOrEmpty(disk.SHA1)) if (!String.IsNullOrEmpty(disk.SHA1))
{ {
sha1query += " (\"" + disk.SHA1 + "\"),"; sha1query += " ("" + disk.SHA1 + "\"),";
if (!String.IsNullOrEmpty(disk.MD5)) 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 = new SqliteCommand(datquery, dbc);
slc.ExecuteNonQuery(); slc.ExecuteNonQuery();
slc.Dispose(); slc.Dispose();
@@ -603,7 +603,7 @@ namespace SabreTools
// If we have it, then check for all hashes that are in that depot // If we have it, then check for all hashes that are in that depot
List<string> hashes = new List<string>(); List<string> hashes = new List<string>();
string query = "SELECT sha1 FROM sha1 WHERE depot=\"" + depotname + "\""; string query = "SELECT sha1 FROM sha1 WHERE depot="" + depotname + """;
SqliteCommand slc = new SqliteCommand(query, dbc); SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader(); SqliteDataReader sldr = slc.ExecuteReader();
if (sldr.HasRows) if (sldr.HasRows)
@@ -643,23 +643,23 @@ namespace SabreTools
{ {
if (!String.IsNullOrEmpty(rom.CRC)) if (!String.IsNullOrEmpty(rom.CRC))
{ {
crcquery += " (\"" + rom.CRC + "\"),"; crcquery += " ("" + rom.CRC + "\"),";
} }
if (!String.IsNullOrEmpty(rom.MD5)) if (!String.IsNullOrEmpty(rom.MD5))
{ {
md5query += " (\"" + rom.MD5 + "\"),"; md5query += " ("" + rom.MD5 + "\"),";
} }
if (!String.IsNullOrEmpty(rom.SHA1)) if (!String.IsNullOrEmpty(rom.SHA1))
{ {
sha1query += " (\"" + rom.SHA1 + "\", \"" + depotname + "\"),"; sha1query += " ("" + rom.SHA1 + "\", "" + depotname + "\"),";
if (!String.IsNullOrEmpty(rom.CRC)) if (!String.IsNullOrEmpty(rom.CRC))
{ {
crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; crcsha1query += " ("" + rom.CRC + "\", "" + rom.SHA1 + "\"),";
} }
if (!String.IsNullOrEmpty(rom.MD5)) 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 ON crcsha1.crc=crc.crc
JOIN md5 JOIN md5
ON md5sha1.md5=md5.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 = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery(); slc.ExecuteNonQuery();

View File

@@ -73,9 +73,9 @@ namespace SabreTools
if (onlyNeeded) if (onlyNeeded)
{ {
string query = "SELECT * FROM crcsha1 JOIN md5sha1 ON crcsha1.sha1=md5sha1.sha1" string query = "SELECT * FROM crcsha1 JOIN md5sha1 ON crcsha1.sha1=md5sha1.sha1"
+ " WHERE crcsha1.crc=\"" + rom.CRC + "\"" + " WHERE crcsha1.crc="" + rom.CRC + """
+ " OR md5sha1.md5=\"" + rom.MD5 + "\"" + " OR md5sha1.md5="" + rom.MD5 + """
+ " OR md5sha1.sha1=\"" + rom.SHA1 + "\""; + " OR md5sha1.sha1="" + rom.SHA1 + """;
SqliteCommand slc = new SqliteCommand(query, dbc); SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader(); SqliteDataReader sldr = slc.ExecuteReader();
@@ -84,23 +84,23 @@ namespace SabreTools
// Add to the queries // Add to the queries
if (!String.IsNullOrEmpty(rom.CRC)) if (!String.IsNullOrEmpty(rom.CRC))
{ {
crcquery += " (\"" + rom.CRC + "\"),"; crcquery += " ("" + rom.CRC + "\"),";
} }
if (!String.IsNullOrEmpty(rom.MD5)) if (!String.IsNullOrEmpty(rom.MD5))
{ {
md5query += " (\"" + rom.MD5 + "\"),"; md5query += " ("" + rom.MD5 + "\"),";
} }
if (!String.IsNullOrEmpty(rom.SHA1)) if (!String.IsNullOrEmpty(rom.SHA1))
{ {
sha1query += " (\"" + rom.SHA1 + "\", \"" + _depots.Keys.ToList()[0] + "\"),"; sha1query += " ("" + rom.SHA1 + "\", "" + _depots.Keys.ToList()[0] + "\"),";
if (!String.IsNullOrEmpty(rom.CRC)) if (!String.IsNullOrEmpty(rom.CRC))
{ {
crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; crcsha1query += " ("" + rom.CRC + "\", "" + rom.SHA1 + "\"),";
} }
if (!String.IsNullOrEmpty(rom.MD5)) 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 // Add to the queries
if (!String.IsNullOrEmpty(rom.CRC)) if (!String.IsNullOrEmpty(rom.CRC))
{ {
crcquery += " (\"" + rom.CRC + "\"),"; crcquery += " ("" + rom.CRC + "\"),";
} }
if (!String.IsNullOrEmpty(rom.MD5)) if (!String.IsNullOrEmpty(rom.MD5))
{ {
md5query += " (\"" + rom.MD5 + "\"),"; md5query += " ("" + rom.MD5 + "\"),";
} }
if (!String.IsNullOrEmpty(rom.SHA1)) if (!String.IsNullOrEmpty(rom.SHA1))
{ {
sha1query += " (\"" + rom.SHA1 + "\", \"" + _depots.Keys.ToList()[0] + "\"),"; sha1query += " ("" + rom.SHA1 + "\", "" + _depots.Keys.ToList()[0] + "\"),";
if (!String.IsNullOrEmpty(rom.CRC)) if (!String.IsNullOrEmpty(rom.CRC))
{ {
crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; crcsha1query += " ("" + rom.CRC + "\", "" + rom.SHA1 + "\"),";
} }
if (!String.IsNullOrEmpty(rom.MD5)) 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 // Now, search for each of them and return true or false for each
foreach (string input in crc) 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); SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader(); SqliteDataReader sldr = slc.ExecuteReader();
if (sldr.HasRows) if (sldr.HasRows)
@@ -337,7 +337,7 @@ namespace SabreTools
} }
foreach (string input in md5) 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); SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader(); SqliteDataReader sldr = slc.ExecuteReader();
if (sldr.HasRows) if (sldr.HasRows)
@@ -354,7 +354,7 @@ namespace SabreTools
} }
foreach (string input in sha1) 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); SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader(); SqliteDataReader sldr = slc.ExecuteReader();
if (sldr.HasRows) if (sldr.HasRows)

View File

@@ -6,13 +6,13 @@ using System.Runtime.InteropServices;
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("RombaSharp")] [assembly: AssemblyTitle("RombaSharp")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription(String.Empty)]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration(String.Empty)]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany(String.Empty)]
[assembly: AssemblyProduct("RombaSharp")] [assembly: AssemblyProduct("RombaSharp")]
[assembly: AssemblyCopyright("Copyright © 2016")] [assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark(String.Empty)]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture(String.Empty)]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from

View File

@@ -178,7 +178,7 @@ namespace SabreTools
outdat = args[i]; outdat = args[i];
break; break;
default: 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("=")) if (temparg.StartsWith("-") && temparg.Contains("="))
{ {

View File

@@ -478,7 +478,7 @@ namespace SabreTools.Helper.Dats
if (File.Exists(inputFileName)) if (File.Exists(inputFileName))
{ {
DatFile innerDatdata = new DatFile(this); 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, innerDatdata.Parse(inputFileName, 0, 0, filter, splitType, trim, single,
root, logger, true, clean, softlist, root, logger, true, clean, softlist,
keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0)); keepext: ((innerDatdata.DatFormat & DatFormat.TSV) != 0 || (innerDatdata.DatFormat & DatFormat.CSV) != 0));
@@ -497,7 +497,7 @@ namespace SabreTools.Helper.Dats
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism }, new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
file => 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); DatFile innerDatdata = new DatFile(this);
innerDatdata.Parse(file, 0, 0, filter, splitType, innerDatdata.Parse(file, 0, 0, filter, splitType,
trim, single, root, logger, true, clean, softlist, trim, single, root, logger, true, clean, softlist,

View File

@@ -369,7 +369,7 @@ namespace SabreTools.Helper.Dats
// If we have a sample, treat it special // If we have a sample, treat it special
if (temptype == ItemType.Sample) 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; item.Name = line;
// Now process and add the sample // Now process and add the sample
@@ -421,7 +421,7 @@ namespace SabreTools.Helper.Dats
else if (gc[i] == "date") else if (gc[i] == "date")
{ {
i++; 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; i += 3;
} }
@@ -429,7 +429,7 @@ namespace SabreTools.Helper.Dats
else if (gc[i] == "crc") else if (gc[i] == "crc")
{ {
i++; 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++) for (int i = 0; i < gc.Length; i++)
{ {
// Look at the current item and use it if possible // 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) switch (quoteless)
{ {
//If the item is empty, we automatically skip it because it's a fluke //If the item is empty, we automatically skip it because it's a fluke
case "": case String.Empty:
continue; continue;
// Special cases for standalone item statuses // Special cases for standalone item statuses
@@ -495,14 +495,14 @@ namespace SabreTools.Helper.Dats
// Regular attributes // Regular attributes
case "name": case "name":
i++; i++;
quoteless = gc[i].Replace("\"", String.Empty); quoteless = gc[i].Replace(""", String.Empty);
item.Name = quoteless; item.Name = quoteless;
break; break;
case "size": case "size":
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
i++; i++;
quoteless = gc[i].Replace("\"", String.Empty); quoteless = gc[i].Replace(""", String.Empty);
long size = -1; long size = -1;
if (Int64.TryParse(quoteless, out size)) if (Int64.TryParse(quoteless, out size))
{ {
@@ -515,7 +515,7 @@ namespace SabreTools.Helper.Dats
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
i++; i++;
quoteless = gc[i].Replace("\"", String.Empty); quoteless = gc[i].Replace(""", String.Empty);
((Rom)item).CRC = quoteless.ToLowerInvariant(); ((Rom)item).CRC = quoteless.ToLowerInvariant();
} }
break; break;
@@ -523,13 +523,13 @@ namespace SabreTools.Helper.Dats
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
i++; i++;
quoteless = gc[i].Replace("\"", String.Empty); quoteless = gc[i].Replace(""", String.Empty);
((Rom)item).MD5 = quoteless.ToLowerInvariant(); ((Rom)item).MD5 = quoteless.ToLowerInvariant();
} }
else if (item.Type == ItemType.Disk) else if (item.Type == ItemType.Disk)
{ {
i++; i++;
quoteless = gc[i].Replace("\"", String.Empty); quoteless = gc[i].Replace(""", String.Empty);
((Disk)item).MD5 = quoteless.ToLowerInvariant(); ((Disk)item).MD5 = quoteless.ToLowerInvariant();
} }
break; break;
@@ -537,20 +537,20 @@ namespace SabreTools.Helper.Dats
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
i++; i++;
quoteless = gc[i].Replace("\"", String.Empty); quoteless = gc[i].Replace(""", String.Empty);
((Rom)item).SHA1 = quoteless.ToLowerInvariant(); ((Rom)item).SHA1 = quoteless.ToLowerInvariant();
} }
else if (item.Type == ItemType.Disk) else if (item.Type == ItemType.Disk)
{ {
i++; i++;
quoteless = gc[i].Replace("\"", String.Empty); quoteless = gc[i].Replace(""", String.Empty);
((Disk)item).SHA1 = quoteless.ToLowerInvariant(); ((Disk)item).SHA1 = quoteless.ToLowerInvariant();
} }
break; break;
case "status": case "status":
case "flags": case "flags":
i++; i++;
quoteless = gc[i].Replace("\"", String.Empty); quoteless = gc[i].Replace(""", String.Empty);
if (quoteless.ToLowerInvariant() == "good") if (quoteless.ToLowerInvariant() == "good")
{ {
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
@@ -600,7 +600,7 @@ namespace SabreTools.Helper.Dats
if (item.Type == ItemType.Rom) if (item.Type == ItemType.Rom)
{ {
i++; 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; ((Rom)item).Date = quoteless;
} }
i++; i++;
@@ -620,7 +620,7 @@ namespace SabreTools.Helper.Dats
if (blockname != "header") if (blockname != "header")
{ {
string itemval = gc[2].Value.Replace("\"", String.Empty); string itemval = gc[2].Value.Replace(""", String.Empty);
switch (gc[1].Value) switch (gc[1].Value)
{ {
case "name": case "name":
@@ -648,7 +648,7 @@ namespace SabreTools.Helper.Dats
} }
else else
{ {
string itemval = gc[2].Value.Replace("\"", String.Empty); string itemval = gc[2].Value.Replace(""", String.Empty);
if (line.Trim().StartsWith("Name:")) if (line.Trim().StartsWith("Name:"))
{ {
@@ -1418,7 +1418,7 @@ namespace SabreTools.Helper.Dats
machine.Description = subreader.ReadElementContentAsString(); machine.Description = subreader.ReadElementContentAsString();
if (!softlist && temptype == "software") if (!softlist && temptype == "software")
{ {
machine.Name = machine.Description.Replace('/', '_').Replace("\"", "''"); machine.Name = machine.Description.Replace('/', '_').Replace(""", "''");
} }
break; break;
case "year": case "year":
@@ -1580,13 +1580,13 @@ namespace SabreTools.Helper.Dats
if (subreader.GetAttribute("flags") == "baddump" || subreader.GetAttribute("status") == "baddump") if (subreader.GetAttribute("flags") == "baddump" || subreader.GetAttribute("status") == "baddump")
{ {
logger.Verbose("Bad dump detected: " + 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; its = ItemStatus.BadDump;
} }
if (subreader.GetAttribute("flags") == "nodump" || subreader.GetAttribute("status") == "nodump") if (subreader.GetAttribute("flags") == "nodump" || subreader.GetAttribute("status") == "nodump")
{ {
logger.Verbose("Nodump detected: " + 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; its = ItemStatus.Nodump;
} }
if (subreader.GetAttribute("flags") == "verified" || subreader.GetAttribute("status") == "verified") if (subreader.GetAttribute("flags") == "verified" || subreader.GetAttribute("status") == "verified")
@@ -1765,12 +1765,12 @@ namespace SabreTools.Helper.Dats
break; break;
case "baddump": case "baddump":
logger.Verbose("Bad dump detected: " + (xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != String.Empty ? 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; its = ItemStatus.BadDump;
break; break;
case "nodump": case "nodump":
logger.Verbose("Nodump detected: " + (xtr.GetAttribute("name") != null && xtr.GetAttribute("name") != String.Empty ? 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; its = ItemStatus.Nodump;
break; break;
case "verified": 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 // 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)) 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; itemRom.ItemStatus = ItemStatus.Nodump;
} }
// If the file has a size but aboslutely no hashes, skip and log // 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.MD5)
&& String.IsNullOrEmpty(itemRom.SHA1)) && 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; itemRom.ItemStatus = ItemStatus.Nodump;
} }
@@ -2333,7 +2333,7 @@ namespace SabreTools.Helper.Dats
&& String.IsNullOrEmpty(itemDisk.MD5) && String.IsNullOrEmpty(itemDisk.MD5)
&& String.IsNullOrEmpty(itemDisk.SHA1)) && 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; itemDisk.ItemStatus = ItemStatus.Nodump;
} }

View File

@@ -158,22 +158,22 @@ namespace SabreTools.Helper.Dats
} }
if (outputs.ContainsKey(StatDatFormat.CSV)) if (outputs.ContainsKey(StatDatFormat.CSV))
{ {
line = "\"" + FileName + "\"," line = """ + FileName + "\","
+ "\"" + TotalSize + "\"," + """ + TotalSize + "\","
+ "\"" + (game == -1 ? Count : game) + "\"," + """ + (game == -1 ? Count : game) + "\","
+ "\"" + RomCount + "\"," + """ + RomCount + "\","
+ "\"" + DiskCount + "\"," + """ + DiskCount + "\","
+ "\"" + CRCCount + "\"," + """ + CRCCount + "\","
+ "\"" + MD5Count + "\"," + """ + MD5Count + "\","
+ "\"" + SHA1Count + "\""; + """ + SHA1Count + """;
if (baddumpCol) if (baddumpCol)
{ {
line += ",\"" + BaddumpCount + "\""; line += ","" + BaddumpCount + """;
} }
if (nodumpCol) if (nodumpCol)
{ {
line += ",\"" + NodumpCount + "\""; line += ","" + NodumpCount + """;
} }
line += "\n"; line += "\n";
@@ -206,22 +206,22 @@ namespace SabreTools.Helper.Dats
} }
if (outputs.ContainsKey(StatDatFormat.TSV)) if (outputs.ContainsKey(StatDatFormat.TSV))
{ {
line = "\"" + FileName + "\"\t" line = """ + FileName + "\"\t"
+ "\"" + TotalSize + "\"\t" + """ + TotalSize + "\"\t"
+ "\"" + (game == -1 ? Count : game) + "\"\t" + """ + (game == -1 ? Count : game) + "\"\t"
+ "\"" + RomCount + "\"\t" + """ + RomCount + "\"\t"
+ "\"" + DiskCount + "\"\t" + """ + DiskCount + "\"\t"
+ "\"" + CRCCount + "\"\t" + """ + CRCCount + "\"\t"
+ "\"" + MD5Count + "\"\t" + """ + MD5Count + "\"\t"
+ "\"" + SHA1Count + "\""; + """ + SHA1Count + """;
if (baddumpCol) if (baddumpCol)
{ {
line += "\t\"" + BaddumpCount + "\""; line += "\t"" + BaddumpCount + """;
} }
if (nodumpCol) if (nodumpCol)
{ {
line += "\t\"" + NodumpCount + "\""; line += "\t"" + NodumpCount + """;
} }
line += "\n"; line += "\n";
@@ -530,8 +530,8 @@ Please check the log folder if the stats scrolled offscreen", false);
} }
if (outputs.ContainsKey(StatDatFormat.CSV)) if (outputs.ContainsKey(StatDatFormat.CSV))
{ {
outputs[StatDatFormat.CSV].Write("\"File Name\",\"Total Size\",\"Games\",\"Roms\",\"Disks\",\"# with CRC\",\"# with MD5\",\"# with SHA-1\"" 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"); + (baddumpCol ? ",\"BadDumps"" : String.Empty) + (nodumpCol ? ",\"Nodumps"" : String.Empty) + "\n");
} }
if (outputs.ContainsKey(StatDatFormat.HTML)) 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)) 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\"" 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"); + (baddumpCol ? "\t\"BadDumps"" : String.Empty) + (nodumpCol ? "\t\"Nodumps"" : String.Empty) + "\n");
} }
// Now write the mid header for those who need it // 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)) if (outputs.ContainsKey(StatDatFormat.HTML))
{ {
outputs[StatDatFormat.HTML].Write("<tr><td colspan=\"" outputs[StatDatFormat.HTML].Write("<tr><td colspan=""
+ (baddumpCol && nodumpCol + (baddumpCol && nodumpCol
? "11" ? "11"
: (baddumpCol ^ nodumpCol : (baddumpCol ^ nodumpCol
@@ -648,7 +648,7 @@ Please check the log folder if the stats scrolled offscreen", false);
} }
if (outputs.ContainsKey(StatDatFormat.HTML)) if (outputs.ContainsKey(StatDatFormat.HTML))
{ {
outputs[StatDatFormat.HTML].Write("<tr border=\"0\"><td colspan=\"" outputs[StatDatFormat.HTML].Write("<tr border=\"0\"><td colspan=""
+ (baddumpCol && nodumpCol + (baddumpCol && nodumpCol
? "11" ? "11"
: (baddumpCol ^ nodumpCol : (baddumpCol ^ nodumpCol

View File

@@ -1,171 +1,171 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// This code was generated by a tool. // This code was generated by a tool.
// Runtime Version:4.0.30319.42000 // Runtime Version:4.0.30319.42000
// //
// Changes to this file may cause incorrect behavior and will be lost if // Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated. // the code is regenerated.
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace SabreTools.Helper.Resources { namespace SabreTools.Helper.Resources {
using System; using System;
/// <summary> /// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc. /// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary> /// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder // This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio. // class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen // To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project. // with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources { public class Resources {
private static global::System.Resources.ResourceManager resourceMan; private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture; private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() { internal Resources() {
} }
/// <summary> /// <summary>
/// Returns the cached ResourceManager instance used by this class. /// Returns the cached ResourceManager instance used by this class.
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager { public static global::System.Resources.ResourceManager ResourceManager {
get { get {
if (object.ReferenceEquals(resourceMan, null)) { if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SabreTools.Helper.Resources.Resources", typeof(Resources).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SabreTools.Helper.Resources.Resources", typeof(Resources).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;
} }
} }
/// <summary> /// <summary>
/// Overrides the current thread's CurrentUICulture property for all /// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class. /// resource lookups using this strongly typed resource class.
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Globalization.CultureInfo Culture { public static global::System.Globalization.CultureInfo Culture {
get { get {
return resourceCulture; return resourceCulture;
} }
set { set {
resourceCulture = value; resourceCulture = value;
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to This is the default help output. /// Looks up a localized string similar to This is the default help output.
/// </summary> /// </summary>
public static string Default_Desc { public static string Default_Desc {
get { get {
return ResourceManager.GetString("Default_Desc", resourceCulture); return ResourceManager.GetString("Default_Desc", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Remove and restore rom headers. /// Looks up a localized string similar to Remove and restore rom headers.
/// </summary> /// </summary>
public static string Headerer_Desc { public static string Headerer_Desc {
get { get {
return ResourceManager.GetString("Headerer_Desc", resourceCulture); return ResourceManager.GetString("Headerer_Desc", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Headerer. /// Looks up a localized string similar to Headerer.
/// </summary> /// </summary>
public static string Headerer_Name { public static string Headerer_Name {
get { get {
return ResourceManager.GetString("Headerer_Name", resourceCulture); return ResourceManager.GetString("Headerer_Name", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to C# port of the Romba rom management tool. /// Looks up a localized string similar to C# port of the Romba rom management tool.
/// </summary> /// </summary>
public static string RombaSharp_Desc { public static string RombaSharp_Desc {
get { get {
return ResourceManager.GetString("RombaSharp_Desc", resourceCulture); return ResourceManager.GetString("RombaSharp_Desc", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to RombaSharp. /// Looks up a localized string similar to RombaSharp.
/// </summary> /// </summary>
public static string RombaSharp_Name { public static string RombaSharp_Name {
get { get {
return ResourceManager.GetString("RombaSharp_Name", resourceCulture); return ResourceManager.GetString("RombaSharp_Name", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Import, generate, manipulate DAT files. /// Looks up a localized string similar to Import, generate, manipulate DAT files.
/// </summary> /// </summary>
public static string SabreTools_Desc { public static string SabreTools_Desc {
get { get {
return ResourceManager.GetString("SabreTools_Desc", resourceCulture); return ResourceManager.GetString("SabreTools_Desc", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to SabreTools. /// Looks up a localized string similar to SabreTools.
/// </summary> /// </summary>
public static string SabreTools_Name { public static string SabreTools_Name {
get { get {
return ResourceManager.GetString("SabreTools_Name", resourceCulture); return ResourceManager.GetString("SabreTools_Name", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Basic rebuild using a DAT. /// Looks up a localized string similar to Basic rebuild using a DAT.
/// </summary> /// </summary>
public static string SimpleSort_Desc { public static string SimpleSort_Desc {
get { get {
return ResourceManager.GetString("SimpleSort_Desc", resourceCulture); return ResourceManager.GetString("SimpleSort_Desc", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to SimpleSort. /// Looks up a localized string similar to SimpleSort.
/// </summary> /// </summary>
public static string SimpleSort_Name { public static string SimpleSort_Name {
get { get {
return ResourceManager.GetString("SimpleSort_Name", resourceCulture); return ResourceManager.GetString("SimpleSort_Name", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Convert files to TGZ output. /// Looks up a localized string similar to Convert files to TGZ output.
/// </summary> /// </summary>
public static string TGZTest_Desc { public static string TGZTest_Desc {
get { get {
return ResourceManager.GetString("TGZTest_Desc", resourceCulture); return ResourceManager.GetString("TGZTest_Desc", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to TGZConvert. /// Looks up a localized string similar to TGZConvert.
/// </summary> /// </summary>
public static string TGZTest_Name { public static string TGZTest_Name {
get { get {
return ResourceManager.GetString("TGZTest_Name", resourceCulture); return ResourceManager.GetString("TGZTest_Name", resourceCulture);
} }
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Usage. /// Looks up a localized string similar to Usage.
/// </summary> /// </summary>
public static string Usage { public static string Usage {
get { get {
return ResourceManager.GetString("Usage", resourceCulture); return ResourceManager.GetString("Usage", resourceCulture);
} }
} }
} }
} }

View File

@@ -59,7 +59,7 @@
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns=String.Empty xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>

View File

@@ -59,7 +59,7 @@
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns=String.Empty xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>

View File

@@ -59,7 +59,7 @@
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns=String.Empty xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>

View File

@@ -59,7 +59,7 @@
: using a System.ComponentModel.TypeConverter : using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding. : and then encoded with base64 encoding.
--> -->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns=String.Empty xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType> <xsd:complexType>

View File

@@ -1102,13 +1102,6 @@ namespace SabreTools.Helper.Tools
public static bool WriteTAR(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false) public static bool WriteTAR(List<string> inputFiles, string outDir, List<Rom> roms, Logger logger, bool date = false)
{ {
bool success = 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 the number of inputs is less than the number of available roms, return
if (inputFiles.Count < roms.Count) if (inputFiles.Count < roms.Count)
@@ -1129,8 +1122,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")); string archiveFileName = Path.Combine(outDir, Style.RemovePathUnsafeCharacters(roms[0].Machine.Name) + (roms[0].Machine.Name.EndsWith(".tar") ? String.Empty : ".tar"));
// Set internal variables // Set internal variables
TarArchive oldTarFile = TarArchive.Create(); Stream tarstream = new MemoryStream();
TarArchive tarFile = TarArchive.Create(); TarArchive tarchive = TarArchive.Create();
try try
{ {
@@ -1140,120 +1133,42 @@ namespace SabreTools.Helper.Tools
Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName)); Directory.CreateDirectory(Path.GetDirectoryName(archiveFileName));
} }
// If the archive doesn't exist, create it and put the single file // We can only overwrite at this point, sorry
if (!File.Exists(archiveFileName)) tarstream = File.Open(archiveFileName, FileMode.Create, FileAccess.Write);
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
for (int i = 0; i < inputFiles.Count; i++)
{ {
// Map all inputs to index inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), i);
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
for (int i = 0; i < inputFiles.Count; i++)
{
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), i);
}
// Sort the keys in TZIP order
List<string> 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]);
}
} }
// Otherwise, sort the input files and write out in the correct order // Sort the keys in TZIP order
else List<string> keys = inputIndexMap.Keys.ToList();
keys.Sort(ZipFile.TorrentZipStringCompare);
// Now add each of the files
foreach (string key in keys)
{ {
// Open the old archive for reading int index = inputIndexMap[key];
oldTarFile = TarArchive.Open(archiveFileName); tarchive.AddEntry(key, inputFiles[index]);
// Get a list of all current entries
List<string> entries = oldTarFile.Entries.Select(i => i.Key).ToList();
// Map all inputs to index
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
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<string> 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);
}
}
} }
// Close the output tar file tarchive.SaveTo(tarstream, new WriterOptions(CompressionType.None));
tarFile.SaveTo(tempFile, new WriterOptions(CompressionType.None));
success = true; success = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex);
success = false; success = false;
logger.Error(ex.ToString());
} }
finally finally
{ {
tarFile.Dispose(); tarstream?.Dispose();
oldTarFile.Dispose(); tarchive?.Dispose();
} }
// If the old file exists, delete it and replace return success;
if (File.Exists(archiveFileName))
{
File.Delete(archiveFileName);
}
File.Move(tempFile, archiveFileName);
return true;
} }
/// <summary> /// <summary>

View File

@@ -79,7 +79,7 @@ namespace SabreTools.Helper.Tools
} }
// Read the input file, if possible // 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 // Check if file exists
if (!File.Exists(filename)) if (!File.Exists(filename))
@@ -437,7 +437,7 @@ namespace SabreTools.Helper.Tools
/// <returns>The XmlTextReader representing the (possibly converted) file, null otherwise</returns> /// <returns>The XmlTextReader representing the (possibly converted) file, null otherwise</returns>
public static XmlReader GetXmlTextReader(string filename, Logger logger) 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 // Check if file exists
if (!File.Exists(filename)) if (!File.Exists(filename))

View File

@@ -7,12 +7,12 @@ using System.Runtime.InteropServices;
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("SabreTools")] [assembly: AssemblyTitle("SabreTools")]
[assembly: AssemblyDescription("DAT manipulation toolset")] [assembly: AssemblyDescription("DAT manipulation toolset")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration(String.Empty)]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany(String.Empty)]
[assembly: AssemblyProduct("SabreTools")] [assembly: AssemblyProduct("SabreTools")]
[assembly: AssemblyCopyright("Copyright © 2016")] [assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark(String.Empty)]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture(String.Empty)]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from