Replace RVX with Depth

This commit is contained in:
Matt Nadareski
2020-08-18 23:39:13 -07:00
parent a703e22234
commit 52c15d4732
23 changed files with 473 additions and 546 deletions

View File

@@ -62,8 +62,8 @@ structure according to the original DAT master directory tree structure.";
// Now scan all of those depots and rebuild // Now scan all of those depots and rebuild
datFile.RebuildDepot( datFile.RebuildDepot(
onlineDepots, onlineDepots,
romroot: false, indepth: 4,
rvx: false, outdepth: 4,
outDir: outputFolder, outDir: outputFolder,
outputFormat: (copy ? OutputFormat.TorrentGzipRomba : OutputFormat.TorrentZip), outputFormat: (copy ? OutputFormat.TorrentGzipRomba : OutputFormat.TorrentZip),
updateDat: false); updateDat: false);

View File

@@ -2103,7 +2103,7 @@ namespace SabreTools.Library.DatFiles
}); });
// Now find all folders that are empty, if we are supposed to // Now find all folders that are empty, if we are supposed to
if (Header.Romba == null && addBlanks) if (!Header.Romba && addBlanks)
{ {
List<string> empties = DirectoryExtensions.ListEmpty(basePath); List<string> empties = DirectoryExtensions.ListEmpty(basePath);
Parallel.ForEach(empties, Globals.ParallelOptions, dir => Parallel.ForEach(empties, Globals.ParallelOptions, dir =>
@@ -2177,8 +2177,8 @@ namespace SabreTools.Library.DatFiles
bool addDate, bool addDate,
bool copyFiles) bool copyFiles)
{ {
// Special case for if we are in Romba or RVX mode (all names are supposed to be SHA-1 hashes) // Special case for if we are in Romba mode (all names are supposed to be SHA-1 hashes)
if (Header.Romba != null) if (Header.Romba)
{ {
GZipArchive gzarc = new GZipArchive(item); GZipArchive gzarc = new GZipArchive(item);
BaseFile baseFile = gzarc.GetTorrentGZFileInfo(); BaseFile baseFile = gzarc.GetTorrentGZFileInfo();
@@ -2400,8 +2400,8 @@ namespace SabreTools.Library.DatFiles
/// Process the DAT and find all matches in input files and folders assuming they're a depot /// Process the DAT and find all matches in input files and folders assuming they're a depot
/// </summary> /// </summary>
/// <param name="inputs">List of input files/folders to check</param> /// <param name="inputs">List of input files/folders to check</param>
/// <param name="romroot">True to build from 2-deep, false to default to 4-deep</param> /// <param name="indepth">Positive value representing depth of input depot</param>
/// <param name="rvx">True to only go to 2-deep, false to default to 4-deep</param> /// <param name="outdepth">Positive value representing depth of output depot</param>
/// <param name="outDir">Output directory to use to build to</param> /// <param name="outDir">Output directory to use to build to</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
/// <param name="delete">True if input files should be deleted, false otherwise</param> /// <param name="delete">True if input files should be deleted, false otherwise</param>
@@ -2411,8 +2411,8 @@ namespace SabreTools.Library.DatFiles
/// <returns>True if rebuilding was a success, false otherwise</returns> /// <returns>True if rebuilding was a success, false otherwise</returns>
public bool RebuildDepot( public bool RebuildDepot(
List<string> inputs, List<string> inputs,
bool romroot = false, int indepth = 4,
bool rvx = false, int outdepth = 4,
string outDir = null, string outDir = null,
bool date = false, bool date = false,
bool delete = false, bool delete = false,
@@ -2521,7 +2521,7 @@ namespace SabreTools.Library.DatFiles
Globals.Logger.User($"Checking hash '{hash}'"); Globals.Logger.User($"Checking hash '{hash}'");
// Get the extension path for the hash // Get the extension path for the hash
string subpath = PathExtensions.GetRombaPath(hash, romroot); string subpath = PathExtensions.GetRombaPath(hash, indepth);
// Find the first depot that includes the hash // Find the first depot that includes the hash
string foundpath = null; string foundpath = null;
@@ -2553,9 +2553,9 @@ namespace SabreTools.Library.DatFiles
// 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 (Items[hash][0].ItemType == ItemType.Disk) if (Items[hash][0].ItemType == ItemType.Disk)
usedInternally = RebuildIndividualFile(new Disk(fileinfo), foundpath, outDir, rvx, date, inverse, outputFormat, updateDat, false /* isZip */); usedInternally = RebuildIndividualFile(new Disk(fileinfo), foundpath, outDir, outdepth, date, inverse, outputFormat, updateDat, false /* isZip */);
else else
usedInternally = RebuildIndividualFile(new Rom(fileinfo), foundpath, outDir, rvx, date, inverse, outputFormat, updateDat, false /* isZip */); usedInternally = RebuildIndividualFile(new Rom(fileinfo), foundpath, outDir, outdepth, date, inverse, outputFormat, updateDat, false /* isZip */);
// 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)
@@ -2584,7 +2584,7 @@ namespace SabreTools.Library.DatFiles
/// </summary> /// </summary>
/// <param name="inputs">List of input files/folders to check</param> /// <param name="inputs">List of input files/folders to check</param>
/// <param name="outDir">Output directory to use to build to</param> /// <param name="outDir">Output directory to use to build to</param>
/// <param name="rvx">True to only go to 2-deep, false to default to 4-deep</param> /// <param name="outdepth">Positive value representing depth of output depot</param>
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param> /// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
/// <param name="delete">True if input files should be deleted, false otherwise</param> /// <param name="delete">True if input files should be deleted, false otherwise</param>
@@ -2596,7 +2596,7 @@ namespace SabreTools.Library.DatFiles
public bool RebuildGeneric( public bool RebuildGeneric(
List<string> inputs, List<string> inputs,
string outDir = null, string outDir = null,
bool rvx = false, int outdepth = 4,
bool quickScan = false, bool quickScan = false,
bool date = false, bool date = false,
bool delete = false, bool delete = false,
@@ -2684,7 +2684,7 @@ namespace SabreTools.Library.DatFiles
if (File.Exists(input)) if (File.Exists(input))
{ {
Globals.Logger.User($"Checking file: {input}"); Globals.Logger.User($"Checking file: {input}");
RebuildGenericHelper(input, outDir, rvx, quickScan, date, delete, inverse, outputFormat, updateDat, asFiles); RebuildGenericHelper(input, outDir, outdepth, quickScan, date, delete, inverse, outputFormat, updateDat, asFiles);
} }
// If the input is a directory // If the input is a directory
@@ -2694,7 +2694,7 @@ namespace SabreTools.Library.DatFiles
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories)) foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
{ {
Globals.Logger.User($"Checking file: {file}"); Globals.Logger.User($"Checking file: {file}");
RebuildGenericHelper(file, outDir, rvx, quickScan, date, delete, inverse, outputFormat, updateDat, asFiles); RebuildGenericHelper(file, outDir, outdepth, quickScan, date, delete, inverse, outputFormat, updateDat, asFiles);
} }
} }
} }
@@ -2721,7 +2721,7 @@ namespace SabreTools.Library.DatFiles
/// </summary> /// </summary>
/// <param name="file">Name of the file to process</param> /// <param name="file">Name of the file to process</param>
/// <param name="outDir">Output directory to use to build to</param> /// <param name="outDir">Output directory to use to build to</param>
/// <param name="rvx">True to only go to 2-deep, false to default to 4-deep</param> /// <param name="outdepth">Positive value representing depth of output depot</param>
/// <param name="quickScan">True to enable external scanning of archives, false otherwise</param> /// <param name="quickScan">True to enable external scanning of archives, false otherwise</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
/// <param name="delete">True if input files should be deleted, false otherwise</param> /// <param name="delete">True if input files should be deleted, false otherwise</param>
@@ -2732,7 +2732,7 @@ namespace SabreTools.Library.DatFiles
private void RebuildGenericHelper( private void RebuildGenericHelper(
string file, string file,
string outDir, string outDir,
bool rvx, int outdepth,
bool quickScan, bool quickScan,
bool date, bool date,
bool delete, bool delete,
@@ -2760,7 +2760,7 @@ namespace SabreTools.Library.DatFiles
else if (externalFileInfo.Type == FileType.None) else if (externalFileInfo.Type == FileType.None)
externalDatItem = new Rom(externalFileInfo); externalDatItem = new Rom(externalFileInfo);
usedExternally = RebuildIndividualFile(externalDatItem, file, outDir, rvx, date, inverse, outputFormat, updateDat, null /* isZip */); usedExternally = RebuildIndividualFile(externalDatItem, file, outDir, outdepth, date, inverse, outputFormat, updateDat, null /* isZip */);
// Scan the file internally // Scan the file internally
@@ -2793,7 +2793,7 @@ namespace SabreTools.Library.DatFiles
else if (internalFileInfo.Type == FileType.None) else if (internalFileInfo.Type == FileType.None)
internalDatItem = new Rom(internalFileInfo); internalDatItem = new Rom(internalFileInfo);
usedExternally = RebuildIndividualFile(internalDatItem, file, outDir, rvx, date, inverse, outputFormat, updateDat, null /* isZip */); usedExternally = RebuildIndividualFile(internalDatItem, file, outDir, outdepth, date, inverse, outputFormat, updateDat, null /* isZip */);
} }
// Otherwise, loop through the entries and try to match // Otherwise, loop through the entries and try to match
else else
@@ -2801,7 +2801,7 @@ namespace SabreTools.Library.DatFiles
foreach (BaseFile entry in entries) foreach (BaseFile entry in entries)
{ {
DatItem internalDatItem = DatItem.Create(entry); DatItem internalDatItem = DatItem.Create(entry);
usedInternally |= RebuildIndividualFile(internalDatItem, file, outDir, rvx, date, inverse, outputFormat, updateDat, !isTorrentGzip /* isZip */); usedInternally |= RebuildIndividualFile(internalDatItem, file, outDir, outdepth, date, inverse, outputFormat, updateDat, !isTorrentGzip /* isZip */);
} }
} }
@@ -2816,7 +2816,7 @@ namespace SabreTools.Library.DatFiles
/// <param name="datItem">Information for the current file to rebuild from</param> /// <param name="datItem">Information for the current file to rebuild from</param>
/// <param name="file">Name of the file to process</param> /// <param name="file">Name of the file to process</param>
/// <param name="outDir">Output directory to use to build to</param> /// <param name="outDir">Output directory to use to build to</param>
/// <param name="rvx">True to only go to 2-deep, false to default to 4-deep</param> /// <param name="outdepth">Positive value representing depth of output depot</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise</param>
/// <param name="inverse">True if the DAT should be used as a filter instead of a template, false otherwise</param> /// <param name="inverse">True if the DAT should be used as a filter instead of a template, false otherwise</param>
/// <param name="outputFormat">Output format that files should be written to</param> /// <param name="outputFormat">Output format that files should be written to</param>
@@ -2827,7 +2827,7 @@ namespace SabreTools.Library.DatFiles
DatItem datItem, DatItem datItem,
string file, string file,
string outDir, string outDir,
bool rvx, int outdepth,
bool date, bool date,
bool inverse, bool inverse,
OutputFormat outputFormat, OutputFormat outputFormat,
@@ -2869,7 +2869,7 @@ namespace SabreTools.Library.DatFiles
// Get the proper output path // Get the proper output path
if (outputFormat == OutputFormat.TorrentGzipRomba) if (outputFormat == OutputFormat.TorrentGzipRomba)
outDir = Path.Combine(outDir, PathExtensions.GetRombaPath(sha1, rvx)); outDir = Path.Combine(outDir, PathExtensions.GetRombaPath(sha1, outdepth));
else else
outDir = Path.Combine(outDir, sha1 + ".gz"); outDir = Path.Combine(outDir, sha1 + ".gz");
@@ -2897,7 +2897,7 @@ namespace SabreTools.Library.DatFiles
// Get the proper output path // Get the proper output path
if (outputFormat == OutputFormat.TorrentXZRomba) if (outputFormat == OutputFormat.TorrentXZRomba)
outDir = Path.Combine(outDir, PathExtensions.GetRombaPath(sha1, rvx)); outDir = Path.Combine(outDir, PathExtensions.GetRombaPath(sha1, outdepth));
else else
outDir = Path.Combine(outDir, sha1 + ".xz"); outDir = Path.Combine(outDir, sha1 + ".xz");
@@ -2969,13 +2969,8 @@ namespace SabreTools.Library.DatFiles
// Get the output archive, if possible // Get the output archive, if possible
Folder outputArchive = Folder.Create(outputFormat); Folder outputArchive = Folder.Create(outputFormat);
// Get the romba value
bool? romba = null;
if (outputFormat == OutputFormat.TorrentGzipRomba || outputFormat == OutputFormat.TorrentXZRomba)
romba = rvx;
// Now rebuild to the output file // Now rebuild to the output file
outputArchive.Write(fileStream, outDir, (Rom)item, date: date, romba: romba); outputArchive.Write(fileStream, outDir, (Rom)item, date: date, depth: outdepth);
} }
// Close the input stream // Close the input stream
@@ -3041,14 +3036,9 @@ namespace SabreTools.Library.DatFiles
// Get the output archive, if possible // Get the output archive, if possible
Folder outputArchive = Folder.Create(outputFormat); Folder outputArchive = Folder.Create(outputFormat);
// Get the romba value
bool? romba = null;
if (outputFormat == OutputFormat.TorrentGzipRomba || outputFormat == OutputFormat.TorrentXZRomba)
romba = rvx;
// Now rebuild to the output file // Now rebuild to the output file
eitherSuccess |= outputArchive.Write(transformStream, outDir, (Rom)item, date: date, romba: romba); eitherSuccess |= outputArchive.Write(transformStream, outDir, (Rom)item, date: date, depth: outdepth);
eitherSuccess |= outputArchive.Write(fileStream, outDir, (Rom)datItem, date: date, romba: romba); eitherSuccess |= outputArchive.Write(fileStream, outDir, (Rom)datItem, date: date, depth: outdepth);
// Now add the success of either rebuild // Now add the success of either rebuild
rebuilt &= eitherSuccess; rebuilt &= eitherSuccess;
@@ -3071,10 +3061,10 @@ namespace SabreTools.Library.DatFiles
/// Process the DAT and verify from the depots /// Process the DAT and verify from the depots
/// </summary> /// </summary>
/// <param name="inputs">List of input directories to compare against</param> /// <param name="inputs">List of input directories to compare against</param>
/// <param name="rvx">True to only go to 2-deep, false to default to 4-deep</param> /// <param name="depth">Positive value representing depot depth, defaults to 4</param>
/// <param name="outDir">Optional param for output directory</param> /// <param name="outDir">Optional param for output directory</param>
/// <returns>True if verification was a success, false otherwise</returns> /// <returns>True if verification was a success, false otherwise</returns>
public bool VerifyDepot(List<string> inputs, bool rvx = false, string outDir = null) public bool VerifyDepot(List<string> inputs, int depth = 4, string outDir = null)
{ {
bool success = true; bool success = true;
@@ -3110,7 +3100,7 @@ namespace SabreTools.Library.DatFiles
Globals.Logger.User($"Checking hash '{hash}'"); Globals.Logger.User($"Checking hash '{hash}'");
// Get the extension path for the hash // Get the extension path for the hash
string subpath = PathExtensions.GetRombaPath(hash, rvx); string subpath = PathExtensions.GetRombaPath(hash, depth);
// Find the first depot that includes the hash // Find the first depot that includes the hash
string foundpath = null; string foundpath = null;
@@ -3792,7 +3782,7 @@ namespace SabreTools.Library.DatFiles
string post = CreatePrefixPostfix(item, false); string post = CreatePrefixPostfix(item, false);
// If we're in Romba mode, take care of that instead // If we're in Romba mode, take care of that instead
if (Header.Romba == true) if (Header.Romba)
{ {
if (item.ItemType == ItemType.Rom) if (item.ItemType == ItemType.Rom)
{ {
@@ -3801,7 +3791,7 @@ namespace SabreTools.Library.DatFiles
// We can only write out if there's a SHA-1 // We can only write out if there's a SHA-1
if (!string.IsNullOrWhiteSpace(romItem.SHA1)) if (!string.IsNullOrWhiteSpace(romItem.SHA1))
{ {
name = PathExtensions.GetRombaPath(romItem.SHA1, Header.Romba == false).Replace('\\', '/'); name = PathExtensions.GetRombaPath(romItem.SHA1, Header.RombaDepth).Replace('\\', '/');
item.Name = $"{pre}{name}{post}"; item.Name = $"{pre}{name}{post}";
} }
} }
@@ -3812,36 +3802,7 @@ namespace SabreTools.Library.DatFiles
// We can only write out if there's a SHA-1 // We can only write out if there's a SHA-1
if (!string.IsNullOrWhiteSpace(diskItem.SHA1)) if (!string.IsNullOrWhiteSpace(diskItem.SHA1))
{ {
name = PathExtensions.GetRombaPath(diskItem.SHA1, Header.Romba == false).Replace('\\', '/'); name = PathExtensions.GetRombaPath(diskItem.SHA1, Header.RombaDepth).Replace('\\', '/');
item.Name = pre + name + post;
}
}
return;
}
// If we're in RVX mode, take care of that instead
if (Header.Romba == false)
{
if (item.ItemType == ItemType.Rom)
{
Rom romItem = item as Rom;
// We can only write out if there's a SHA-1
if (!string.IsNullOrWhiteSpace(romItem.SHA1))
{
name = PathExtensions.GetRombaPath(romItem.SHA1, Header.Romba == false).Replace('\\', '/');
item.Name = $"{pre}{name}{post}";
}
}
else if (item.ItemType == ItemType.Disk)
{
Disk diskItem = item as Disk;
// We can only write out if there's a SHA-1
if (!string.IsNullOrWhiteSpace(diskItem.SHA1))
{
name = PathExtensions.GetRombaPath(diskItem.SHA1, Header.Romba == false).Replace('\\', '/');
item.Name = pre + name + post; item.Name = pre + name + post;
} }
} }

View File

@@ -211,11 +211,16 @@ namespace SabreTools.Library.DatFiles
public bool RemoveExtension { get; set; } public bool RemoveExtension { get; set; }
/// <summary> /// <summary>
/// Romba or RVX output mode /// Romba output mode
/// </summary> /// </summary>
/// <remarks>Null means neither, false means RVX, true means Romba</remarks>
[JsonIgnore] [JsonIgnore]
public bool? Romba { get; set; } = null; public bool Romba { get; set; }
/// <summary>
/// Romba depth
/// </summary>
[JsonIgnore]
public int RombaDepth { get; set; } = 4;
/// <summary> /// <summary>
/// Output the machine name /// Output the machine name
@@ -290,6 +295,7 @@ namespace SabreTools.Library.DatFiles
RemoveExtension = this.RemoveExtension, RemoveExtension = this.RemoveExtension,
GameName = this.GameName, GameName = this.GameName,
Romba = this.Romba, Romba = this.Romba,
RombaDepth = this.RombaDepth,
}; };
} }
@@ -353,6 +359,7 @@ namespace SabreTools.Library.DatFiles
RemoveExtension = this.RemoveExtension, RemoveExtension = this.RemoveExtension,
GameName = this.GameName, GameName = this.GameName,
Romba = this.Romba, Romba = this.Romba,
RombaDepth = this.RombaDepth,
}; };
} }
@@ -439,6 +446,7 @@ namespace SabreTools.Library.DatFiles
this.RemoveExtension = datHeader.RemoveExtension; this.RemoveExtension = datHeader.RemoveExtension;
this.Romba = datHeader.Romba; this.Romba = datHeader.Romba;
this.RombaDepth = datHeader.RombaDepth;
this.GameName = datHeader.GameName; this.GameName = datHeader.GameName;
this.Quotes = datHeader.Quotes; this.Quotes = datHeader.Quotes;
this.UseRomName = datHeader.UseRomName; this.UseRomName = datHeader.UseRomName;

