Add nullable context to SabreTools.Core

This commit is contained in:
Matt Nadareski
2023-08-12 00:55:41 -04:00
parent 12ee5895f9
commit ce6a64d4cd
18 changed files with 362 additions and 315 deletions

View File

@@ -397,7 +397,7 @@ namespace SabreTools.DatFiles
Header.UseRomName = true;
// Get the name to update
string name = (Header.UseRomName ? item.GetName() : item.Machine.Name) ?? string.Empty;
string? name = (Header.UseRomName ? item.GetName() : item.Machine.Name) ?? string.Empty;
// Create the proper Prefix and Postfix
string pre = CreatePrefixPostfix(item, true);
@@ -411,7 +411,7 @@ namespace SabreTools.DatFiles
// We can only write out if there's a SHA-1
if (!string.IsNullOrWhiteSpace(disk.SHA1))
{
name = Utilities.GetDepotPath(disk.SHA1, Header.OutputDepot.Depth).Replace('\\', '/');
name = Utilities.GetDepotPath(disk.SHA1, Header.OutputDepot.Depth)?.Replace('\\', '/');
item.SetName($"{pre}{name}{post}");
}
}
@@ -420,7 +420,7 @@ namespace SabreTools.DatFiles
// We can only write out if there's a SHA-1
if (!string.IsNullOrWhiteSpace(media.SHA1))
{
name = Utilities.GetDepotPath(media.SHA1, Header.OutputDepot.Depth).Replace('\\', '/');
name = Utilities.GetDepotPath(media.SHA1, Header.OutputDepot.Depth)?.Replace('\\', '/');
item.SetName($"{pre}{name}{post}");
}
}
@@ -429,7 +429,7 @@ namespace SabreTools.DatFiles
// We can only write out if there's a SHA-1
if (!string.IsNullOrWhiteSpace(rom.SHA1))
{
name = Utilities.GetDepotPath(rom.SHA1, Header.OutputDepot.Depth).Replace('\\', '/');
name = Utilities.GetDepotPath(rom.SHA1, Header.OutputDepot.Depth)?.Replace('\\', '/');
item.SetName($"{pre}{name}{post}");
}
}

View File

@@ -60,11 +60,11 @@ namespace SabreTools.DatFiles.Formats
Header.HeaderSkipper ??= cmp.Header;
Header.Type ??= cmp.Type;
if (Header.ForceMerging == MergingFlag.None)
Header.ForceMerging = cmp.ForceMerging.AsMergingFlag();
Header.ForceMerging = cmp.ForceMerging?.AsMergingFlag() ?? MergingFlag.None;
if (Header.ForcePacking == PackingFlag.None)
Header.ForcePacking = cmp.ForceZipping.AsPackingFlag();
Header.ForcePacking = cmp.ForceZipping?.AsPackingFlag() ?? PackingFlag.None;
if (Header.ForcePacking == PackingFlag.None)
Header.ForcePacking = cmp.ForcePacking.AsPackingFlag();
Header.ForcePacking = cmp.ForcePacking?.AsPackingFlag() ?? PackingFlag.None;
// Handle implied SuperDAT
if (cmp.Name?.Contains(" - SuperDAT") == true && keep)

View File

@@ -1040,7 +1040,9 @@ namespace SabreTools.DatFiles
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
{
// Get the possibly unsorted list
ConcurrentList<DatItem> sortedlist = this[key].ToConcurrentList();
ConcurrentList<DatItem>? sortedlist = this[key]?.ToConcurrentList();
if (sortedlist == null)
return;
// Sort the list of items to be consistent
DatItem.Sort(ref sortedlist, false);

View File

@@ -1240,7 +1240,9 @@ CREATE TABLE IF NOT EXISTS groups (
Parallel.ForEach(keys, Globals.ParallelOptions, key =>
{
// Get the possibly unsorted list
ConcurrentList<DatItem> sortedlist = this[key].ToConcurrentList();
ConcurrentList<DatItem>? sortedlist = this[key]?.ToConcurrentList();
if (sortedlist == null)
return;
// Sort the list of items to be consistent
DatItem.Sort(ref sortedlist, false);