mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add conversion helpers, fix build
This commit is contained in:
@@ -65,6 +65,50 @@ namespace SabreTools.Core
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Conversion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a Disk to a Rom
|
||||||
|
/// </summary>
|
||||||
|
public static Rom? ConvertToRom(this Disk? disk)
|
||||||
|
{
|
||||||
|
// If the Disk is missing, we can't do anything
|
||||||
|
if (disk == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new Rom
|
||||||
|
{
|
||||||
|
[Rom.NameKey] = disk.ReadString(Disk.NameKey) + ".chd",
|
||||||
|
[Rom.MergeKey] = disk.ReadString(Disk.MergeKey),
|
||||||
|
[Rom.RegionKey] = disk.ReadString(Disk.RegionKey),
|
||||||
|
[Rom.StatusKey] = disk.ReadString(Disk.StatusKey),
|
||||||
|
[Rom.OptionalKey] = disk.ReadString(Disk.OptionalKey),
|
||||||
|
[Rom.MD5Key] = disk.ReadString(Disk.MD5Key),
|
||||||
|
[Rom.SHA1Key] = disk.ReadString(Disk.SHA1Key),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a Media to a Rom
|
||||||
|
/// </summary>
|
||||||
|
public static Rom? ConvertToRom(this Media? media)
|
||||||
|
{
|
||||||
|
// If the Media is missing, we can't do anything
|
||||||
|
if (media == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new Rom
|
||||||
|
{
|
||||||
|
[Rom.NameKey] = media.ReadString(Media.NameKey) + ".aaruf",
|
||||||
|
[Rom.MD5Key] = media.ReadString(Media.MD5Key),
|
||||||
|
[Rom.SHA1Key] = media.ReadString(Media.SHA1Key),
|
||||||
|
[Rom.SHA256Key] = media.ReadString(Media.SHA256Key),
|
||||||
|
[Rom.SpamSumKey] = media.ReadString(Media.SpamSumKey),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Equality Checking
|
#region Equality Checking
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -472,8 +516,5 @@ namespace SabreTools.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
// TODO: Add DatItem conversion extensions here
|
|
||||||
// TODO: Once done with the above, replace innards on each current model
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,9 +248,8 @@ namespace SabreTools.DatItems.Formats
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Rom ConvertToRom()
|
public Rom ConvertToRom()
|
||||||
{
|
{
|
||||||
var rom = new Rom()
|
var rom = new Rom(_disk.ConvertToRom())
|
||||||
{
|
{
|
||||||
Name = this.Name + ".chd",
|
|
||||||
ItemType = ItemType.Rom,
|
ItemType = ItemType.Rom,
|
||||||
DupeType = this.DupeType,
|
DupeType = this.DupeType,
|
||||||
|
|
||||||
@@ -258,14 +257,6 @@ namespace SabreTools.DatItems.Formats
|
|||||||
Source = this.Source?.Clone() as Source,
|
Source = this.Source?.Clone() as Source,
|
||||||
Remove = this.Remove,
|
Remove = this.Remove,
|
||||||
|
|
||||||
MergeTag = this.MergeTag,
|
|
||||||
Region = this.Region,
|
|
||||||
ItemStatus = this.ItemStatus,
|
|
||||||
Optional = this.Optional,
|
|
||||||
|
|
||||||
MD5 = this.MD5,
|
|
||||||
SHA1 = this.SHA1,
|
|
||||||
|
|
||||||
DataArea = new DataArea { Name = this.DiskArea?.Name },
|
DataArea = new DataArea { Name = this.DiskArea?.Name },
|
||||||
Part = this.Part,
|
Part = this.Part,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Xml.Serialization;
|
using System;
|
||||||
|
using System.Xml.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
using SabreTools.Core.Tools;
|
using SabreTools.Core.Tools;
|
||||||
@@ -104,7 +105,7 @@ namespace SabreTools.DatItems.Formats
|
|||||||
MD5 = TextHelper.ByteArrayToString(baseFile.MD5);
|
MD5 = TextHelper.ByteArrayToString(baseFile.MD5);
|
||||||
SHA1 = TextHelper.ByteArrayToString(baseFile.SHA1);
|
SHA1 = TextHelper.ByteArrayToString(baseFile.SHA1);
|
||||||
SHA256 = TextHelper.ByteArrayToString(baseFile.SHA256);
|
SHA256 = TextHelper.ByteArrayToString(baseFile.SHA256);
|
||||||
SpamSum = TextHelper.ByteArrayToString(baseFile.SpamSum);
|
SpamSum = System.Text.Encoding.UTF8.GetString(baseFile.SpamSum ?? Array.Empty<byte>());
|
||||||
|
|
||||||
ItemType = ItemType.Media;
|
ItemType = ItemType.Media;
|
||||||
DupeType = 0x00;
|
DupeType = 0x00;
|
||||||
@@ -142,7 +143,7 @@ namespace SabreTools.DatItems.Formats
|
|||||||
MD5 = TextHelper.StringToByteArray(this.MD5),
|
MD5 = TextHelper.StringToByteArray(this.MD5),
|
||||||
SHA1 = TextHelper.StringToByteArray(this.SHA1),
|
SHA1 = TextHelper.StringToByteArray(this.SHA1),
|
||||||
SHA256 = TextHelper.StringToByteArray(this.SHA256),
|
SHA256 = TextHelper.StringToByteArray(this.SHA256),
|
||||||
SpamSum = TextHelper.StringToByteArray(this.SpamSum),
|
SpamSum = System.Text.Encoding.UTF8.GetBytes(this.SpamSum ?? string.Empty),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ namespace SabreTools.DatItems.Formats
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Rom ConvertToRom()
|
public Rom ConvertToRom()
|
||||||
{
|
{
|
||||||
var rom = new Rom()
|
var rom = new Rom(_media.ConvertToRom())
|
||||||
{
|
{
|
||||||
ItemType = ItemType.Rom,
|
ItemType = ItemType.Rom,
|
||||||
DupeType = this.DupeType,
|
DupeType = this.DupeType,
|
||||||
@@ -160,12 +161,6 @@ namespace SabreTools.DatItems.Formats
|
|||||||
Machine = this.Machine?.Clone() as Machine,
|
Machine = this.Machine?.Clone() as Machine,
|
||||||
Source = this.Source?.Clone() as Source,
|
Source = this.Source?.Clone() as Source,
|
||||||
Remove = this.Remove,
|
Remove = this.Remove,
|
||||||
|
|
||||||
Name = this.Name + ".aif",
|
|
||||||
MD5 = this.MD5,
|
|
||||||
SHA1 = this.SHA1,
|
|
||||||
SHA256 = this.SHA256,
|
|
||||||
SpamSum = this.SpamSum,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return rom;
|
return rom;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Xml.Serialization;
|
using System;
|
||||||
|
using System.Xml.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Converters;
|
using Newtonsoft.Json.Converters;
|
||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
@@ -487,7 +488,7 @@ namespace SabreTools.DatItems.Formats
|
|||||||
SHA256 = TextHelper.ByteArrayToString(baseFile.SHA256);
|
SHA256 = TextHelper.ByteArrayToString(baseFile.SHA256);
|
||||||
SHA384 = TextHelper.ByteArrayToString(baseFile.SHA384);
|
SHA384 = TextHelper.ByteArrayToString(baseFile.SHA384);
|
||||||
SHA512 = TextHelper.ByteArrayToString(baseFile.SHA512);
|
SHA512 = TextHelper.ByteArrayToString(baseFile.SHA512);
|
||||||
SpamSum = TextHelper.ByteArrayToString(baseFile.SpamSum);
|
SpamSum = System.Text.Encoding.UTF8.GetString(baseFile.SpamSum ?? Array.Empty<byte>());
|
||||||
|
|
||||||
ItemType = ItemType.Rom;
|
ItemType = ItemType.Rom;
|
||||||
DupeType = 0x00;
|
DupeType = 0x00;
|
||||||
@@ -495,6 +496,18 @@ namespace SabreTools.DatItems.Formats
|
|||||||
Date = baseFile.Date;
|
Date = baseFile.Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a Rom object from the internal model
|
||||||
|
/// </summary>
|
||||||
|
public Rom(Models.Internal.Rom? rom)
|
||||||
|
{
|
||||||
|
_rom = rom ?? new Models.Internal.Rom();
|
||||||
|
|
||||||
|
ItemType = ItemType.Rom;
|
||||||
|
DupeType = 0x00;
|
||||||
|
ItemStatus = ItemStatus.None;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
@@ -536,7 +549,7 @@ namespace SabreTools.DatItems.Formats
|
|||||||
SHA256 = TextHelper.StringToByteArray(this.SHA256),
|
SHA256 = TextHelper.StringToByteArray(this.SHA256),
|
||||||
SHA384 = TextHelper.StringToByteArray(this.SHA384),
|
SHA384 = TextHelper.StringToByteArray(this.SHA384),
|
||||||
SHA512 = TextHelper.StringToByteArray(this.SHA512),
|
SHA512 = TextHelper.StringToByteArray(this.SHA512),
|
||||||
SpamSum = TextHelper.StringToByteArray(this.SpamSum),
|
SpamSum = System.Text.Encoding.UTF8.GetBytes(this.SpamSum ?? string.Empty),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
using SabreTools.Core;
|
|
||||||
using SabreTools.Core.Tools;
|
|
||||||
using Compress;
|
using Compress;
|
||||||
using Compress.ZipFile;
|
using Compress.ZipFile;
|
||||||
using NaturalSort;
|
using NaturalSort;
|
||||||
|
using SabreTools.Core;
|
||||||
|
using SabreTools.Core.Tools;
|
||||||
|
|
||||||
namespace SabreTools.FileTypes.Archives
|
namespace SabreTools.FileTypes.Archives
|
||||||
{
|
{
|
||||||
@@ -753,7 +752,7 @@ namespace SabreTools.FileTypes.Archives
|
|||||||
DateTime dt = DateTime.Now;
|
DateTime dt = DateTime.Now;
|
||||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt))
|
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||||
{
|
{
|
||||||
long msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
long msDosDateTime = DateTimeHelper.ConvertToMsDosTimeFormat(dt);
|
||||||
TimeStamps ts = new() { ModTime = msDosDateTime };
|
TimeStamps ts = new() { ModTime = msDosDateTime };
|
||||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, out writeStream, ts);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -875,7 +875,7 @@ namespace SabreTools.Test.Core
|
|||||||
[InlineData(FeatureStatus.NULL, 2)]
|
[InlineData(FeatureStatus.NULL, 2)]
|
||||||
[InlineData(FeatureType.NULL, 14)]
|
[InlineData(FeatureType.NULL, 14)]
|
||||||
[InlineData(ItemStatus.NULL, 7)]
|
[InlineData(ItemStatus.NULL, 7)]
|
||||||
[InlineData(ItemType.NULL, 51)]
|
[InlineData(ItemType.NULL, 54)]
|
||||||
[InlineData(LoadFlag.NULL, 14)]
|
[InlineData(LoadFlag.NULL, 14)]
|
||||||
[InlineData(LogLevel.VERBOSE, 4)]
|
[InlineData(LogLevel.VERBOSE, 4)]
|
||||||
[InlineData(MachineField.NULL, 68)]
|
[InlineData(MachineField.NULL, 68)]
|
||||||
|
|||||||
Reference in New Issue
Block a user