View File

@@ -136,7 +136,7 @@ namespace SabreTools.Library.DatFiles
ProcessItemName(datItem, false, forceRomName: false); ProcessItemName(datItem, false, forceRomName: false);
// Romba mode automatically uses item name // Romba mode automatically uses item name
if (Header.Romba != null || Header.UseRomName) if (Header.Romba || Header.UseRomName)
{ {
sw.Write($"{datItem.GetField(Field.Name, Header.ExcludeFields)}\n"); sw.Write($"{datItem.GetField(Field.Name, Header.ExcludeFields)}\n");
} }

View File

@@ -176,9 +176,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override abstract bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null); public override abstract bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4);
/// <summary> /// <summary>
/// Write an input stream to an archive /// Write an input stream to an archive
@@ -187,9 +187,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override abstract bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null); public override abstract bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4);
/// <summary> /// <summary>
/// Write a set of input files to an archive (assuming the same output archive name) /// Write a set of input files to an archive (assuming the same output archive name)

View File

@@ -293,13 +293,13 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public virtual bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public virtual bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
FileStream fs = FileExtensions.TryOpenRead(inputFile); FileStream fs = FileExtensions.TryOpenRead(inputFile);
return Write(fs, outDir, rom, date, romba); return Write(fs, outDir, rom, date, depth);
} }
/// <summary> /// <summary>
@@ -309,10 +309,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public virtual bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public virtual bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
bool success = false; bool success = false;

