[ALL] Take care of possible null strings

This commit is contained in:
Matt Nadareski
2017-12-14 13:22:22 -08:00
parent 296fc2154c
commit e8d59e6970
9 changed files with 30 additions and 30 deletions

View File

@@ -301,7 +301,7 @@ namespace RombaSharp
if (input.Length == Constants.CRCLength) if (input.Length == Constants.CRCLength)
{ {
temp = Utilities.CleanHashData(input, Constants.CRCLength); temp = Utilities.CleanHashData(input, Constants.CRCLength);
if (temp != "") if (!String.IsNullOrWhiteSpace(temp))
{ {
crc.Add(temp); crc.Add(temp);
} }
@@ -309,7 +309,7 @@ namespace RombaSharp
else if (input.Length == Constants.MD5Length) else if (input.Length == Constants.MD5Length)
{ {
temp = Utilities.CleanHashData(input, Constants.MD5Length); temp = Utilities.CleanHashData(input, Constants.MD5Length);
if (temp != "") if (!String.IsNullOrWhiteSpace(temp))
{ {
md5.Add(temp); md5.Add(temp);
} }
@@ -317,7 +317,7 @@ namespace RombaSharp
else if (input.Length == Constants.SHA1Length) else if (input.Length == Constants.SHA1Length)
{ {
temp = Utilities.CleanHashData(input, Constants.SHA1Length); temp = Utilities.CleanHashData(input, Constants.SHA1Length);
if (temp != "") if (!String.IsNullOrWhiteSpace(temp))
{ {
sha1.Add(temp); sha1.Add(temp);
} }

View File

@@ -2196,7 +2196,7 @@ namespace SabreTools.Library.DatFiles
string filename = inputs[newItem.SystemID].Split('¬')[0]; string filename = inputs[newItem.SystemID].Split('¬')[0];
string rootpath = inputs[newItem.SystemID].Split('¬')[1]; string rootpath = inputs[newItem.SystemID].Split('¬')[1];
rootpath += (rootpath == "" ? "" : Path.DirectorySeparatorChar.ToString()); rootpath += (String.IsNullOrWhiteSpace(rootpath) ? "" : Path.DirectorySeparatorChar.ToString());
filename = filename.Remove(0, rootpath.Length); filename = filename.Remove(0, rootpath.Length);
newItem.MachineName = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar newItem.MachineName = Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar
+ Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(filename) + Path.DirectorySeparatorChar
@@ -3584,7 +3584,7 @@ namespace SabreTools.Library.DatFiles
string romname = ""; string romname = "";
// If the parent is blank, then we have a non-archive file // If the parent is blank, then we have a non-archive file
if (parent == "") if (String.IsNullOrWhiteSpace(parent))
{ {
// If we have a SuperDAT, we want anything that's not the base path as the game, and the file as the rom // If we have a SuperDAT, we want anything that's not the base path as the game, and the file as the rom
if (Type == "SuperDAT") if (Type == "SuperDAT")

View File

@@ -570,7 +570,7 @@ namespace SabreTools.Library.DatFiles
if (superdat && !keep) if (superdat && !keep)
{ {
string tempout = Regex.Match(machine.Name, @".*?\\(.*)").Groups[1].Value; string tempout = Regex.Match(machine.Name, @".*?\\(.*)").Groups[1].Value;
if (tempout != "") if (!String.IsNullOrWhiteSpace(tempout))
{ {
machine.Name = tempout; machine.Name = tempout;
} }
@@ -994,11 +994,11 @@ namespace SabreTools.Library.DatFiles
superdat = true; superdat = true;
if (keep) if (keep)
{ {
Type = (Type == "" ? "SuperDAT" : Type); Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type);
} }
string foldername = (xtr.GetAttribute("name") ?? ""); string foldername = (xtr.GetAttribute("name") ?? "");
if (foldername != "") if (!String.IsNullOrWhiteSpace(foldername))
{ {
parent.Add(foldername); parent.Add(foldername);
} }
@@ -1099,7 +1099,7 @@ namespace SabreTools.Library.DatFiles
if (!keep || !superdat) if (!keep || !superdat)
{ {
string tempout = Regex.Match(dir.Name, @".*?\\(.*)").Groups[1].Value; string tempout = Regex.Match(dir.Name, @".*?\\(.*)").Groups[1].Value;
if (tempout != "") if (!String.IsNullOrWhiteSpace(tempout))
{ {
dir.Name = tempout; dir.Name = tempout;
} }

View File

@@ -240,7 +240,7 @@ namespace SabreTools.Library.DatFiles
if (rom.Type == ItemType.Rom) if (rom.Type == ItemType.Rom)
{ {
// We can only write out if there's a SHA-1 // We can only write out if there's a SHA-1
if (((Rom)rom).SHA1 != "") if (!String.IsNullOrWhiteSpace(((Rom)rom).SHA1))
{ {
name = ((Rom)rom).SHA1.Substring(0, 2) name = ((Rom)rom).SHA1.Substring(0, 2)
+ "/" + ((Rom)rom).SHA1.Substring(2, 2) + "/" + ((Rom)rom).SHA1.Substring(2, 2)
@@ -253,7 +253,7 @@ namespace SabreTools.Library.DatFiles
else if (rom.Type == ItemType.Disk) else if (rom.Type == ItemType.Disk)
{ {
// We can only write out if there's a SHA-1 // We can only write out if there's a SHA-1
if (((Disk)rom).SHA1 != "") if (!String.IsNullOrWhiteSpace(((Disk)rom).SHA1))
{ {
name = ((Disk)rom).SHA1.Substring(0, 2) name = ((Disk)rom).SHA1.Substring(0, 2)
+ "/" + ((Disk)rom).SHA1.Substring(2, 2) + "/" + ((Disk)rom).SHA1.Substring(2, 2)
@@ -269,7 +269,7 @@ namespace SabreTools.Library.DatFiles
else else
{ {
name = (UseGame ? rom.MachineName : rom.Name); name = (UseGame ? rom.MachineName : rom.Name);
if (ReplaceExtension != "" || RemoveExtension) if (!String.IsNullOrWhiteSpace(ReplaceExtension) || RemoveExtension)
{ {
if (RemoveExtension) if (RemoveExtension)
{ {
@@ -280,7 +280,7 @@ namespace SabreTools.Library.DatFiles
dir = (dir.StartsWith(Path.DirectorySeparatorChar.ToString()) ? dir.Remove(0, 1) : dir); dir = (dir.StartsWith(Path.DirectorySeparatorChar.ToString()) ? dir.Remove(0, 1) : dir);
name = Path.Combine(dir, Path.GetFileNameWithoutExtension(name) + ReplaceExtension); name = Path.Combine(dir, Path.GetFileNameWithoutExtension(name) + ReplaceExtension);
} }
if (AddExtension != "") if (!String.IsNullOrWhiteSpace(AddExtension))
{ {
name += AddExtension; name += AddExtension;
} }

View File

@@ -208,7 +208,7 @@ namespace SabreTools.Library.DatFiles
break; break;
case "Rom.Name": case "Rom.Name":
case "Disk.Name": case "Disk.Name":
name = value == "" ? name : value; name = String.IsNullOrWhiteSpace(value) ? name : value;
break; break;
case "DatItem.Size": case "DatItem.Size":
if (!Int64.TryParse(value, out size)) if (!Int64.TryParse(value, out size))

View File

@@ -42,13 +42,13 @@ namespace NaturalSort
if (!table.TryGetValue(x, out string[] x1)) if (!table.TryGetValue(x, out string[] x1))
{ {
//x1 = Regex.Split(x.Replace(" ", ""), "([0-9]+)"); //x1 = Regex.Split(x.Replace(" ", ""), "([0-9]+)");
x1 = Regex.Split(x.ToLowerInvariant(), "([0-9]+)").Where(s => s != "").ToArray(); x1 = Regex.Split(x.ToLowerInvariant(), "([0-9]+)").Where(s => !String.IsNullOrWhiteSpace(s)).ToArray();
table.Add(x, x1); table.Add(x, x1);
} }
if (!table.TryGetValue(y, out string[] y1)) if (!table.TryGetValue(y, out string[] y1))
{ {
//y1 = Regex.Split(y.Replace(" ", ""), "([0-9]+)"); //y1 = Regex.Split(y.Replace(" ", ""), "([0-9]+)");
y1 = Regex.Split(y.ToLowerInvariant(), "([0-9]+)").Where(s => s != "").ToArray(); y1 = Regex.Split(y.ToLowerInvariant(), "([0-9]+)").Where(s => !String.IsNullOrWhiteSpace(s)).ToArray();
table.Add(y, y1); table.Add(y, y1);
} }

View File

@@ -42,13 +42,13 @@ namespace NaturalSort
if (!table.TryGetValue(x, out string[] x1)) if (!table.TryGetValue(x, out string[] x1))
{ {
//x1 = Regex.Split(x.Replace(" ", ""), "([0-9]+)"); //x1 = Regex.Split(x.Replace(" ", ""), "([0-9]+)");
x1 = Regex.Split(x.ToLowerInvariant(), "([0-9]+)").Where(s => s != "").ToArray(); x1 = Regex.Split(x.ToLowerInvariant(), "([0-9]+)").Where(s => !String.IsNullOrWhiteSpace(s)).ToArray();
table.Add(x, x1); table.Add(x, x1);
} }
if (!table.TryGetValue(y, out string[] y1)) if (!table.TryGetValue(y, out string[] y1))
{ {
//y1 = Regex.Split(y.Replace(" ", ""), "([0-9]+)"); //y1 = Regex.Split(y.Replace(" ", ""), "([0-9]+)");
y1 = Regex.Split(y.ToLowerInvariant(), "([0-9]+)").Where(s => s != "").ToArray(); y1 = Regex.Split(y.ToLowerInvariant(), "([0-9]+)").Where(s => !String.IsNullOrWhiteSpace(s)).ToArray();
table.Add(y, y1); table.Add(y, y1);
} }

View File

@@ -1333,7 +1333,7 @@ namespace SabreTools.Library.Tools
public static bool DetectSkipperAndTransform(string file, string outDir, bool nostore) public static bool DetectSkipperAndTransform(string file, string outDir, bool nostore)
{ {
// Create the output directory if it doesn't exist // Create the output directory if it doesn't exist
if (outDir != "" && !Directory.Exists(outDir)) if (!String.IsNullOrWhiteSpace(outDir) && !Directory.Exists(outDir))
{ {
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
} }
@@ -1361,7 +1361,7 @@ namespace SabreTools.Library.Tools
br.Dispose(); br.Dispose();
// Apply the rule to the file // Apply the rule to the file
string newfile = (outDir == "" ? Path.GetFullPath(file) + ".new" : Path.Combine(outDir, Path.GetFileName(file))); string newfile = (String.IsNullOrWhiteSpace(outDir) ? Path.GetFullPath(file) + ".new" : Path.Combine(outDir, Path.GetFileName(file)));
rule.TransformFile(file, newfile); rule.TransformFile(file, newfile);
// If the output file doesn't exist, return false // If the output file doesn't exist, return false
@@ -1467,7 +1467,7 @@ namespace SabreTools.Library.Tools
public static bool RestoreHeader(string file, string outDir) public static bool RestoreHeader(string file, string outDir)
{ {
// Create the output directory if it doesn't exist // Create the output directory if it doesn't exist
if (outDir != "" && !Directory.Exists(outDir)) if (!String.IsNullOrWhiteSpace(outDir) && !Directory.Exists(outDir))
{ {
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
} }
@@ -1488,9 +1488,9 @@ namespace SabreTools.Library.Tools
for (int i = 0; i < headers.Count; i++) for (int i = 0; i < headers.Count; i++)
{ {
Globals.Logger.User("Creating reheadered file: " + Globals.Logger.User("Creating reheadered file: " +
(outDir == "" ? Path.GetFullPath(file) + ".new" : Path.Combine(outDir, Path.GetFileName(file))) + i); (String.IsNullOrWhiteSpace(outDir) ? Path.GetFullPath(file) + ".new" : Path.Combine(outDir, Path.GetFileName(file))) + i);
AppendBytesToFile(file, AppendBytesToFile(file,
(outDir == "" ? Path.GetFullPath(file) + ".new" : Path.Combine(outDir, Path.GetFileName(file))) + i, headers[i], string.Empty); (String.IsNullOrWhiteSpace(outDir) ? Path.GetFullPath(file) + ".new" : Path.Combine(outDir, Path.GetFileName(file))) + i, headers[i], string.Empty);
Globals.Logger.User("Reheadered file created!"); Globals.Logger.User("Reheadered file created!");
} }

View File

@@ -259,10 +259,10 @@ namespace SabreTools
bool updateHashes) bool updateHashes)
{ {
// Normalize the extensions // Normalize the extensions
datHeader.AddExtension = (datHeader.AddExtension == "" || datHeader.AddExtension.StartsWith(".") datHeader.AddExtension = (String.IsNullOrWhiteSpace(datHeader.AddExtension) || datHeader.AddExtension.StartsWith(".")
? datHeader.AddExtension ? datHeader.AddExtension
: "." + datHeader.AddExtension); : "." + datHeader.AddExtension);
datHeader.ReplaceExtension = (datHeader.ReplaceExtension == "" || datHeader.ReplaceExtension.StartsWith(".") datHeader.ReplaceExtension = (String.IsNullOrWhiteSpace(datHeader.ReplaceExtension) || datHeader.ReplaceExtension.StartsWith(".")
? datHeader.ReplaceExtension ? datHeader.ReplaceExtension
: "." + datHeader.ReplaceExtension); : "." + datHeader.ReplaceExtension);
@@ -270,17 +270,17 @@ namespace SabreTools
if (updateMode != 0) if (updateMode != 0)
{ {
// Get the values that will be used // Get the values that will be used
if (datHeader.Date == "") if (String.IsNullOrWhiteSpace(datHeader.Date))
{ {
datHeader.Date = DateTime.Now.ToString("yyyy-MM-dd"); datHeader.Date = DateTime.Now.ToString("yyyy-MM-dd");
} }
if (datHeader.Name == "") if (String.IsNullOrWhiteSpace(datHeader.Name))
{ {
datHeader.Name = (updateMode != 0 ? "DiffDAT" : "MergeDAT") datHeader.Name = (updateMode != 0 ? "DiffDAT" : "MergeDAT")
+ (datHeader.Type == "SuperDAT" ? "-SuperDAT" : "") + (datHeader.Type == "SuperDAT" ? "-SuperDAT" : "")
+ (datHeader.DedupeRoms != DedupeType.None ? "-deduped" : ""); + (datHeader.DedupeRoms != DedupeType.None ? "-deduped" : "");
} }
if (datHeader.Description == "") if (String.IsNullOrWhiteSpace(datHeader.Description))
{ {
datHeader.Description = (updateMode != 0 ? "DiffDAT" : "MergeDAT") datHeader.Description = (updateMode != 0 ? "DiffDAT" : "MergeDAT")
+ (datHeader.Type == "SuperDAT" ? "-SuperDAT" : "") + (datHeader.Type == "SuperDAT" ? "-SuperDAT" : "")
@@ -290,11 +290,11 @@ namespace SabreTools
datHeader.Description += " (" + datHeader.Date + ")"; datHeader.Description += " (" + datHeader.Date + ")";
} }
} }
if (datHeader.Category == "" && updateMode != 0) if (String.IsNullOrWhiteSpace(datHeader.Category) && updateMode != 0)
{ {
datHeader.Category = "DiffDAT"; datHeader.Category = "DiffDAT";
} }
if (datHeader.Author == "") if (String.IsNullOrWhiteSpace(datHeader.Author))
{ {
datHeader.Author = "SabreTools"; datHeader.Author = "SabreTools";
} }