mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Use OfflineList serializer for writing
This commit is contained in:
@@ -1,12 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Xml;
|
|
||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
using SabreTools.DatItems;
|
using SabreTools.DatItems;
|
||||||
using SabreTools.DatItems.Formats;
|
using SabreTools.DatItems.Formats;
|
||||||
using SabreTools.IO;
|
|
||||||
|
|
||||||
namespace SabreTools.DatFiles.Formats
|
namespace SabreTools.DatFiles.Formats
|
||||||
{
|
{
|
||||||
@@ -53,62 +50,13 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
logger.User($"Writing to '{outfile}'...");
|
logger.User($"Writing to '{outfile}'...");
|
||||||
FileStream fs = System.IO.File.Create(outfile);
|
|
||||||
|
|
||||||
// If we get back null for some reason, just log and return
|
var datafile = CreateDat(ignoreblanks);
|
||||||
if (fs == null)
|
if (!Serialization.OfflineList.SerializeToFile(datafile, outfile))
|
||||||
{
|
{
|
||||||
logger.Warning($"File '{outfile}' could not be created for writing! Please check to see if the file is writable");
|
logger.Warning($"File '{outfile}' could not be written! See the log for more details.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
XmlTextWriter xtw = new(fs, new UTF8Encoding(false))
|
|
||||||
{
|
|
||||||
Formatting = Formatting.Indented,
|
|
||||||
IndentChar = '\t',
|
|
||||||
Indentation = 1
|
|
||||||
};
|
|
||||||
|
|
||||||
// Write out the header
|
|
||||||
WriteHeader(xtw);
|
|
||||||
|
|
||||||
// Write out each of the machines and roms
|
|
||||||
string lastgame = null;
|
|
||||||
|
|
||||||
// Use a sorted list of games to output
|
|
||||||
foreach (string key in Items.SortedKeys)
|
|
||||||
{
|
|
||||||
ConcurrentList<DatItem> datItems = Items.FilteredItems(key);
|
|
||||||
|
|
||||||
// If this machine doesn't contain any writable items, skip
|
|
||||||
if (!ContainsWritable(datItems))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Resolve the names in the block
|
|
||||||
datItems = DatItem.ResolveNames(datItems);
|
|
||||||
|
|
||||||
for (int index = 0; index < datItems.Count; index++)
|
|
||||||
{
|
|
||||||
DatItem datItem = datItems[index];
|
|
||||||
|
|
||||||
// Check for a "null" item
|
|
||||||
datItem = ProcessNullifiedItem(datItem);
|
|
||||||
|
|
||||||
// Write out the item if we're not ignoring
|
|
||||||
if (!ShouldIgnore(datItem, ignoreblanks))
|
|
||||||
WriteDatItem(xtw, datItem);
|
|
||||||
|
|
||||||
// Set the new data to compare against
|
|
||||||
lastgame = datItem.Machine.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the file footer out
|
|
||||||
WriteFooter(xtw);
|
|
||||||
|
|
||||||
logger.User($"'{outfile}' written!{Environment.NewLine}");
|
|
||||||
xtw.Dispose();
|
|
||||||
fs.Dispose();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (!throwOnError)
|
catch (Exception ex) when (!throwOnError)
|
||||||
{
|
{
|
||||||
@@ -116,220 +64,353 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.User($"'{outfile}' written!{Environment.NewLine}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Converters
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT header using the supplied StreamWriter
|
/// Create a Dat from the current internal information
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise</param>
|
||||||
private void WriteHeader(XmlTextWriter xtw)
|
private Models.OfflineList.Dat CreateDat(bool ignoreblanks)
|
||||||
{
|
{
|
||||||
xtw.WriteStartDocument(false);
|
var dat = new Models.OfflineList.Dat
|
||||||
|
|
||||||
xtw.WriteStartElement("dat");
|
|
||||||
xtw.WriteAttributeString("xsi", "xmlns", "http://www.w3.org/2001/XMLSchema-instance");
|
|
||||||
xtw.WriteAttributeString("noNamespaceSchemaLocation", "xsi", "datas.xsd");
|
|
||||||
|
|
||||||
xtw.WriteStartElement("configuration");
|
|
||||||
xtw.WriteRequiredElementString("datName", Header.Name);
|
|
||||||
xtw.WriteElementString("datVersion", Items.TotalCount.ToString());
|
|
||||||
xtw.WriteRequiredElementString("system", Header.System);
|
|
||||||
xtw.WriteRequiredElementString("screenshotsWidth", Header.ScreenshotsWidth);
|
|
||||||
xtw.WriteRequiredElementString("screenshotsHeight", Header.ScreenshotsHeight);
|
|
||||||
|
|
||||||
if (Header.Infos != null)
|
|
||||||
{
|
{
|
||||||
xtw.WriteStartElement("infos");
|
NoNamespaceSchemaLocation = "datas.xsd",
|
||||||
|
Configuration = CreateConfiguration(),
|
||||||
|
Games = CreateGames(ignoreblanks),
|
||||||
|
GUI = CreateGUI(),
|
||||||
|
};
|
||||||
|
|
||||||
foreach (var info in Header.Infos)
|
return dat;
|
||||||
{
|
|
||||||
xtw.WriteStartElement(info.Name);
|
|
||||||
xtw.WriteAttributeString("visible", info.Visible?.ToString());
|
|
||||||
xtw.WriteAttributeString("inNamingOption", info.InNamingOption?.ToString());
|
|
||||||
xtw.WriteAttributeString("default", info.Default?.ToString());
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
// End infos
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Header.CanOpen != null)
|
|
||||||
{
|
|
||||||
xtw.WriteStartElement("canOpen");
|
|
||||||
|
|
||||||
foreach (string extension in Header.CanOpen)
|
|
||||||
{
|
|
||||||
xtw.WriteElementString("extension", extension);
|
|
||||||
}
|
|
||||||
|
|
||||||
// End canOpen
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
xtw.WriteStartElement("newDat");
|
|
||||||
xtw.WriteRequiredElementString("datVersionURL", Header.Url);
|
|
||||||
|
|
||||||
xtw.WriteStartElement("datUrl");
|
|
||||||
xtw.WriteAttributeString("fileName", $"{Header.FileName ?? string.Empty}.zip");
|
|
||||||
xtw.WriteString(Header.Url);
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteRequiredElementString("imURL", Header.Url);
|
|
||||||
|
|
||||||
// End newDat
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteStartElement("search");
|
|
||||||
|
|
||||||
xtw.WriteStartElement("to");
|
|
||||||
xtw.WriteAttributeString("value", "location");
|
|
||||||
xtw.WriteAttributeString("default", "true");
|
|
||||||
xtw.WriteAttributeString("auto", "true");
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteStartElement("to");
|
|
||||||
xtw.WriteAttributeString("value", "romSize");
|
|
||||||
xtw.WriteAttributeString("default", "true");
|
|
||||||
xtw.WriteAttributeString("auto", "false");
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteStartElement("to");
|
|
||||||
xtw.WriteAttributeString("value", "languages");
|
|
||||||
xtw.WriteAttributeString("default", "true");
|
|
||||||
xtw.WriteAttributeString("auto", "true");
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteStartElement("to");
|
|
||||||
xtw.WriteAttributeString("value", "saveType");
|
|
||||||
xtw.WriteAttributeString("default", "false");
|
|
||||||
xtw.WriteAttributeString("auto", "false");
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteStartElement("to");
|
|
||||||
xtw.WriteAttributeString("value", "publisher");
|
|
||||||
xtw.WriteAttributeString("default", "false");
|
|
||||||
xtw.WriteAttributeString("auto", "true");
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteStartElement("to");
|
|
||||||
xtw.WriteAttributeString("value", "sourceRom");
|
|
||||||
xtw.WriteAttributeString("default", "false");
|
|
||||||
xtw.WriteAttributeString("auto", "true");
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
// End search
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteRequiredElementString("romTitle", Header.RomTitle ?? "%u - %n");
|
|
||||||
|
|
||||||
// End configuration
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.WriteStartElement("games");
|
|
||||||
|
|
||||||
xtw.Flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DatItem using the supplied StreamWriter
|
/// Create a Configuration from the current internal information
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
private Models.OfflineList.Configuration? CreateConfiguration()
|
||||||
/// <param name="datItem">DatItem object to be output</param>
|
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
|
||||||
private void WriteDatItem(XmlTextWriter xtw, DatItem datItem)
|
|
||||||
{
|
{
|
||||||
// Pre-process the item name
|
// If we don't have a header, we can't do anything
|
||||||
ProcessItemName(datItem, true);
|
if (this.Header == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
// Build the state
|
var configuration = new Models.OfflineList.Configuration
|
||||||
xtw.WriteStartElement("game");
|
|
||||||
xtw.WriteElementString("imageNumber", "1");
|
|
||||||
xtw.WriteElementString("releaseNumber", "1");
|
|
||||||
xtw.WriteRequiredElementString("title", datItem.GetName() ?? string.Empty);
|
|
||||||
xtw.WriteElementString("saveType", "None");
|
|
||||||
|
|
||||||
if (datItem.ItemType == ItemType.Rom)
|
|
||||||
{
|
{
|
||||||
var rom = datItem as Rom;
|
DatName = Header.Name,
|
||||||
xtw.WriteRequiredElementString("romSize", rom.Size?.ToString());
|
//ImFolder = Header.ImFolder; // TODO: Add to internal model
|
||||||
}
|
DatVersion = Header.Version,
|
||||||
|
System = Header.System,
|
||||||
|
ScreenshotsWidth = Header.ScreenshotsWidth,
|
||||||
|
ScreenshotsHeight = Header.ScreenshotsHeight,
|
||||||
|
Infos = CreateInfos(),
|
||||||
|
CanOpen = CreateCanOpen(),
|
||||||
|
NewDat = CreateNewDat(),
|
||||||
|
Search = CreateSearch(),
|
||||||
|
RomTitle = Header.RomTitle,
|
||||||
|
};
|
||||||
|
|
||||||
xtw.WriteRequiredElementString("publisher", datItem.Machine.Publisher);
|
return configuration;
|
||||||
xtw.WriteElementString("location", "0");
|
|
||||||
xtw.WriteElementString("sourceRom", "None");
|
|
||||||
xtw.WriteElementString("language", "0");
|
|
||||||
|
|
||||||
if (datItem.ItemType == ItemType.Rom)
|
|
||||||
{
|
|
||||||
var rom = datItem as Rom;
|
|
||||||
string tempext = "." + rom.Name.GetNormalizedExtension();
|
|
||||||
|
|
||||||
xtw.WriteStartElement("files");
|
|
||||||
if (!string.IsNullOrWhiteSpace(rom.CRC))
|
|
||||||
{
|
|
||||||
xtw.WriteStartElement("romCRC");
|
|
||||||
xtw.WriteRequiredAttributeString("extension", tempext);
|
|
||||||
xtw.WriteString(rom.CRC?.ToUpperInvariant());
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
// End files
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
}
|
|
||||||
|
|
||||||
xtw.WriteElementString("im1CRC", "00000000");
|
|
||||||
xtw.WriteElementString("im2CRC", "00000000");
|
|
||||||
xtw.WriteRequiredElementString("comment", datItem.Machine.Comment);
|
|
||||||
xtw.WriteRequiredElementString("duplicateID", datItem.Machine.CloneOf);
|
|
||||||
|
|
||||||
// End game
|
|
||||||
xtw.WriteEndElement();
|
|
||||||
|
|
||||||
xtw.Flush();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Write out DAT footer using the supplied StreamWriter
|
/// Create a Infos from the current internal information
|
||||||
/// </summary>
|
/// <summary>
|
||||||
/// <param name="xtw">XmlTextWriter to output to</param>
|
private Models.OfflineList.Infos? CreateInfos()
|
||||||
/// <returns>True if the data was written, false on error</returns>
|
|
||||||
private void WriteFooter(XmlTextWriter xtw)
|
|
||||||
{
|
{
|
||||||
// End games
|
// If we don't have infos, we can't do anything
|
||||||
xtw.WriteEndElement();
|
if (!Header.InfosSpecified)
|
||||||
|
return null;
|
||||||
|
|
||||||
xtw.WriteStartElement("gui");
|
var infos = new Models.OfflineList.Infos();
|
||||||
|
foreach (var info in Header.Infos)
|
||||||
|
{
|
||||||
|
switch (info.Name)
|
||||||
|
{
|
||||||
|
case "title":
|
||||||
|
infos.Title = new Models.OfflineList.Title
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
xtw.WriteStartElement("images");
|
case "location":
|
||||||
xtw.WriteAttributeString("width", "487");
|
infos.Location = new Models.OfflineList.Location
|
||||||
xtw.WriteAttributeString("height", "162");
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
xtw.WriteStartElement("image");
|
case "publisher":
|
||||||
xtw.WriteAttributeString("x", "0");
|
infos.Publisher = new Models.OfflineList.Publisher
|
||||||
xtw.WriteAttributeString("y", "0");
|
{
|
||||||
xtw.WriteAttributeString("width", "240");
|
Visible = info.Visible?.ToString(),
|
||||||
xtw.WriteAttributeString("height", "160");
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
xtw.WriteEndElement();
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
xtw.WriteStartElement("image");
|
case "sourceRom":
|
||||||
xtw.WriteAttributeString("x", "245");
|
infos.SourceRom = new Models.OfflineList.SourceRom
|
||||||
xtw.WriteAttributeString("y", "0");
|
{
|
||||||
xtw.WriteAttributeString("width", "240");
|
Visible = info.Visible?.ToString(),
|
||||||
xtw.WriteAttributeString("height", "160");
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
xtw.WriteEndElement();
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
// End images
|
case "saveType":
|
||||||
xtw.WriteEndElement();
|
infos.SaveType = new Models.OfflineList.SaveType
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
// End gui
|
case "romSize":
|
||||||
xtw.WriteEndElement();
|
infos.RomSize = new Models.OfflineList.RomSize
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
// End dat
|
case "releaseNumber":
|
||||||
xtw.WriteEndElement();
|
infos.ReleaseNumber = new Models.OfflineList.ReleaseNumber
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
xtw.Flush();
|
case "languageNumber":
|
||||||
|
infos.LanguageNumber = new Models.OfflineList.LanguageNumber
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "comment":
|
||||||
|
infos.Comment = new Models.OfflineList.Comment
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "romCRC":
|
||||||
|
infos.RomCRC = new Models.OfflineList.RomCRC
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "im1CRC":
|
||||||
|
infos.Im1CRC = new Models.OfflineList.Im1CRC
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "im2CRC":
|
||||||
|
infos.Im2CRC = new Models.OfflineList.Im2CRC
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "languages":
|
||||||
|
infos.Languages = new Models.OfflineList.Languages
|
||||||
|
{
|
||||||
|
Visible = info.Visible?.ToString(),
|
||||||
|
InNamingOption = info.InNamingOption?.ToString(),
|
||||||
|
Default = info.Default?.ToString(),
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return infos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a CanOpen from the current internal information
|
||||||
|
/// <summary>
|
||||||
|
private Models.OfflineList.CanOpen? CreateCanOpen()
|
||||||
|
{
|
||||||
|
// If we don't have a canopen, we can't do anything
|
||||||
|
if (!Header.CanOpenSpecified)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var canOpen = new Models.OfflineList.CanOpen
|
||||||
|
{
|
||||||
|
Extension = Header.CanOpen.ToArray(),
|
||||||
|
};
|
||||||
|
|
||||||
|
return canOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a NewDat from the current internal information
|
||||||
|
/// <summary>
|
||||||
|
private Models.OfflineList.NewDat? CreateNewDat()
|
||||||
|
{
|
||||||
|
// If we don't have a Header, we can't do anything
|
||||||
|
if (Header == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var newDat = new Models.OfflineList.NewDat
|
||||||
|
{
|
||||||
|
DatVersionUrl = Header.Url,
|
||||||
|
//DatUrl = Header.DatUrl; // TODO: Add to internal model
|
||||||
|
//ImUrl = Header.ImUrl; // TODO: Add to internal model
|
||||||
|
};
|
||||||
|
|
||||||
|
return newDat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a Search from the current internal information
|
||||||
|
/// <summary>
|
||||||
|
private Models.OfflineList.Search? CreateSearch()
|
||||||
|
{
|
||||||
|
// If we don't have a Header, we can't do anything
|
||||||
|
if (Header == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// TODO: Add to internal model
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a Games from the current internal information
|
||||||
|
/// <summary>
|
||||||
|
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise</param>
|
||||||
|
private Models.OfflineList.Games? CreateGames(bool ignoreblanks)
|
||||||
|
{
|
||||||
|
// If we don't have items, we can't do anything
|
||||||
|
if (this.Items == null || !this.Items.Any())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Create a list of hold the games
|
||||||
|
var games = new List<Models.OfflineList.Game>();
|
||||||
|
|
||||||
|
// Loop through the sorted items and create games for them
|
||||||
|
foreach (string key in Items.SortedKeys)
|
||||||
|
{
|
||||||
|
var items = Items.FilteredItems(key);
|
||||||
|
if (items == null || !items.Any())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Get the first item for game information
|
||||||
|
var machine = items[0].Machine;
|
||||||
|
var game = CreateGame(machine);
|
||||||
|
|
||||||
|
// Create holders for all item types
|
||||||
|
var romCRCs = new List<Models.OfflineList.FileRomCRC>();
|
||||||
|
|
||||||
|
// Loop through and convert the items to respective lists
|
||||||
|
for (int index = 0; index < items.Count; index++)
|
||||||
|
{
|
||||||
|
// Get the item
|
||||||
|
var item = items[index];
|
||||||
|
|
||||||
|
// Check for a "null" item
|
||||||
|
item = ProcessNullifiedItem(item);
|
||||||
|
|
||||||
|
// Skip if we're ignoring the item
|
||||||
|
if (ShouldIgnore(item, ignoreblanks))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
switch (item)
|
||||||
|
{
|
||||||
|
case Rom rom:
|
||||||
|
romCRCs.Add(CreateRomCRC(rom));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign the values to the game
|
||||||
|
game.Files = new Models.OfflineList.Files { RomCRC = romCRCs.ToArray() };
|
||||||
|
|
||||||
|
// Add the game to the list
|
||||||
|
games.Add(game);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Models.OfflineList.Games { Game = games.ToArray() };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a Machine from the current internal information
|
||||||
|
/// <summary>
|
||||||
|
private Models.OfflineList.Game? CreateGame(Machine machine)
|
||||||
|
{
|
||||||
|
// If we don't have a machine, we can't do anything
|
||||||
|
if (machine == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var game = new Models.OfflineList.Game
|
||||||
|
{
|
||||||
|
//ImageNumber = machine.ImageNumber, // TODO: Add to internal model
|
||||||
|
//ReleaseNumber = machine.ReleaseNumber, // TODO: Add to internal model
|
||||||
|
Title = machine.Name,
|
||||||
|
//SaveType = machine.SaveType, // TODO: Add to internal model
|
||||||
|
Publisher = machine.Publisher,
|
||||||
|
//Location = machine.Location, // TODO: Add to internal model
|
||||||
|
//SourceRom = machine.SourceRom, // TODO: Add to internal model
|
||||||
|
//Language = machine.Language, // TODO: Add to internal model
|
||||||
|
//Im1CRC = machine.Im1CRC, // TODO: Add to internal model
|
||||||
|
//Im2CRC = machine.Im2CRC, // TODO: Add to internal model
|
||||||
|
Comment = machine.Comment,
|
||||||
|
DuplicateID = machine.CloneOf,
|
||||||
|
};
|
||||||
|
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a RomCRC from the current Rom DatItem
|
||||||
|
/// <summary>
|
||||||
|
private static Models.OfflineList.FileRomCRC CreateRomCRC(Rom item)
|
||||||
|
{
|
||||||
|
var romCRC = new Models.OfflineList.FileRomCRC
|
||||||
|
{
|
||||||
|
Content = item.CRC,
|
||||||
|
};
|
||||||
|
|
||||||
|
return romCRC;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a GUI from the current internal information
|
||||||
|
/// <summary>
|
||||||
|
private Models.OfflineList.GUI? CreateGUI()
|
||||||
|
{
|
||||||
|
// If we don't have a header, we can't do anything
|
||||||
|
if (this.Header == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// TODO: Add to internal model
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user