View File

@@ -411,10 +411,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom = null, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom = null, bool date = false, int depth = 4)
{ {
// Check that the input file exists // Check that the input file exists
if (!File.Exists(inputFile)) if (!File.Exists(inputFile))
@@ -426,7 +426,7 @@ namespace SabreTools.Library.FileTypes
inputFile = Path.GetFullPath(inputFile); inputFile = Path.GetFullPath(inputFile);
// Get the file stream for the file and write out // Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, romba); return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, depth);
} }
/// <summary> /// <summary>
@@ -436,10 +436,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom = null, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom = null, bool date = false, int depth = 4)
{ {
bool success = false; bool success = false;
@@ -457,31 +457,11 @@ namespace SabreTools.Library.FileTypes
rom = new Rom(inputStream.GetInfo(keepReadOpen: true)); rom = new Rom(inputStream.GetInfo(keepReadOpen: true));
// Get the output file name // Get the output file name
string outfile; string outfile = Path.Combine(outDir, PathExtensions.GetRombaPath(rom.SHA1, depth)); // TODO: When updating to SHA-256, this needs to update to SHA256
// If we have a Romba output, add the depot path // Check to see if the folder needs to be created
if (romba == true) if (!Directory.Exists(Path.GetDirectoryName(outfile)))
{ Directory.CreateDirectory(Path.GetDirectoryName(outfile));
outfile = Path.Combine(outDir, PathExtensions.GetRombaPath(rom.SHA1, false)); // TODO: When updating to SHA-256, this needs to update to SHA256
// Check to see if the folder needs to be created
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
Directory.CreateDirectory(Path.GetDirectoryName(outfile));
}
// If we have an RVX output, add the RomRoot path
else if (romba == false)
{
outfile = Path.Combine(outDir, PathExtensions.GetRombaPath(rom.SHA1, true)); // TODO: When updating to SHA-256, this needs to update to SHA256
// Check to see if the folder needs to be created
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
Directory.CreateDirectory(Path.GetDirectoryName(outfile));
}
// Otherwise, we're just rebuilding to the main directory
else
{
outfile = Path.Combine(outDir, rom.SHA1 + ".gz"); // TODO: When updating to SHA-256, this needs to update to SHA256
}
// If the output file exists, don't try to write again // If the output file exists, don't try to write again
if (!File.Exists(outfile)) if (!File.Exists(outfile))

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles; using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems; using SabreTools.Library.DatItems;
@@ -117,10 +116,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@@ -132,10 +131,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles; using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems; using SabreTools.Library.DatItems;
@@ -117,10 +116,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@@ -132,10 +131,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -13,313 +13,313 @@ using SharpCompress.Readers;
namespace SabreTools.Library.FileTypes namespace SabreTools.Library.FileTypes
{ {
/// <summary> /// <summary>
/// Represents a TorrentRAR archive for reading and writing /// Represents a TorrentRAR archive for reading and writing
/// </summary> /// </summary>
public class RarArchive : BaseArchive public class RarArchive : BaseArchive
{ {
#region Constructors #region Constructors
/// <summary> /// <summary>
/// Create a new TorrentRARArchive with no base file /// Create a new TorrentRARArchive with no base file
/// </summary> /// </summary>
public RarArchive() public RarArchive()
: base() : base()
{ {
this.Type = FileType.RarArchive; this.Type = FileType.RarArchive;
} }
/// <summary> /// <summary>
/// Create a new TorrentRARArchive from the given file /// Create a new TorrentRARArchive from the given file
/// </summary> /// </summary>
/// <param name="filename">Name of the file to use as an archive</param> /// <param name="filename">Name of the file to use as an archive</param>
/// <param name="read">True for opening file as read, false for opening file as write</param> /// <param name="read">True for opening file as read, false for opening file as write</param>
/// <param name="getHashes">True if hashes for this file should be calculated, false otherwise (default)</param> /// <param name="getHashes">True if hashes for this file should be calculated, false otherwise (default)</param>
public RarArchive(string filename, bool getHashes = false) public RarArchive(string filename, bool getHashes = false)
: base(filename, getHashes) : base(filename, getHashes)
{ {
this.Type = FileType.RarArchive; this.Type = FileType.RarArchive;
} }
#endregion #endregion
#region Extraction #region Extraction
/// <summary> /// <summary>
/// Attempt to extract a file as an archive /// Attempt to extract a file as an archive
/// </summary> /// </summary>
/// <param name="outDir">Output directory for archive extraction</param> /// <param name="outDir">Output directory for archive extraction</param>
/// <returns>True if the extraction was a success, false otherwise</returns> /// <returns>True if the extraction was a success, false otherwise</returns>
public override bool CopyAll(string outDir) public override bool CopyAll(string outDir)
{ {
bool encounteredErrors = true; bool encounteredErrors = true;
try try
{ {
// Create the temp directory // Create the temp directory
Directory.CreateDirectory(outDir); Directory.CreateDirectory(outDir);
// Extract all files to the temp directory // Extract all files to the temp directory
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename); SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename);
foreach (RarArchiveEntry entry in ra.Entries) foreach (RarArchiveEntry entry in ra.Entries)
{ {
entry.WriteToDirectory(outDir, new SharpCompress.Common.ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true }); entry.WriteToDirectory(outDir, new SharpCompress.Common.ExtractionOptions { PreserveFileTime = true, ExtractFullPath = true, Overwrite = true });
} }
encounteredErrors = false; encounteredErrors = false;
ra.Dispose(); ra.Dispose();
} }
catch (EndOfStreamException) catch (EndOfStreamException)
{ {
// Catch this but don't count it as an error because SharpCompress is unsafe // Catch this but don't count it as an error because SharpCompress is unsafe
} }
catch (InvalidOperationException) catch (InvalidOperationException)
{ {
encounteredErrors = true; encounteredErrors = true;
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex.ToString()); Globals.Logger.Error(ex.ToString());
encounteredErrors = true; encounteredErrors = true;
} }
return encounteredErrors; return encounteredErrors;
} }
/// <summary> /// <summary>
/// Attempt to extract a file from an archive /// Attempt to extract a file from an archive
/// </summary> /// </summary>
/// <param name="entryName">Name of the entry to be extracted</param> /// <param name="entryName">Name of the entry to be extracted</param>
/// <param name="outDir">Output directory for archive extraction</param> /// <param name="outDir">Output directory for archive extraction</param>
/// <returns>Name of the extracted file, null on error</returns> /// <returns>Name of the extracted file, null on error</returns>
public override string CopyToFile(string entryName, string outDir) public override string CopyToFile(string entryName, string outDir)
{ {
// Try to extract a stream using the given information // Try to extract a stream using the given information
(MemoryStream ms, string realEntry) = CopyToStream(entryName); (MemoryStream ms, string realEntry) = CopyToStream(entryName);
// If the memory stream and the entry name are both non-null, we write to file // If the memory stream and the entry name are both non-null, we write to file
if (ms != null && realEntry != null) if (ms != null && realEntry != null)
{ {
realEntry = Path.Combine(outDir, realEntry); realEntry = Path.Combine(outDir, realEntry);
// Create the output subfolder now // Create the output subfolder now
Directory.CreateDirectory(Path.GetDirectoryName(realEntry)); Directory.CreateDirectory(Path.GetDirectoryName(realEntry));
// Now open and write the file if possible // Now open and write the file if possible
FileStream fs = FileExtensions.TryCreate(realEntry); FileStream fs = FileExtensions.TryCreate(realEntry);
if (fs != null) if (fs != null)
{ {
ms.Seek(0, SeekOrigin.Begin); ms.Seek(0, SeekOrigin.Begin);
byte[] zbuffer = new byte[_bufferSize]; byte[] zbuffer = new byte[_bufferSize];
int zlen; int zlen;
while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0) while ((zlen = ms.Read(zbuffer, 0, _bufferSize)) > 0)
{ {
fs.Write(zbuffer, 0, zlen); fs.Write(zbuffer, 0, zlen);
fs.Flush(); fs.Flush();
} }
ms?.Dispose(); ms?.Dispose();
fs?.Dispose(); fs?.Dispose();
} }
else else
{ {
ms?.Dispose(); ms?.Dispose();
fs?.Dispose(); fs?.Dispose();
realEntry = null; realEntry = null;
} }
} }
return realEntry; return realEntry;
} }
/// <summary> /// <summary>
/// Attempt to extract a stream from an archive /// Attempt to extract a stream from an archive
/// </summary> /// </summary>
/// <param name="entryName">Name of the entry to be extracted</param> /// <param name="entryName">Name of the entry to be extracted</param>
/// <param name="realEntry">Output representing the entry name that was found</param> /// <param name="realEntry">Output representing the entry name that was found</param>
/// <returns>MemoryStream representing the entry, null on error</returns> /// <returns>MemoryStream representing the entry, null on error</returns>
public override (MemoryStream, string) CopyToStream(string entryName) public override (MemoryStream, string) CopyToStream(string entryName)
{ {
MemoryStream ms = new MemoryStream(); MemoryStream ms = new MemoryStream();
string realEntry = null; string realEntry = null;
try try
{ {
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false, }); SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false, });
foreach (RarArchiveEntry entry in ra.Entries) foreach (RarArchiveEntry entry in ra.Entries)
{ {
if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName)) if (entry != null && !entry.IsDirectory && entry.Key.Contains(entryName))
{ {
// Write the file out // Write the file out
realEntry = entry.Key; realEntry = entry.Key;
entry.WriteTo(ms); entry.WriteTo(ms);
} }
} }
ra.Dispose(); ra.Dispose();
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex.ToString()); Globals.Logger.Error(ex.ToString());
ms = null; ms = null;
realEntry = null; realEntry = null;
} }
return (ms, realEntry); return (ms, realEntry);
} }
#endregion #endregion
#region Information #region Information
/// <summary> /// <summary>
/// Generate a list of DatItem objects from the header values in an archive /// Generate a list of DatItem objects from the header values in an archive
/// </summary> /// </summary>
/// <param name="omitFromScan">Hash representing the hashes that should be skipped</param> /// <param name="omitFromScan">Hash representing the hashes that should be skipped</param>
/// <param name="date">True if entry dates should be included, false otherwise (default)</param> /// <param name="date">True if entry dates should be included, false otherwise (default)</param>
/// <returns>List of DatItem objects representing the found data</returns> /// <returns>List of DatItem objects representing the found data</returns>
/// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks> /// <remarks>TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually</remarks>
public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false) public override List<BaseFile> GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false)
{ {
List<BaseFile> found = new List<BaseFile>(); List<BaseFile> found = new List<BaseFile>();
string gamename = Path.GetFileNameWithoutExtension(this.Filename); string gamename = Path.GetFileNameWithoutExtension(this.Filename);
try try
{ {
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(FileExtensions.TryOpenRead(this.Filename)); SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(FileExtensions.TryOpenRead(this.Filename));
foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory)) foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory))
{ {
// If secure hashes are disabled, do a quickscan // If secure hashes are disabled, do a quickscan
if (omitFromScan == Hash.SecureHashes) if (omitFromScan == Hash.SecureHashes)
{ {
found.Add(new BaseFile found.Add(new BaseFile
{ {
Filename = entry.Key, Filename = entry.Key,
Size = entry.Size, Size = entry.Size,
CRC = BitConverter.GetBytes(entry.Crc), CRC = BitConverter.GetBytes(entry.Crc),
Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null), Date = (date && entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null),
Parent = gamename, Parent = gamename,
}); });
} }
// Otherwise, use the stream directly // Otherwise, use the stream directly
else else
{ {
Stream entryStream = entry.OpenEntryStream(); Stream entryStream = entry.OpenEntryStream();
BaseFile rarEntryRom = entryStream.GetInfo(entry.Size, omitFromScan); BaseFile rarEntryRom = entryStream.GetInfo(entry.Size, omitFromScan);
rarEntryRom.Filename = entry.Key; rarEntryRom.Filename = entry.Key;
rarEntryRom.Parent = gamename; rarEntryRom.Parent = gamename;
rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss");
found.Add(rarEntryRom); found.Add(rarEntryRom);
entryStream.Dispose(); entryStream.Dispose();
} }
} }
// Dispose of the archive // Dispose of the archive
ra.Dispose(); ra.Dispose();
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex.ToString()); Globals.Logger.Error(ex.ToString());
return null; return null;
} }
return found; return found;
} }
/// <summary> /// <summary>
/// Generate a list of empty folders in an archive /// Generate a list of empty folders in an archive
/// </summary> /// </summary>
/// <param name="input">Input file to get data from</param> /// <param name="input">Input file to get data from</param>
/// <returns>List of empty folders in the archive</returns> /// <returns>List of empty folders in the archive</returns>
public override List<string> GetEmptyFolders() public override List<string> GetEmptyFolders()
{ {
List<string> empties = new List<string>(); List<string> empties = new List<string>();
try try
{ {
SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false }); SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(this.Filename, new ReaderOptions { LeaveStreamOpen = false });
List<RarArchiveEntry> rarEntries = ra.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList(); List<RarArchiveEntry> rarEntries = ra.Entries.OrderBy(e => e.Key, new NaturalSort.NaturalReversedComparer()).ToList();
string lastRarEntry = null; string lastRarEntry = null;
foreach (RarArchiveEntry entry in rarEntries) foreach (RarArchiveEntry entry in rarEntries)
{ {
if (entry != null) if (entry != null)
{ {
// If the current is a superset of last, we skip it // If the current is a superset of last, we skip it
if (lastRarEntry != null && lastRarEntry.StartsWith(entry.Key)) if (lastRarEntry != null && lastRarEntry.StartsWith(entry.Key))
{ {
// No-op // No-op
} }
// If the entry is a directory, we add it // If the entry is a directory, we add it
else if (entry.IsDirectory) else if (entry.IsDirectory)
{ {
empties.Add(entry.Key); empties.Add(entry.Key);
lastRarEntry = entry.Key; lastRarEntry = entry.Key;
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Globals.Logger.Error(ex.ToString()); Globals.Logger.Error(ex.ToString());
} }
return empties; return empties;
} }
/// <summary> /// <summary>
/// Check whether the input file is a standardized format /// Check whether the input file is a standardized format
/// </summary> /// </summary>
public override bool IsTorrent() public override bool IsTorrent()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion #endregion
#region Writing #region Writing
/// <summary> /// <summary>
/// Write an input file to a torrentrar archive /// Write an input file to a torrentrar archive
/// </summary> /// </summary>
/// <param name="inputFile">Input filename to be moved</param> /// <param name="inputFile">Input filename to be moved</param>
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
// Get the file stream for the file and write out // Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, romba); return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, depth);
} }
/// <summary> /// <summary>
/// Write an input stream to a torrentrar archive /// Write an input stream to a torrentrar archive
/// </summary> /// </summary>
/// <param name="inputStream">Input stream to be moved</param> /// <param name="inputStream">Input stream to be moved</param>
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <summary> /// <summary>
/// Write a set of input files to a torrentrar archive (assuming the same output archive name) /// Write a set of input files to a torrentrar archive (assuming the same output archive name)
/// </summary> /// </summary>
/// <param name="inputFiles">Input files to be moved</param> /// <param name="inputFiles">Input files to be moved</param>
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param> /// <param name="romba">True if files should be output in Romba depot folders, false otherwise</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false) public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms, bool date = false, bool romba = false)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
#endregion #endregion
} }
} }

