diff --git a/SabreTools.Helper/Data/Build.cs b/SabreTools.Helper/Data/Build.cs index f7f11326..0323efe2 100644 --- a/SabreTools.Helper/Data/Build.cs +++ b/SabreTools.Helper/Data/Build.cs @@ -230,7 +230,7 @@ namespace SabreTools.Helper.Data //helptext.Add(" -trar Enable TorrentRAR output"); //helptext.Add(" -txz Enable TorrentXZ output"); helptext.Add(" -tzip Enable TorrentZip output"); - //helptext.Add(" -h=, --header= Set a header skipper to use, blank means all"); + helptext.Add(" -h=, --header= Set a header skipper to use, blank means all"); helptext.Add(" -7z={1} Set scanning level for 7z archives"); helptext.Add(" -gz={2} Set scanning level for GZip archives"); helptext.Add(" -rar={2} Set scanning level for RAR archives"); diff --git a/SabreTools.Helper/Dats/Partials/DatFile.Rebuild.cs b/SabreTools.Helper/Dats/Partials/DatFile.Rebuild.cs index e3dd1e88..1c48b1e2 100644 --- a/SabreTools.Helper/Dats/Partials/DatFile.Rebuild.cs +++ b/SabreTools.Helper/Dats/Partials/DatFile.Rebuild.cs @@ -355,16 +355,6 @@ namespace SabreTools.Helper.Dats break; } } - - // And now clear the temp folder to get rid of any transient files if we unzipped - if (isZip) - { - try - { - Directory.Delete(tempDir, true); - } - catch { } - } } // If we have no duplicates and we're filtering, rebuild it @@ -401,7 +391,7 @@ namespace SabreTools.Helper.Dats item.Machine.Description = machinename; } - logger.User("Matches found for '" + file + "', rebuilding accordingly..."); + logger.User("No matches found for '" + file + "', rebuilding accordingly from inverse flag..."); // Now rebuild to the output file switch (outputFormat) @@ -447,18 +437,117 @@ namespace SabreTools.Helper.Dats rebuilt &= ArchiveTools.WriteTorrentZip(file, outDir, item, logger, date: date); break; } + } - // And now clear the temp folder to get rid of any transient files if we unzipped - if (isZip) + // Now we want to take care of headers, if applicable + if (headerToCheckAgainst != null) + { + // Check to see if we have a matching header first + SkipperRule rule = Skipper.GetMatchingRule(file, Path.GetFileNameWithoutExtension(headerToCheckAgainst), logger); + + // If there's a match, create the new file to write + if (rule.Tests != null && rule.Tests.Count != 0) { - try + // If the file could be transformed correctly + if (rule.TransformFile(file, file + ".new", logger)) { - Directory.Delete(tempDir, true); + // Get the file informations that we will be using + Rom headerless = FileTools.GetFileInfo(file + ".new", logger); + + // Find if the file has duplicates in the DAT + hasDuplicates = headerless.HasDuplicates(this, logger); + + // If it has duplicates and we're not filtering, rebuild it + if (hasDuplicates && !inverse) + { + // Get the list of duplicates to rebuild to + List dupes = headerless.GetDuplicates(this, logger, remove: updateDat); + + // If we don't have any duplicates, continue + if (dupes.Count == 0) + { + return rebuilt; + } + + logger.User("Headerless matches found for '" + file + "', rebuilding accordingly..."); + rebuilt = true; + + // Now loop through the list and rebuild accordingly + foreach (Rom item in dupes) + { + // Create a headered item to use as well + Rom headeredItem = (Rom)item.Clone(); + headeredItem.Name += "_" + headeredItem.CRC; + + switch (outputFormat) + { + case OutputFormat.Folder: + string outfile = Path.Combine(outDir, Style.RemovePathUnsafeCharacters(item.Machine.Name), item.Name); + string headeredOutfile = Path.Combine(outDir, Style.RemovePathUnsafeCharacters(headeredItem.Machine.Name), headeredItem.Name); + + // Make sure the output folder is created + Directory.CreateDirectory(Path.GetDirectoryName(outfile)); + + // Now copy the files over + try + { + File.Copy(file + ".new", outfile); + if (date && !String.IsNullOrEmpty(item.Date)) + { + File.SetCreationTime(outfile, DateTime.Parse(item.Date)); + } + + File.Copy(file, headeredOutfile); + if (date && !String.IsNullOrEmpty(headeredItem.Date)) + { + File.SetCreationTime(outfile, DateTime.Parse(headeredItem.Date)); + } + + rebuilt &= true; + } + catch + { + rebuilt = false; + } + + break; + case OutputFormat.TapeArchive: + rebuilt &= ArchiveTools.WriteTAR(file + ".new", outDir, item, logger, date: date); + rebuilt &= ArchiveTools.WriteTAR(file, outDir, headeredItem, logger, date: date); + break; + case OutputFormat.Torrent7Zip: + break; + case OutputFormat.TorrentGzip: + rebuilt &= ArchiveTools.WriteTorrentGZ(file + ".new", outDir, romba, logger); + rebuilt &= ArchiveTools.WriteTorrentGZ(file, outDir, romba, logger); + break; + case OutputFormat.TorrentLrzip: + break; + case OutputFormat.TorrentRar: + break; + case OutputFormat.TorrentXZ: + break; + case OutputFormat.TorrentZip: + rebuilt &= ArchiveTools.WriteTorrentZip(file + ".new", outDir, item, logger, date: date); + rebuilt &= ArchiveTools.WriteTorrentZip(file, outDir, headeredItem, logger, date: date); + break; + } + } + } } - catch { } } } + // And now clear the temp folder to get rid of any transient files if we unzipped + if (isZip) + { + try + { + Directory.Delete(tempDir, true); + } + catch { } + } + return rebuilt; } diff --git a/SabreTools.Helper/README.1ST b/SabreTools.Helper/README.1ST index 36ecf43c..7258daea 100644 --- a/SabreTools.Helper/README.1ST +++ b/SabreTools.Helper/README.1ST @@ -461,7 +461,7 @@ Options: This is primarily used by external tool RomVault (http://www.romvault.com/) and is already widely used. - -h=, --header= Remove headers from hash calculations [NOT IMPLEMENTED] + -h=, --header= Remove headers from hash calculations If this is set, then all files that have copier headers that are detected will have them removed from the hash calculation. This will allow for a headered collection to be hashed without possibly variant information. If a particular header skipper is