mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Wire up skeleton formats to DatItem
This commit is contained in:
@@ -169,6 +169,7 @@ namespace SabreTools.DatItems
|
|||||||
ItemType.Chip => new Chip(),
|
ItemType.Chip => new Chip(),
|
||||||
ItemType.Condition => new Condition(),
|
ItemType.Condition => new Condition(),
|
||||||
ItemType.Configuration => new Configuration(),
|
ItemType.Configuration => new Configuration(),
|
||||||
|
ItemType.Details => new Details(),
|
||||||
ItemType.Device => new Device(),
|
ItemType.Device => new Device(),
|
||||||
ItemType.DeviceReference => new DeviceReference(),
|
ItemType.DeviceReference => new DeviceReference(),
|
||||||
ItemType.DipSwitch => new DipSwitch(),
|
ItemType.DipSwitch => new DipSwitch(),
|
||||||
@@ -177,6 +178,7 @@ namespace SabreTools.DatItems
|
|||||||
ItemType.Driver => new Driver(),
|
ItemType.Driver => new Driver(),
|
||||||
ItemType.Extension => new Extension(),
|
ItemType.Extension => new Extension(),
|
||||||
ItemType.Feature => new Feature(),
|
ItemType.Feature => new Feature(),
|
||||||
|
ItemType.File => new Formats.File(),
|
||||||
ItemType.Info => new Info(),
|
ItemType.Info => new Info(),
|
||||||
ItemType.Instance => new Instance(),
|
ItemType.Instance => new Instance(),
|
||||||
ItemType.Location => new Location(),
|
ItemType.Location => new Location(),
|
||||||
@@ -187,6 +189,7 @@ namespace SabreTools.DatItems
|
|||||||
ItemType.Release => new Release(),
|
ItemType.Release => new Release(),
|
||||||
ItemType.Rom => new Rom(),
|
ItemType.Rom => new Rom(),
|
||||||
ItemType.Sample => new Sample(),
|
ItemType.Sample => new Sample(),
|
||||||
|
ItemType.Serials => new Serials(),
|
||||||
ItemType.SharedFeature => new SharedFeature(),
|
ItemType.SharedFeature => new SharedFeature(),
|
||||||
ItemType.Slot => new Slot(),
|
ItemType.Slot => new Slot(),
|
||||||
ItemType.SlotOption => new SlotOption(),
|
ItemType.SlotOption => new SlotOption(),
|
||||||
@@ -548,9 +551,12 @@ namespace SabreTools.DatItems
|
|||||||
if (file == null)
|
if (file == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// If we don't have a Disk, Media, or Rom, we skip checking for duplicates
|
// If we don't have a Disk, File, Media, or Rom, we skip checking for duplicates
|
||||||
if (file.ItemType != ItemType.Disk && file.ItemType != ItemType.Media && file.ItemType != ItemType.Rom)
|
if (file.ItemType != ItemType.Disk && file.ItemType != ItemType.File
|
||||||
|
&& file.ItemType != ItemType.Media && file.ItemType != ItemType.Rom)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// If it's a nodump, add and skip
|
// If it's a nodump, add and skip
|
||||||
if (file.ItemType == ItemType.Rom && (file as Rom).ItemStatus == ItemStatus.Nodump)
|
if (file.ItemType == ItemType.Rom && (file as Rom).ItemStatus == ItemStatus.Nodump)
|
||||||
@@ -592,6 +598,8 @@ namespace SabreTools.DatItems
|
|||||||
// Disks, Media, and Roms have more information to fill
|
// Disks, Media, and Roms have more information to fill
|
||||||
if (file.ItemType == ItemType.Disk)
|
if (file.ItemType == ItemType.Disk)
|
||||||
(saveditem as Disk).FillMissingInformation(file as Disk);
|
(saveditem as Disk).FillMissingInformation(file as Disk);
|
||||||
|
else if (file.ItemType == ItemType.File)
|
||||||
|
(saveditem as Formats.File).FillMissingInformation(file as Formats.File);
|
||||||
else if (file.ItemType == ItemType.Media)
|
else if (file.ItemType == ItemType.Media)
|
||||||
(saveditem as Media).FillMissingInformation(file as Media);
|
(saveditem as Media).FillMissingInformation(file as Media);
|
||||||
else if (file.ItemType == ItemType.Rom)
|
else if (file.ItemType == ItemType.Rom)
|
||||||
@@ -682,7 +690,8 @@ namespace SabreTools.DatItems
|
|||||||
{
|
{
|
||||||
staticLogger.Verbose($"Name duplicate found for '{datItemName}'");
|
staticLogger.Verbose($"Name duplicate found for '{datItemName}'");
|
||||||
|
|
||||||
if (datItem.ItemType == ItemType.Disk || datItem.ItemType == ItemType.Media || datItem.ItemType == ItemType.Rom)
|
if (datItem.ItemType == ItemType.Disk || datItem.ItemType == ItemType.File
|
||||||
|
|| datItem.ItemType == ItemType.Media || datItem.ItemType == ItemType.Rom)
|
||||||
{
|
{
|
||||||
datItemName += GetDuplicateSuffix(datItem);
|
datItemName += GetDuplicateSuffix(datItem);
|
||||||
lastrenamed ??= datItemName;
|
lastrenamed ??= datItemName;
|
||||||
@@ -731,6 +740,8 @@ namespace SabreTools.DatItems
|
|||||||
{
|
{
|
||||||
if (datItem.ItemType == ItemType.Disk)
|
if (datItem.ItemType == ItemType.Disk)
|
||||||
return (datItem as Disk).GetDuplicateSuffix();
|
return (datItem as Disk).GetDuplicateSuffix();
|
||||||
|
else if (datItem.ItemType == ItemType.File)
|
||||||
|
return (datItem as Formats.File).GetDuplicateSuffix();
|
||||||
else if (datItem.ItemType == ItemType.Media)
|
else if (datItem.ItemType == ItemType.Media)
|
||||||
return (datItem as Media).GetDuplicateSuffix();
|
return (datItem as Media).GetDuplicateSuffix();
|
||||||
else if (datItem.ItemType == ItemType.Rom)
|
else if (datItem.ItemType == ItemType.Rom)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using System.Xml.Serialization;
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using SabreTools.Core;
|
using SabreTools.Core;
|
||||||
using SabreTools.Core.Tools;
|
using SabreTools.Core.Tools;
|
||||||
|
using SabreTools.FileTypes;
|
||||||
|
|
||||||
// TODO: Add item mappings for all fields
|
// TODO: Add item mappings for all fields
|
||||||
namespace SabreTools.DatItems.Formats
|
namespace SabreTools.DatItems.Formats
|
||||||
@@ -104,6 +105,21 @@ namespace SabreTools.DatItems.Formats
|
|||||||
ItemType = ItemType.File;
|
ItemType = ItemType.File;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a File object from a BaseFile
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="baseFile"></param>
|
||||||
|
public File(BaseFile baseFile)
|
||||||
|
{
|
||||||
|
_crc = baseFile.CRC;
|
||||||
|
_md5 = baseFile.MD5;
|
||||||
|
_sha1 = baseFile.SHA1;
|
||||||
|
_sha256 = baseFile.SHA256;
|
||||||
|
|
||||||
|
ItemType = ItemType.File;
|
||||||
|
DupeType = 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Cloning Methods
|
#region Cloning Methods
|
||||||
@@ -131,6 +147,46 @@ namespace SabreTools.DatItems.Formats
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert Disk object to a BaseFile
|
||||||
|
/// </summary>
|
||||||
|
public BaseFile ConvertToBaseFile()
|
||||||
|
{
|
||||||
|
return new BaseFile()
|
||||||
|
{
|
||||||
|
Parent = this.Machine?.Name,
|
||||||
|
CRC = this._crc,
|
||||||
|
MD5 = this._md5,
|
||||||
|
SHA1 = this._sha1,
|
||||||
|
SHA256 = this._sha256,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Convert a disk to the closest Rom approximation
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Rom ConvertToRom()
|
||||||
|
{
|
||||||
|
var rom = new Rom()
|
||||||
|
{
|
||||||
|
Name = $"{this.Id}.{this.Extension}",
|
||||||
|
ItemType = ItemType.Rom,
|
||||||
|
DupeType = this.DupeType,
|
||||||
|
|
||||||
|
Machine = this.Machine.Clone() as Machine,
|
||||||
|
Source = this.Source.Clone() as Source,
|
||||||
|
Remove = this.Remove,
|
||||||
|
|
||||||
|
CRC = this.CRC,
|
||||||
|
MD5 = this.MD5,
|
||||||
|
SHA1 = this.SHA1,
|
||||||
|
SHA256 = this.SHA256,
|
||||||
|
};
|
||||||
|
|
||||||
|
return rom;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Comparision Methods
|
#region Comparision Methods
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace SabreTools.DatTools
|
|||||||
string foundpath = null;
|
string foundpath = null;
|
||||||
foreach (string directory in directories)
|
foreach (string directory in directories)
|
||||||
{
|
{
|
||||||
if (File.Exists(Path.Combine(directory, subpath)))
|
if (System.IO.File.Exists(Path.Combine(directory, subpath)))
|
||||||
{
|
{
|
||||||
foundpath = Path.Combine(directory, subpath);
|
foundpath = Path.Combine(directory, subpath);
|
||||||
break;
|
break;
|
||||||
@@ -143,15 +143,17 @@ namespace SabreTools.DatTools
|
|||||||
// Otherwise, we rebuild that file to all locations that we need to
|
// Otherwise, we rebuild that file to all locations that we need to
|
||||||
bool usedInternally;
|
bool usedInternally;
|
||||||
if (datFile.Items[hash][0].ItemType == ItemType.Disk)
|
if (datFile.Items[hash][0].ItemType == ItemType.Disk)
|
||||||
usedInternally = RebuildIndividualFile(datFile, new Disk(fileinfo), foundpath, outDir, date, inverse, outputFormat, false /* isZip */);
|
usedInternally = RebuildIndividualFile(datFile, new Disk(fileinfo), foundpath, outDir, date, inverse, outputFormat, isZip: false);
|
||||||
|
else if (datFile.Items[hash][0].ItemType == ItemType.File)
|
||||||
|
usedInternally = RebuildIndividualFile(datFile, new DatItems.Formats.File(fileinfo), foundpath, outDir, date, inverse, outputFormat, isZip: false);
|
||||||
else if (datFile.Items[hash][0].ItemType == ItemType.Media)
|
else if (datFile.Items[hash][0].ItemType == ItemType.Media)
|
||||||
usedInternally = RebuildIndividualFile(datFile, new Media(fileinfo), foundpath, outDir, date, inverse, outputFormat, false /* isZip */);
|
usedInternally = RebuildIndividualFile(datFile, new Media(fileinfo), foundpath, outDir, date, inverse, outputFormat, isZip: false);
|
||||||
else
|
else
|
||||||
usedInternally = RebuildIndividualFile(datFile, new Rom(fileinfo), foundpath, outDir, date, inverse, outputFormat, false /* isZip */);
|
usedInternally = RebuildIndividualFile(datFile, new Rom(fileinfo), foundpath, outDir, date, inverse, outputFormat, isZip: false);
|
||||||
|
|
||||||
// If we are supposed to delete the depot file, do so
|
// If we are supposed to delete the depot file, do so
|
||||||
if (delete && usedInternally)
|
if (delete && usedInternally)
|
||||||
File.Delete(foundpath);
|
System.IO.File.Delete(foundpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
watch.Stop();
|
watch.Stop();
|
||||||
@@ -219,14 +221,14 @@ namespace SabreTools.DatTools
|
|||||||
foreach (string input in inputs)
|
foreach (string input in inputs)
|
||||||
{
|
{
|
||||||
// If the input is a file
|
// If the input is a file
|
||||||
if (File.Exists(input))
|
if (System.IO.File.Exists(input))
|
||||||
{
|
{
|
||||||
logger.User($"Checking file: {input}");
|
logger.User($"Checking file: {input}");
|
||||||
bool rebuilt = RebuildGenericHelper(datFile, input, outDir, quickScan, date, inverse, outputFormat, asFiles);
|
bool rebuilt = RebuildGenericHelper(datFile, input, outDir, quickScan, date, inverse, outputFormat, asFiles);
|
||||||
|
|
||||||
// If we are supposed to delete the file, do so
|
// If we are supposed to delete the file, do so
|
||||||
if (delete && rebuilt)
|
if (delete && rebuilt)
|
||||||
File.Delete(input);
|
System.IO.File.Delete(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the input is a directory
|
// If the input is a directory
|
||||||
@@ -240,7 +242,7 @@ namespace SabreTools.DatTools
|
|||||||
|
|
||||||
// If we are supposed to delete the file, do so
|
// If we are supposed to delete the file, do so
|
||||||
if (delete && rebuilt)
|
if (delete && rebuilt)
|
||||||
File.Delete(input);
|
System.IO.File.Delete(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -300,7 +302,7 @@ namespace SabreTools.DatTools
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the entries list is null, we encountered an error or have a file and should scan externally
|
// If the entries list is null, we encountered an error or have a file and should scan externally
|
||||||
if (entries == null && File.Exists(file))
|
if (entries == null && System.IO.File.Exists(file))
|
||||||
{
|
{
|
||||||
BaseFile internalFileInfo = BaseFile.GetInfo(file, asFiles: asFiles);
|
BaseFile internalFileInfo = BaseFile.GetInfo(file, asFiles: asFiles);
|
||||||
|
|
||||||
@@ -361,9 +363,11 @@ namespace SabreTools.DatTools
|
|||||||
outputFormat = OutputFormat.Folder;
|
outputFormat = OutputFormat.Folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have a Disk or Media, change it into a Rom for later use
|
// If we have a Disk, File, or Media, change it into a Rom for later use
|
||||||
if (datItem.ItemType == ItemType.Disk)
|
if (datItem.ItemType == ItemType.Disk)
|
||||||
datItem = (datItem as Disk).ConvertToRom();
|
datItem = (datItem as Disk).ConvertToRom();
|
||||||
|
else if (datItem.ItemType == ItemType.File)
|
||||||
|
datItem = (datItem as DatItems.Formats.File).ConvertToRom();
|
||||||
else if (datItem.ItemType == ItemType.Media)
|
else if (datItem.ItemType == ItemType.Media)
|
||||||
datItem = (datItem as Media).ConvertToRom();
|
datItem = (datItem as Media).ConvertToRom();
|
||||||
|
|
||||||
@@ -558,7 +562,7 @@ namespace SabreTools.DatTools
|
|||||||
// Now copy the file over
|
// Now copy the file over
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Copy(file, outDir);
|
System.IO.File.Copy(file, outDir);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -602,7 +606,7 @@ namespace SabreTools.DatTools
|
|||||||
// Now copy the file over
|
// Now copy the file over
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Copy(file, outDir);
|
System.IO.File.Copy(file, outDir);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -637,7 +641,7 @@ namespace SabreTools.DatTools
|
|||||||
// Otherwise, just open the filestream
|
// Otherwise, just open the filestream
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stream = File.OpenRead(file);
|
stream = System.IO.File.OpenRead(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the stream is null, then continue
|
// If the stream is null, then continue
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ namespace SabreTools.DatTools
|
|||||||
string foundpath = null;
|
string foundpath = null;
|
||||||
foreach (string directory in directories)
|
foreach (string directory in directories)
|
||||||
{
|
{
|
||||||
if (File.Exists(Path.Combine(directory, subpath)))
|
if (System.IO.File.Exists(Path.Combine(directory, subpath)))
|
||||||
{
|
{
|
||||||
foundpath = Path.Combine(directory, subpath);
|
foundpath = Path.Combine(directory, subpath);
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user