View File

@@ -414,9 +414,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
// Get the file stream for the file and write out // Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date); return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date);
@@ -429,9 +429,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
bool success = false; bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}"); string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");

View File

@@ -289,9 +289,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
// Get the file stream for the file and write out // Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date); return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date);
@@ -304,9 +304,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
bool success = false; bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}"); string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");

View File

@@ -312,10 +312,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
// Check that the input file exists // Check that the input file exists
if (!File.Exists(inputFile)) if (!File.Exists(inputFile))
@@ -327,7 +327,7 @@ namespace SabreTools.Library.FileTypes
inputFile = Path.GetFullPath(inputFile); inputFile = Path.GetFullPath(inputFile);
// Get the file stream for the file and write out // Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, romba); return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date, depth);
} }
/// <summary> /// <summary>
@@ -337,9 +337,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
bool success = false; bool success = false;
@@ -357,31 +357,12 @@ namespace SabreTools.Library.FileTypes
rom = new Rom(inputStream.GetInfo(keepReadOpen: true)); rom = new Rom(inputStream.GetInfo(keepReadOpen: true));
// Get the output file name // Get the output file name
string outfile; string outfile = Path.Combine(outDir, PathExtensions.GetRombaPath(rom.SHA1, depth)); // TODO: When updating to SHA-256, this needs to update to SHA256
outfile = outfile.Replace(".gz", ".xz");
// If we have a Romba output, add the depot path // Check to see if the folder needs to be created
if (romba == true) if (!Directory.Exists(Path.GetDirectoryName(outfile)))
{ Directory.CreateDirectory(Path.GetDirectoryName(outfile));
outfile = Path.Combine(outDir, PathExtensions.GetRombaPath(rom.SHA1, false)); // TODO: When updating to SHA-256, this needs to update to SHA256
// Check to see if the folder needs to be created
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
Directory.CreateDirectory(Path.GetDirectoryName(outfile));
}
// If we have an RVX output, add the RomRoot path
else if (romba == false)
{
outfile = Path.Combine(outDir, PathExtensions.GetRombaPath(rom.SHA1, true)); // TODO: When updating to SHA-256, this needs to update to SHA256
// Check to see if the folder needs to be created
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
Directory.CreateDirectory(Path.GetDirectoryName(outfile));
}
// Otherwise, we're just rebuilding to the main directory
else
{
outfile = Path.Combine(outDir, rom.SHA1 + ".xz"); // TODO: When updating to SHA-256, this needs to update to SHA256
}
// If the output file exists, don't try to write again // If the output file exists, don't try to write again
if (!File.Exists(outfile)) if (!File.Exists(outfile))

