mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add nullable context to SabreTools.DatItems
This change also starts migrating the internals of the DatItem formats to the new internal models. Right now, it's basically just acting like a wrapper around those models.
This commit is contained in:
@@ -113,7 +113,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
SHA1 = file.SHA1,
|
||||
//FileCount = file.FileCount, // TODO: Add to internal model
|
||||
ArchiveDotOrgFormat = file.Format,
|
||||
//Original = file.Original, // TODO: Add to internal model
|
||||
OriginalFilename = file.Original,
|
||||
Summation = file.Summation,
|
||||
//MatrixNumber = file.MatrixNumber, // TODO: Add to internal model
|
||||
//CollectionCatalogNumber = file.CollectionCatalogNumber, // TODO: Add to internal model
|
||||
|
||||
@@ -121,23 +121,23 @@ namespace SabreTools.DatFiles.Formats
|
||||
{
|
||||
var row = new Models.AttractMode.Row
|
||||
{
|
||||
Name = rom.Machine.Name,
|
||||
Title = rom.Machine.Description,
|
||||
Name = rom.Machine?.Name,
|
||||
Title = rom.Machine?.Description,
|
||||
Emulator = Header.FileName,
|
||||
CloneOf = rom.Machine.CloneOf,
|
||||
Year = rom.Machine.Year,
|
||||
Manufacturer = rom.Machine.Manufacturer,
|
||||
Category = rom.Machine.Category,
|
||||
Players = rom.Machine.Players,
|
||||
Rotation = rom.Machine.Rotation,
|
||||
Control = rom.Machine.Control,
|
||||
Status = rom.Machine.Status,
|
||||
DisplayCount = rom.Machine.DisplayCount,
|
||||
DisplayType = rom.Machine.DisplayType,
|
||||
CloneOf = rom.Machine?.CloneOf,
|
||||
Year = rom.Machine?.Year,
|
||||
Manufacturer = rom.Machine?.Manufacturer,
|
||||
Category = rom.Machine?.Category,
|
||||
Players = rom.Machine?.Players,
|
||||
Rotation = rom.Machine?.Rotation,
|
||||
Control = rom.Machine?.Control,
|
||||
Status = rom.Machine?.Status,
|
||||
DisplayCount = rom.Machine?.DisplayCount,
|
||||
DisplayType = rom.Machine?.DisplayType,
|
||||
AltRomname = rom.AltName,
|
||||
AltTitle = rom.AltTitle,
|
||||
Extra = rom.Machine.Comment,
|
||||
Buttons = rom.Machine.Buttons,
|
||||
Extra = rom.Machine?.Comment,
|
||||
Buttons = rom.Machine?.Buttons,
|
||||
// TODO: Add extended fields
|
||||
};
|
||||
return row;
|
||||
|
||||
@@ -571,7 +571,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
var item = new DipSwitch
|
||||
{
|
||||
Name = dipswitch.Name,
|
||||
Values = new List<Setting>(),
|
||||
Values = new List<DipValue>(),
|
||||
|
||||
Source = new Source
|
||||
{
|
||||
@@ -582,13 +582,13 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
foreach (string entry in dipswitch.Entry ?? Array.Empty<string>())
|
||||
{
|
||||
var setting = new Setting
|
||||
var dipValue = new DipValue
|
||||
{
|
||||
Name = dipswitch.Name,
|
||||
Value = entry,
|
||||
Default = entry == dipswitch.Default,
|
||||
};
|
||||
item.Values.Add(setting);
|
||||
item.Values.Add(dipValue);
|
||||
}
|
||||
|
||||
item.CopyMachineInformation(machine);
|
||||
|
||||
@@ -232,14 +232,14 @@ namespace SabreTools.DatFiles.Formats
|
||||
// We normalize to all "game"
|
||||
var game = new Models.ClrMamePro.Game
|
||||
{
|
||||
Name = machine.Name,
|
||||
Description = machine.Description,
|
||||
Year = machine.Year,
|
||||
Manufacturer = machine.Manufacturer,
|
||||
Category = machine.Category,
|
||||
CloneOf = machine.CloneOf,
|
||||
RomOf = machine.RomOf,
|
||||
SampleOf = machine.SampleOf,
|
||||
Name = machine?.Name,
|
||||
Description = machine?.Description,
|
||||
Year = machine?.Year,
|
||||
Manufacturer = machine?.Manufacturer,
|
||||
Category = machine?.Category,
|
||||
CloneOf = machine?.CloneOf,
|
||||
RomOf = machine?.RomOf,
|
||||
SampleOf = machine?.SampleOf,
|
||||
};
|
||||
|
||||
// Create holders for all item types
|
||||
@@ -535,7 +535,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
};
|
||||
|
||||
if (item.ControlsSpecified)
|
||||
input.Buttons = item.Controls[0].Buttons?.ToString();
|
||||
input.Buttons = item.Controls![0].Buttons?.ToString();
|
||||
|
||||
return input;
|
||||
}
|
||||
@@ -553,9 +553,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
if (item.ValuesSpecified)
|
||||
{
|
||||
var entries = new List<string>();
|
||||
foreach (var setting in item.Values)
|
||||
foreach (var setting in item.Values!)
|
||||
{
|
||||
entries.Add(setting.Value);
|
||||
entries.Add(setting.Value!);
|
||||
if (setting.Default == true)
|
||||
dipswitch.Default = setting.Value;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
// We re-add the missing parts of the game name
|
||||
var game = new Models.DosCenter.Game
|
||||
{
|
||||
Name = $"\"{machine.Name}.zip\""
|
||||
Name = $"\"{machine?.Name ?? string.Empty}.zip\""
|
||||
};
|
||||
|
||||
// Create holders for all item types
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
var row = new Models.EverdriveSMDB.Row
|
||||
{
|
||||
SHA256 = rom.SHA256,
|
||||
Name = $"{rom.Machine.Name}/{rom.Name}",
|
||||
Name = $"{rom.Machine?.Name ?? string.Empty}/{rom.Name}",
|
||||
SHA1 = rom.SHA1,
|
||||
MD5 = rom.MD5,
|
||||
CRC32 = rom.CRC,
|
||||
|
||||
@@ -116,8 +116,8 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
var set = new Models.Listrom.Set
|
||||
{
|
||||
Driver = !items[0].Machine.MachineType.HasFlag(MachineType.Device) ? items[0].Machine.Name : null,
|
||||
Device = items[0].Machine.MachineType.HasFlag(MachineType.Device) ? items[0].Machine.Name : null,
|
||||
Driver = items[0]!.Machine!.MachineType.HasFlag(MachineType.Device) ? items[0]!.Machine!.Name : null,
|
||||
Device = items[0]!.Machine!.MachineType.HasFlag(MachineType.Device) ? items[0]!.Machine!.Name : null,
|
||||
};
|
||||
|
||||
// Loop through and convert the items to respective lists
|
||||
|
||||
@@ -615,10 +615,10 @@ namespace SabreTools.DatFiles.Formats
|
||||
item.Conditions = new List<Condition> { condition };
|
||||
}
|
||||
|
||||
var locations = new List<Location>();
|
||||
var locations = new List<DipLocation>();
|
||||
foreach (var diplocation in dipswitch.DipLocation ?? Array.Empty<Models.Listxml.DipLocation>())
|
||||
{
|
||||
var locationItem = new Location
|
||||
var locationItem = new DipLocation
|
||||
{
|
||||
Name = diplocation.Name,
|
||||
Number = NumberHelper.ConvertToInt64(diplocation.Number),
|
||||
@@ -630,10 +630,10 @@ namespace SabreTools.DatFiles.Formats
|
||||
if (locations.Any())
|
||||
item.Locations = locations;
|
||||
|
||||
var settings = new List<Setting>();
|
||||
var settings = new List<DipValue>();
|
||||
foreach (var dipvalue in dipswitch.DipValue ?? Array.Empty<Models.Listxml.DipValue>())
|
||||
{
|
||||
var settingItem = new Setting
|
||||
var dipValueItem = new DipValue
|
||||
{
|
||||
Name = dipvalue.Name,
|
||||
Value = dipvalue.Value,
|
||||
@@ -649,10 +649,10 @@ namespace SabreTools.DatFiles.Formats
|
||||
Relation = dipvalue.Condition.Relation.AsRelation(),
|
||||
Value = dipvalue.Condition.Value,
|
||||
};
|
||||
settingItem.Conditions = new List<Condition> { condition };
|
||||
dipValueItem.Conditions = new List<Condition> { condition };
|
||||
}
|
||||
|
||||
settings.Add(settingItem);
|
||||
settings.Add(dipValueItem);
|
||||
}
|
||||
|
||||
if (settings.Any())
|
||||
@@ -696,20 +696,20 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
if (configuration.Condition != null)
|
||||
{
|
||||
var condition = new Condition
|
||||
var condition = new DatItems.Formats.Condition
|
||||
{
|
||||
Tag = configuration.Condition.Tag,
|
||||
Mask = configuration.Condition.Mask,
|
||||
Relation = configuration.Condition.Relation.AsRelation(),
|
||||
Value = configuration.Condition.Value,
|
||||
};
|
||||
item.Conditions = new List<Condition> { condition };
|
||||
item.Conditions = new List<DatItems.Formats.Condition> { condition };
|
||||
}
|
||||
|
||||
var locations = new List<Location>();
|
||||
var locations = new List<ConfLocation>();
|
||||
foreach (var confLocation in configuration.ConfLocation ?? Array.Empty<Models.Listxml.ConfLocation>())
|
||||
{
|
||||
var locationItem = new Location
|
||||
var locationItem = new ConfLocation
|
||||
{
|
||||
Name = confLocation.Name,
|
||||
Number = NumberHelper.ConvertToInt64(confLocation.Number),
|
||||
@@ -721,10 +721,10 @@ namespace SabreTools.DatFiles.Formats
|
||||
if (locations.Any())
|
||||
item.Locations = locations;
|
||||
|
||||
var settings = new List<Setting>();
|
||||
var settings = new List<ConfSetting>();
|
||||
foreach (var dipvalue in configuration.ConfSetting ?? Array.Empty<Models.Listxml.ConfSetting>())
|
||||
{
|
||||
var settingItem = new Setting
|
||||
var settingItem = new ConfSetting
|
||||
{
|
||||
Name = dipvalue.Name,
|
||||
Value = dipvalue.Value,
|
||||
@@ -1094,6 +1094,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
{
|
||||
Name = ramoption.Name,
|
||||
Default = ramoption.Default.AsYesNo(),
|
||||
Content = ramoption.Content,
|
||||
|
||||
Source = new Source
|
||||
{
|
||||
|
||||
@@ -244,7 +244,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
// Get the first item for game information
|
||||
var machine = items[0].Machine;
|
||||
var game = CreateGame(machine);
|
||||
var game = CreateGame(machine!);
|
||||
|
||||
// Create holders for all item types
|
||||
var biosSets = new List<Models.Listxml.BiosSet>();
|
||||
@@ -604,19 +604,19 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
if (item.ConditionsSpecified)
|
||||
{
|
||||
var conditionItem = item.Conditions[0];
|
||||
var conditionItem = item.Conditions?.FirstOrDefault();
|
||||
var condition = new Models.Listxml.Condition
|
||||
{
|
||||
Tag = conditionItem.Tag,
|
||||
Mask = conditionItem.Mask,
|
||||
Relation = conditionItem.Relation.FromRelation(),
|
||||
Value = conditionItem.Value,
|
||||
Tag = conditionItem?.Tag,
|
||||
Mask = conditionItem?.Mask,
|
||||
Relation = conditionItem?.Relation.FromRelation(),
|
||||
Value = conditionItem?.Value,
|
||||
};
|
||||
dipswitch.Condition = condition;
|
||||
}
|
||||
|
||||
var diplocations = new List<Models.Listxml.DipLocation>();
|
||||
foreach (var locationItem in item.Locations ?? new List<Location>())
|
||||
foreach (var locationItem in item.Locations ?? new List<DipLocation>())
|
||||
{
|
||||
var control = CreateDipLocation(locationItem);
|
||||
diplocations.Add(control);
|
||||
@@ -626,9 +626,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
dipswitch.DipLocation = diplocations.ToArray();
|
||||
|
||||
var dipvalues = new List<Models.Listxml.DipValue>();
|
||||
foreach (var settingItem in item.Values ?? new List<Setting>())
|
||||
foreach (var dipValueItem in item.Values ?? new List<DipValue>())
|
||||
{
|
||||
var dipvalue = CreateDipValue(settingItem);
|
||||
var dipvalue = CreateDipValue(dipValueItem);
|
||||
dipvalues.Add(dipvalue);
|
||||
}
|
||||
|
||||
@@ -639,9 +639,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a DipLocation from the current Location DatItem
|
||||
/// Create a DipLocation from the current DipLocation DatItem
|
||||
/// <summary>
|
||||
private static Models.Listxml.DipLocation CreateDipLocation(Location item)
|
||||
private static Models.Listxml.DipLocation CreateDipLocation(DipLocation item)
|
||||
{
|
||||
var diplocation = new Models.Listxml.DipLocation
|
||||
{
|
||||
@@ -654,9 +654,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a DipValue from the current Setting DatItem
|
||||
/// Create a DipValue from the current DipValue DatItem
|
||||
/// <summary>
|
||||
private static Models.Listxml.DipValue CreateDipValue(Setting item)
|
||||
private static Models.Listxml.DipValue CreateDipValue(DipValue item)
|
||||
{
|
||||
var dipvalue = new Models.Listxml.DipValue
|
||||
{
|
||||
@@ -667,13 +667,13 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
if (item.ConditionsSpecified)
|
||||
{
|
||||
var conditionItem = item.Conditions[0];
|
||||
var conditionItem = item.Conditions?.FirstOrDefault();
|
||||
var condition = new Models.Listxml.Condition
|
||||
{
|
||||
Tag = conditionItem.Tag,
|
||||
Mask = conditionItem.Mask,
|
||||
Relation = conditionItem.Relation.FromRelation(),
|
||||
Value = conditionItem.Value,
|
||||
Tag = conditionItem?.Tag,
|
||||
Mask = conditionItem?.Mask,
|
||||
Relation = conditionItem?.Relation.FromRelation(),
|
||||
Value = conditionItem?.Value,
|
||||
};
|
||||
dipvalue.Condition = condition;
|
||||
}
|
||||
@@ -695,19 +695,19 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
if (item.ConditionsSpecified)
|
||||
{
|
||||
var conditionItem = item.Conditions[0];
|
||||
var conditionItem = item.Conditions?.FirstOrDefault();
|
||||
var condition = new Models.Listxml.Condition
|
||||
{
|
||||
Tag = conditionItem.Tag,
|
||||
Mask = conditionItem.Mask,
|
||||
Relation = conditionItem.Relation.FromRelation(),
|
||||
Value = conditionItem.Value,
|
||||
Tag = conditionItem?.Tag,
|
||||
Mask = conditionItem?.Mask,
|
||||
Relation = conditionItem?.Relation.FromRelation(),
|
||||
Value = conditionItem?.Value,
|
||||
};
|
||||
configuration.Condition = condition;
|
||||
}
|
||||
|
||||
var confLocations = new List<Models.Listxml.ConfLocation>();
|
||||
foreach (var location in item.Locations ?? new List<Location>())
|
||||
foreach (var location in item.Locations ?? new List<ConfLocation>())
|
||||
{
|
||||
var control = CreateConfLocation(location);
|
||||
confLocations.Add(control);
|
||||
@@ -717,9 +717,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
configuration.ConfLocation = confLocations.ToArray();
|
||||
|
||||
var confsettings = new List<Models.Listxml.ConfSetting>();
|
||||
foreach (var settingItem in item.Settings ?? new List<Setting>())
|
||||
foreach (var confSettingItem in item.Settings ?? new List<ConfSetting>())
|
||||
{
|
||||
var dipvalue = CreateConfSetting(settingItem);
|
||||
var dipvalue = CreateConfSetting(confSettingItem);
|
||||
confsettings.Add(dipvalue);
|
||||
}
|
||||
|
||||
@@ -730,9 +730,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a ConfLocation from the current Location DatItem
|
||||
/// Create a ConfLocation from the current ConfLocation DatItem
|
||||
/// <summary>
|
||||
private static Models.Listxml.ConfLocation CreateConfLocation(Location item)
|
||||
private static Models.Listxml.ConfLocation CreateConfLocation(ConfLocation item)
|
||||
{
|
||||
var conflocation = new Models.Listxml.ConfLocation
|
||||
{
|
||||
@@ -745,9 +745,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a ConfSetting from the current Setting DatItem
|
||||
/// Create a ConfSetting from the current ConfSetting DatItem
|
||||
/// <summary>
|
||||
private static Models.Listxml.ConfSetting CreateConfSetting(Setting item)
|
||||
private static Models.Listxml.ConfSetting CreateConfSetting(ConfSetting item)
|
||||
{
|
||||
var confsetting = new Models.Listxml.ConfSetting
|
||||
{
|
||||
@@ -758,13 +758,13 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
if (item.ConditionsSpecified)
|
||||
{
|
||||
var conditionItem = item.Conditions[0];
|
||||
var conditionItem = item.Conditions?.FirstOrDefault();
|
||||
var condition = new Models.Listxml.Condition
|
||||
{
|
||||
Tag = conditionItem.Tag,
|
||||
Mask = conditionItem.Mask,
|
||||
Relation = conditionItem.Relation.FromRelation(),
|
||||
Value = conditionItem.Value,
|
||||
Tag = conditionItem?.Tag,
|
||||
Mask = conditionItem?.Mask,
|
||||
Relation = conditionItem?.Relation.FromRelation(),
|
||||
Value = conditionItem?.Value,
|
||||
};
|
||||
confsetting.Condition = condition;
|
||||
}
|
||||
@@ -798,13 +798,13 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
if (item.ConditionsSpecified)
|
||||
{
|
||||
var conditionItem = item.Conditions[0];
|
||||
var conditionItem = item.Conditions?.FirstOrDefault();
|
||||
var condition = new Models.Listxml.Condition
|
||||
{
|
||||
Tag = conditionItem.Tag,
|
||||
Mask = conditionItem.Mask,
|
||||
Relation = conditionItem.Relation.FromRelation(),
|
||||
Value = conditionItem.Value,
|
||||
Tag = conditionItem?.Tag,
|
||||
Mask = conditionItem?.Mask,
|
||||
Relation = conditionItem?.Relation.FromRelation(),
|
||||
Value = conditionItem?.Value,
|
||||
};
|
||||
adjuster.Condition = condition;
|
||||
}
|
||||
@@ -866,11 +866,11 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
if (item.InstancesSpecified)
|
||||
{
|
||||
var instanceItem = item.Instances[0];
|
||||
var instanceItem = item.Instances?.FirstOrDefault();
|
||||
var instance = new Models.Listxml.Instance
|
||||
{
|
||||
Name = instanceItem.Name,
|
||||
BriefName = instanceItem.BriefName,
|
||||
Name = instanceItem?.Name,
|
||||
BriefName = instanceItem?.BriefName,
|
||||
};
|
||||
device.Instance = instance;
|
||||
}
|
||||
@@ -944,6 +944,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
{
|
||||
Name = item.Name,
|
||||
Default = item.Default.FromYesNo(),
|
||||
Content = item.Content,
|
||||
};
|
||||
|
||||
return softwarelist;
|
||||
|
||||
@@ -303,7 +303,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
// Get the first item for game information
|
||||
var machine = items[0].Machine;
|
||||
var game = CreateGame(machine);
|
||||
var game = CreateGame(machine!);
|
||||
|
||||
// Create holders for all item types
|
||||
var releases = new List<Models.Logiqx.Release>();
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
WriteDatItem(sw, datItem, lastgame);
|
||||
|
||||
// Set the new data to compare against
|
||||
lastgame = datItem.Machine.Name;
|
||||
lastgame = datItem.Machine?.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ namespace SabreTools.DatFiles.Formats
|
||||
// Romba mode automatically uses item name
|
||||
if (Header.OutputDepot?.IsActive == true || Header.UseRomName)
|
||||
sw.Write($"{datItem.GetName() ?? string.Empty}\n");
|
||||
else if (!Header.UseRomName && datItem.Machine.Name != lastgame)
|
||||
sw.Write($"{datItem.Machine.Name}\n");
|
||||
else if (!Header.UseRomName && datItem.Machine?.Name != lastgame)
|
||||
sw.Write($"{datItem.Machine?.Name ?? string.Empty}\n");
|
||||
|
||||
sw.Flush();
|
||||
}
|
||||
|
||||
@@ -321,7 +321,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
// Get the first item for game information
|
||||
var machine = items[0].Machine;
|
||||
var game = CreateGame(machine);
|
||||
var game = CreateGame(machine!);
|
||||
|
||||
// Create holders for all item types
|
||||
var romCRCs = new List<Models.OfflineList.FileRomCRC>();
|
||||
|
||||
@@ -105,12 +105,12 @@ namespace SabreTools.DatFiles.Formats
|
||||
var machine = items[0].Machine;
|
||||
var software = new Models.OpenMSX.Software
|
||||
{
|
||||
Title = machine.Name,
|
||||
GenMSXID = machine.GenMSXID,
|
||||
System = machine.System,
|
||||
Company = machine.Manufacturer,
|
||||
Year = machine.Year,
|
||||
Country = machine.Country,
|
||||
Title = machine?.Name,
|
||||
GenMSXID = machine?.GenMSXID,
|
||||
System = machine?.System,
|
||||
Company = machine?.Manufacturer,
|
||||
Year = machine?.Year,
|
||||
Country = machine?.Country,
|
||||
};
|
||||
|
||||
// Create holder for dumps
|
||||
|
||||
@@ -183,14 +183,14 @@ namespace SabreTools.DatFiles.Formats
|
||||
{
|
||||
var rom = new Models.RomCenter.Rom
|
||||
{
|
||||
ParentName = item.Machine.CloneOf,
|
||||
//ParentDescription = item.Machine.CloneOfDescription, // TODO: Add to internal model or find mapping
|
||||
GameName = item.Machine.Name,
|
||||
GameDescription = item.Machine.Description,
|
||||
ParentName = item.Machine?.CloneOf,
|
||||
//ParentDescription = item.Machine?.CloneOfDescription, // TODO: Add to internal model or find mapping
|
||||
GameName = item.Machine?.Name,
|
||||
GameDescription = item.Machine?.Description,
|
||||
RomName = item.Name,
|
||||
RomCRC = item.CRC,
|
||||
RomSize = item.Size?.ToString(),
|
||||
RomOf = item.Machine.RomOf,
|
||||
RomOf = item.Machine?.RomOf,
|
||||
MergeName = item.MergeTag,
|
||||
};
|
||||
return rom;
|
||||
|
||||
@@ -235,6 +235,12 @@ namespace SabreTools.DatFiles.Formats
|
||||
case ItemType.Configuration:
|
||||
datItem = datItemObj.ToObject<Configuration>();
|
||||
break;
|
||||
case ItemType.ConfLocation:
|
||||
datItem = datItemObj.ToObject<ConfLocation>();
|
||||
break;
|
||||
case ItemType.ConfSetting:
|
||||
datItem = datItemObj.ToObject<ConfSetting>();
|
||||
break;
|
||||
case ItemType.Control:
|
||||
datItem = datItemObj.ToObject<Control>();
|
||||
break;
|
||||
@@ -247,6 +253,12 @@ namespace SabreTools.DatFiles.Formats
|
||||
case ItemType.DeviceReference:
|
||||
datItem = datItemObj.ToObject<DeviceReference>();
|
||||
break;
|
||||
case ItemType.DipLocation:
|
||||
datItem = datItemObj.ToObject<DipLocation>();
|
||||
break;
|
||||
case ItemType.DipValue:
|
||||
datItem = datItemObj.ToObject<DipValue>();
|
||||
break;
|
||||
case ItemType.DipSwitch:
|
||||
datItem = datItemObj.ToObject<DipSwitch>();
|
||||
break;
|
||||
@@ -277,9 +289,6 @@ namespace SabreTools.DatFiles.Formats
|
||||
case ItemType.Instance:
|
||||
datItem = datItemObj.ToObject<Instance>();
|
||||
break;
|
||||
case ItemType.Location:
|
||||
datItem = datItemObj.ToObject<Location>();
|
||||
break;
|
||||
case ItemType.Media:
|
||||
datItem = datItemObj.ToObject<Media>();
|
||||
break;
|
||||
@@ -310,9 +319,6 @@ namespace SabreTools.DatFiles.Formats
|
||||
case ItemType.Serials:
|
||||
datItem = datItemObj.ToObject<Serials>();
|
||||
break;
|
||||
case ItemType.Setting:
|
||||
datItem = datItemObj.ToObject<Setting>();
|
||||
break;
|
||||
case ItemType.SharedFeature:
|
||||
datItem = datItemObj.ToObject<SharedFeature>();
|
||||
break;
|
||||
@@ -389,11 +395,11 @@ namespace SabreTools.DatFiles.Formats
|
||||
DatItem datItem = datItems[index];
|
||||
|
||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
||||
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine?.Name?.ToLowerInvariant())
|
||||
WriteEndGame(jtw);
|
||||
|
||||
// If we have a new game, output the beginning of the new item
|
||||
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
||||
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine?.Name?.ToLowerInvariant())
|
||||
WriteStartGame(jtw, datItem);
|
||||
|
||||
// Check for a "null" item
|
||||
@@ -404,7 +410,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
WriteDatItem(jtw, datItem);
|
||||
|
||||
// Set the new data to compare against
|
||||
lastgame = datItem.Machine.Name;
|
||||
lastgame = datItem.Machine?.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -451,7 +457,8 @@ namespace SabreTools.DatFiles.Formats
|
||||
private void WriteStartGame(JsonTextWriter jtw, DatItem datItem)
|
||||
{
|
||||
// No game should start with a path separator
|
||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
||||
if (!string.IsNullOrWhiteSpace(datItem.Machine?.Name))
|
||||
datItem.Machine.Name = datItem.Machine.Name.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
||||
|
||||
// Build the state
|
||||
jtw.WriteStartObject();
|
||||
|
||||
@@ -223,11 +223,11 @@ namespace SabreTools.DatFiles.Formats
|
||||
DatItem datItem = datItems[index];
|
||||
|
||||
// If we have a different game and we're not at the start of the list, output the end of last item
|
||||
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
||||
if (lastgame != null && lastgame.ToLowerInvariant() != datItem.Machine?.Name?.ToLowerInvariant())
|
||||
WriteEndGame(xtw);
|
||||
|
||||
// If we have a new game, output the beginning of the new item
|
||||
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine.Name.ToLowerInvariant())
|
||||
if (lastgame == null || lastgame.ToLowerInvariant() != datItem.Machine?.Name?.ToLowerInvariant())
|
||||
WriteStartGame(xtw, datItem);
|
||||
|
||||
// Check for a "null" item
|
||||
@@ -238,7 +238,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
WriteDatItem(xtw, datItem);
|
||||
|
||||
// Set the new data to compare against
|
||||
lastgame = datItem.Machine.Name;
|
||||
lastgame = datItem.Machine?.Name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
private void WriteStartGame(XmlTextWriter xtw, DatItem datItem)
|
||||
{
|
||||
// No game should start with a path separator
|
||||
datItem.Machine.Name = datItem.Machine.Name?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
||||
datItem.Machine!.Name = datItem.Machine.Name?.TrimStart(Path.DirectorySeparatorChar) ?? string.Empty;
|
||||
|
||||
// Write the machine
|
||||
xtw.WriteStartElement("directory");
|
||||
|
||||
@@ -162,8 +162,8 @@ namespace SabreTools.DatFiles.Formats
|
||||
FileName = Header.FileName,
|
||||
InternalName = Header.Name,
|
||||
Description = Header.Description,
|
||||
GameName = disk.Machine.Name,
|
||||
GameDescription = disk.Machine.Description,
|
||||
GameName = disk.Machine?.Name,
|
||||
GameDescription = disk.Machine?.Description,
|
||||
Type = disk.ItemType.FromItemType(),
|
||||
RomName = string.Empty,
|
||||
DiskName = disk.Name,
|
||||
@@ -190,8 +190,8 @@ namespace SabreTools.DatFiles.Formats
|
||||
FileName = Header.FileName,
|
||||
InternalName = Header.Name,
|
||||
Description = Header.Description,
|
||||
GameName = media.Machine.Name,
|
||||
GameDescription = media.Machine.Description,
|
||||
GameName = media.Machine?.Name,
|
||||
GameDescription = media.Machine?.Description,
|
||||
Type = media.ItemType.FromItemType(),
|
||||
RomName = string.Empty,
|
||||
DiskName = media.Name,
|
||||
@@ -218,8 +218,8 @@ namespace SabreTools.DatFiles.Formats
|
||||
FileName = Header.FileName,
|
||||
InternalName = Header.Name,
|
||||
Description = Header.Description,
|
||||
GameName = rom.Machine.Name,
|
||||
GameDescription = rom.Machine.Description,
|
||||
GameName = rom.Machine?.Name,
|
||||
GameDescription = rom.Machine?.Description,
|
||||
Type = rom.ItemType.FromItemType(),
|
||||
RomName = rom.Name,
|
||||
DiskName = string.Empty,
|
||||
|
||||
@@ -418,7 +418,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
Name = dipswitch.Name,
|
||||
Tag = dipswitch.Tag,
|
||||
Mask = dipswitch.Mask,
|
||||
Values = CreateSettings(dipswitch.DipValue, machine, filename, indexId),
|
||||
Values = CreateDipValues(dipswitch.DipValue, machine, filename, indexId),
|
||||
|
||||
Part = part,
|
||||
|
||||
@@ -441,16 +441,16 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <param name="machine">Prefilled machine to use</param>
|
||||
/// <param name="filename">Name of the file to be parsed</param>
|
||||
/// <param name="indexId">Index ID for the DAT</param>
|
||||
private static List<Setting>? CreateSettings(Models.SoftwareList.DipValue[]? dipvalues, Machine machine, string filename, int indexId)
|
||||
private static List<DipValue>? CreateDipValues(Models.SoftwareList.DipValue[]? dipvalues, Machine machine, string filename, int indexId)
|
||||
{
|
||||
// If the feature array is missing, we can't do anything
|
||||
if (dipvalues == null || !dipvalues.Any())
|
||||
return null;
|
||||
|
||||
var settings = new List<Setting>();
|
||||
var settings = new List<DipValue>();
|
||||
foreach (var dipvalue in dipvalues)
|
||||
{
|
||||
var item = new Setting
|
||||
var item = new DipValue
|
||||
{
|
||||
Name = dipvalue.Name,
|
||||
Value = dipvalue.Value,
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(dipSwitch.Part.Name))
|
||||
if (string.IsNullOrWhiteSpace(dipSwitch.Part!.Name))
|
||||
missingFields.Add(DatItemField.Part_Name);
|
||||
if (string.IsNullOrWhiteSpace(dipSwitch.Part.Interface))
|
||||
missingFields.Add(DatItemField.Part_Interface);
|
||||
@@ -54,9 +54,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
missingFields.Add(DatItemField.Mask);
|
||||
if (dipSwitch.ValuesSpecified)
|
||||
{
|
||||
if (dipSwitch.Values.Any(dv => string.IsNullOrWhiteSpace(dv.Name)))
|
||||
if (dipSwitch.Values!.Any(dv => string.IsNullOrWhiteSpace(dv.Name)))
|
||||
missingFields.Add(DatItemField.Part_Feature_Name);
|
||||
if (dipSwitch.Values.Any(dv => string.IsNullOrWhiteSpace(dv.Value)))
|
||||
if (dipSwitch.Values!.Any(dv => string.IsNullOrWhiteSpace(dv.Value)))
|
||||
missingFields.Add(DatItemField.Part_Feature_Value);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(disk.Part.Name))
|
||||
if (string.IsNullOrWhiteSpace(disk.Part!.Name))
|
||||
missingFields.Add(DatItemField.Part_Name);
|
||||
if (string.IsNullOrWhiteSpace(disk.Part.Interface))
|
||||
missingFields.Add(DatItemField.Part_Interface);
|
||||
@@ -81,7 +81,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(disk.DiskArea.Name))
|
||||
if (string.IsNullOrWhiteSpace(disk.DiskArea!.Name))
|
||||
missingFields.Add(DatItemField.AreaName);
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(disk.Name))
|
||||
@@ -101,7 +101,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rom.Part.Name))
|
||||
if (string.IsNullOrWhiteSpace(rom.Part!.Name))
|
||||
missingFields.Add(DatItemField.Part_Name);
|
||||
if (string.IsNullOrWhiteSpace(rom.Part.Interface))
|
||||
missingFields.Add(DatItemField.Part_Interface);
|
||||
@@ -113,7 +113,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(rom.DataArea.Name))
|
||||
if (string.IsNullOrWhiteSpace(rom.DataArea!.Name))
|
||||
missingFields.Add(DatItemField.AreaName);
|
||||
if (!rom.DataArea.SizeSpecified)
|
||||
missingFields.Add(DatItemField.AreaSize);
|
||||
@@ -197,7 +197,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
|
||||
// Get the first item for game information
|
||||
var machine = items[0].Machine;
|
||||
var sw = CreateSoftware(machine);
|
||||
var sw = CreateSoftware(machine!);
|
||||
|
||||
// Create holders for all item types
|
||||
var infos = new List<Models.SoftwareList.Info>();
|
||||
@@ -304,9 +304,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
{
|
||||
var part = new Models.SoftwareList.Part
|
||||
{
|
||||
Name = item.Part.Name,
|
||||
Interface = item.Part.Interface,
|
||||
Feature = CreateFeatures(item.Part.Features),
|
||||
Name = item.Part?.Name,
|
||||
Interface = item.Part?.Interface,
|
||||
Feature = CreateFeatures(item.Part?.Features),
|
||||
DataArea = CreateDataAreas(item),
|
||||
DiskArea = null,
|
||||
DipSwitch = null,
|
||||
@@ -321,9 +321,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
{
|
||||
var part = new Models.SoftwareList.Part
|
||||
{
|
||||
Name = item.Part.Name,
|
||||
Interface = item.Part.Interface,
|
||||
Feature = CreateFeatures(item.Part.Features),
|
||||
Name = item.Part?.Name,
|
||||
Interface = item.Part?.Interface,
|
||||
Feature = CreateFeatures(item.Part?.Features),
|
||||
DataArea = null,
|
||||
DiskArea = CreateDiskAreas(item),
|
||||
DipSwitch = null,
|
||||
@@ -338,9 +338,9 @@ namespace SabreTools.DatFiles.Formats
|
||||
{
|
||||
var part = new Models.SoftwareList.Part
|
||||
{
|
||||
Name = item.Part.Name,
|
||||
Interface = item.Part.Interface,
|
||||
Feature = CreateFeatures(item.Part.Features),
|
||||
Name = item.Part?.Name,
|
||||
Interface = item.Part?.Interface,
|
||||
Feature = CreateFeatures(item.Part?.Features),
|
||||
DataArea = null,
|
||||
DiskArea = null,
|
||||
DipSwitch = CreateDipSwitches(item),
|
||||
@@ -351,7 +351,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
/// <summary>
|
||||
/// Create a Feature array from the current list of PartFeature DatItems
|
||||
/// <summary>
|
||||
private static Models.SoftwareList.Feature[]? CreateFeatures(List<PartFeature> items)
|
||||
private static Models.SoftwareList.Feature[]? CreateFeatures(List<PartFeature>? items)
|
||||
{
|
||||
// If we don't have features, we can't do anything
|
||||
if (items == null || !items.Any())
|
||||
@@ -378,10 +378,10 @@ namespace SabreTools.DatFiles.Formats
|
||||
{
|
||||
var dataArea = new Models.SoftwareList.DataArea
|
||||
{
|
||||
Name = item.DataArea.Name,
|
||||
Size = item.DataArea.Size?.ToString(),
|
||||
Width = item.DataArea.Width?.ToString(),
|
||||
Endianness = item.DataArea.Endianness.FromEndianness(),
|
||||
Name = item.DataArea?.Name,
|
||||
Size = item.DataArea?.Size?.ToString(),
|
||||
Width = item.DataArea?.Width?.ToString(),
|
||||
Endianness = item.DataArea?.Endianness.FromEndianness(),
|
||||
Rom = CreateRom(item),
|
||||
};
|
||||
return new Models.SoftwareList.DataArea[] { dataArea };
|
||||
@@ -441,7 +441,7 @@ namespace SabreTools.DatFiles.Formats
|
||||
private static Models.SoftwareList.DipSwitch[]? CreateDipSwitches(DipSwitch item)
|
||||
{
|
||||
var dipValues = new List<Models.SoftwareList.DipValue>();
|
||||
foreach (var setting in item.Values ?? new List<Setting>())
|
||||
foreach (var setting in item.Values ?? new List<DipValue>())
|
||||
{
|
||||
var dipValue = new Models.SoftwareList.DipValue
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user