diff --git a/RombaSharp/RombaSharp.Helpers.cs b/RombaSharp/RombaSharp.Helpers.cs index 05951c6c..231e7925 100644 --- a/RombaSharp/RombaSharp.Helpers.cs +++ b/RombaSharp/RombaSharp.Helpers.cs @@ -377,7 +377,7 @@ namespace RombaSharp private static void RefreshDatabase() { // Make sure the db is set - if (String.IsNullOrEmpty(_db)) + if (String.IsNullOrWhiteSpace(_db)) { _db = "db.sqlite"; _connectionString = "Data Source=" + _db + ";Version = 3;"; @@ -390,7 +390,7 @@ namespace RombaSharp } // Make sure the dats dir is set - if (String.IsNullOrEmpty(_dats)) + if (String.IsNullOrWhiteSpace(_dats)) { _dats = "dats"; } @@ -500,23 +500,23 @@ namespace RombaSharp { Rom rom = (Rom)datItem; - if (!String.IsNullOrEmpty(rom.CRC)) + if (!String.IsNullOrWhiteSpace(rom.CRC)) { crcquery += " (\"" + rom.CRC + "\"),"; } - if (!String.IsNullOrEmpty(rom.MD5)) + if (!String.IsNullOrWhiteSpace(rom.MD5)) { md5query += " (\"" + rom.MD5 + "\"),"; } - if (!String.IsNullOrEmpty(rom.SHA1)) + if (!String.IsNullOrWhiteSpace(rom.SHA1)) { sha1query += " (\"" + rom.SHA1 + "\"),"; - if (!String.IsNullOrEmpty(rom.CRC)) + if (!String.IsNullOrWhiteSpace(rom.CRC)) { crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; } - if (!String.IsNullOrEmpty(rom.MD5)) + if (!String.IsNullOrWhiteSpace(rom.MD5)) { md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),"; } @@ -526,15 +526,15 @@ namespace RombaSharp { Disk disk = (Disk)datItem; - if (!String.IsNullOrEmpty(disk.MD5)) + if (!String.IsNullOrWhiteSpace(disk.MD5)) { md5query += " (\"" + disk.MD5 + "\"),"; } - if (!String.IsNullOrEmpty(disk.SHA1)) + if (!String.IsNullOrWhiteSpace(disk.SHA1)) { sha1query += " (\"" + disk.SHA1 + "\"),"; - if (!String.IsNullOrEmpty(disk.MD5)) + if (!String.IsNullOrWhiteSpace(disk.MD5)) { md5sha1query += " (\"" + disk.MD5 + "\", \"" + disk.SHA1 + "\"),"; } @@ -642,23 +642,23 @@ namespace RombaSharp } else if (!dupehashes.Contains(rom.SHA1)) { - if (!String.IsNullOrEmpty(rom.CRC)) + if (!String.IsNullOrWhiteSpace(rom.CRC)) { crcquery += " (\"" + rom.CRC + "\"),"; } - if (!String.IsNullOrEmpty(rom.MD5)) + if (!String.IsNullOrWhiteSpace(rom.MD5)) { md5query += " (\"" + rom.MD5 + "\"),"; } - if (!String.IsNullOrEmpty(rom.SHA1)) + if (!String.IsNullOrWhiteSpace(rom.SHA1)) { sha1query += " (\"" + rom.SHA1 + "\", \"" + depotname + "\"),"; - if (!String.IsNullOrEmpty(rom.CRC)) + if (!String.IsNullOrWhiteSpace(rom.CRC)) { crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; } - if (!String.IsNullOrEmpty(rom.MD5)) + if (!String.IsNullOrWhiteSpace(rom.MD5)) { md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),"; } diff --git a/RombaSharp/RombaSharp.Inits.cs b/RombaSharp/RombaSharp.Inits.cs index 15e810f9..d02128e1 100644 --- a/RombaSharp/RombaSharp.Inits.cs +++ b/RombaSharp/RombaSharp.Inits.cs @@ -84,23 +84,23 @@ namespace RombaSharp if (sldr.HasRows) { // Add to the queries - if (!String.IsNullOrEmpty(rom.CRC)) + if (!String.IsNullOrWhiteSpace(rom.CRC)) { crcquery += " (\"" + rom.CRC + "\"),"; } - if (!String.IsNullOrEmpty(rom.MD5)) + if (!String.IsNullOrWhiteSpace(rom.MD5)) { md5query += " (\"" + rom.MD5 + "\"),"; } - if (!String.IsNullOrEmpty(rom.SHA1)) + if (!String.IsNullOrWhiteSpace(rom.SHA1)) { sha1query += " (\"" + rom.SHA1 + "\", \"" + _depots.Keys.ToList()[0] + "\"),"; - if (!String.IsNullOrEmpty(rom.CRC)) + if (!String.IsNullOrWhiteSpace(rom.CRC)) { crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; } - if (!String.IsNullOrEmpty(rom.MD5)) + if (!String.IsNullOrWhiteSpace(rom.MD5)) { md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),"; } @@ -114,23 +114,23 @@ namespace RombaSharp else { // Add to the queries - if (!String.IsNullOrEmpty(rom.CRC)) + if (!String.IsNullOrWhiteSpace(rom.CRC)) { crcquery += " (\"" + rom.CRC + "\"),"; } - if (!String.IsNullOrEmpty(rom.MD5)) + if (!String.IsNullOrWhiteSpace(rom.MD5)) { md5query += " (\"" + rom.MD5 + "\"),"; } - if (!String.IsNullOrEmpty(rom.SHA1)) + if (!String.IsNullOrWhiteSpace(rom.SHA1)) { sha1query += " (\"" + rom.SHA1 + "\", \"" + _depots.Keys.ToList()[0] + "\"),"; - if (!String.IsNullOrEmpty(rom.CRC)) + if (!String.IsNullOrWhiteSpace(rom.CRC)) { crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),"; } - if (!String.IsNullOrEmpty(rom.MD5)) + if (!String.IsNullOrWhiteSpace(rom.MD5)) { md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),"; } diff --git a/SabreTools.Library/DatFiles/ClrMamePro.cs b/SabreTools.Library/DatFiles/ClrMamePro.cs index cb10f424..5d240d84 100644 --- a/SabreTools.Library/DatFiles/ClrMamePro.cs +++ b/SabreTools.Library/DatFiles/ClrMamePro.cs @@ -495,11 +495,11 @@ namespace SabreTools.Library.DatFiles if (line.Trim().StartsWith("Name:")) { - Name = (String.IsNullOrEmpty(Name) ? line.Substring(6) : Name); + Name = (String.IsNullOrWhiteSpace(Name) ? line.Substring(6) : Name); superdat = superdat || itemval.Contains(" - SuperDAT"); if (keep && superdat) { - Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); + Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type); } continue; } @@ -508,54 +508,54 @@ namespace SabreTools.Library.DatFiles { case "name": case "Name:": - Name = (String.IsNullOrEmpty(Name) ? itemval : Name); + Name = (String.IsNullOrWhiteSpace(Name) ? itemval : Name); superdat = superdat || itemval.Contains(" - SuperDAT"); if (keep && superdat) { - Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); + Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type); } break; case "description": case "Description:": - Description = (String.IsNullOrEmpty(Description) ? itemval : Description); + Description = (String.IsNullOrWhiteSpace(Description) ? itemval : Description); break; case "rootdir": - RootDir = (String.IsNullOrEmpty(RootDir) ? itemval : RootDir); + RootDir = (String.IsNullOrWhiteSpace(RootDir) ? itemval : RootDir); break; case "category": - Category = (String.IsNullOrEmpty(Category) ? itemval : Category); + Category = (String.IsNullOrWhiteSpace(Category) ? itemval : Category); break; case "version": case "Version:": - Version = (String.IsNullOrEmpty(Version) ? itemval : Version); + Version = (String.IsNullOrWhiteSpace(Version) ? itemval : Version); break; case "date": case "Date:": - Date = (String.IsNullOrEmpty(Date) ? itemval : Date); + Date = (String.IsNullOrWhiteSpace(Date) ? itemval : Date); break; case "author": case "Author:": - Author = (String.IsNullOrEmpty(Author) ? itemval : Author); + Author = (String.IsNullOrWhiteSpace(Author) ? itemval : Author); break; case "email": - Email = (String.IsNullOrEmpty(Email) ? itemval : Email); + Email = (String.IsNullOrWhiteSpace(Email) ? itemval : Email); break; case "homepage": case "Homepage:": - Homepage = (String.IsNullOrEmpty(Homepage) ? itemval : Homepage); + Homepage = (String.IsNullOrWhiteSpace(Homepage) ? itemval : Homepage); break; case "url": - Url = (String.IsNullOrEmpty(Url) ? itemval : Url); + Url = (String.IsNullOrWhiteSpace(Url) ? itemval : Url); break; case "comment": case "Comment:": - Comment = (String.IsNullOrEmpty(Comment) ? itemval : Comment); + Comment = (String.IsNullOrWhiteSpace(Comment) ? itemval : Comment); break; case "header": - Header = (String.IsNullOrEmpty(Header) ? itemval : Header); + Header = (String.IsNullOrWhiteSpace(Header) ? itemval : Header); break; case "type": - Type = (String.IsNullOrEmpty(Type) ? itemval : Type); + Type = (String.IsNullOrWhiteSpace(Type) ? itemval : Type); superdat = superdat || itemval.Contains("SuperDAT"); break; case "forcemerging": @@ -741,14 +741,14 @@ namespace SabreTools.Library.DatFiles string header = "clrmamepro (\n" + "\tname \"" + Name + "\"\n" + "\tdescription \"" + Description + "\"\n" + - (!String.IsNullOrEmpty(Category) ? "\tcategory \"" + Category + "\"\n" : "") + + (!String.IsNullOrWhiteSpace(Category) ? "\tcategory \"" + Category + "\"\n" : "") + "\tversion \"" + Version + "\"\n" + - (!String.IsNullOrEmpty(Date) ? "\tdate \"" + Date + "\"\n" : "") + + (!String.IsNullOrWhiteSpace(Date) ? "\tdate \"" + Date + "\"\n" : "") + "\tauthor \"" + Author + "\"\n" + - (!String.IsNullOrEmpty(Email) ? "\temail \"" + Email + "\"\n" : "") + - (!String.IsNullOrEmpty(Homepage) ? "\thomepage \"" + Homepage + "\"\n" : "") + - (!String.IsNullOrEmpty(Url) ? "\turl \"" + Url + "\"\n" : "") + - (!String.IsNullOrEmpty(Comment) ? "\tcomment \"" + Comment + "\"\n" : "") + + (!String.IsNullOrWhiteSpace(Email) ? "\temail \"" + Email + "\"\n" : "") + + (!String.IsNullOrWhiteSpace(Homepage) ? "\thomepage \"" + Homepage + "\"\n" : "") + + (!String.IsNullOrWhiteSpace(Url) ? "\turl \"" + Url + "\"\n" : "") + + (!String.IsNullOrWhiteSpace(Comment) ? "\tcomment \"" + Comment + "\"\n" : "") + (ForcePacking == ForcePacking.Unzip ? "\tforcezipping no\n" : "") + (ForcePacking == ForcePacking.Zip ? "\tforcezipping yes\n" : "") + (ForceMerging == ForceMerging.Full ? "\tforcemerging full\n" : "") + @@ -788,13 +788,13 @@ namespace SabreTools.Library.DatFiles string state = "game (\n\tname \"" + rom.MachineName + "\"\n" + (ExcludeOf ? "" : - (String.IsNullOrEmpty(rom.RomOf) ? "" : "\tromof \"" + rom.RomOf + "\"\n") + - (String.IsNullOrEmpty(rom.CloneOf) ? "" : "\tcloneof \"" + rom.CloneOf + "\"\n") + - (String.IsNullOrEmpty(rom.SampleOf) ? "" : "\tsampleof \"" + rom.SampleOf + "\"\n") + (String.IsNullOrWhiteSpace(rom.RomOf) ? "" : "\tromof \"" + rom.RomOf + "\"\n") + + (String.IsNullOrWhiteSpace(rom.CloneOf) ? "" : "\tcloneof \"" + rom.CloneOf + "\"\n") + + (String.IsNullOrWhiteSpace(rom.SampleOf) ? "" : "\tsampleof \"" + rom.SampleOf + "\"\n") ) + - "\tdescription \"" + (String.IsNullOrEmpty(rom.MachineDescription) ? rom.MachineName : rom.MachineDescription) + "\"\n" + - (String.IsNullOrEmpty(rom.Year) ? "" : "\tyear " + rom.Year + "\n") + - (String.IsNullOrEmpty(rom.Manufacturer) ? "" : "\tmanufacturer \"" + rom.Manufacturer + "\"\n"); + "\tdescription \"" + (String.IsNullOrWhiteSpace(rom.MachineDescription) ? rom.MachineName : rom.MachineDescription) + "\"\n" + + (String.IsNullOrWhiteSpace(rom.Year) ? "" : "\tyear " + rom.Year + "\n") + + (String.IsNullOrWhiteSpace(rom.Manufacturer) ? "" : "\tmanufacturer \"" + rom.Manufacturer + "\"\n"); sw.Write(state); sw.Flush(); @@ -818,7 +818,7 @@ namespace SabreTools.Library.DatFiles { try { - string state = (String.IsNullOrEmpty(rom.SampleOf) ? "" : "\tsampleof \"" + rom.SampleOf + "\"\n") + ")\n"; + string state = (String.IsNullOrWhiteSpace(rom.SampleOf) ? "" : "\tsampleof \"" + rom.SampleOf + "\"\n") + ")\n"; sw.Write(state); sw.Flush(); @@ -861,7 +861,7 @@ namespace SabreTools.Library.DatFiles break; case ItemType.BiosSet: state += "\tbiosset ( name\"" + rom.Name + "\"" - + (!String.IsNullOrEmpty(((BiosSet)rom).Description) ? " description \"" + ((BiosSet)rom).Description + "\"" : "") + + (!String.IsNullOrWhiteSpace(((BiosSet)rom).Description) ? " description \"" + ((BiosSet)rom).Description + "\"" : "") + (((BiosSet)rom).Default != null ? "default " + ((BiosSet)rom).Default.ToString().ToLowerInvariant() : "") @@ -869,19 +869,19 @@ namespace SabreTools.Library.DatFiles break; case ItemType.Disk: state += "\tdisk ( name \"" + rom.Name + "\"" - + (!String.IsNullOrEmpty(((Disk)rom).MD5) ? " md5 " + ((Disk)rom).MD5.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Disk)rom).SHA1) ? " sha1 " + ((Disk)rom).SHA1.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Disk)rom).SHA256) ? " sha256 " + ((Disk)rom).SHA256.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Disk)rom).SHA384) ? " sha384 " + ((Disk)rom).SHA384.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Disk)rom).SHA512) ? " sha512 " + ((Disk)rom).SHA512.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Disk)rom).MD5) ? " md5 " + ((Disk)rom).MD5.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Disk)rom).SHA1) ? " sha1 " + ((Disk)rom).SHA1.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Disk)rom).SHA256) ? " sha256 " + ((Disk)rom).SHA256.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Disk)rom).SHA384) ? " sha384 " + ((Disk)rom).SHA384.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Disk)rom).SHA512) ? " sha512 " + ((Disk)rom).SHA512.ToLowerInvariant() : "") + (((Disk)rom).ItemStatus != ItemStatus.None ? " flags " + ((Disk)rom).ItemStatus.ToString().ToLowerInvariant() : "") + " )\n"; break; case ItemType.Release: state += "\trelease ( name\"" + rom.Name + "\"" - + (!String.IsNullOrEmpty(((Release)rom).Region) ? " region \"" + ((Release)rom).Region + "\"" : "") - + (!String.IsNullOrEmpty(((Release)rom).Language) ? " language \"" + ((Release)rom).Language + "\"" : "") - + (!String.IsNullOrEmpty(((Release)rom).Date) ? " date \"" + ((Release)rom).Date + "\"" : "") + + (!String.IsNullOrWhiteSpace(((Release)rom).Region) ? " region \"" + ((Release)rom).Region + "\"" : "") + + (!String.IsNullOrWhiteSpace(((Release)rom).Language) ? " language \"" + ((Release)rom).Language + "\"" : "") + + (!String.IsNullOrWhiteSpace(((Release)rom).Date) ? " date \"" + ((Release)rom).Date + "\"" : "") + (((Release)rom).Default != null ? "default " + ((Release)rom).Default.ToString().ToLowerInvariant() : "") @@ -890,13 +890,13 @@ namespace SabreTools.Library.DatFiles case ItemType.Rom: state += "\trom ( name \"" + rom.Name + "\"" + (((Rom)rom).Size != -1 ? " size " + ((Rom)rom).Size : "") - + (!String.IsNullOrEmpty(((Rom)rom).CRC) ? " crc " + ((Rom)rom).CRC.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Rom)rom).MD5) ? " md5 " + ((Rom)rom).MD5.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Rom)rom).SHA1) ? " sha1 " + ((Rom)rom).SHA1.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Rom)rom).SHA256) ? " sha256 " + ((Rom)rom).SHA256.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Rom)rom).SHA384) ? " sha384 " + ((Rom)rom).SHA384.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Rom)rom).SHA512) ? " sha512 " + ((Rom)rom).SHA512.ToLowerInvariant() : "") - + (!String.IsNullOrEmpty(((Rom)rom).Date) ? " date \"" + ((Rom)rom).Date + "\"" : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).CRC) ? " crc " + ((Rom)rom).CRC.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).MD5) ? " md5 " + ((Rom)rom).MD5.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).SHA1) ? " sha1 " + ((Rom)rom).SHA1.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).SHA256) ? " sha256 " + ((Rom)rom).SHA256.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).SHA384) ? " sha384 " + ((Rom)rom).SHA384.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).SHA512) ? " sha512 " + ((Rom)rom).SHA512.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).Date) ? " date \"" + ((Rom)rom).Date + "\"" : "") + (((Rom)rom).ItemStatus != ItemStatus.None ? " flags " + ((Rom)rom).ItemStatus.ToString().ToLowerInvariant() : "") + " )\n"; break; diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 9b740be8..a02b100c 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -1518,7 +1518,7 @@ namespace SabreTools.Library.DatFiles : item.SystemID.ToString().PadLeft(10, '0') + "-" + item.SourceID.ToString().PadLeft(10, '0') + "-") - + (String.IsNullOrEmpty(item.MachineName) + + (String.IsNullOrWhiteSpace(item.MachineName) ? "Default" : item.MachineName); if (lower) @@ -1625,6 +1625,9 @@ namespace SabreTools.Library.DatFiles public void DetermineUpdateType(List inputPaths, List basePaths, string outDir, bool merge, UpdateMode updateMode, bool inplace, bool skip, bool bare, bool clean, bool remUnicode, bool descAsName, Filter filter, SplitType splitType, bool trim, bool single, string root) { + // First, we want to ensure the output directory + outDir = Utilities.EnsureOutputDirectory(outDir); + // If we're in merging or diffing mode, use the full list of inputs if (merge || (updateMode != UpdateMode.None && (updateMode & UpdateMode.DiffAgainst) == 0) @@ -1830,32 +1833,18 @@ namespace SabreTools.Library.DatFiles }); // Determine the output path for the DAT - string interOutDir = outDir; + string interOutDir = Utilities.EnsureOutputDirectory(outDir); if (inplace) { interOutDir = Path.GetDirectoryName(splitpath[1]); } - else if (!String.IsNullOrEmpty(interOutDir)) + else if (splitpath[0].Length == splitpath[1].Length) { - if (splitpath[0].Length == splitpath[1].Length) - { - interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, Path.GetFileName(splitpath[0]))); - } - else - { - interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, splitpath[0].Remove(0, splitpath[1].Length + 1))); - } + interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, Path.GetFileName(splitpath[0]))); } else { - if (splitpath[0].Length == splitpath[1].Length) - { - interOutDir = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, Path.GetFileName(splitpath[0]))); - } - else - { - interOutDir = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, splitpath[0].Remove(0, splitpath[1].Length + 1))); - } + interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, splitpath[0].Remove(0, splitpath[1].Length + 1))); } // Once we're done, try writing out @@ -1934,32 +1923,18 @@ namespace SabreTools.Library.DatFiles }); // Determine the output path for the DAT - string interOutDir = outDir; + string interOutDir = Utilities.EnsureOutputDirectory(outDir); if (inplace) { interOutDir = Path.GetDirectoryName(splitpath[1]); } - else if (!String.IsNullOrEmpty(interOutDir)) + else if (splitpath[0].Length == splitpath[1].Length) { - if (splitpath[0].Length == splitpath[1].Length) - { - interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, Path.GetFileName(splitpath[0]))); - } - else - { - interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, splitpath[0].Remove(0, splitpath[1].Length + 1))); - } + interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, Path.GetFileName(splitpath[0]))); } else { - if (splitpath[0].Length == splitpath[1].Length) - { - interOutDir = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, Path.GetFileName(splitpath[0]))); - } - else - { - interOutDir = Path.GetDirectoryName(Path.Combine(Environment.CurrentDirectory, splitpath[0].Remove(0, splitpath[1].Length + 1))); - } + interOutDir = Path.GetDirectoryName(Path.Combine(interOutDir, splitpath[0].Remove(0, splitpath[1].Length + 1))); } // Once we're done, try writing out @@ -2086,15 +2061,15 @@ namespace SabreTools.Library.DatFiles DatFile dupeData = new DatFile(); // Fill in any information not in the base DAT - if (String.IsNullOrEmpty(FileName)) + if (String.IsNullOrWhiteSpace(FileName)) { FileName = "All DATs"; } - if (String.IsNullOrEmpty(Name)) + if (String.IsNullOrWhiteSpace(Name)) { Name = "All DATs"; } - if (String.IsNullOrEmpty(Description)) + if (String.IsNullOrWhiteSpace(Description)) { Description = "All DATs"; } @@ -2514,25 +2489,25 @@ namespace SabreTools.Library.DatFiles foreach (DatItem item in items) { // Update machine name - if (!String.IsNullOrEmpty(item.MachineName) && mapping.ContainsKey(item.MachineName)) + if (!String.IsNullOrWhiteSpace(item.MachineName) && mapping.ContainsKey(item.MachineName)) { item.MachineName = mapping[item.MachineName]; } // Update cloneof - if (!String.IsNullOrEmpty(item.CloneOf) && mapping.ContainsKey(item.CloneOf)) + if (!String.IsNullOrWhiteSpace(item.CloneOf) && mapping.ContainsKey(item.CloneOf)) { item.CloneOf = mapping[item.CloneOf]; } // Update romof - if (!String.IsNullOrEmpty(item.RomOf) && mapping.ContainsKey(item.RomOf)) + if (!String.IsNullOrWhiteSpace(item.RomOf) && mapping.ContainsKey(item.RomOf)) { item.RomOf = mapping[item.RomOf]; } // Update sampleof - if (!String.IsNullOrEmpty(item.SampleOf) && mapping.ContainsKey(item.SampleOf)) + if (!String.IsNullOrWhiteSpace(item.SampleOf) && mapping.ContainsKey(item.SampleOf)) { item.SampleOf = mapping[item.SampleOf]; } @@ -2820,13 +2795,13 @@ namespace SabreTools.Library.DatFiles // Determine if the game has a parent or not string parent = null; - if (!String.IsNullOrEmpty(this[game][0].RomOf)) + if (!String.IsNullOrWhiteSpace(this[game][0].RomOf)) { parent = this[game][0].RomOf; } // If the parent doesnt exist, we want to continue - if (String.IsNullOrEmpty(parent)) + if (String.IsNullOrWhiteSpace(parent)) { continue; } @@ -2908,13 +2883,13 @@ namespace SabreTools.Library.DatFiles // Determine if the game has a parent or not string parent = null; - if (!String.IsNullOrEmpty(this[game][0].CloneOf)) + if (!String.IsNullOrWhiteSpace(this[game][0].CloneOf)) { parent = this[game][0].CloneOf; } // If the parent doesnt exist, we want to continue - if (String.IsNullOrEmpty(parent)) + if (String.IsNullOrWhiteSpace(parent)) { continue; } @@ -2958,13 +2933,13 @@ namespace SabreTools.Library.DatFiles { // Determine if the game has a parent or not string parent = null; - if (!String.IsNullOrEmpty(this[game][0].CloneOf)) + if (!String.IsNullOrWhiteSpace(this[game][0].CloneOf)) { parent = this[game][0].CloneOf; } // If there is no parent, then we continue - if (String.IsNullOrEmpty(parent)) + if (String.IsNullOrWhiteSpace(parent)) { continue; } @@ -3034,13 +3009,13 @@ namespace SabreTools.Library.DatFiles // Determine if the game has a parent or not string parent = null; - if (!String.IsNullOrEmpty(this[game][0].RomOf)) + if (!String.IsNullOrWhiteSpace(this[game][0].RomOf)) { parent = this[game][0].RomOf; } // If the parent doesnt exist, we want to continue - if (String.IsNullOrEmpty(parent)) + if (String.IsNullOrWhiteSpace(parent)) { continue; } @@ -3077,13 +3052,13 @@ namespace SabreTools.Library.DatFiles // Determine if the game has a parent or not string parent = null; - if (!String.IsNullOrEmpty(this[game][0].CloneOf)) + if (!String.IsNullOrWhiteSpace(this[game][0].CloneOf)) { parent = this[game][0].CloneOf; } // If the parent doesnt exist, we want to continue - if (String.IsNullOrEmpty(parent)) + if (String.IsNullOrWhiteSpace(parent)) { continue; } @@ -3196,7 +3171,7 @@ namespace SabreTools.Library.DatFiles } // If the output filename isn't set already, get the internal filename - FileName = (String.IsNullOrEmpty(FileName) ? (keepext ? Path.GetFileName(filename) : Path.GetFileNameWithoutExtension(filename)) : FileName); + FileName = (String.IsNullOrWhiteSpace(FileName) ? (keepext ? Path.GetFileName(filename) : Path.GetFileNameWithoutExtension(filename)) : FileName); // If the output type isn't set already, get the internal output type DatFormat = (DatFormat == 0 ? Utilities.GetDatFormat(filename) : DatFormat); @@ -3370,7 +3345,7 @@ namespace SabreTools.Library.DatFiles // If we have a rom and it's missing size AND the hashes match a 0-byte file, fill in the rest of the info if ((itemRom.Size == 0 || itemRom.Size == -1) - && ((itemRom.CRC == Constants.CRCZero || String.IsNullOrEmpty(itemRom.CRC)) + && ((itemRom.CRC == Constants.CRCZero || String.IsNullOrWhiteSpace(itemRom.CRC)) || itemRom.MD5 == Constants.MD5Zero || itemRom.SHA1 == Constants.SHA1Zero || itemRom.SHA256 == Constants.SHA256Zero @@ -3398,12 +3373,12 @@ namespace SabreTools.Library.DatFiles // If the file has a size but aboslutely no hashes, skip and log else if (itemRom.ItemStatus != ItemStatus.Nodump && itemRom.Size > 0 - && String.IsNullOrEmpty(itemRom.CRC) - && String.IsNullOrEmpty(itemRom.MD5) - && String.IsNullOrEmpty(itemRom.SHA1) - && String.IsNullOrEmpty(itemRom.SHA256) - && String.IsNullOrEmpty(itemRom.SHA384) - && String.IsNullOrEmpty(itemRom.SHA512)) + && String.IsNullOrWhiteSpace(itemRom.CRC) + && String.IsNullOrWhiteSpace(itemRom.MD5) + && String.IsNullOrWhiteSpace(itemRom.SHA1) + && String.IsNullOrWhiteSpace(itemRom.SHA256) + && String.IsNullOrWhiteSpace(itemRom.SHA384) + && String.IsNullOrWhiteSpace(itemRom.SHA512)) { Globals.Logger.Verbose("{0}: Incomplete entry for '{1}' will be output as nodump", FileName, itemRom.Name); itemRom.ItemStatus = ItemStatus.Nodump; @@ -3424,11 +3399,11 @@ namespace SabreTools.Library.DatFiles // If the file has aboslutely no hashes, skip and log if (itemDisk.ItemStatus != ItemStatus.Nodump - && String.IsNullOrEmpty(itemDisk.MD5) - && String.IsNullOrEmpty(itemDisk.SHA1) - && String.IsNullOrEmpty(itemDisk.SHA256) - && String.IsNullOrEmpty(itemDisk.SHA384) - && String.IsNullOrEmpty(itemDisk.SHA512)) + && String.IsNullOrWhiteSpace(itemDisk.MD5) + && String.IsNullOrWhiteSpace(itemDisk.SHA1) + && String.IsNullOrWhiteSpace(itemDisk.SHA256) + && String.IsNullOrWhiteSpace(itemDisk.SHA384) + && String.IsNullOrWhiteSpace(itemDisk.SHA512)) { Globals.Logger.Verbose("Incomplete entry for '{0}' will be output as nodump", itemDisk.Name); itemDisk.ItemStatus = ItemStatus.Nodump; @@ -3498,19 +3473,19 @@ namespace SabreTools.Library.DatFiles bool addBlanks, bool addDate, string tempDir, bool copyFiles, string headerToCheckAgainst, bool chdsAsFiles) { // If the description is defined but not the name, set the name from the description - if (String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Description)) + if (String.IsNullOrWhiteSpace(Name) && !String.IsNullOrWhiteSpace(Description)) { Name = Description; } // If the name is defined but not the description, set the description from the name - else if (!String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Description)) + else if (!String.IsNullOrWhiteSpace(Name) && String.IsNullOrWhiteSpace(Description)) { Description = Name + (bare ? "" : " (" + Date + ")"); } // If neither the name or description are defined, set them from the automatic values - else if (String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Description)) + else if (String.IsNullOrWhiteSpace(Name) && String.IsNullOrWhiteSpace(Description)) { Name = basePath.Split(Path.DirectorySeparatorChar).Last(); Description = Name + (bare ? "" : " (" + Date + ")"); @@ -3856,7 +3831,7 @@ namespace SabreTools.Library.DatFiles { romname = romname.Substring(0, romname.Length - 1); } - if (!String.IsNullOrEmpty(gamename) && String.IsNullOrEmpty(romname)) + if (!String.IsNullOrWhiteSpace(gamename) && String.IsNullOrWhiteSpace(romname)) { romname = gamename; gamename = "Default"; @@ -4518,7 +4493,7 @@ namespace SabreTools.Library.DatFiles } writeStream.Dispose(); - if (date && !String.IsNullOrEmpty(item.Date)) + if (date && !String.IsNullOrWhiteSpace(item.Date)) { File.SetCreationTime(outfile, DateTime.Parse(item.Date)); } @@ -5107,38 +5082,38 @@ namespace SabreTools.Library.DatFiles nodump.Add(key, item); } // If the file has a SHA-512 - else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA512)) - || (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA512))) + else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA512)) + || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA512))) { sha512.Add(key, item); } // If the file has a SHA-384 - else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA384)) - || (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA384))) + else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA384)) + || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA384))) { sha384.Add(key, item); } // If the file has a SHA-256 - else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA256)) - || (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA256))) + else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA256)) + || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA256))) { sha256.Add(key, item); } // If the file has a SHA-1 - else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA1)) - || (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA1))) + else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA1)) + || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA1))) { sha1.Add(key, item); } // If the file has no SHA-1 but has an MD5 - else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).MD5)) - || (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).MD5))) + else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).MD5)) + || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).MD5))) { md5.Add(key, item); } // If the file has no MD5 but a CRC - else if ((item.Type == ItemType.Rom && !String.IsNullOrEmpty(((Rom)item).SHA1)) - || (item.Type == ItemType.Disk && !String.IsNullOrEmpty(((Disk)item).SHA1))) + else if ((item.Type == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)item).SHA1)) + || (item.Type == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)item).SHA1))) { crc.Add(key, item); } @@ -5266,12 +5241,12 @@ namespace SabreTools.Library.DatFiles string expName = name.Replace("/", " - ").Replace("\\", " - "); // Get the path that the file will be written out to - string path = HttpUtility.HtmlDecode(String.IsNullOrEmpty(name) + string path = HttpUtility.HtmlDecode(String.IsNullOrWhiteSpace(name) ? outDir : Path.Combine(outDir, name)); // Now set the new output values - datFile.FileName = HttpUtility.HtmlDecode(String.IsNullOrEmpty(name) + datFile.FileName = HttpUtility.HtmlDecode(String.IsNullOrWhiteSpace(name) ? FileName : (shortname ? Path.GetFileName(name) @@ -5280,7 +5255,7 @@ namespace SabreTools.Library.DatFiles ); datFile.FileName = (restore ? FileName + " (" + datFile.FileName + ")" : datFile.FileName); datFile.Name = Name + " (" + expName + ")"; - datFile.Description = (String.IsNullOrEmpty(Description) ? datFile.Name : Description + " (" + expName + ")"); + datFile.Description = (String.IsNullOrWhiteSpace(Description) ? datFile.Name : Description + " (" + expName + ")"); datFile.Type = null; // Write out the temporary DAT to the proper directory @@ -5512,18 +5487,8 @@ namespace SabreTools.Library.DatFiles return false; } - // If output directory is empty, use the current folder - if (outDir == null || outDir.Trim() == "") - { - Globals.Logger.Verbose("No output directory defined, defaulting to curent folder"); - outDir = Environment.CurrentDirectory; - } - - // Create the output directory if it doesn't already exist - if (!Directory.Exists(outDir)) - { - Directory.CreateDirectory(outDir); - } + // Ensure the output directory is set and created + outDir = Utilities.EnsureOutputDirectory(outDir, create: true); // If the DAT has no output format, default to XML if (DatFormat == 0) @@ -5533,35 +5498,35 @@ namespace SabreTools.Library.DatFiles } // Make sure that the three essential fields are filled in - if (String.IsNullOrEmpty(FileName) && String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Description)) + if (String.IsNullOrWhiteSpace(FileName) && String.IsNullOrWhiteSpace(Name) && String.IsNullOrWhiteSpace(Description)) { FileName = Name = Description = "Default"; } - else if (String.IsNullOrEmpty(FileName) && String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Description)) + else if (String.IsNullOrWhiteSpace(FileName) && String.IsNullOrWhiteSpace(Name) && !String.IsNullOrWhiteSpace(Description)) { FileName = Name = Description; } - else if (String.IsNullOrEmpty(FileName) && !String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Description)) + else if (String.IsNullOrWhiteSpace(FileName) && !String.IsNullOrWhiteSpace(Name) && String.IsNullOrWhiteSpace(Description)) { FileName = Description = Name; } - else if (String.IsNullOrEmpty(FileName) && !String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Description)) + else if (String.IsNullOrWhiteSpace(FileName) && !String.IsNullOrWhiteSpace(Name) && !String.IsNullOrWhiteSpace(Description)) { FileName = Description; } - else if (!String.IsNullOrEmpty(FileName) && String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Description)) + else if (!String.IsNullOrWhiteSpace(FileName) && String.IsNullOrWhiteSpace(Name) && String.IsNullOrWhiteSpace(Description)) { Name = Description = FileName; } - else if (!String.IsNullOrEmpty(FileName) && String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Description)) + else if (!String.IsNullOrWhiteSpace(FileName) && String.IsNullOrWhiteSpace(Name) && !String.IsNullOrWhiteSpace(Description)) { Name = Description; } - else if (!String.IsNullOrEmpty(FileName) && !String.IsNullOrEmpty(Name) && String.IsNullOrEmpty(Description)) + else if (!String.IsNullOrWhiteSpace(FileName) && !String.IsNullOrWhiteSpace(Name) && String.IsNullOrWhiteSpace(Description)) { Description = Name; } - else if (!String.IsNullOrEmpty(FileName) && !String.IsNullOrEmpty(Name) && !String.IsNullOrEmpty(Description)) + else if (!String.IsNullOrWhiteSpace(FileName) && !String.IsNullOrWhiteSpace(Name) && !String.IsNullOrWhiteSpace(Description)) { // Nothing is needed } @@ -5863,7 +5828,7 @@ namespace SabreTools.Library.DatFiles /// String containing the new filename private string CreateOutfileNamesHelper(string outDir, string extension, bool overwrite) { - string filename = (String.IsNullOrEmpty(FileName) ? Description : FileName); + string filename = (String.IsNullOrWhiteSpace(FileName) ? Description : FileName); string outfile = outDir + filename + extension; outfile = (outfile.Contains(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString()) ? outfile.Replace(Path.DirectorySeparatorChar.ToString() + Path.DirectorySeparatorChar.ToString(), Path.DirectorySeparatorChar.ToString()) : @@ -5911,17 +5876,13 @@ namespace SabreTools.Library.DatFiles } // Get the proper output file name - if (String.IsNullOrEmpty(reportName)) + if (String.IsNullOrWhiteSpace(reportName)) { reportName = "report"; } // Get the proper output directory name - if (outDir == null) - { - outDir = Environment.CurrentDirectory; - } - outDir = Path.GetFullPath(outDir); + outDir = Utilities.EnsureOutputDirectory(outDir); // Get the dictionary of desired output report names Dictionary outputs = CreateOutStatsNames(outDir, statDatFormat, reportName); diff --git a/SabreTools.Library/DatFiles/DatStats.cs b/SabreTools.Library/DatFiles/DatStats.cs index ed9ef559..30e3dee7 100644 --- a/SabreTools.Library/DatFiles/DatStats.cs +++ b/SabreTools.Library/DatFiles/DatStats.cs @@ -196,11 +196,11 @@ namespace SabreTools.Library.DatFiles _diskCount += 1; if (((Disk)item).ItemStatus != ItemStatus.Nodump) { - _md5Count += (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1); - _sha1Count += (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1); - _sha256Count += (String.IsNullOrEmpty(((Disk)item).SHA256) ? 0 : 1); - _sha384Count += (String.IsNullOrEmpty(((Disk)item).SHA384) ? 0 : 1); - _sha512Count += (String.IsNullOrEmpty(((Disk)item).SHA512) ? 0 : 1); + _md5Count += (String.IsNullOrWhiteSpace(((Disk)item).MD5) ? 0 : 1); + _sha1Count += (String.IsNullOrWhiteSpace(((Disk)item).SHA1) ? 0 : 1); + _sha256Count += (String.IsNullOrWhiteSpace(((Disk)item).SHA256) ? 0 : 1); + _sha384Count += (String.IsNullOrWhiteSpace(((Disk)item).SHA384) ? 0 : 1); + _sha512Count += (String.IsNullOrWhiteSpace(((Disk)item).SHA512) ? 0 : 1); } _baddumpCount += (((Disk)item).ItemStatus == ItemStatus.BadDump ? 1 : 0); @@ -216,12 +216,12 @@ namespace SabreTools.Library.DatFiles if (((Rom)item).ItemStatus != ItemStatus.Nodump) { _totalSize += ((Rom)item).Size; - _crcCount += (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1); - _md5Count += (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1); - _sha1Count += (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1); - _sha256Count += (String.IsNullOrEmpty(((Rom)item).SHA256) ? 0 : 1); - _sha384Count += (String.IsNullOrEmpty(((Rom)item).SHA384) ? 0 : 1); - _sha512Count += (String.IsNullOrEmpty(((Rom)item).SHA512) ? 0 : 1); + _crcCount += (String.IsNullOrWhiteSpace(((Rom)item).CRC) ? 0 : 1); + _md5Count += (String.IsNullOrWhiteSpace(((Rom)item).MD5) ? 0 : 1); + _sha1Count += (String.IsNullOrWhiteSpace(((Rom)item).SHA1) ? 0 : 1); + _sha256Count += (String.IsNullOrWhiteSpace(((Rom)item).SHA256) ? 0 : 1); + _sha384Count += (String.IsNullOrWhiteSpace(((Rom)item).SHA384) ? 0 : 1); + _sha512Count += (String.IsNullOrWhiteSpace(((Rom)item).SHA512) ? 0 : 1); } _baddumpCount += (((Rom)item).ItemStatus == ItemStatus.BadDump ? 1 : 0); @@ -295,11 +295,11 @@ namespace SabreTools.Library.DatFiles _diskCount -= 1; if (((Disk)item).ItemStatus != ItemStatus.Nodump) { - _md5Count -= (String.IsNullOrEmpty(((Disk)item).MD5) ? 0 : 1); - _sha1Count -= (String.IsNullOrEmpty(((Disk)item).SHA1) ? 0 : 1); - _sha256Count -= (String.IsNullOrEmpty(((Disk)item).SHA256) ? 0 : 1); - _sha384Count -= (String.IsNullOrEmpty(((Disk)item).SHA384) ? 0 : 1); - _sha512Count -= (String.IsNullOrEmpty(((Disk)item).SHA512) ? 0 : 1); + _md5Count -= (String.IsNullOrWhiteSpace(((Disk)item).MD5) ? 0 : 1); + _sha1Count -= (String.IsNullOrWhiteSpace(((Disk)item).SHA1) ? 0 : 1); + _sha256Count -= (String.IsNullOrWhiteSpace(((Disk)item).SHA256) ? 0 : 1); + _sha384Count -= (String.IsNullOrWhiteSpace(((Disk)item).SHA384) ? 0 : 1); + _sha512Count -= (String.IsNullOrWhiteSpace(((Disk)item).SHA512) ? 0 : 1); } _baddumpCount -= (((Disk)item).ItemStatus == ItemStatus.BadDump ? 1 : 0); @@ -315,12 +315,12 @@ namespace SabreTools.Library.DatFiles if (((Rom)item).ItemStatus != ItemStatus.Nodump) { _totalSize -= ((Rom)item).Size; - _crcCount -= (String.IsNullOrEmpty(((Rom)item).CRC) ? 0 : 1); - _md5Count -= (String.IsNullOrEmpty(((Rom)item).MD5) ? 0 : 1); - _sha1Count -= (String.IsNullOrEmpty(((Rom)item).SHA1) ? 0 : 1); - _sha256Count -= (String.IsNullOrEmpty(((Rom)item).SHA256) ? 0 : 1); - _sha384Count -= (String.IsNullOrEmpty(((Rom)item).SHA384) ? 0 : 1); - _sha512Count -= (String.IsNullOrEmpty(((Rom)item).SHA512) ? 0 : 1); + _crcCount -= (String.IsNullOrWhiteSpace(((Rom)item).CRC) ? 0 : 1); + _md5Count -= (String.IsNullOrWhiteSpace(((Rom)item).MD5) ? 0 : 1); + _sha1Count -= (String.IsNullOrWhiteSpace(((Rom)item).SHA1) ? 0 : 1); + _sha256Count -= (String.IsNullOrWhiteSpace(((Rom)item).SHA256) ? 0 : 1); + _sha384Count -= (String.IsNullOrWhiteSpace(((Rom)item).SHA384) ? 0 : 1); + _sha512Count -= (String.IsNullOrWhiteSpace(((Rom)item).SHA512) ? 0 : 1); } _baddumpCount -= (((Rom)item).ItemStatus == ItemStatus.BadDump ? 1 : 0); diff --git a/SabreTools.Library/DatFiles/DosCenter.cs b/SabreTools.Library/DatFiles/DosCenter.cs index c9eacf4a..ebeae8c0 100644 --- a/SabreTools.Library/DatFiles/DosCenter.cs +++ b/SabreTools.Library/DatFiles/DosCenter.cs @@ -238,7 +238,7 @@ namespace SabreTools.Library.DatFiles { try { - string state = (String.IsNullOrEmpty(rom.SampleOf) ? "" : "\tsampleof \"" + rom.SampleOf + "\"\n") + ")\n"; + string state = (String.IsNullOrWhiteSpace(rom.SampleOf) ? "" : "\tsampleof \"" + rom.SampleOf + "\"\n") + ")\n"; sw.Write(state); sw.Flush(); @@ -284,8 +284,8 @@ namespace SabreTools.Library.DatFiles case ItemType.Rom: state += "\tfile ( name " + ((Rom)rom).Name + (((Rom)rom).Size != -1 ? " size " + ((Rom)rom).Size : "") - + (!String.IsNullOrEmpty(((Rom)rom).Date) ? " date " + ((Rom)rom).Date : "") - + (!String.IsNullOrEmpty(((Rom)rom).CRC) ? " crc " + ((Rom)rom).CRC.ToLowerInvariant() : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).Date) ? " date " + ((Rom)rom).Date : "") + + (!String.IsNullOrWhiteSpace(((Rom)rom).CRC) ? " crc " + ((Rom)rom).CRC.ToLowerInvariant() : "") + " )\n"; break; } diff --git a/SabreTools.Library/DatFiles/Filter.cs b/SabreTools.Library/DatFiles/Filter.cs index 2fde23e1..1344b8ae 100644 --- a/SabreTools.Library/DatFiles/Filter.cs +++ b/SabreTools.Library/DatFiles/Filter.cs @@ -621,7 +621,7 @@ namespace SabreTools.Library.DatFiles bool found = false; foreach (string straw in haystack) { - if (!String.IsNullOrEmpty(straw)) + if (!String.IsNullOrWhiteSpace(straw)) { string regexStraw = straw; diff --git a/SabreTools.Library/DatFiles/Listroms.cs b/SabreTools.Library/DatFiles/Listroms.cs index 8e16f673..2f4b9b50 100644 --- a/SabreTools.Library/DatFiles/Listroms.cs +++ b/SabreTools.Library/DatFiles/Listroms.cs @@ -77,7 +77,7 @@ namespace SabreTools.Library.DatFiles string line = sr.ReadLine().Trim(); // If we have a blank line, we just skip it - if (String.IsNullOrEmpty(line)) + if (String.IsNullOrWhiteSpace(line)) { continue; } diff --git a/SabreTools.Library/DatFiles/Logiqx.cs b/SabreTools.Library/DatFiles/Logiqx.cs index 9ba7bdf8..5187c191 100644 --- a/SabreTools.Library/DatFiles/Logiqx.cs +++ b/SabreTools.Library/DatFiles/Logiqx.cs @@ -111,7 +111,7 @@ namespace SabreTools.Library.DatFiles parent.RemoveAt(parent.Count - 1); if (keep && parentcount > 1) { - Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); + Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type); superdat = true; } } @@ -130,8 +130,8 @@ namespace SabreTools.Library.DatFiles case "mame": if (xtr.GetAttribute("build") != null) { - Name = (String.IsNullOrEmpty(Name) ? xtr.GetAttribute("build") : Name); - Description = (String.IsNullOrEmpty(Description) ? Name : Name); + Name = (String.IsNullOrWhiteSpace(Name) ? xtr.GetAttribute("build") : Name); + Description = (String.IsNullOrWhiteSpace(Description) ? Name : Name); } xtr.Read(); break; @@ -139,11 +139,11 @@ namespace SabreTools.Library.DatFiles case "softwarelist": if (xtr.GetAttribute("name") != null) { - Name = (String.IsNullOrEmpty(Name) ? xtr.GetAttribute("name") : Name); + Name = (String.IsNullOrWhiteSpace(Name) ? xtr.GetAttribute("name") : Name); } if (xtr.GetAttribute("description") != null) { - Description = (String.IsNullOrEmpty(Description) ? xtr.GetAttribute("description") : Description); + Description = (String.IsNullOrWhiteSpace(Description) ? xtr.GetAttribute("description") : Description); } if (xtr.GetAttribute("forcemerging") != null && ForceMerging == ForceMerging.None) { @@ -197,11 +197,11 @@ namespace SabreTools.Library.DatFiles break; // Handle M1 DATs since they're 99% the same as a SL DAT case "m1": - Name = (String.IsNullOrEmpty(Name) ? "M1" : Name); - Description = (String.IsNullOrEmpty(Description) ? "M1" : Description); + Name = (String.IsNullOrWhiteSpace(Name) ? "M1" : Name); + Description = (String.IsNullOrWhiteSpace(Description) ? "M1" : Description); if (xtr.GetAttribute("version") != null) { - Version = (String.IsNullOrEmpty(Version) ? xtr.GetAttribute("version") : Version); + Version = (String.IsNullOrWhiteSpace(Version) ? xtr.GetAttribute("version") : Version); } xtr.Read(); break; @@ -232,16 +232,16 @@ namespace SabreTools.Library.DatFiles { case "datname": content = headreader.ReadElementContentAsString(); ; - Name = (String.IsNullOrEmpty(Name) ? content : Name); + Name = (String.IsNullOrWhiteSpace(Name) ? content : Name); superdat = superdat || content.Contains(" - SuperDAT"); if (keep && superdat) { - Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); + Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type); } break; case "datversionurl": content = headreader.ReadElementContentAsString(); ; - Url = (String.IsNullOrEmpty(Name) ? content : Url); + Url = (String.IsNullOrWhiteSpace(Name) ? content : Url); break; default: headreader.Read(); @@ -277,75 +277,75 @@ namespace SabreTools.Library.DatFiles { case "name": content = headreader.ReadElementContentAsString(); ; - Name = (String.IsNullOrEmpty(Name) ? content : Name); + Name = (String.IsNullOrWhiteSpace(Name) ? content : Name); superdat = superdat || content.Contains(" - SuperDAT"); if (keep && superdat) { - Type = (String.IsNullOrEmpty(Type) ? "SuperDAT" : Type); + Type = (String.IsNullOrWhiteSpace(Type) ? "SuperDAT" : Type); } break; case "description": content = headreader.ReadElementContentAsString(); - Description = (String.IsNullOrEmpty(Description) ? content : Description); + Description = (String.IsNullOrWhiteSpace(Description) ? content : Description); break; case "rootdir": content = headreader.ReadElementContentAsString(); - RootDir = (String.IsNullOrEmpty(RootDir) ? content : RootDir); + RootDir = (String.IsNullOrWhiteSpace(RootDir) ? content : RootDir); break; case "category": content = headreader.ReadElementContentAsString(); - Category = (String.IsNullOrEmpty(Category) ? content : Category); + Category = (String.IsNullOrWhiteSpace(Category) ? content : Category); break; case "version": content = headreader.ReadElementContentAsString(); - Version = (String.IsNullOrEmpty(Version) ? content : Version); + Version = (String.IsNullOrWhiteSpace(Version) ? content : Version); break; case "date": content = headreader.ReadElementContentAsString(); - Date = (String.IsNullOrEmpty(Date) ? content.Replace(".", "/") : Date); + Date = (String.IsNullOrWhiteSpace(Date) ? content.Replace(".", "/") : Date); break; case "author": content = headreader.ReadElementContentAsString(); - Author = (String.IsNullOrEmpty(Author) ? content : Author); + Author = (String.IsNullOrWhiteSpace(Author) ? content : Author); // Special cases for SabreDAT - Email = (String.IsNullOrEmpty(Email) && !String.IsNullOrEmpty(headreader.GetAttribute("email")) ? + Email = (String.IsNullOrWhiteSpace(Email) && !String.IsNullOrWhiteSpace(headreader.GetAttribute("email")) ? headreader.GetAttribute("email") : Email); - Homepage = (String.IsNullOrEmpty(Homepage) && !String.IsNullOrEmpty(headreader.GetAttribute("homepage")) ? + Homepage = (String.IsNullOrWhiteSpace(Homepage) && !String.IsNullOrWhiteSpace(headreader.GetAttribute("homepage")) ? headreader.GetAttribute("homepage") : Homepage); - Url = (String.IsNullOrEmpty(Url) && !String.IsNullOrEmpty(headreader.GetAttribute("url")) ? + Url = (String.IsNullOrWhiteSpace(Url) && !String.IsNullOrWhiteSpace(headreader.GetAttribute("url")) ? headreader.GetAttribute("url") : Url); break; case "email": content = headreader.ReadElementContentAsString(); - Email = (String.IsNullOrEmpty(Email) ? content : Email); + Email = (String.IsNullOrWhiteSpace(Email) ? content : Email); break; case "homepage": content = headreader.ReadElementContentAsString(); - Homepage = (String.IsNullOrEmpty(Homepage) ? content : Homepage); + Homepage = (String.IsNullOrWhiteSpace(Homepage) ? content : Homepage); break; case "url": content = headreader.ReadElementContentAsString(); - Url = (String.IsNullOrEmpty(Url) ? content : Url); + Url = (String.IsNullOrWhiteSpace(Url) ? content : Url); break; case "comment": content = headreader.ReadElementContentAsString(); - Comment = (String.IsNullOrEmpty(Comment) ? content : Comment); + Comment = (String.IsNullOrWhiteSpace(Comment) ? content : Comment); break; case "type": content = headreader.ReadElementContentAsString(); - Type = (String.IsNullOrEmpty(Type) ? content : Type); + Type = (String.IsNullOrWhiteSpace(Type) ? content : Type); superdat = superdat || content.Contains("SuperDAT"); break; case "clrmamepro": case "romcenter": if (headreader.GetAttribute("header") != null) { - Header = (String.IsNullOrEmpty(Header) ? headreader.GetAttribute("header") : Header); + Header = (String.IsNullOrWhiteSpace(Header) ? headreader.GetAttribute("header") : Header); } if (headreader.GetAttribute("plugin") != null) { - Header = (String.IsNullOrEmpty(Header) ? headreader.GetAttribute("plugin") : Header); + Header = (String.IsNullOrWhiteSpace(Header) ? headreader.GetAttribute("plugin") : Header); } if (headreader.GetAttribute("forcemerging") != null && ForceMerging == ForceMerging.None) { @@ -425,7 +425,7 @@ namespace SabreTools.Library.DatFiles switch (flagreader.GetAttribute("name")) { case "type": - Type = (String.IsNullOrEmpty(Type) ? content : Type); + Type = (String.IsNullOrWhiteSpace(Type) ? content : Type); superdat = superdat || content.Contains("SuperDAT"); break; case "forcemerging": @@ -1288,16 +1288,16 @@ namespace SabreTools.Library.DatFiles "\t
\n" + "\t\t" + HttpUtility.HtmlEncode(Name) + "\n" + "\t\t" + HttpUtility.HtmlEncode(Description) + "\n" + - (!String.IsNullOrEmpty(RootDir) ? "\t\t" + HttpUtility.HtmlEncode(RootDir) + "\n" : "") + - (!String.IsNullOrEmpty(Category) ? "\t\t" + HttpUtility.HtmlEncode(Category) + "\n" : "") + + (!String.IsNullOrWhiteSpace(RootDir) ? "\t\t" + HttpUtility.HtmlEncode(RootDir) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Category) ? "\t\t" + HttpUtility.HtmlEncode(Category) + "\n" : "") + "\t\t" + HttpUtility.HtmlEncode(Version) + "\n" + - (!String.IsNullOrEmpty(Date) ? "\t\t" + HttpUtility.HtmlEncode(Date) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Date) ? "\t\t" + HttpUtility.HtmlEncode(Date) + "\n" : "") + "\t\t" + HttpUtility.HtmlEncode(Author) + "\n" + - (!String.IsNullOrEmpty(Email) ? "\t\t" + HttpUtility.HtmlEncode(Email) + "\n" : "") + - (!String.IsNullOrEmpty(Homepage) ? "\t\t" + HttpUtility.HtmlEncode(Homepage) + "\n" : "") + - (!String.IsNullOrEmpty(Url) ? "\t\t" + HttpUtility.HtmlEncode(Url) + "\n" : "") + - (!String.IsNullOrEmpty(Comment) ? "\t\t" + HttpUtility.HtmlEncode(Comment) + "\n" : "") + - (!String.IsNullOrEmpty(Type) ? "\t\t" + HttpUtility.HtmlEncode(Type) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Email) ? "\t\t" + HttpUtility.HtmlEncode(Email) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Homepage) ? "\t\t" + HttpUtility.HtmlEncode(Homepage) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Url) ? "\t\t" + HttpUtility.HtmlEncode(Url) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Comment) ? "\t\t" + HttpUtility.HtmlEncode(Comment) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Type) ? "\t\t" + HttpUtility.HtmlEncode(Type) + "\n" : "") + (ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ? "\t\t\n" + - (String.IsNullOrEmpty(rom.Comment) ? "" : "\t\t" + HttpUtility.HtmlEncode(rom.Comment) + "\n") + - "\t\t" + HttpUtility.HtmlEncode((String.IsNullOrEmpty(rom.MachineDescription) ? rom.MachineName : rom.MachineDescription)) + "\n" + - (String.IsNullOrEmpty(rom.Year) ? "" : "\t\t" + HttpUtility.HtmlEncode(rom.Year) + "\n") + - (String.IsNullOrEmpty(rom.Manufacturer) ? "" : "\t\t" + HttpUtility.HtmlEncode(rom.Manufacturer) + "\n"); + (String.IsNullOrWhiteSpace(rom.Comment) ? "" : "\t\t" + HttpUtility.HtmlEncode(rom.Comment) + "\n") + + "\t\t" + HttpUtility.HtmlEncode((String.IsNullOrWhiteSpace(rom.MachineDescription) ? rom.MachineName : rom.MachineDescription)) + "\n" + + (String.IsNullOrWhiteSpace(rom.Year) ? "" : "\t\t" + HttpUtility.HtmlEncode(rom.Year) + "\n") + + (String.IsNullOrWhiteSpace(rom.Manufacturer) ? "" : "\t\t" + HttpUtility.HtmlEncode(rom.Manufacturer) + "\n"); sw.Write(state); sw.Flush(); @@ -1427,7 +1427,7 @@ namespace SabreTools.Library.DatFiles break; case ItemType.BiosSet: state += "\t\t\n"; break; case ItemType.Release: state += "\t\t\n"; break; diff --git a/SabreTools.Library/DatFiles/RomCenter.cs b/SabreTools.Library/DatFiles/RomCenter.cs index e8986ed6..22893d52 100644 --- a/SabreTools.Library/DatFiles/RomCenter.cs +++ b/SabreTools.Library/DatFiles/RomCenter.cs @@ -91,7 +91,7 @@ namespace SabreTools.Library.DatFiles // If we have an author if (line.ToLowerInvariant().StartsWith("author=")) { - Author = (String.IsNullOrEmpty(Author) ? line.Split('=')[1] : Author); + Author = (String.IsNullOrWhiteSpace(Author) ? line.Split('=')[1] : Author); } // If we have one of the three version tags else if (line.ToLowerInvariant().StartsWith("version=")) @@ -99,22 +99,22 @@ namespace SabreTools.Library.DatFiles switch (blocktype) { case "credits": - Version = (String.IsNullOrEmpty(Version) ? line.Split('=')[1] : Version); + Version = (String.IsNullOrWhiteSpace(Version) ? line.Split('=')[1] : Version); break; case "emulator": - Description = (String.IsNullOrEmpty(Description) ? line.Split('=')[1] : Description); + Description = (String.IsNullOrWhiteSpace(Description) ? line.Split('=')[1] : Description); break; } } // If we have a URL else if (line.ToLowerInvariant().StartsWith("url=")) { - Url = (String.IsNullOrEmpty(Url) ? line.Split('=')[1] : Url); + Url = (String.IsNullOrWhiteSpace(Url) ? line.Split('=')[1] : Url); } // If we have a comment else if (line.ToLowerInvariant().StartsWith("comment=")) { - Comment = (String.IsNullOrEmpty(Comment) ? line.Split('=')[1] : Comment); + Comment = (String.IsNullOrWhiteSpace(Comment) ? line.Split('=')[1] : Comment); } // If we have the split flag else if (line.ToLowerInvariant().StartsWith("split=")) @@ -141,7 +141,7 @@ namespace SabreTools.Library.DatFiles // If we have the refname tag else if (line.ToLowerInvariant().StartsWith("refname=")) { - Name = (String.IsNullOrEmpty(Name) ? line.Split('=')[1] : Name); + Name = (String.IsNullOrWhiteSpace(Name) ? line.Split('=')[1] : Name); } // If we have a rom else if (line.StartsWith("¬")) @@ -343,20 +343,20 @@ namespace SabreTools.Library.DatFiles string state = ""; if (rom.Type == ItemType.Rom) { - state += "¬" + (String.IsNullOrEmpty(rom.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.CloneOf)) + - "¬" + (String.IsNullOrEmpty(rom.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.CloneOf)) + + state += "¬" + (String.IsNullOrWhiteSpace(rom.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.CloneOf)) + + "¬" + (String.IsNullOrWhiteSpace(rom.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.CloneOf)) + "¬" + HttpUtility.HtmlEncode(rom.MachineName) + - "¬" + HttpUtility.HtmlEncode((String.IsNullOrEmpty(rom.MachineDescription) ? rom.MachineName : rom.MachineDescription)) + + "¬" + HttpUtility.HtmlEncode((String.IsNullOrWhiteSpace(rom.MachineDescription) ? rom.MachineName : rom.MachineDescription)) + "¬" + HttpUtility.HtmlEncode(rom.Name) + "¬" + ((Rom)rom).CRC.ToLowerInvariant() + "¬" + (((Rom)rom).Size != -1 ? ((Rom)rom).Size.ToString() : "") + "¬¬¬\n"; } else if (rom.Type == ItemType.Disk) { - state += "¬" + (String.IsNullOrEmpty(rom.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.CloneOf)) + - "¬" + (String.IsNullOrEmpty(rom.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.CloneOf)) + + state += "¬" + (String.IsNullOrWhiteSpace(rom.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.CloneOf)) + + "¬" + (String.IsNullOrWhiteSpace(rom.CloneOf) ? "" : HttpUtility.HtmlEncode(rom.CloneOf)) + "¬" + HttpUtility.HtmlEncode(rom.MachineName) + - "¬" + HttpUtility.HtmlEncode((String.IsNullOrEmpty(rom.MachineDescription) ? rom.MachineName : rom.MachineDescription)) + + "¬" + HttpUtility.HtmlEncode((String.IsNullOrWhiteSpace(rom.MachineDescription) ? rom.MachineName : rom.MachineDescription)) + "¬" + HttpUtility.HtmlEncode(rom.Name) + "¬¬¬¬¬\n"; } diff --git a/SabreTools.Library/DatFiles/SabreDat.cs b/SabreTools.Library/DatFiles/SabreDat.cs index d5241da4..67c86e57 100644 --- a/SabreTools.Library/DatFiles/SabreDat.cs +++ b/SabreTools.Library/DatFiles/SabreDat.cs @@ -181,15 +181,15 @@ namespace SabreTools.Library.DatFiles "\t
\n" + "\t\t" + HttpUtility.HtmlEncode(Name) + "\n" + "\t\t" + HttpUtility.HtmlEncode(Description) + "\n" + - (!String.IsNullOrEmpty(RootDir) ? "\t\t" + HttpUtility.HtmlEncode(RootDir) + "\n" : "") + - (!String.IsNullOrEmpty(Category) ? "\t\t" + HttpUtility.HtmlEncode(Category) + "\n" : "") + + (!String.IsNullOrWhiteSpace(RootDir) ? "\t\t" + HttpUtility.HtmlEncode(RootDir) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Category) ? "\t\t" + HttpUtility.HtmlEncode(Category) + "\n" : "") + "\t\t" + HttpUtility.HtmlEncode(Version) + "\n" + - (!String.IsNullOrEmpty(Date) ? "\t\t" + HttpUtility.HtmlEncode(Date) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Date) ? "\t\t" + HttpUtility.HtmlEncode(Date) + "\n" : "") + "\t\t" + HttpUtility.HtmlEncode(Author) + "\n" + - (!String.IsNullOrEmpty(Comment) ? "\t\t" + HttpUtility.HtmlEncode(Comment) + "\n" : "") + - (!String.IsNullOrEmpty(Type) || ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ? + (!String.IsNullOrWhiteSpace(Comment) ? "\t\t" + HttpUtility.HtmlEncode(Comment) + "\n" : "") + + (!String.IsNullOrWhiteSpace(Type) || ForcePacking != ForcePacking.None || ForceMerging != ForceMerging.None || ForceNodump != ForceNodump.None ? "\t\t\n" + - (!String.IsNullOrEmpty(Type) ? "\t\t\t\n" : "") + + (!String.IsNullOrWhiteSpace(Type) ? "\t\t\t\n" : "") + (ForcePacking == ForcePacking.Unzip ? "\t\t\t\n" : "") + (ForcePacking == ForcePacking.Zip ? "\t\t\t\n" : "") + (ForceMerging == ForceMerging.Full ? "\t\t\t\n" : "") + @@ -353,7 +353,7 @@ namespace SabreTools.Library.DatFiles break; case ItemType.BiosSet: state += "\n" + prefix + "\t\n" + prefix + "\t\t\n" + prefix + "\t\n" + @@ -373,9 +373,9 @@ namespace SabreTools.Library.DatFiles break; case ItemType.Release: state += "\n" + prefix + "\t\n" + prefix + "\t\t\n" + prefix + "\t\n" + diff --git a/SabreTools.Library/DatFiles/SeparatedValue.cs b/SabreTools.Library/DatFiles/SeparatedValue.cs index 47b2a68a..46b01947 100644 --- a/SabreTools.Library/DatFiles/SeparatedValue.cs +++ b/SabreTools.Library/DatFiles/SeparatedValue.cs @@ -186,13 +186,13 @@ namespace SabreTools.Library.DatFiles switch (columns[i]) { case "DatFile.FileName": - FileName = (String.IsNullOrEmpty(FileName) ? value : FileName); + FileName = (String.IsNullOrWhiteSpace(FileName) ? value : FileName); break; case "DatFile.Name": - Name = (String.IsNullOrEmpty(Name) ? value : Name); + Name = (String.IsNullOrWhiteSpace(Name) ? value : Name); break; case "DatFile.Description": - Description = (String.IsNullOrEmpty(Description) ? value : Description); + Description = (String.IsNullOrWhiteSpace(Description) ? value : Description); break; case "Machine.Name": machineName = value; diff --git a/SabreTools.Library/DatFiles/SoftwareList.cs b/SabreTools.Library/DatFiles/SoftwareList.cs index 174d21d8..0a162bfe 100644 --- a/SabreTools.Library/DatFiles/SoftwareList.cs +++ b/SabreTools.Library/DatFiles/SoftwareList.cs @@ -218,13 +218,13 @@ namespace SabreTools.Library.DatFiles string state = "\t\n" @@ -302,17 +302,17 @@ namespace SabreTools.Library.DatFiles switch (rom.Type) { case ItemType.Archive: - state += "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n"; break; case ItemType.BiosSet: - state += "\t\t\t\n" + "\t\t\t\t\n"; break; case ItemType.Disk: - state += "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n"; break; case ItemType.Release: - state += "\t\t\t\n" + "\t\t\t\t\n"; break; case ItemType.Rom: - state += "\t\t\t\n" + "\t\t\t\t\n" + "\t\t\t\n"; break; case ItemType.Sample: - state += "\t\t\t\n" + "\t\t\t\t\n" diff --git a/SabreTools.Library/DatItems/DatItem.cs b/SabreTools.Library/DatItems/DatItem.cs index f4e1c484..fe0b92ac 100644 --- a/SabreTools.Library/DatItems/DatItem.cs +++ b/SabreTools.Library/DatItems/DatItem.cs @@ -654,24 +654,24 @@ namespace SabreTools.Library.DatItems { // If all items are supposed to have a SHA-512, we sort by that if (datdata.RomCount + datdata.DiskCount - datdata.NodumpCount == datdata.SHA512Count - && ((_itemType == ItemType.Rom && !String.IsNullOrEmpty(((Rom)this).SHA512)) - || (_itemType == ItemType.Disk && !String.IsNullOrEmpty(((Disk)this).SHA512)))) + && ((_itemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)this).SHA512)) + || (_itemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)this).SHA512)))) { datdata.BucketBy(SortedBy.SHA512, DedupeType.None); } // If all items are supposed to have a SHA-384, we sort by that else if (datdata.RomCount + datdata.DiskCount - datdata.NodumpCount == datdata.SHA384Count - && ((_itemType == ItemType.Rom && !String.IsNullOrEmpty(((Rom)this).SHA384)) - || (_itemType == ItemType.Disk && !String.IsNullOrEmpty(((Disk)this).SHA384)))) + && ((_itemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)this).SHA384)) + || (_itemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)this).SHA384)))) { datdata.BucketBy(SortedBy.SHA384, DedupeType.None); } // If all items are supposed to have a SHA-256, we sort by that else if (datdata.RomCount + datdata.DiskCount - datdata.NodumpCount == datdata.SHA256Count - && ((_itemType == ItemType.Rom && !String.IsNullOrEmpty(((Rom)this).SHA256)) - || (_itemType == ItemType.Disk && !String.IsNullOrEmpty(((Disk)this).SHA256)))) + && ((_itemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)this).SHA256)) + || (_itemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)this).SHA256)))) { if (_itemType == ItemType.Rom) { @@ -687,8 +687,8 @@ namespace SabreTools.Library.DatItems // If all items are supposed to have a SHA-1, we sort by that else if (datdata.RomCount + datdata.DiskCount - datdata.NodumpCount == datdata.SHA1Count - && ((_itemType == ItemType.Rom && !String.IsNullOrEmpty(((Rom)this).SHA1)) - || (_itemType == ItemType.Disk && !String.IsNullOrEmpty(((Disk)this).SHA1)))) + && ((_itemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)this).SHA1)) + || (_itemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)this).SHA1)))) { if (_itemType == ItemType.Rom) { @@ -704,8 +704,8 @@ namespace SabreTools.Library.DatItems // If all items are supposed to have an MD5, we sort by that else if (datdata.RomCount + datdata.DiskCount - datdata.NodumpCount == datdata.MD5Count - && ((_itemType == ItemType.Rom && !String.IsNullOrEmpty(((Rom)this).MD5)) - || (_itemType == ItemType.Disk && !String.IsNullOrEmpty(((Disk)this).MD5)))) + && ((_itemType == ItemType.Rom && !String.IsNullOrWhiteSpace(((Rom)this).MD5)) + || (_itemType == ItemType.Disk && !String.IsNullOrWhiteSpace(((Disk)this).MD5)))) { if (_itemType == ItemType.Rom) { @@ -887,22 +887,22 @@ namespace SabreTools.Library.DatItems if (file.Type == ItemType.Rom) { ((Rom)saveditem).Size = ((Rom)saveditem).Size; - ((Rom)saveditem).CRC = (String.IsNullOrEmpty(((Rom)saveditem).CRC) && !String.IsNullOrEmpty(((Rom)file).CRC) + ((Rom)saveditem).CRC = (String.IsNullOrWhiteSpace(((Rom)saveditem).CRC) && !String.IsNullOrWhiteSpace(((Rom)file).CRC) ? ((Rom)file).CRC : ((Rom)saveditem).CRC); - ((Rom)saveditem).MD5 = (String.IsNullOrEmpty(((Rom)saveditem).MD5) && !String.IsNullOrEmpty(((Rom)file).MD5) + ((Rom)saveditem).MD5 = (String.IsNullOrWhiteSpace(((Rom)saveditem).MD5) && !String.IsNullOrWhiteSpace(((Rom)file).MD5) ? ((Rom)file).MD5 : ((Rom)saveditem).MD5); - ((Rom)saveditem).SHA1 = (String.IsNullOrEmpty(((Rom)saveditem).SHA1) && !String.IsNullOrEmpty(((Rom)file).SHA1) + ((Rom)saveditem).SHA1 = (String.IsNullOrWhiteSpace(((Rom)saveditem).SHA1) && !String.IsNullOrWhiteSpace(((Rom)file).SHA1) ? ((Rom)file).SHA1 : ((Rom)saveditem).SHA1); } else { - ((Disk)saveditem).MD5 = (String.IsNullOrEmpty(((Disk)saveditem).MD5) && !String.IsNullOrEmpty(((Disk)file).MD5) + ((Disk)saveditem).MD5 = (String.IsNullOrWhiteSpace(((Disk)saveditem).MD5) && !String.IsNullOrWhiteSpace(((Disk)file).MD5) ? ((Disk)file).MD5 : ((Disk)saveditem).MD5); - ((Disk)saveditem).SHA1 = (String.IsNullOrEmpty(((Disk)saveditem).SHA1) && !String.IsNullOrEmpty(((Disk)file).SHA1) + ((Disk)saveditem).SHA1 = (String.IsNullOrWhiteSpace(((Disk)saveditem).SHA1) && !String.IsNullOrWhiteSpace(((Disk)file).SHA1) ? ((Disk)file).SHA1 : ((Disk)saveditem).SHA1); } @@ -997,9 +997,9 @@ namespace SabreTools.Library.DatItems if (datItem.Type == ItemType.Disk) { Disk disk = (Disk)datItem; - disk.Name += "_" + (!String.IsNullOrEmpty(disk.MD5) + disk.Name += "_" + (!String.IsNullOrWhiteSpace(disk.MD5) ? disk.MD5 - : !String.IsNullOrEmpty(disk.SHA1) + : !String.IsNullOrWhiteSpace(disk.SHA1) ? disk.SHA1 : "1"); datItem = disk; @@ -1008,11 +1008,11 @@ namespace SabreTools.Library.DatItems else if (datItem.Type == ItemType.Rom) { Rom rom = (Rom)datItem; - rom.Name += "_" + (!String.IsNullOrEmpty(rom.CRC) + rom.Name += "_" + (!String.IsNullOrWhiteSpace(rom.CRC) ? rom.CRC - : !String.IsNullOrEmpty(rom.MD5) + : !String.IsNullOrWhiteSpace(rom.MD5) ? rom.MD5 - : !String.IsNullOrEmpty(rom.SHA1) + : !String.IsNullOrWhiteSpace(rom.SHA1) ? rom.SHA1 : "1"); datItem = rom; diff --git a/SabreTools.Library/DatItems/Disk.cs b/SabreTools.Library/DatItems/Disk.cs index bec48eab..a0b4cb0f 100644 --- a/SabreTools.Library/DatItems/Disk.cs +++ b/SabreTools.Library/DatItems/Disk.cs @@ -27,27 +27,27 @@ namespace SabreTools.Library.DatItems // Disk information public string MD5 { - get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); } + get { return _md5.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_md5); } set { _md5 = Utilities.StringToByteArray(value); } } public string SHA1 { - get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); } + get { return _sha1.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha1); } set { _sha1 = Utilities.StringToByteArray(value); } } public string SHA256 { - get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); } + get { return _sha256.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha256); } set { _sha256 = Utilities.StringToByteArray(value); } } public string SHA384 { - get { return _sha384.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha384); } + get { return _sha384.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha384); } set { _sha384 = Utilities.StringToByteArray(value); } } public string SHA512 { - get { return _sha512.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha512); } + get { return _sha512.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha512); } set { _sha512 = Utilities.StringToByteArray(value); } } public ItemStatus ItemStatus @@ -145,19 +145,19 @@ namespace SabreTools.Library.DatItems } // If we can determine that the disks have no non-empty hashes in common, we return false - if ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) - && (this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) - && (this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) - && (this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) - && (this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty())) + if ((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) + && (this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace()) + && (this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace()) + && (this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace()) + && (this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace())) { dupefound = false; } - else if (((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5)) - && ((this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1)) - && ((this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256)) - && ((this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384)) - && ((this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512))) + else if (((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._md5, newOther._md5)) + && ((this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1)) + && ((this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256)) + && ((this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384)) + && ((this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512))) { dupefound = true; } diff --git a/SabreTools.Library/DatItems/Rom.cs b/SabreTools.Library/DatItems/Rom.cs index 59a2ba03..b70885d6 100644 --- a/SabreTools.Library/DatItems/Rom.cs +++ b/SabreTools.Library/DatItems/Rom.cs @@ -35,32 +35,32 @@ namespace SabreTools.Library.DatItems } public string CRC { - get { return _crc.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_crc); } + get { return _crc.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_crc); } set { _crc = Utilities.StringToByteArray(value); } } public string MD5 { - get { return _md5.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_md5); } + get { return _md5.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_md5); } set { _md5 = Utilities.StringToByteArray(value); } } public string SHA1 { - get { return _sha1.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha1); } + get { return _sha1.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha1); } set { _sha1 = Utilities.StringToByteArray(value); } } public string SHA256 { - get { return _sha256.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha256); } + get { return _sha256.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha256); } set { _sha256 = Utilities.StringToByteArray(value); } } public string SHA384 { - get { return _sha384.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha384); } + get { return _sha384.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha384); } set { _sha384 = Utilities.StringToByteArray(value); } } public string SHA512 { - get { return _sha512.IsNullOrEmpty() ? null : Utilities.ByteArrayToString(_sha512); } + get { return _sha512.IsNullOrWhiteSpace() ? null : Utilities.ByteArrayToString(_sha512); } set { _sha512 = Utilities.StringToByteArray(value); } } public string Date @@ -212,22 +212,22 @@ namespace SabreTools.Library.DatItems } // If we can determine that the roms have no non-empty hashes in common, we return false - if ((_crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty()) - && (this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) - && (this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) - && (this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) - && (this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) - && (this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty())) + if ((_crc.IsNullOrWhiteSpace() || newOther._crc.IsNullOrWhiteSpace()) + && (this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) + && (this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace()) + && (this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace()) + && (this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace()) + && (this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace())) { dupefound = false; } else if ((this.Size == newOther.Size) - && ((this._crc.IsNullOrEmpty() || newOther._crc.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._crc, newOther._crc)) - && ((this._md5.IsNullOrEmpty() || newOther._md5.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._md5, newOther._md5)) - && ((this._sha1.IsNullOrEmpty() || newOther._sha1.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1)) - && ((this._sha256.IsNullOrEmpty() || newOther._sha256.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256)) - && ((this._sha384.IsNullOrEmpty() || newOther._sha384.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384)) - && ((this._sha512.IsNullOrEmpty() || newOther._sha512.IsNullOrEmpty()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512))) + && ((this._crc.IsNullOrWhiteSpace() || newOther._crc.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._crc, newOther._crc)) + && ((this._md5.IsNullOrWhiteSpace() || newOther._md5.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._md5, newOther._md5)) + && ((this._sha1.IsNullOrWhiteSpace() || newOther._sha1.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha1, newOther._sha1)) + && ((this._sha256.IsNullOrWhiteSpace() || newOther._sha256.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha256, newOther._sha256)) + && ((this._sha384.IsNullOrWhiteSpace() || newOther._sha384.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha384, newOther._sha384)) + && ((this._sha512.IsNullOrWhiteSpace() || newOther._sha512.IsNullOrWhiteSpace()) || Enumerable.SequenceEqual(this._sha512, newOther._sha512))) { dupefound = true; } diff --git a/SabreTools.Library/FileTypes/Folder.cs b/SabreTools.Library/FileTypes/Folder.cs index fbad7450..a2fbe6c7 100644 --- a/SabreTools.Library/FileTypes/Folder.cs +++ b/SabreTools.Library/FileTypes/Folder.cs @@ -102,7 +102,7 @@ namespace SabreTools.Library.FileTypes string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault(); // If we had a file, copy that over to the new name - if (!String.IsNullOrEmpty(match)) + if (!String.IsNullOrWhiteSpace(match)) { realentry = match; File.Copy(match, Path.Combine(outDir, entryName)); @@ -141,7 +141,7 @@ namespace SabreTools.Library.FileTypes string match = files.Where(s => s.EndsWith(entryName)).FirstOrDefault(); // If we had a file, copy that over to the new name - if (!String.IsNullOrEmpty(match)) + if (!String.IsNullOrWhiteSpace(match)) { Utilities.TryOpenRead(match).CopyTo(ms); realentry = match; @@ -269,7 +269,7 @@ namespace SabreTools.Library.FileTypes if (rom.Type == ItemType.Rom) { - if (date && !String.IsNullOrEmpty(((Rom)rom).Date)) + if (date && !String.IsNullOrWhiteSpace(((Rom)rom).Date)) { File.SetCreationTime(fileName, DateTime.Parse(((Rom)rom).Date)); } diff --git a/SabreTools.Library/FileTypes/TapeArchive.cs b/SabreTools.Library/FileTypes/TapeArchive.cs index 495e8dba..e6d25496 100644 --- a/SabreTools.Library/FileTypes/TapeArchive.cs +++ b/SabreTools.Library/FileTypes/TapeArchive.cs @@ -351,7 +351,7 @@ namespace SabreTools.Library.FileTypes { // Get temporary date-time if possible DateTime? usableDate = null; - if (date && !String.IsNullOrEmpty(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt)) + if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt)) { usableDate = dt; } @@ -404,7 +404,7 @@ namespace SabreTools.Library.FileTypes // Get temporary date-time if possible DateTime? usableDate = null; - if (date && !String.IsNullOrEmpty(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt)) + if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt)) { usableDate = dt; } @@ -530,7 +530,7 @@ namespace SabreTools.Library.FileTypes // Get temporary date-time if possible DateTime? usableDate = null; - if (date && !String.IsNullOrEmpty(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out DateTime dt)) + if (date && !String.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out DateTime dt)) { usableDate = dt; } @@ -590,7 +590,7 @@ namespace SabreTools.Library.FileTypes { // Get temporary date-time if possible DateTime? usableDate = null; - if (date && !String.IsNullOrEmpty(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out DateTime dt)) + if (date && !String.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out DateTime dt)) { usableDate = dt; } diff --git a/SabreTools.Library/FileTypes/TorrentZipArchive.cs b/SabreTools.Library/FileTypes/TorrentZipArchive.cs index 4b68a4f9..8aa6615f 100644 --- a/SabreTools.Library/FileTypes/TorrentZipArchive.cs +++ b/SabreTools.Library/FileTypes/TorrentZipArchive.cs @@ -81,7 +81,7 @@ namespace SabreTools.Library.FileTypes zr = zf.OpenReadStream(i, false, out Stream readStream, out ulong streamsize, out SabreTools.Library.Data.CompressionMethod cm, out uint lastMod); // Create the rest of the path, if needed - if (!String.IsNullOrEmpty(Path.GetDirectoryName(zf.Entries[i].FileName))) + if (!String.IsNullOrWhiteSpace(Path.GetDirectoryName(zf.Entries[i].FileName))) { Directory.CreateDirectory(Path.Combine(outDir, Path.GetDirectoryName(zf.Entries[i].FileName))); } @@ -465,7 +465,7 @@ namespace SabreTools.Library.FileTypes ulong istreamSize = (ulong)(inputStream.Length); DateTime dt = DateTime.Now; - if (date && !String.IsNullOrEmpty(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt)) + if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt)) { uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); zipFile.OpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, @@ -536,7 +536,7 @@ namespace SabreTools.Library.FileTypes ulong istreamSize = (ulong)(inputStream.Length); DateTime dt = DateTime.Now; - if (date && !String.IsNullOrEmpty(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt)) + if (date && !String.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt)) { uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); zipFile.OpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, @@ -686,7 +686,7 @@ namespace SabreTools.Library.FileTypes ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length); DateTime dt = DateTime.Now; - if (date && !String.IsNullOrEmpty(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt)) + if (date && !String.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt)) { uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); zipFile.OpenWriteStream(false, false, roms[index].Name.Replace('\\', '/'), istreamSize, @@ -763,7 +763,7 @@ namespace SabreTools.Library.FileTypes ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length); DateTime dt = DateTime.Now; - if (date && !String.IsNullOrEmpty(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt)) + if (date && !String.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt)) { uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt); zipFile.OpenWriteStream(false, false, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, diff --git a/SabreTools.Library/Skippers/Skipper.cs b/SabreTools.Library/Skippers/Skipper.cs index fb92196c..61c0c419 100644 --- a/SabreTools.Library/Skippers/Skipper.cs +++ b/SabreTools.Library/Skippers/Skipper.cs @@ -376,9 +376,9 @@ namespace SabreTools.Library.Skippers foreach (Skipper skipper in tempList) { // If we're searching for the skipper OR we have a match to an inputted one - if (String.IsNullOrEmpty(skipperName) - || (!String.IsNullOrEmpty(skipper.Name) && skipperName.ToLowerInvariant() == skipper.Name.ToLowerInvariant()) - || (!String.IsNullOrEmpty(skipper.Name) && skipperName.ToLowerInvariant() == skipper.SourceFile.ToLowerInvariant())) + if (String.IsNullOrWhiteSpace(skipperName) + || (!String.IsNullOrWhiteSpace(skipper.Name) && skipperName.ToLowerInvariant() == skipper.Name.ToLowerInvariant()) + || (!String.IsNullOrWhiteSpace(skipper.Name) && skipperName.ToLowerInvariant() == skipper.SourceFile.ToLowerInvariant())) { // Loop through the rules until one is found that works BinaryReader br = new BinaryReader(input); diff --git a/SabreTools.Library/Tools/Utilities.cs b/SabreTools.Library/Tools/Utilities.cs index 290081bf..15d1e700 100644 --- a/SabreTools.Library/Tools/Utilities.cs +++ b/SabreTools.Library/Tools/Utilities.cs @@ -242,7 +242,7 @@ namespace SabreTools.Library.Tools public static string CleanHashData(string hash, int padding) { // If we have a known blank hash, return blank - if (string.IsNullOrEmpty(hash) || hash == "-" || hash == "_") + if (string.IsNullOrWhiteSpace(hash) || hash == "-" || hash == "_") { return ""; } @@ -251,7 +251,7 @@ namespace SabreTools.Library.Tools hash = hash.Trim().Replace("0x", ""); // If we have a blank hash now, return blank - if (string.IsNullOrEmpty(hash)) + if (string.IsNullOrWhiteSpace(hash)) { return ""; } @@ -1862,6 +1862,32 @@ namespace SabreTools.Library.Tools .ToArray()); } + /// + /// Ensure the output directory is a proper format and can be created + /// + /// Output directory to check + /// True if the output directory should be created, false otherwise (default) + /// Full path to the proper output directory + public static string EnsureOutputDirectory(string outDir, bool create = false) + { + // If the output directory is invalid + if (string.IsNullOrWhiteSpace(outDir)) + { + outDir = Environment.CurrentDirectory; + } + + // Get the full path for the output directory + outDir = Path.GetFullPath(outDir); + + // If we're creating the output folder, do so + if (create) + { + Directory.CreateDirectory(outDir); + } + + return outDir; + } + /// /// Get a proper romba sub path /// @@ -2244,7 +2270,7 @@ namespace SabreTools.Library.Tools /// The array to test /// true if the array parameter is null or has a length of zero; otherwise, false. /// https://stackoverflow.com/questions/8560106/isnullorempty-equivalent-for-array-c-sharp - public static bool IsNullOrEmpty(this Array array) + public static bool IsNullOrWhiteSpace(this Array array) { return (array == null || array.Length == 0); } diff --git a/SabreTools/SabreTools.Inits.cs b/SabreTools/SabreTools.Inits.cs index 22ffd699..6a28a2da 100644 --- a/SabreTools/SabreTools.Inits.cs +++ b/SabreTools/SabreTools.Inits.cs @@ -125,7 +125,7 @@ namespace SabreTools }; // Clean the temp directory - tempDir = (String.IsNullOrEmpty(tempDir) ? Path.GetTempPath() : tempDir); + tempDir = (String.IsNullOrWhiteSpace(tempDir) ? Path.GetTempPath() : tempDir); // For each input directory, create a DAT foreach (string path in inputs) @@ -542,7 +542,7 @@ namespace SabreTools { // Set the special flags ForceMerging fm = ForceMerging.None; - if (!String.IsNullOrEmpty(forcemerge)) + if (!String.IsNullOrWhiteSpace(forcemerge)) { switch (forcemerge.ToLowerInvariant()) { @@ -562,7 +562,7 @@ namespace SabreTools } ForceNodump fn = ForceNodump.None; - if (!String.IsNullOrEmpty(forcend)) + if (!String.IsNullOrWhiteSpace(forcend)) { switch (forcend.ToLowerInvariant()) { @@ -585,7 +585,7 @@ namespace SabreTools } ForcePacking fp = ForcePacking.None; - if (!String.IsNullOrEmpty(forcepack)) + if (!String.IsNullOrWhiteSpace(forcepack)) { switch (forcepack.ToLowerInvariant()) { diff --git a/SabreTools/SabreTools.cs b/SabreTools/SabreTools.cs index 2ccb922b..af28f555 100644 --- a/SabreTools/SabreTools.cs +++ b/SabreTools/SabreTools.cs @@ -149,7 +149,7 @@ namespace SabreTools header = null, homepage = null, name = null, - outDir = Environment.CurrentDirectory, + outDir = null, postfix = "", prefix = "", repext = "",