View File

@@ -116,10 +116,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@@ -131,10 +131,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -419,9 +419,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
// Get the file stream for the file and write out // Get the file stream for the file and write out
return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date); return Write(FileExtensions.TryOpenRead(inputFile), outDir, rom, date: date);
@@ -434,9 +434,9 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the archive was written properly, false otherwise</returns> /// <returns>True if the archive was written properly, false otherwise</returns>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
bool success = false; bool success = false;
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}"); string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");

View File

@@ -117,10 +117,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(string inputFile, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@@ -132,10 +132,10 @@ namespace SabreTools.Library.FileTypes
/// <param name="outDir">Output directory to build to</param> /// <param name="outDir">Output directory to build to</param>
/// <param name="rom">DatItem representing the new information</param> /// <param name="rom">DatItem representing the new information</param>
/// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param> /// <param name="date">True if the date from the DAT should be used if available, false otherwise (default)</param>
/// <param name="romba">True if files should be output in Romba depot folders, false for RVX RomRoot folders, null otherwise</param> /// <param name="depth">Positive value for depth of the output depot, defaults to 4</param>
/// <returns>True if the write was a success, false otherwise</returns> /// <returns>True if the write was a success, false otherwise</returns>
/// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks> /// <remarks>This works for now, but it can be sped up by using Ionic.Zip or another zlib wrapper that allows for header values built-in. See edc's code.</remarks>
public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool? romba = null) public override bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, int depth = 4)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -37,21 +37,30 @@ namespace SabreTools.Library.IO
/// Get a proper romba sub path /// Get a proper romba sub path
/// </summary> /// </summary>
/// <param name="hash">SHA-1 hash to get the path for</param> /// <param name="hash">SHA-1 hash to get the path for</param>
/// <param name="rvx">True to only go to 2-deep, false to default to 4-deep</param> /// <param name="depth">Positive value representing the depth of the depot</param>
/// <returns>Subfolder path for the given hash</returns> /// <returns>Subfolder path for the given hash</returns>
public static string GetRombaPath(string hash, bool rvx) public static string GetRombaPath(string hash, int depth)
{ {
// If the hash isn't the right size, then we return null // If the hash isn't the right size, then we return null
if (hash.Length != Constants.SHA1Length) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length if (hash.Length != Constants.SHA1Length) // TODO: When updating to SHA-256, this needs to update to Constants.SHA256Length
return null; return null;
// RVX uses a 2-deep RomRoot // Cap the depth between 0 and 20, for now
if (rvx) if (depth < 0)
return Path.Combine(hash.Substring(0, 2), hash.Substring(2, 2), hash + ".gz"); depth = 0;
else if (depth > Constants.SHA1ZeroBytes.Length)
depth = Constants.SHA1ZeroBytes.Length;
// Romba uses a 4-deep Depot // Loop through and generate the subdirectory
else string path = string.Empty;
return Path.Combine(hash.Substring(0, 2), hash.Substring(2, 2), hash.Substring(4, 2), hash.Substring(6, 2), hash + ".gz"); for (int i = 0; i < depth; i++)
{
path += hash.Substring(i * 2, 2) + Path.DirectorySeparatorChar;
}
// Now append the filename
path += hash + $"{hash}.gz";
return path;
} }
/// <summary> /// <summary>

