Perform mass cleanup

This is cleanup based on both new .NET functionality (in 6 and 7) as well as a ton of simplifications and things that were missed that were caught due to the cleanup.
This commit is contained in:
Matt Nadareski
2023-04-19 16:39:58 -04:00
parent fd5fd79b95
commit 728b5d6b27
95 changed files with 1353 additions and 1572 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Serialization;
using SabreTools.Core;
@@ -417,119 +416,119 @@ namespace SabreTools.DatFiles
{
#region Common
if (mappings.Keys.Contains(DatHeaderField.FileName))
if (mappings.ContainsKey(DatHeaderField.FileName))
FileName = mappings[DatHeaderField.FileName];
if (mappings.Keys.Contains(DatHeaderField.Name))
if (mappings.ContainsKey(DatHeaderField.Name))
Name = mappings[DatHeaderField.Name];
if (mappings.Keys.Contains(DatHeaderField.Description))
if (mappings.ContainsKey(DatHeaderField.Description))
Description = mappings[DatHeaderField.Description];
if (mappings.Keys.Contains(DatHeaderField.RootDir))
if (mappings.ContainsKey(DatHeaderField.RootDir))
RootDir = mappings[DatHeaderField.RootDir];
if (mappings.Keys.Contains(DatHeaderField.Category))
if (mappings.ContainsKey(DatHeaderField.Category))
Category = mappings[DatHeaderField.Category];
if (mappings.Keys.Contains(DatHeaderField.Version))
if (mappings.ContainsKey(DatHeaderField.Version))
Version = mappings[DatHeaderField.Version];
if (mappings.Keys.Contains(DatHeaderField.Date))
if (mappings.ContainsKey(DatHeaderField.Date))
Date = mappings[DatHeaderField.Date];
if (mappings.Keys.Contains(DatHeaderField.Author))
if (mappings.ContainsKey(DatHeaderField.Author))
Author = mappings[DatHeaderField.Author];
if (mappings.Keys.Contains(DatHeaderField.Email))
if (mappings.ContainsKey(DatHeaderField.Email))
Email = mappings[DatHeaderField.Email];
if (mappings.Keys.Contains(DatHeaderField.Homepage))
if (mappings.ContainsKey(DatHeaderField.Homepage))
Homepage = mappings[DatHeaderField.Homepage];
if (mappings.Keys.Contains(DatHeaderField.Url))
if (mappings.ContainsKey(DatHeaderField.Url))
Url = mappings[DatHeaderField.Url];
if (mappings.Keys.Contains(DatHeaderField.Comment))
if (mappings.ContainsKey(DatHeaderField.Comment))
Comment = mappings[DatHeaderField.Comment];
if (mappings.Keys.Contains(DatHeaderField.HeaderSkipper))
if (mappings.ContainsKey(DatHeaderField.HeaderSkipper))
HeaderSkipper = mappings[DatHeaderField.HeaderSkipper];
if (mappings.Keys.Contains(DatHeaderField.Type))
if (mappings.ContainsKey(DatHeaderField.Type))
Type = mappings[DatHeaderField.Type];
if (mappings.Keys.Contains(DatHeaderField.ForceMerging))
if (mappings.ContainsKey(DatHeaderField.ForceMerging))
ForceMerging = mappings[DatHeaderField.ForceMerging].AsMergingFlag();
if (mappings.Keys.Contains(DatHeaderField.ForceNodump))
if (mappings.ContainsKey(DatHeaderField.ForceNodump))
ForceNodump = mappings[DatHeaderField.ForceNodump].AsNodumpFlag();
if (mappings.Keys.Contains(DatHeaderField.ForcePacking))
if (mappings.ContainsKey(DatHeaderField.ForcePacking))
ForcePacking = mappings[DatHeaderField.ForcePacking].AsPackingFlag();
#endregion
#region ListXML
if (mappings.Keys.Contains(DatHeaderField.Debug))
if (mappings.ContainsKey(DatHeaderField.Debug))
Debug = mappings[DatHeaderField.Debug].AsYesNo();
if (mappings.Keys.Contains(DatHeaderField.MameConfig))
if (mappings.ContainsKey(DatHeaderField.MameConfig))
MameConfig = mappings[DatHeaderField.MameConfig];
#endregion
#region Logiqx
if (mappings.Keys.Contains(DatHeaderField.NoIntroID))
if (mappings.ContainsKey(DatHeaderField.NoIntroID))
NoIntroID = mappings[DatHeaderField.NoIntroID];
if (mappings.Keys.Contains(DatHeaderField.Build))
if (mappings.ContainsKey(DatHeaderField.Build))
Build = mappings[DatHeaderField.Build];
if (mappings.Keys.Contains(DatHeaderField.RomMode))
if (mappings.ContainsKey(DatHeaderField.RomMode))
RomMode = mappings[DatHeaderField.RomMode].AsMergingFlag();
if (mappings.Keys.Contains(DatHeaderField.BiosMode))
if (mappings.ContainsKey(DatHeaderField.BiosMode))
BiosMode = mappings[DatHeaderField.BiosMode].AsMergingFlag();
if (mappings.Keys.Contains(DatHeaderField.SampleMode))
if (mappings.ContainsKey(DatHeaderField.SampleMode))
SampleMode = mappings[DatHeaderField.SampleMode].AsMergingFlag();
if (mappings.Keys.Contains(DatHeaderField.LockRomMode))
if (mappings.ContainsKey(DatHeaderField.LockRomMode))
LockRomMode = mappings[DatHeaderField.LockRomMode].AsYesNo();
if (mappings.Keys.Contains(DatHeaderField.LockBiosMode))
if (mappings.ContainsKey(DatHeaderField.LockBiosMode))
LockBiosMode = mappings[DatHeaderField.LockBiosMode].AsYesNo();
if (mappings.Keys.Contains(DatHeaderField.LockSampleMode))
if (mappings.ContainsKey(DatHeaderField.LockSampleMode))
LockSampleMode = mappings[DatHeaderField.LockSampleMode].AsYesNo();
#endregion
#region OfflineList
if (mappings.Keys.Contains(DatHeaderField.System))
if (mappings.ContainsKey(DatHeaderField.System))
System = mappings[DatHeaderField.System];
if (mappings.Keys.Contains(DatHeaderField.ScreenshotsWidth))
if (mappings.ContainsKey(DatHeaderField.ScreenshotsWidth))
ScreenshotsWidth = mappings[DatHeaderField.ScreenshotsWidth];
if (mappings.Keys.Contains(DatHeaderField.ScreenshotsHeight))
if (mappings.ContainsKey(DatHeaderField.ScreenshotsHeight))
ScreenshotsHeight = mappings[DatHeaderField.ScreenshotsHeight];
// TODO: Add DatHeader_Info*
// TDOO: Add DatHeader_CanOpen*
if (mappings.Keys.Contains(DatHeaderField.RomTitle))
if (mappings.ContainsKey(DatHeaderField.RomTitle))
RomTitle = mappings[DatHeaderField.RomTitle];
#endregion
#region RomCenter
if (mappings.Keys.Contains(DatHeaderField.RomCenterVersion))
if (mappings.ContainsKey(DatHeaderField.RomCenterVersion))
RomCenterVersion = mappings[DatHeaderField.RomCenterVersion];
#endregion
@@ -742,14 +741,14 @@ namespace SabreTools.DatFiles
public Dictionary<DatFormat, string> CreateOutFileNames(string outDir, bool overwrite = true)
{
// Create the output dictionary
Dictionary<DatFormat, string> outfileNames = new Dictionary<DatFormat, string>();
Dictionary<DatFormat, string> outfileNames = new();
// Double check the outDir for the end delim
if (!outDir.EndsWith(Path.DirectorySeparatorChar.ToString()))
outDir += Path.DirectorySeparatorChar;
// Get all used extensions
List<string> usedExtensions = new List<string>();
List<string> usedExtensions = new();
// Get the extensions from the output type

View File

@@ -162,7 +162,7 @@ namespace SabreTools.DatFiles.Formats
reader.MoveToContent();
// Create the Rom to store the info
Rom rom = new Rom
Rom rom = new()
{
Name = reader.GetAttribute("name"),
ArchiveDotOrgSource = reader.GetAttribute("source"),
@@ -187,7 +187,7 @@ namespace SabreTools.DatFiles.Formats
rom.Machine.Name = splitpath[0];
rom.Machine.Description = splitpath[0];
rom.Name = rom.Name.Substring(splitpath[0].Length + 1);
rom.Name = rom.Name[(splitpath[0].Length + 1)..];
}
// TODO: Handle SuperDAT
@@ -287,7 +287,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
{
Formatting = Formatting.Indented,
IndentChar = ' ',

View File

@@ -30,7 +30,7 @@ namespace SabreTools.DatFiles.Formats
{
// Open a file reader
Encoding enc = filename.GetEncoding();
SeparatedValueReader svr = new SeparatedValueReader(System.IO.File.OpenRead(filename), enc)
SeparatedValueReader svr = new(System.IO.File.OpenRead(filename), enc)
{
Header = true,
Quotes = false,
@@ -56,7 +56,7 @@ namespace SabreTools.DatFiles.Formats
// Get the current line, split and parse
svr.ReadNextLine();
Rom rom = new Rom
Rom rom = new()
{
Name = "-",
Size = Constants.SizeZero,
@@ -134,7 +134,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
SeparatedValueWriter svw = new SeparatedValueWriter(fs, new UTF8Encoding(false))
SeparatedValueWriter svw = new(fs, new UTF8Encoding(false))
{
Quotes = false,
Separator = ';',

View File

@@ -42,7 +42,7 @@ namespace SabreTools.DatFiles.Formats
{
// Open a file reader
Encoding enc = filename.GetEncoding();
ClrMameProReader cmpr = new ClrMameProReader(System.IO.File.OpenRead(filename), enc)
ClrMameProReader cmpr = new(System.IO.File.OpenRead(filename), enc)
{
DosCenter = false,
Quotes = Quotes,
@@ -210,7 +210,7 @@ namespace SabreTools.DatFiles.Formats
{
// Prepare all internal variables
bool containsItems = false;
Machine machine = new Machine()
Machine machine = new()
{
MachineType = (resource ? MachineType.Bios : MachineType.NULL),
};
@@ -402,7 +402,7 @@ namespace SabreTools.DatFiles.Formats
// If no items were found for this machine, add a Blank placeholder
if (!containsItems)
{
Blank blank = new Blank()
Blank blank = new()
{
Source = new Source
{
@@ -455,7 +455,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
ClrMameProWriter cmpw = new ClrMameProWriter(fs, new UTF8Encoding(false))
ClrMameProWriter cmpw = new(fs, new UTF8Encoding(false))
{
Quotes = Quotes
};

View File

@@ -32,7 +32,7 @@ namespace SabreTools.DatFiles.Formats
{
// Open a file reader
Encoding enc = filename.GetEncoding();
ClrMameProReader cmpr = new ClrMameProReader(System.IO.File.OpenRead(filename), enc)
ClrMameProReader cmpr = new(System.IO.File.OpenRead(filename), enc)
{
DosCenter = true
};
@@ -143,7 +143,7 @@ namespace SabreTools.DatFiles.Formats
{
// Prepare all internal variables
bool containsItems = false;
Machine machine = new Machine()
Machine machine = new()
{
MachineType = MachineType.NULL,
};
@@ -236,7 +236,7 @@ namespace SabreTools.DatFiles.Formats
// If no items were found for this machine, add a Blank placeholder
if (!containsItems)
{
Blank blank = new Blank()
Blank blank = new()
{
Source = new Source
{
@@ -280,7 +280,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
ClrMameProWriter cmpw = new ClrMameProWriter(fs, new UTF8Encoding(false))
ClrMameProWriter cmpw = new(fs, new UTF8Encoding(false))
{
Quotes = false
};

View File

@@ -31,7 +31,7 @@ namespace SabreTools.DatFiles.Formats
{
// Open a file reader
Encoding enc = filename.GetEncoding();
SeparatedValueReader svr = new SeparatedValueReader(System.IO.File.OpenRead(filename), enc)
SeparatedValueReader svr = new(System.IO.File.OpenRead(filename), enc)
{
Header = false,
Quotes = false,
@@ -63,7 +63,7 @@ namespace SabreTools.DatFiles.Formats
string[] fullname = svr.Line[1].Split('/');
Rom rom = new Rom
Rom rom = new()
{
Name = svr.Line[1][(fullname[0].Length + 1)..],
Size = null, // No size provided, but we don't want the size being 0
@@ -131,7 +131,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
SeparatedValueWriter svw = new SeparatedValueWriter(fs, new UTF8Encoding(false))
SeparatedValueWriter svw = new(fs, new UTF8Encoding(false))
{
Quotes = false,
Separator = '\t',

View File

@@ -34,7 +34,7 @@ namespace SabreTools.DatFiles.Formats
{
// Open a file reader
Encoding enc = filename.GetEncoding();
StreamReader sr = new StreamReader(System.IO.File.OpenRead(filename), enc);
StreamReader sr = new(System.IO.File.OpenRead(filename), enc);
while (!sr.EndOfStream)
{
@@ -66,16 +66,16 @@ namespace SabreTools.DatFiles.Formats
{
split = name.Split('/');
machine = split[0];
name = name.Substring(machine.Length + 1);
name = name[(machine.Length + 1)..];
}
else if (name.Contains('\\'))
{
split = name.Split('\\');
machine = split[0];
name = name.Substring(machine.Length + 1);
name = name[(machine.Length + 1)..];
}
Rom rom = new Rom
Rom rom = new()
{
Name = name,
Size = null,
@@ -122,7 +122,7 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override List<DatItemField> GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new List<DatItemField>();
List<DatItemField> missingFields = new();
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -259,7 +259,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
SeparatedValueWriter svw = new SeparatedValueWriter(fs, new UTF8Encoding(false))
SeparatedValueWriter svw = new(fs, new UTF8Encoding(false))
{
Quotes = false,
Separator = ' ',

View File

@@ -39,7 +39,7 @@ namespace SabreTools.DatFiles.Formats
{
// Open a file reader
Encoding enc = filename.GetEncoding();
StreamReader sr = new StreamReader(System.IO.File.OpenRead(filename), enc);
StreamReader sr = new(System.IO.File.OpenRead(filename), enc);
string gamename = string.Empty;
while (!sr.EndOfStream)
@@ -90,12 +90,12 @@ namespace SabreTools.DatFiles.Formats
line = line[romname.Length..];
// Next we separate the ROM into pieces
split = line.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
split = line.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
// Standard Disks have 2 pieces (name, sha1)
if (split.Length == 1)
{
Disk disk = new Disk()
Disk disk = new()
{
Name = romname,
SHA1 = CleanListromHashData(split[0]),
@@ -118,7 +118,7 @@ namespace SabreTools.DatFiles.Formats
// Baddump Disks have 4 pieces (name, BAD, sha1, BAD_DUMP)
else if (split.Length == 3 && line.EndsWith("BAD_DUMP"))
{
Disk disk = new Disk()
Disk disk = new()
{
Name = romname,
SHA1 = CleanListromHashData(split[1]),
@@ -142,7 +142,7 @@ namespace SabreTools.DatFiles.Formats
// Standard ROMs have 4 pieces (name, size, crc, sha1)
else if (split.Length == 3)
{
Rom rom = new Rom()
Rom rom = new()
{
Name = romname,
Size = Utilities.CleanLong(split[0]),
@@ -167,7 +167,7 @@ namespace SabreTools.DatFiles.Formats
// Nodump Disks have 5 pieces (name, NO, GOOD, DUMP, KNOWN)
else if (split.Length == 4 && line.EndsWith("NO GOOD DUMP KNOWN"))
{
Disk disk = new Disk()
Disk disk = new()
{
Name = romname,
ItemStatus = ItemStatus.Nodump,
@@ -190,7 +190,7 @@ namespace SabreTools.DatFiles.Formats
// Baddump ROMs have 6 pieces (name, size, BAD, crc, sha1, BAD_DUMP)
else if (split.Length == 5 && line.EndsWith("BAD_DUMP"))
{
Rom rom = new Rom()
Rom rom = new()
{
Name = romname,
Size = Utilities.CleanLong(split[0]),
@@ -216,7 +216,7 @@ namespace SabreTools.DatFiles.Formats
// Nodump ROMs have 6 pieces (name, size, NO, GOOD, DUMP, KNOWN)
else if (split.Length == 5 && line.EndsWith("NO GOOD DUMP KNOWN"))
{
Rom rom = new Rom()
Rom rom = new()
{
Name = romname,
Size = Utilities.CleanLong(split[0]),
@@ -261,7 +261,7 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override List<DatItemField> GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new List<DatItemField>();
List<DatItemField> missingFields = new();
// Check item name
if (string.IsNullOrWhiteSpace(datItem.GetName()))
@@ -287,7 +287,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
StreamWriter sw = new(fs, new UTF8Encoding(false));
// Write out each of the machines and roms
string lastgame = null;

View File

@@ -295,7 +295,7 @@ namespace SabreTools.DatFiles.Formats
if (reader.GetAttribute("ismechanical").AsYesNo() == true)
machineType |= MachineType.Mechanical;
Machine machine = new Machine
Machine machine = new()
{
Name = reader.GetAttribute("name"),
Description = reader.GetAttribute("name"),
@@ -309,7 +309,7 @@ namespace SabreTools.DatFiles.Formats
};
// Get list for new DatItems
List<DatItem> datItems = new List<DatItem>();
List<DatItem> datItems = new();
while (!reader.EOF)
{
@@ -776,7 +776,7 @@ namespace SabreTools.DatFiles.Formats
// If no items were found for this machine, add a Blank placeholder
else
{
Blank blank = new Blank()
Blank blank = new()
{
Source = new Source
{
@@ -1370,7 +1370,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
{
Formatting = Formatting.Indented,
IndentChar = '\t',

View File

@@ -213,7 +213,7 @@ namespace SabreTools.DatFiles.Formats
ValidationType = ValidationType.None,
});
List<string> dirs = new List<string>();
List<string> dirs = new();
// If we got a null reader, just return
if (xtr == null)
@@ -474,8 +474,8 @@ namespace SabreTools.DatFiles.Formats
if (reader.GetAttribute("ismechanical").AsYesNo() == true) // Listxml-specific, used by older DATs
machineType |= MachineType.Mechanical;
string dirsString = (dirs != null && dirs.Count() > 0 ? string.Join("/", dirs) + "/" : string.Empty);
Machine machine = new Machine
string dirsString = (dirs != null && dirs.Count > 0 ? string.Join("/", dirs) + "/" : string.Empty);
Machine machine = new()
{
Name = dirsString + reader.GetAttribute("name"),
Description = dirsString + reader.GetAttribute("name"),
@@ -727,7 +727,7 @@ namespace SabreTools.DatFiles.Formats
// If no items were found for this machine, add a Blank placeholder
if (!containsItems)
{
Blank blank = new Blank()
Blank blank = new()
{
Source = new Source
{
@@ -869,7 +869,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
{
Formatting = Formatting.Indented,
IndentChar = '\t',

View File

@@ -50,7 +50,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
StreamWriter sw = new(fs, new UTF8Encoding(false));
// Write out each of the machines and roms
string lastgame = null;

View File

@@ -470,8 +470,8 @@ namespace SabreTools.DatFiles.Formats
// Prepare all internal variables
string releaseNumber = string.Empty, duplicateid;
long? size = null;
List<Rom> datItems = new List<Rom>();
Machine machine = new Machine();
List<Rom> datItems = new();
Machine machine = new();
// If there's no subtree to the configuration, skip it
if (reader == null)
@@ -683,7 +683,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
{
Formatting = Formatting.Indented,
IndentChar = '\t',

View File

@@ -125,7 +125,7 @@ namespace SabreTools.DatFiles.Formats
bool containsItems = false;
// Create a new machine
Machine machine = new Machine();
Machine machine = new();
while (!reader.EOF)
{
@@ -180,7 +180,7 @@ namespace SabreTools.DatFiles.Formats
// If no items were found for this machine, add a Blank placeholder
if (!containsItems)
{
Blank blank = new Blank()
Blank blank = new()
{
Source = new Source
{
@@ -215,7 +215,7 @@ namespace SabreTools.DatFiles.Formats
string filename,
int indexId)
{
List<DatItem> items = new List<DatItem>();
List<DatItem> items = new();
Original original = null;
while (!reader.EOF)
@@ -556,7 +556,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
{
Formatting = Formatting.Indented,
IndentChar = '\t',

View File

@@ -29,7 +29,7 @@ namespace SabreTools.DatFiles.Formats
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all intenral variables
IniReader ir = new IniReader(filename) { ValidateRows = false };
IniReader ir = new(filename) { ValidateRows = false };
// If we got a null reader, just return
if (ir == null)
@@ -326,7 +326,7 @@ namespace SabreTools.DatFiles.Formats
9 - merge name
*/
string[] rominfo = line.Split('¬');
Rom rom = new Rom
Rom rom = new()
{
Name = rominfo[5],
Size = Utilities.CleanLong(rominfo[7]),
@@ -385,14 +385,14 @@ namespace SabreTools.DatFiles.Formats
return false;
}
IniWriter iw = new IniWriter(fs, new UTF8Encoding(false));
IniWriter iw = new(fs, new UTF8Encoding(false));
// Write out the header
WriteHeader(iw);
// Write out each of the machines and roms
string lastgame = null;
List<string> splitpath = new List<string>();
List<string> splitpath = new();
// Use a sorted list of games to output
foreach (string key in Items.SortedKeys)

View File

@@ -31,8 +31,8 @@ namespace SabreTools.DatFiles.Formats
public override void ParseFile(string filename, int indexId, bool keep, bool statsOnly = false, bool throwOnError = false)
{
// Prepare all internal variables
StreamReader sr = new StreamReader(System.IO.File.OpenRead(filename), new UTF8Encoding(false));
JsonTextReader jtr = new JsonTextReader(sr);
StreamReader sr = new(System.IO.File.OpenRead(filename), new UTF8Encoding(false));
JsonTextReader jtr = new(sr);
// If we got a null reader, just return
if (jtr == null)
@@ -91,7 +91,7 @@ namespace SabreTools.DatFiles.Formats
// Read in the header and apply any new fields
jtr.Read();
JsonSerializer js = new JsonSerializer();
JsonSerializer js = new();
DatHeader header = js.Deserialize<DatHeader>(jtr);
Header.ConditionalCopy(header);
}
@@ -111,7 +111,7 @@ namespace SabreTools.DatFiles.Formats
// Read in the machine array
jtr.Read();
JsonSerializer js = new JsonSerializer();
JsonSerializer js = new();
JArray machineArray = js.Deserialize<JArray>(jtr);
// Loop through each machine object and process
@@ -355,8 +355,8 @@ namespace SabreTools.DatFiles.Formats
return false;
}
StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
JsonTextWriter jtw = new JsonTextWriter(sw)
StreamWriter sw = new(fs, new UTF8Encoding(false));
JsonTextWriter jtw = new(sw)
{
Formatting = Formatting.Indented,
IndentChar = '\t',
@@ -431,7 +431,7 @@ namespace SabreTools.DatFiles.Formats
// Write the DatHeader
jtw.WritePropertyName("header");
JsonSerializer js = new JsonSerializer() { Formatting = Formatting.Indented };
JsonSerializer js = new() { Formatting = Formatting.Indented };
js.Serialize(jtw, Header);
jtw.WritePropertyName("machines");
@@ -455,7 +455,7 @@ namespace SabreTools.DatFiles.Formats
// Write the Machine
jtw.WritePropertyName("machine");
JsonSerializer js = new JsonSerializer() { Formatting = Formatting.Indented };
JsonSerializer js = new() { Formatting = Formatting.Indented };
js.Serialize(jtw, datItem.Machine);
jtw.WritePropertyName("items");
@@ -494,7 +494,7 @@ namespace SabreTools.DatFiles.Formats
// Write the DatItem
jtw.WritePropertyName("datitem");
JsonSerializer js = new JsonSerializer() { ContractResolver = new BaseFirstContractResolver(), Formatting = Formatting.Indented };
JsonSerializer js = new() { ContractResolver = new BaseFirstContractResolver(), Formatting = Formatting.Indented };
js.Serialize(jtw, datItem);
// End item

View File

@@ -57,7 +57,7 @@ namespace SabreTools.DatFiles.Formats
switch (xtr.Name)
{
case "header":
XmlSerializer xs = new XmlSerializer(typeof(DatHeader));
XmlSerializer xs = new(typeof(DatHeader));
DatHeader header = xs.Deserialize(xtr.ReadSubtree()) as DatHeader;
Header.ConditionalCopy(header);
xtr.Skip();
@@ -116,7 +116,7 @@ namespace SabreTools.DatFiles.Formats
switch (xtr.Name)
{
case "machine":
XmlSerializer xs = new XmlSerializer(typeof(Machine));
XmlSerializer xs = new(typeof(Machine));
machine = xs.Deserialize(xtr.ReadSubtree()) as Machine;
xtr.Skip();
break;
@@ -162,7 +162,7 @@ namespace SabreTools.DatFiles.Formats
switch (xtr.Name)
{
case "datitem":
XmlSerializer xs = new XmlSerializer(typeof(DatItem));
XmlSerializer xs = new(typeof(DatItem));
DatItem item = xs.Deserialize(xtr.ReadSubtree()) as DatItem;
item.CopyMachineInformation(machine);
item.Source = new Source { Name = filename, Index = indexId };
@@ -191,7 +191,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
{
Formatting = Formatting.Indented,
IndentChar = '\t',
@@ -266,8 +266,8 @@ namespace SabreTools.DatFiles.Formats
xtw.WriteStartElement("datafile");
XmlSerializer xs = new XmlSerializer(typeof(DatHeader));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
XmlSerializer xs = new(typeof(DatHeader));
XmlSerializerNamespaces ns = new();
ns.Add("", "");
xs.Serialize(xtw, Header, ns);
@@ -288,8 +288,8 @@ namespace SabreTools.DatFiles.Formats
// Write the machine
xtw.WriteStartElement("directory");
XmlSerializer xs = new XmlSerializer(typeof(Machine));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
XmlSerializer xs = new(typeof(Machine));
XmlSerializerNamespaces ns = new();
ns.Add("", "");
xs.Serialize(xtw, datItem.Machine, ns);
@@ -324,8 +324,8 @@ namespace SabreTools.DatFiles.Formats
ProcessItemName(datItem, true);
// Write the DatItem
XmlSerializer xs = new XmlSerializer(typeof(DatItem));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
XmlSerializer xs = new(typeof(DatItem));
XmlSerializerNamespaces ns = new();
ns.Add("", "");
xs.Serialize(xtw, datItem, ns);

View File

@@ -36,7 +36,7 @@ namespace SabreTools.DatFiles.Formats
{
// Open a file reader
Encoding enc = filename.GetEncoding();
SeparatedValueReader svr = new SeparatedValueReader(System.IO.File.OpenRead(filename), enc)
SeparatedValueReader svr = new(System.IO.File.OpenRead(filename), enc)
{
Header = true,
Quotes = true,
@@ -60,11 +60,11 @@ namespace SabreTools.DatFiles.Formats
svr.ReadNextLine();
// Create mapping dictionaries
Setter setter = new Setter();
Setter setter = new();
setter.PopulateSettersFromList(svr.HeaderValues, svr.Line);
// Set DatHeader fields
DatHeader datHeader = new DatHeader();
DatHeader datHeader = new();
setter.SetFields(datHeader);
Header.ConditionalCopy(datHeader);
@@ -117,7 +117,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
SeparatedValueWriter svw = new SeparatedValueWriter(fs, new UTF8Encoding(false))
SeparatedValueWriter svw = new(fs, new UTF8Encoding(false))
{
Quotes = true,
Separator = this._delim,

View File

@@ -176,7 +176,7 @@ namespace SabreTools.DatFiles.Formats
bool containsItems = false;
// Create a new machine
Machine machine = new Machine
Machine machine = new()
{
Name = reader.GetAttribute("name"),
CloneOf = reader.GetAttribute("cloneof"),
@@ -262,7 +262,7 @@ namespace SabreTools.DatFiles.Formats
// If no items were found for this machine, add a Blank placeholder
if (!containsItems)
{
Blank blank = new Blank()
Blank blank = new()
{
Source = new Source
{
@@ -295,7 +295,7 @@ namespace SabreTools.DatFiles.Formats
// Get lists ready
part.Features = new List<PartFeature>();
List<DatItem> items = new List<DatItem>();
List<DatItem> items = new();
while (!reader.EOF)
{
@@ -434,7 +434,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="dataArea">DataArea representing the enclosing area</param>
private List<DatItem> ReadDataArea(XmlReader reader, DataArea dataArea)
{
List<DatItem> items = new List<DatItem>();
List<DatItem> items = new();
while (!reader.EOF)
{
@@ -483,7 +483,7 @@ namespace SabreTools.DatFiles.Formats
/// <param name="diskArea">DiskArea representing the enclosing area</param>
private List<DatItem> ReadDiskArea(XmlReader reader, DiskArea diskArea)
{
List<DatItem> items = new List<DatItem>();
List<DatItem> items = new();
while (!reader.EOF)
{
@@ -586,7 +586,7 @@ namespace SabreTools.DatFiles.Formats
/// <inheritdoc/>
protected override List<DatItemField> GetMissingRequiredFields(DatItem datItem)
{
List<DatItemField> missingFields = new List<DatItemField>();
List<DatItemField> missingFields = new();
switch (datItem.ItemType)
{
@@ -705,7 +705,7 @@ namespace SabreTools.DatFiles.Formats
return false;
}
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
{
Formatting = Formatting.Indented,
IndentChar = '\t',

View File

@@ -44,7 +44,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Lock for statistics calculation
/// </summary>
private readonly object statsLock = new object();
private readonly object statsLock = new();
/// <summary>
/// Logging object
@@ -981,7 +981,7 @@ namespace SabreTools.DatFiles
public void BucketBy(ItemKey bucketBy, DedupeType dedupeType, bool lower = true, bool norename = true)
{
// If we have a situation where there's no dictionary or no keys at all, we skip
if (items == null || items.Count == 0)
if (items == null || items.IsEmpty)
return;
// If the sorted type isn't the same, we want to sort the dictionary accordingly
@@ -1084,7 +1084,7 @@ namespace SabreTools.DatFiles
items.TryRemove(key, out _);
// If there are no non-blank items, remove
else if (items[key].Count(i => i != null && i.ItemType != ItemType.Blank) == 0)
else if (!items[key].Any(i => i != null && i.ItemType != ItemType.Blank))
items.TryRemove(key, out _);
}
}
@@ -1113,7 +1113,7 @@ namespace SabreTools.DatFiles
/// <returns>List of matched DatItem objects</returns>
public ConcurrentList<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
{
ConcurrentList<DatItem> output = new ConcurrentList<DatItem>();
ConcurrentList<DatItem> output = new();
// Check for an empty rom list first
if (TotalCount == 0)
@@ -1128,7 +1128,7 @@ namespace SabreTools.DatFiles
// Try to find duplicates
ConcurrentList<DatItem> roms = this[key];
ConcurrentList<DatItem> left = new ConcurrentList<DatItem>();
ConcurrentList<DatItem> left = new();
for (int i = 0; i < roms.Count; i++)
{
DatItem other = roms[i];

View File

@@ -47,7 +47,7 @@ namespace SabreTools.DatFiles
/// <summary>
/// Lock for statistics calculation
/// </summary>
private readonly object statsLock = new object();
private readonly object statsLock = new();
/// <summary>
/// Logging object
@@ -100,10 +100,10 @@ namespace SabreTools.DatFiles
dbc.Open();
string query = $"SELECT key FROM keys";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteCommand slc = new(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader();
List<string> keys = new List<string>();
List<string> keys = GetKeys();
if (sldr.HasRows)
{
while (sldr.Read())
@@ -121,6 +121,11 @@ namespace SabreTools.DatFiles
}
}
private static List<string> GetKeys()
{
return new List<string>();
}
/// <summary>
/// Get the keys in sorted order from the file dictionary
/// </summary>
@@ -457,10 +462,10 @@ namespace SabreTools.DatFiles
dbc.Open();
string query = $"SELECT item FROM groups WHERE key='{key}'";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteCommand slc = new(query, dbc);
SqliteDataReader sldr = slc.ExecuteReader();
ConcurrentList<DatItem> items = new ConcurrentList<DatItem>();
ConcurrentList<DatItem> items = new();
if (sldr.HasRows)
{
while (sldr.Read())
@@ -495,7 +500,7 @@ namespace SabreTools.DatFiles
// Now remove the value
string itemString = JsonConvert.SerializeObject(value);
string query = $"DELETE FROM groups WHERE key='{key}'";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteCommand slc = new(query, dbc);
slc.ExecuteNonQuery();
// Dispose of database objects
@@ -536,7 +541,7 @@ namespace SabreTools.DatFiles
// Now add the value
string itemString = JsonConvert.SerializeObject(value);
string query = $"INSERT INTO groups (key, item) VALUES ('{key}', '{itemString}')";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteCommand slc = new(query, dbc);
slc.ExecuteNonQuery();
// Dispose of database objects
@@ -836,7 +841,7 @@ namespace SabreTools.DatFiles
dbc.Open();
string query = $"INSERT INTO keys (key) VALUES ('{key}')";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteCommand slc = new(query, dbc);
slc.ExecuteNonQuery();
// Dispose of database objects
@@ -917,7 +922,7 @@ namespace SabreTools.DatFiles
// Now remove the value
string itemString = JsonConvert.SerializeObject(value);
string query = $"DELETE FROM groups WHERE key='{key}' AND item='{itemString}'";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteCommand slc = new(query, dbc);
slc.ExecuteNonQuery();
// Dispose of database objects
@@ -1142,7 +1147,7 @@ CREATE TABLE IF NOT EXISTS keys (
'key' TEXT NOT NULL
PRIMARY KEY (key)
)";
SqliteCommand slc = new SqliteCommand(query, dbc);
SqliteCommand slc = new(query, dbc);
slc.ExecuteNonQuery();
query = @"
@@ -1275,7 +1280,7 @@ CREATE TABLE IF NOT EXISTS groups (
this[key] = null;
// If there are no non-blank items, remove
else if (this[key].Count(i => i != null && i.ItemType != ItemType.Blank) == 0)
else if (!this[key].Any(i => i != null && i.ItemType != ItemType.Blank))
this[key] = null;
}
}
@@ -1304,7 +1309,7 @@ CREATE TABLE IF NOT EXISTS groups (
/// <returns>List of matched DatItem objects</returns>
public ConcurrentList<DatItem> GetDuplicates(DatItem datItem, bool sorted = false)
{
ConcurrentList<DatItem> output = new ConcurrentList<DatItem>();
ConcurrentList<DatItem> output = new();
// Check for an empty rom list first
if (TotalCount == 0)
@@ -1319,7 +1324,7 @@ CREATE TABLE IF NOT EXISTS groups (
// Try to find duplicates
ConcurrentList<DatItem> roms = this[key];
ConcurrentList<DatItem> left = new ConcurrentList<DatItem>();
ConcurrentList<DatItem> left = new();
for (int i = 0; i < roms.Count; i++)
{
DatItem other = roms[i];

View File

File diff suppressed because it is too large Load Diff