mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] More work on conversion
This commit is contained in:
@@ -25,13 +25,40 @@ namespace SabreTools.Helper
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Intermediate struct for holding and processing Hash data (NEW SYSTEM)
|
/// Intermediate struct for holding and processing Hash data (NEW SYSTEM)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct HashData
|
public struct HashData : IEquatable<HashData>
|
||||||
{
|
{
|
||||||
public long Size;
|
public long Size;
|
||||||
public byte[] CRC;
|
public byte[] CRC;
|
||||||
public byte[] MD5;
|
public byte[] MD5;
|
||||||
public byte[] SHA1;
|
public byte[] SHA1;
|
||||||
public List<RomData> Roms;
|
public List<RomData> Roms;
|
||||||
|
|
||||||
|
public bool Equals(HashData other)
|
||||||
|
{
|
||||||
|
return this.Equals(other, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(HashData other, bool IsDisk)
|
||||||
|
{
|
||||||
|
bool equals = false;
|
||||||
|
|
||||||
|
if (!IsDisk &&
|
||||||
|
((this.MD5 == null || other.MD5 == null) || this.MD5 == other.MD5) &&
|
||||||
|
((this.SHA1 == null || other.SHA1 == null) || this.SHA1 == other.SHA1))
|
||||||
|
{
|
||||||
|
equals = true;
|
||||||
|
}
|
||||||
|
else if (!IsDisk &&
|
||||||
|
(this.Size == other.Size) &&
|
||||||
|
((this.CRC == null || other.CRC != null) || this.CRC == other.CRC) &&
|
||||||
|
((this.MD5 == null || other.MD5 == null) || this.MD5 == other.MD5) &&
|
||||||
|
((this.SHA1 == null || other.SHA1 == null) || this.SHA1 == other.SHA1))
|
||||||
|
{
|
||||||
|
equals = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return equals;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -853,9 +853,9 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="output">Output directory to build to</param>
|
/// <param name="output">Output directory to build to</param>
|
||||||
/// <param name="hash">RomData representing the new information</param>
|
/// <param name="hash">RomData representing the new information</param>
|
||||||
/// <remarks>This uses the new system that is not implemented anywhere yet</remarks>
|
/// <remarks>This uses the new system that is not implemented anywhere yet</remarks>
|
||||||
public static void WriteToArchive(string input, string output, RomData rom, int machineIndex)
|
public static void WriteToArchive(string input, string output, RomData rom)
|
||||||
{
|
{
|
||||||
string archiveFileName = Path.Combine(output, rom.Machines[machineIndex] + ".zip");
|
string archiveFileName = Path.Combine(output, rom.Machine + ".zip");
|
||||||
|
|
||||||
ZipArchive outarchive = null;
|
ZipArchive outarchive = null;
|
||||||
try
|
try
|
||||||
@@ -904,9 +904,9 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="output">Output directory to build to</param>
|
/// <param name="output">Output directory to build to</param>
|
||||||
/// <param name="rom">RomData representing the new information</param>
|
/// <param name="rom">RomData representing the new information</param>
|
||||||
/// <remarks>This uses the new system that is not implemented anywhere yet</remarks>
|
/// <remarks>This uses the new system that is not implemented anywhere yet</remarks>
|
||||||
public static void WriteToManagedArchive(string input, string output, RomData rom, int machineIndex)
|
public static void WriteToManagedArchive(string input, string output, RomData rom)
|
||||||
{
|
{
|
||||||
string archiveFileName = Path.Combine(output, rom.Machines[machineIndex] + ".zip");
|
string archiveFileName = Path.Combine(output, rom.Machine + ".zip");
|
||||||
|
|
||||||
// Delete an empty file first
|
// Delete an empty file first
|
||||||
if (File.Exists(archiveFileName) && new FileInfo(archiveFileName).Length == 0)
|
if (File.Exists(archiveFileName) && new FileInfo(archiveFileName).Length == 0)
|
||||||
@@ -1013,18 +1013,16 @@ namespace SabreTools.Helper
|
|||||||
+ (size == 0 ? reader.Entry.Size : size) + ", "
|
+ (size == 0 ? reader.Entry.Size : size) + ", "
|
||||||
+ (crc == null ? BitConverter.GetBytes(reader.Entry.Crc) : crc));
|
+ (crc == null ? BitConverter.GetBytes(reader.Entry.Crc) : crc));
|
||||||
|
|
||||||
MachineData tempmachine = new MachineData
|
|
||||||
{
|
|
||||||
Name = gamename,
|
|
||||||
Description = gamename,
|
|
||||||
};
|
|
||||||
RomData temprom = new RomData
|
RomData temprom = new RomData
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Type = ItemType.Rom,
|
||||||
Name = reader.Entry.Key,
|
Name = reader.Entry.Key,
|
||||||
Machines = new List<MachineData>(),
|
Machine = new MachineData
|
||||||
|
{
|
||||||
|
Name = gamename,
|
||||||
|
Description = gamename,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
temprom.Machines.Add(tempmachine);
|
|
||||||
HashData temphash = new HashData
|
HashData temphash = new HashData
|
||||||
{
|
{
|
||||||
Size = (size == 0 ? reader.Entry.Size : size),
|
Size = (size == 0 ? reader.Entry.Size : size),
|
||||||
@@ -1105,24 +1103,22 @@ namespace SabreTools.Helper
|
|||||||
// Now convert the size and get the right position
|
// Now convert the size and get the right position
|
||||||
long extractedsize = (long)BitConverter.ToUInt64(headersz.Reverse().ToArray(), 0);
|
long extractedsize = (long)BitConverter.ToUInt64(headersz.Reverse().ToArray(), 0);
|
||||||
|
|
||||||
MachineData tempmachine = new MachineData
|
|
||||||
{
|
|
||||||
Name = sha1,
|
|
||||||
Description = sha1,
|
|
||||||
};
|
|
||||||
RomData temprom = new RomData
|
RomData temprom = new RomData
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Type = ItemType.Rom,
|
||||||
Name = sha1,
|
Name = sha1,
|
||||||
Machines = new List<MachineData>(),
|
Machine = new MachineData
|
||||||
|
{
|
||||||
|
Name = sha1,
|
||||||
|
Description = sha1,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
temprom.Machines.Add(tempmachine);
|
|
||||||
HashData temphash = new HashData
|
HashData temphash = new HashData
|
||||||
{
|
{
|
||||||
Size = extractedsize,
|
Size = extractedsize,
|
||||||
CRC = headercrc,
|
CRC = headercrc,
|
||||||
MD5 = headermd5,
|
MD5 = headermd5,
|
||||||
SHA1 = StringToByteArray(sha1),
|
SHA1 = Style.StringToByteArray(sha1),
|
||||||
Roms = new List<RomData>(),
|
Roms = new List<RomData>(),
|
||||||
};
|
};
|
||||||
temphash.Roms.Add(temprom);
|
temphash.Roms.Add(temprom);
|
||||||
|
|||||||
@@ -2389,19 +2389,17 @@ namespace SabreTools.Helper
|
|||||||
// If we're in cleaning mode, sanitize the game name
|
// If we're in cleaning mode, sanitize the game name
|
||||||
gamename = (clean ? Style.CleanGameName(gamename) : gamename);
|
gamename = (clean ? Style.CleanGameName(gamename) : gamename);
|
||||||
|
|
||||||
MachineData machineData = new MachineData
|
RomData romData = new RomData
|
||||||
|
{
|
||||||
|
Type = (line.Trim().StartsWith("disk (") ? ItemType.Disk : ItemType.Rom),
|
||||||
|
Machine = new MachineData
|
||||||
{
|
{
|
||||||
Name = gamename,
|
Name = gamename,
|
||||||
Description = gamedesc,
|
Description = gamedesc,
|
||||||
SystemID = sysid,
|
SystemID = sysid,
|
||||||
SourceID = srcid,
|
SourceID = srcid,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
RomData romData = new RomData
|
|
||||||
{
|
|
||||||
Type = (line.Trim().StartsWith("disk (") ? ItemType.Disk : ItemType.Rom),
|
|
||||||
Machines = new List<MachineData>(),
|
|
||||||
};
|
|
||||||
romData.Machines.Add(machineData);
|
|
||||||
HashData hashData = new HashData
|
HashData hashData = new HashData
|
||||||
{
|
{
|
||||||
Roms = new List<RomData>(),
|
Roms = new List<RomData>(),
|
||||||
@@ -2788,7 +2786,10 @@ namespace SabreTools.Helper
|
|||||||
// If we're in cleaning mode, sanitize the game name
|
// If we're in cleaning mode, sanitize the game name
|
||||||
rominfo[3] = (clean ? Style.CleanGameName(rominfo[3]) : rominfo[3]);
|
rominfo[3] = (clean ? Style.CleanGameName(rominfo[3]) : rominfo[3]);
|
||||||
|
|
||||||
MachineData machineData = new MachineData
|
RomData romData = new RomData
|
||||||
|
{
|
||||||
|
Name = rominfo[5],
|
||||||
|
Machine = new MachineData
|
||||||
{
|
{
|
||||||
Name = rominfo[3],
|
Name = rominfo[3],
|
||||||
Description = rominfo[4],
|
Description = rominfo[4],
|
||||||
@@ -2796,13 +2797,8 @@ namespace SabreTools.Helper
|
|||||||
RomOf = rominfo[1],
|
RomOf = rominfo[1],
|
||||||
SystemID = sysid,
|
SystemID = sysid,
|
||||||
SourceID = srcid,
|
SourceID = srcid,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
RomData romData = new RomData
|
|
||||||
{
|
|
||||||
Name = rominfo[5],
|
|
||||||
Machines = new List<MachineData>(),
|
|
||||||
};
|
|
||||||
romData.Machines.Add(machineData);
|
|
||||||
HashData hashData = new HashData
|
HashData hashData = new HashData
|
||||||
{
|
{
|
||||||
Size = Int64.Parse(rominfo[7]),
|
Size = Int64.Parse(rominfo[7]),
|
||||||
@@ -2900,18 +2896,16 @@ namespace SabreTools.Helper
|
|||||||
// If we're in cleaning mode, sanitize the game name
|
// If we're in cleaning mode, sanitize the game name
|
||||||
tempgame = (clean ? Style.CleanGameName(tempgame) : tempgame);
|
tempgame = (clean ? Style.CleanGameName(tempgame) : tempgame);
|
||||||
|
|
||||||
MachineData machineData = new MachineData
|
|
||||||
{
|
|
||||||
Name = tempgame,
|
|
||||||
Description = tempgame,
|
|
||||||
};
|
|
||||||
RomData romData = new RomData
|
RomData romData = new RomData
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Type = ItemType.Rom,
|
||||||
Name = "null",
|
Name = "null",
|
||||||
Machines = new List<MachineData>(),
|
Machine = new MachineData
|
||||||
|
{
|
||||||
|
Name = tempgame,
|
||||||
|
Description = tempgame,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
romData.Machines.Add(machineData);
|
|
||||||
HashData hashData = new HashData
|
HashData hashData = new HashData
|
||||||
{
|
{
|
||||||
Size = -1,
|
Size = -1,
|
||||||
@@ -3341,23 +3335,21 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the new values to add
|
// Get the new values to add
|
||||||
MachineData machineData = new MachineData
|
|
||||||
{
|
|
||||||
Name = tempname,
|
|
||||||
Description = gamedesc,
|
|
||||||
SystemID = sysid,
|
|
||||||
System = filename,
|
|
||||||
SourceID = srcid,
|
|
||||||
};
|
|
||||||
RomData romData = new RomData
|
RomData romData = new RomData
|
||||||
{
|
{
|
||||||
Name = subreader.GetAttribute("name"),
|
Name = subreader.GetAttribute("name"),
|
||||||
Type = (subreader.Name.ToLowerInvariant() == "disk" ? ItemType.Disk : ItemType.Rom),
|
Type = (subreader.Name.ToLowerInvariant() == "disk" ? ItemType.Disk : ItemType.Rom),
|
||||||
Nodump = nodump,
|
Nodump = nodump,
|
||||||
Date = date,
|
Date = date,
|
||||||
Machines = new List<MachineData>(),
|
Machine = new MachineData
|
||||||
|
{
|
||||||
|
Name = tempname,
|
||||||
|
Description = gamedesc,
|
||||||
|
SystemID = sysid,
|
||||||
|
System = filename,
|
||||||
|
SourceID = srcid,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
romData.Machines.Add(machineData);
|
|
||||||
HashData hashData = new HashData
|
HashData hashData = new HashData
|
||||||
{
|
{
|
||||||
Size = size,
|
Size = size,
|
||||||
@@ -3396,18 +3388,16 @@ namespace SabreTools.Helper
|
|||||||
// If we're in cleaning mode, sanitize the game name
|
// If we're in cleaning mode, sanitize the game name
|
||||||
tempname = (clean ? Style.CleanGameName(tempname.Split(Path.DirectorySeparatorChar)) : tempname);
|
tempname = (clean ? Style.CleanGameName(tempname.Split(Path.DirectorySeparatorChar)) : tempname);
|
||||||
|
|
||||||
MachineData machineData = new MachineData
|
|
||||||
{
|
|
||||||
Name = tempname,
|
|
||||||
Description = tempname,
|
|
||||||
};
|
|
||||||
RomData romData = new RomData
|
RomData romData = new RomData
|
||||||
{
|
{
|
||||||
Type = ItemType.Rom,
|
Type = ItemType.Rom,
|
||||||
Name = "null",
|
Name = "null",
|
||||||
Machines = new List<MachineData>(),
|
Machine = new MachineData
|
||||||
|
{
|
||||||
|
Name = tempname,
|
||||||
|
Description = tempname,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
romData.Machines.Add(machineData);
|
|
||||||
HashData hashData = new HashData
|
HashData hashData = new HashData
|
||||||
{
|
{
|
||||||
Size = -1,
|
Size = -1,
|
||||||
@@ -3568,22 +3558,20 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the new values to add
|
// Get the new values to add
|
||||||
MachineData machineData = new MachineData
|
|
||||||
{
|
|
||||||
Name = tempname,
|
|
||||||
SystemID = sysid,
|
|
||||||
System = filename,
|
|
||||||
SourceID = srcid,
|
|
||||||
};
|
|
||||||
RomData romData = new RomData
|
RomData romData = new RomData
|
||||||
{
|
{
|
||||||
Name = xtr.GetAttribute("name"),
|
Name = xtr.GetAttribute("name"),
|
||||||
Type = (xtr.GetAttribute("type").ToLowerInvariant() == "disk" ? ItemType.Disk : ItemType.Rom),
|
Type = (xtr.GetAttribute("type").ToLowerInvariant() == "disk" ? ItemType.Disk : ItemType.Rom),
|
||||||
Nodump = nodump,
|
Nodump = nodump,
|
||||||
Date = date,
|
Date = date,
|
||||||
Machines = new List<MachineData>(),
|
Machine = new MachineData
|
||||||
|
{
|
||||||
|
Name = tempname,
|
||||||
|
SystemID = sysid,
|
||||||
|
System = filename,
|
||||||
|
SourceID = srcid,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
romData.Machines.Add(machineData);
|
|
||||||
HashData hashData = new HashData
|
HashData hashData = new HashData
|
||||||
{
|
{
|
||||||
Size = size,
|
Size = size,
|
||||||
@@ -3682,7 +3670,7 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<Rom> temp = new List<Rom>();
|
List<HashData> temp = new List<HashData>();
|
||||||
temp.Add(hash);
|
temp.Add(hash);
|
||||||
sortable.Add(newkey, temp);
|
sortable.Add(newkey, temp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -350,6 +350,26 @@ namespace SabreTools.Helper
|
|||||||
return dupefound;
|
return dupefound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determine if a file is a duplicate using partial matching logic
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">Hash to check for duplicate status</param>
|
||||||
|
/// <param name="lasthash">Hash to use as a baseline</param>
|
||||||
|
/// <param name="logger">Logger object for console and/or file output</param>
|
||||||
|
/// <returns>True if the hashes are duplicates, false otherwise</returns>
|
||||||
|
public static bool IsDuplicate(HashData hash, HashData lasthash, Logger logger)
|
||||||
|
{
|
||||||
|
bool dupefound = hash.Equals(lasthash);
|
||||||
|
|
||||||
|
// More wonderful SHA-1 logging that has to be done
|
||||||
|
if (hash.SHA1 == lasthash.SHA1 && hash.Size != lasthash.Size)
|
||||||
|
{
|
||||||
|
logger.User("SHA-1 mismatch - Hash: " + hash.SHA1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return dupefound;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Return the duplicate status of two roms
|
/// Return the duplicate status of two roms
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -396,6 +416,52 @@ namespace SabreTools.Helper
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Return the duplicate status of two hashes
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="hash">Current hash to check</param>
|
||||||
|
/// <param name="lasthash">Last hash to check against</param>
|
||||||
|
/// <param name="logger">Logger object for console and/or file output</param>
|
||||||
|
/// <returns>The DupeType corresponding to the relationship between the two</returns>
|
||||||
|
public static DupeType GetDuplicateStatus(HashData hash, HashData lasthash, Logger logger)
|
||||||
|
{
|
||||||
|
DupeType output = DupeType.None;
|
||||||
|
|
||||||
|
// If we don't have a duplicate at all, return none
|
||||||
|
if (!IsDuplicate(hash, lasthash, logger))
|
||||||
|
{
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the duplicate is external already or should be, set it
|
||||||
|
if (lasthash.Roms[0].DupeType >= DupeType.ExternalHash || lasthash.Roms[0].Machine.SystemID != hash.Roms[0].Machine.SystemID || lasthash.Roms[0].Machine.SourceID != hash.Roms[0].Machine.SourceID)
|
||||||
|
{
|
||||||
|
if (lasthash.Roms[0].Machine.Name == hash.Roms[0].Machine.Name && lasthash.Roms[0].Name == hash.Roms[0].Name)
|
||||||
|
{
|
||||||
|
output = DupeType.ExternalAll;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output = DupeType.ExternalHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, it's considered an internal dupe
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (lasthash.Roms[0].Machine.Name == hash.Roms[0].Machine.Name && lasthash.Roms[0].Name == hash.Roms[0].Name)
|
||||||
|
{
|
||||||
|
output = DupeType.InternalAll;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output = DupeType.InternalHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sort a list of RomData objects by SystemID, SourceID, Game, and Name (in order)
|
/// Sort a list of RomData objects by SystemID, SourceID, Game, and Name (in order)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user