View File

@@ -248,10 +248,9 @@ Options:
output for physical files. Where appropriate, Romba depot files will output for physical files. Where appropriate, Romba depot files will
be created as well. be created as well.
-rvx, --romvaultx Treat like an RVX RomRoot (requires SHA-1) --depr, --romba-depth Set depth of depot for outputs
This flag allows reading and writing of DATs and output files to and Optionally, set the depth of output depots. Defaults to 4 deep
from a RVX-style RomRoot. This also implies TorrentGZ input and otherwise.
output for physical files.
-ska, --skip-archives Skip all archives -ska, --skip-archives Skip all archives
Skip any files that are treated like archives Skip any files that are treated like archives
@@ -629,10 +628,9 @@ Options:
If this flag is used, all input directories will be assumed to be If this flag is used, all input directories will be assumed to be
romba-style depots. romba-style depots.
-rr, --romroot Assume directories are RVX RomRoots --depd, --depot-depth Set depth of depot for inputs
Normally, input directories will be treated with no special format. Optionally, set the depth of input depots. Defaults to 4 deep
If this flag is used, all input directories will be assumed to be otherwise.
RVX-style RomRoots.
-del, --delete Delete fully rebuilt input files -del, --delete Delete fully rebuilt input files
Optionally, the input files, once processed and fully matched, can be Optionally, the input files, once processed and fully matched, can be
@@ -694,10 +692,9 @@ Options:
and output for physical files. Where appropriate, Romba depot and output for physical files. Where appropriate, Romba depot
files will be created as well. files will be created as well.
-rvx, --romvaultx Treat like an RVX RomRoot (requires SHA-1) --depr, --romba-depth Set depth of depot for outputs
This flag allows reading and writing of DATs and output files to Optionally, set the depth of output depots. Defaults to 4 deep
and from a RVX-style RomRoot. This also implies TorrentGZ input otherwise.
and output for physical files.
-tzip, --torrent-zip Enable Torrent Zip output -tzip, --torrent-zip Enable Torrent Zip output
Instead of outputting files to folder, files will be rebuilt to Instead of outputting files to folder, files will be rebuilt to
@@ -1006,10 +1003,9 @@ Options:
and output for physical files. Where appropriate, Romba depot and output for physical files. Where appropriate, Romba depot
files will be created as well. files will be created as well.
-rvx, --romvaultx Treat like an RVX RomRoot (requires SHA-1) --depr, --romba-depth Set depth of depot for outputs
This flag allows reading and writing of DATs and output files to Optionally, set the depth of output depots. Defaults to 4 deep
and from a RVX-style RomRoot. This also implies TorrentGZ input otherwise.
and output for physical files.
-dpc, --deprecated Output 'game' instead of 'machine' -dpc, --deprecated Output 'game' instead of 'machine'
By default, Logiqx XML DATs output with the more modern "machine" By default, Logiqx XML DATs output with the more modern "machine"
@@ -1537,10 +1533,9 @@ Options:
If this flag is used, all input directories will be assumed to be If this flag is used, all input directories will be assumed to be
romba-style depots. romba-style depots.
-rr, --romroot Assume directories are RVX RomRoots --depd, --depot-depth Set depth of depot for inputs
Normally, input directories will be treated with no special format. Optionally, set the depth of input depots. Defaults to 4 deep
If this flag is used, all input directories will be assumed to be otherwise.
RVX-style RomRoots.
-t=, --temp= Set the temporary directory to use -t=, --temp= Set the temporary directory to use
Optionally, a temp folder can be supplied in the case the default Optionally, a temp folder can be supplied in the case the default

