mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Finalize read/write support for Archive.org
This commit is contained in:
@@ -165,9 +165,8 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
Rom rom = new Rom
|
Rom rom = new Rom
|
||||||
{
|
{
|
||||||
Name = reader.GetAttribute("name"),
|
Name = reader.GetAttribute("name"),
|
||||||
Value = reader.GetAttribute("source"), // TODO: Create new field for this
|
ArchiveDotOrgSource = reader.GetAttribute("source"),
|
||||||
|
|
||||||
// TODO: Derive from path, if possible
|
|
||||||
Machine = new Machine
|
Machine = new Machine
|
||||||
{
|
{
|
||||||
Name = "Default",
|
Name = "Default",
|
||||||
@@ -181,6 +180,16 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// If we have a path, update the machine name and description
|
||||||
|
if (rom.Name.Contains('/'))
|
||||||
|
{
|
||||||
|
string[] splitpath = rom.Name.Split('/');
|
||||||
|
rom.Machine.Name = splitpath[0];
|
||||||
|
rom.Machine.Description = splitpath[0];
|
||||||
|
|
||||||
|
rom.Name = rom.Name.Substring(splitpath[0].Length + 1);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Handle SuperDAT
|
// TODO: Handle SuperDAT
|
||||||
//if (Header.Type == "SuperDAT" && !keep)
|
//if (Header.Type == "SuperDAT" && !keep)
|
||||||
//{
|
//{
|
||||||
@@ -221,24 +230,20 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
rom.Size = Utilities.CleanLong(reader.ReadElementContentAsString());
|
rom.Size = Utilities.CleanLong(reader.ReadElementContentAsString());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO: Create new field for this
|
|
||||||
case "format":
|
case "format":
|
||||||
string format = reader.ReadElementContentAsString();
|
rom.ArchiveDotOrgFormat = reader.ReadElementContentAsString();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO: Create new field for this
|
|
||||||
case "original":
|
case "original":
|
||||||
string original = reader.ReadElementContentAsString();
|
rom.OriginalFilename = reader.ReadElementContentAsString();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO: Create new field for this, Int32?
|
|
||||||
case "rotation":
|
case "rotation":
|
||||||
string rotation = reader.ReadElementContentAsString();
|
rom.Rotation = reader.ReadElementContentAsString();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// TODO: Create new field for this
|
|
||||||
case "summation":
|
case "summation":
|
||||||
string summation = reader.ReadElementContentAsString();
|
rom.Summation = reader.ReadElementContentAsString();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -278,8 +283,8 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
|
XmlTextWriter xtw = new XmlTextWriter(fs, new UTF8Encoding(false))
|
||||||
{
|
{
|
||||||
Formatting = Formatting.Indented,
|
Formatting = Formatting.Indented,
|
||||||
IndentChar = '\t',
|
IndentChar = ' ',
|
||||||
Indentation = 1
|
Indentation = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
// Write out the header
|
// Write out the header
|
||||||
@@ -361,17 +366,24 @@ namespace SabreTools.DatFiles.Formats
|
|||||||
case ItemType.Rom:
|
case ItemType.Rom:
|
||||||
var rom = datItem as Rom;
|
var rom = datItem as Rom;
|
||||||
xtw.WriteStartElement("file");
|
xtw.WriteStartElement("file");
|
||||||
xtw.WriteOptionalAttributeString("source", rom.Value);
|
|
||||||
|
// Filename has to be derived from both machine and item, if possible
|
||||||
|
string filename = rom.Name;
|
||||||
|
if (!string.IsNullOrWhiteSpace(rom.Machine?.Name) && !rom.Machine.Name.Equals("Default", StringComparison.OrdinalIgnoreCase))
|
||||||
|
filename = $"{rom.Machine.Name}/{filename}";
|
||||||
|
|
||||||
|
xtw.WriteRequiredAttributeString("name", filename);
|
||||||
|
xtw.WriteOptionalAttributeString("source", rom.ArchiveDotOrgSource);
|
||||||
|
|
||||||
xtw.WriteOptionalElementString("mtime", rom.Date);
|
xtw.WriteOptionalElementString("mtime", rom.Date);
|
||||||
xtw.WriteOptionalElementString("size", rom.Size?.ToString());
|
xtw.WriteOptionalElementString("size", rom.Size?.ToString());
|
||||||
xtw.WriteOptionalElementString("md5", rom.MD5?.ToLowerInvariant());
|
xtw.WriteOptionalElementString("md5", rom.MD5?.ToLowerInvariant());
|
||||||
xtw.WriteOptionalElementString("crc32", rom.CRC?.ToLowerInvariant());
|
xtw.WriteOptionalElementString("crc32", rom.CRC?.ToLowerInvariant());
|
||||||
xtw.WriteOptionalElementString("sha1", rom.SHA1?.ToLowerInvariant());
|
xtw.WriteOptionalElementString("sha1", rom.SHA1?.ToLowerInvariant());
|
||||||
//xtw.WriteOptionalElementString("format", rom.Format);
|
xtw.WriteOptionalElementString("format", rom.ArchiveDotOrgFormat);
|
||||||
//xtw.WriteOptionalElementString("original", rom.Original);
|
xtw.WriteOptionalElementString("original", rom.OriginalFilename);
|
||||||
//xtw.WriteOptionalElementString("rotation", rom.Rotation?.ToString());
|
xtw.WriteOptionalElementString("rotation", rom.Rotation?.ToString());
|
||||||
//xtw.WriteOptionalElementString("summation", rom.Summation);
|
xtw.WriteOptionalElementString("summation", rom.Summation);
|
||||||
|
|
||||||
// End file
|
// End file
|
||||||
xtw.WriteEndElement();
|
xtw.WriteEndElement();
|
||||||
|
|||||||
@@ -195,6 +195,48 @@ namespace SabreTools.DatItems.Formats
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Archive.org
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Source of file
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("ado_source", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
|
[XmlElement("ado_source")]
|
||||||
|
public string ArchiveDotOrgSource { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Archive.org recognized file format
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("ado_format", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
|
[XmlElement("ado_format")]
|
||||||
|
public string ArchiveDotOrgFormat { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Original filename
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("original_filename", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
|
[XmlElement("original_filename")]
|
||||||
|
public string OriginalFilename { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Image rotation
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// TODO: This might be Int32?
|
||||||
|
/// </remarks>
|
||||||
|
[JsonProperty("rotation", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
|
[XmlElement("rotation")]
|
||||||
|
public string Rotation { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Image rotation
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("summation", DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
|
[XmlElement("summation")]
|
||||||
|
public string Summation { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region AttractMode
|
#region AttractMode
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user