View File

@@ -794,20 +794,6 @@ namespace SabreTools.Features
} }
} }
internal const string RomRootValue = "romroot";
internal static Feature RomRootFlag
{
get
{
return new Feature(
RomRootValue,
new List<string>() { "-rr", "--romroot" },
"Assume directories are RVX RomRoots",
FeatureType.Flag,
longDescription: "Normally, input directories will be treated with no special format. If this flag is used, all input directories will be assumed to be RVX-style RomRoots.");
}
}
internal const string RomsValue = "roms"; internal const string RomsValue = "roms";
internal static Feature RomsFlag internal static Feature RomsFlag
{ {
@@ -836,20 +822,6 @@ namespace SabreTools.Features
} }
} }
internal const string RVXValue = "rvx";
internal static Feature RVXFlag
{
get
{
return new Feature(
RVXValue,
new List<string>() { "-rvx", "--romvaultx" },
"Treat like an RVX RomRoot (requires SHA-1)",
FeatureType.Flag,
longDescription: "This flag allows reading and writing of DATs and output files to and from a RVX-style RomRoot. This also implies TorrentGZ input and output for physical files.");
}
}
internal const string SceneDateStripValue = "scene-date-strip"; internal const string SceneDateStripValue = "scene-date-strip";
internal static Feature SceneDateStripFlag internal static Feature SceneDateStripFlag
{ {
@@ -1248,6 +1220,34 @@ namespace SabreTools.Features
#region Int32 features #region Int32 features
internal const string DepotDepthInt32Value = "depot-depth";
internal static Feature DepotDepthInt32Input
{
get
{
return new Feature(
DepotDepthInt32Value,
new List<string>() { "-depd", "--depot-depth" },
"Set depth of depot for inputs",
FeatureType.Int32,
longDescription: "Optionally, set the depth of input depots. Defaults to 4 deep otherwise.");
}
}
internal const string RombaDepthInt32Value = "romba-depth";
internal static Feature RombaDepthInt32Input
{
get
{
return new Feature(
RombaDepthInt32Value,
new List<string>() { "-depr", "--romba-depth" },
"Set depth of depot for outputs",
FeatureType.Int32,
longDescription: "Optionally, set the depth of output depots. Defaults to 4 deep otherwise.");
}
}
internal const string ThreadsInt32Value = "threads"; internal const string ThreadsInt32Value = "threads";
internal static Feature ThreadsInt32Input internal static Feature ThreadsInt32Input
{ {
@@ -2661,6 +2661,8 @@ Some special strings that can be used:
RegionList = GetList(features, RegionListValue), RegionList = GetList(features, RegionListValue),
RemoveExtension = GetBoolean(features, RemoveExtensionsValue), RemoveExtension = GetBoolean(features, RemoveExtensionsValue),
ReplaceExtension = GetString(features, ReplaceExtensionStringValue), ReplaceExtension = GetString(features, ReplaceExtensionStringValue),
Romba = GetBoolean(features, RombaValue),
RombaDepth = GetInt32(features, RombaDepthInt32Value),
RootDir = GetString(features, RootStringValue), RootDir = GetString(features, RootStringValue),
SceneDateStrip = GetBoolean(features, SceneDateStripValue), SceneDateStrip = GetBoolean(features, SceneDateStripValue),
Type = GetBoolean(features, SuperdatValue) ? "SuperDAT" : null, Type = GetBoolean(features, SuperdatValue) ? "SuperDAT" : null,
@@ -2669,11 +2671,9 @@ Some special strings that can be used:
Version = GetString(features, VersionStringValue), Version = GetString(features, VersionStringValue),
}; };
// Romba overrides RVX for flags // Set a reasonable default for the Romba depth
if (GetBoolean(features, RombaValue)) if (datHeader.RombaDepth == Int32.MinValue)
datHeader.Romba = true; datHeader.RombaDepth = 4;
else if (GetBoolean(features, RVXValue))
datHeader.Romba = false;
bool deprecated = GetBoolean(features, DeprecatedValue); bool deprecated = GetBoolean(features, DeprecatedValue);
foreach (string ot in GetList(features, OutputTypeListValue)) foreach (string ot in GetList(features, OutputTypeListValue))

View File

@@ -35,7 +35,7 @@ namespace SabreTools.Features
AddFeature(OutputTypeListInput); AddFeature(OutputTypeListInput);
this[OutputTypeListInput].AddFeature(DeprecatedFlag); this[OutputTypeListInput].AddFeature(DeprecatedFlag);
AddFeature(RombaFlag); AddFeature(RombaFlag);
AddFeature(RVXFlag); this[RombaFlag].AddFeature(RombaDepthInt32Input);
AddFeature(SkipArchivesFlag); AddFeature(SkipArchivesFlag);
AddFeature(SkipFilesFlag); AddFeature(SkipFilesFlag);
AddHeaderFeatures(); AddHeaderFeatures();

View File

@@ -25,7 +25,7 @@ namespace SabreTools.Features
AddFeature(DatListInput); AddFeature(DatListInput);
AddFeature(OutputDirStringInput); AddFeature(OutputDirStringInput);
AddFeature(DepotFlag); AddFeature(DepotFlag);
AddFeature(RomRootFlag); this[DepotFlag].AddFeature(DepotDepthInt32Input);
AddFeature(DeleteFlag); AddFeature(DeleteFlag);
AddFeature(InverseFlag); AddFeature(InverseFlag);
AddFeature(QuickFlag); AddFeature(QuickFlag);
@@ -38,7 +38,7 @@ namespace SabreTools.Features
AddFeature(TarFlag); AddFeature(TarFlag);
AddFeature(TorrentGzipFlag); AddFeature(TorrentGzipFlag);
this[TorrentGzipFlag].AddFeature(RombaFlag); this[TorrentGzipFlag].AddFeature(RombaFlag);
this[TorrentGzipFlag].AddFeature(RVXFlag); this[TorrentGzipFlag][RombaFlag].AddFeature(RombaDepthInt32Input);
//AddFeature(SharedInputs.TorrentLrzipFlag); //AddFeature(SharedInputs.TorrentLrzipFlag);
//AddFeature(SharedInputs.TorrentLz4Flag); //AddFeature(SharedInputs.TorrentLz4Flag);
//AddFeature(SharedInputs.TorrentRarFlag); //AddFeature(SharedInputs.TorrentRarFlag);
@@ -62,31 +62,27 @@ namespace SabreTools.Features
TreatAsFiles asFiles = GetTreatAsFiles(features); TreatAsFiles asFiles = GetTreatAsFiles(features);
bool date = GetBoolean(features, AddDateValue); bool date = GetBoolean(features, AddDateValue);
bool delete = GetBoolean(features, DeleteValue); bool delete = GetBoolean(features, DeleteValue);
bool depot = GetBoolean(features, DepotValue);
bool inverse = GetBoolean(features, InverseValue); bool inverse = GetBoolean(features, InverseValue);
bool quickScan = GetBoolean(features, QuickValue); bool quickScan = GetBoolean(features, QuickValue);
bool romba = GetBoolean(features, RombaValue);
bool updateDat = GetBoolean(features, UpdateDatValue); bool updateDat = GetBoolean(features, UpdateDatValue);
var outputFormat = GetOutputFormat(features); var outputFormat = GetOutputFormat(features);
// Romba overrides RVX for flags // Get optional depths
bool? romba = null; int depotDepth = 4;
if (GetBoolean(features, RombaValue)) if (features.ContainsKey(DepotDepthInt32Value))
romba = true; depotDepth = GetInt32(features, DepotDepthInt32Value);
else if (GetBoolean(features, RVXValue)) int rombaDepth = 4;
romba = false; if (features.ContainsKey(RombaDepthInt32Value))
rombaDepth = GetInt32(features, RombaDepthInt32Value);
// Depot overrides RomRoot for flags
bool? depot = null;
if (GetBoolean(features, DepotValue))
depot = true;
else if (GetBoolean(features, RomRootValue))
depot = false;
// If we have TorrentGzip output and the romba flag, update // If we have TorrentGzip output and the romba flag, update
if (romba != null && outputFormat == OutputFormat.TorrentGzip) if (romba && outputFormat == OutputFormat.TorrentGzip)
outputFormat = OutputFormat.TorrentGzipRomba; outputFormat = OutputFormat.TorrentGzipRomba;
// If we hae TorrentXZ output and the romba flag, update // If we hae TorrentXZ output and the romba flag, update
if (romba != null && outputFormat == OutputFormat.TorrentXZ) if (romba && outputFormat == OutputFormat.TorrentXZ)
outputFormat = OutputFormat.TorrentXZRomba; outputFormat = OutputFormat.TorrentXZRomba;
// Get a list of files from the input datfiles // Get a list of files from the input datfiles
@@ -106,10 +102,10 @@ namespace SabreTools.Features
datdata.Header.HeaderSkipper = Header.HeaderSkipper; datdata.Header.HeaderSkipper = Header.HeaderSkipper;
// If we have the depot flag, respect it // If we have the depot flag, respect it
if (depot != null) if (depot)
datdata.RebuildDepot(Inputs, depot == false, romba == false, Path.Combine(OutputDir, datdata.Header.FileName), date, delete, inverse, outputFormat, updateDat); datdata.RebuildDepot(Inputs, depotDepth, rombaDepth, Path.Combine(OutputDir, datdata.Header.FileName), date, delete, inverse, outputFormat, updateDat);
else else
datdata.RebuildGeneric(Inputs, Path.Combine(OutputDir, datdata.Header.FileName), romba == false, quickScan, date, delete, inverse, outputFormat, updateDat, asFiles); datdata.RebuildGeneric(Inputs, Path.Combine(OutputDir, datdata.Header.FileName), rombaDepth, quickScan, date, delete, inverse, outputFormat, updateDat, asFiles);
} }
} }
@@ -132,10 +128,10 @@ namespace SabreTools.Features
watch.Stop(); watch.Stop();
// If we have the depot flag, respect it // If we have the depot flag, respect it
if (depot != null) if (depot)
datdata.RebuildDepot(Inputs, depot == false, romba == false, OutputDir, date, delete, inverse, outputFormat, updateDat); datdata.RebuildDepot(Inputs, depotDepth, rombaDepth, OutputDir, date, delete, inverse, outputFormat, updateDat);
else else
datdata.RebuildGeneric(Inputs, OutputDir, romba == false, quickScan, date, delete, inverse, outputFormat, updateDat, asFiles); datdata.RebuildGeneric(Inputs, OutputDir, rombaDepth, quickScan, date, delete, inverse, outputFormat, updateDat, asFiles);
} }
} }
} }

View File

@@ -32,7 +32,7 @@ namespace SabreTools.Features
this[OutputTypeListInput].AddFeature(ReplaceExtensionStringInput); this[OutputTypeListInput].AddFeature(ReplaceExtensionStringInput);
this[OutputTypeListInput].AddFeature(RemoveExtensionsFlag); this[OutputTypeListInput].AddFeature(RemoveExtensionsFlag);
this[OutputTypeListInput].AddFeature(RombaFlag); this[OutputTypeListInput].AddFeature(RombaFlag);
this[OutputTypeListInput].AddFeature(RVXFlag); this[OutputTypeListInput][RombaFlag].AddFeature(RombaDepthInt32Input);
this[OutputTypeListInput].AddFeature(DeprecatedFlag); this[OutputTypeListInput].AddFeature(DeprecatedFlag);
AddHeaderFeatures(); AddHeaderFeatures();

View File

@@ -22,7 +22,7 @@ namespace SabreTools.Features
AddFeature(DatListInput); AddFeature(DatListInput);
AddFeature(DepotFlag); AddFeature(DepotFlag);
AddFeature(RomRootFlag); this[DepotFlag].AddFeature(DepotDepthInt32Input);
AddFeature(TempStringInput); AddFeature(TempStringInput);
AddFeature(OutputDirStringInput); AddFeature(OutputDirStringInput);
AddFeature(HashOnlyFlag); AddFeature(HashOnlyFlag);
@@ -44,15 +44,14 @@ namespace SabreTools.Features
// Get feature flags // Get feature flags
TreatAsFiles asFiles = GetTreatAsFiles(features); TreatAsFiles asFiles = GetTreatAsFiles(features);
bool depot = GetBoolean(features, DepotValue);
bool hashOnly = GetBoolean(features, HashOnlyValue); bool hashOnly = GetBoolean(features, HashOnlyValue);
bool quickScan = GetBoolean(features, QuickValue); bool quickScan = GetBoolean(features, QuickValue);
// Depot overrides RomRoot for flags // Get optional depth
bool? depot = null; int depotDepth = 4;
if (GetBoolean(features, DepotValue)) if (features.ContainsKey(DepotDepthInt32Value))
depot = true; depotDepth = GetInt32(features, DepotDepthInt32Value);
else if (GetBoolean(features, RomRootValue))
depot = false;
// If we are in individual mode, process each DAT on their own // If we are in individual mode, process each DAT on their own
if (GetBoolean(features, IndividualValue)) if (GetBoolean(features, IndividualValue))
@@ -68,8 +67,8 @@ namespace SabreTools.Features
datdata.Header.HeaderSkipper = Header.HeaderSkipper; datdata.Header.HeaderSkipper = Header.HeaderSkipper;
// If we have the depot flag, respect it // If we have the depot flag, respect it
if (depot != null) if (depot)
datdata.VerifyDepot(Inputs, depot == false, OutputDir); datdata.VerifyDepot(Inputs, depotDepth, OutputDir);
else else
datdata.VerifyGeneric(Inputs, OutputDir, hashOnly, quickScan, asFiles, Filter); datdata.VerifyGeneric(Inputs, OutputDir, hashOnly, quickScan, asFiles, Filter);
} }
@@ -94,8 +93,8 @@ namespace SabreTools.Features
watch.Stop(); watch.Stop();
// If we have the depot flag, respect it // If we have the depot flag, respect it
if (depot != null) if (depot)
datdata.VerifyDepot(Inputs, depot == false, OutputDir); datdata.VerifyDepot(Inputs, depotDepth, OutputDir);
else else
datdata.VerifyGeneric(Inputs, OutputDir, hashOnly, quickScan, asFiles, Filter); datdata.VerifyGeneric(Inputs, OutputDir, hashOnly, quickScan, asFiles, Filter);
} }