mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Cleanup between namespace extraction
This commit is contained in:
@@ -5,7 +5,6 @@ using System.Text;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.FileTypes.Aaru;
|
||||
using SabreTools.Library.IO;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
@@ -127,44 +125,23 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override abstract bool CopyAll(string outDir);
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract an entry from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override abstract string CopyToFile(string entryName, string outDir);
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override abstract (MemoryStream, string) CopyToStream(string entryName);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override abstract List<BaseFile> GetChildren();
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override abstract List<string> GetEmptyFolders();
|
||||
|
||||
/// <summary>
|
||||
@@ -176,32 +153,14 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to an archive
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override abstract bool Write(string inputFile, string outDir, Rom rom);
|
||||
/// <inheritdoc/>
|
||||
public override abstract bool Write(string inputFile, string outDir, BaseFile baseFile);
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to an archive
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override abstract bool Write(Stream inputStream, string outDir, Rom rom);
|
||||
/// <inheritdoc/>
|
||||
public override abstract bool Write(Stream inputStream, string outDir, BaseFile baseFile);
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to an archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override abstract bool Write(List<string> inputFiles, string outDir, List<Rom> roms);
|
||||
/// <inheritdoc/>
|
||||
public override abstract bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ using System.Linq;
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Logging;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
@@ -227,7 +226,6 @@ namespace SabreTools.Library.FileTypes
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
public virtual (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
@@ -310,13 +308,13 @@ namespace SabreTools.Library.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <param name="baseFile">BaseFile representing the new information</param>
|
||||
/// <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>
|
||||
public virtual bool Write(string inputFile, string outDir, Rom rom)
|
||||
public virtual bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
FileStream fs = File.OpenRead(inputFile);
|
||||
return Write(fs, outDir, rom);
|
||||
return Write(fs, outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -324,15 +322,15 @@ namespace SabreTools.Library.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <param name="baseFile">BaseFile representing the new information</param>
|
||||
/// <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>
|
||||
public virtual bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
public virtual bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
if (inputStream == null || baseFile == null || baseFile.Filename == null)
|
||||
return success;
|
||||
|
||||
// If the stream is not readable, return
|
||||
@@ -345,9 +343,9 @@ namespace SabreTools.Library.FileTypes
|
||||
// Get the output folder name from the first rebuild rom
|
||||
string fileName;
|
||||
if (writeToParent)
|
||||
fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Name));
|
||||
fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(baseFile.Filename));
|
||||
else
|
||||
fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name), Sanitizer.RemovePathUnsafeCharacters(rom.Name));
|
||||
fileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(baseFile.Parent), Sanitizer.RemovePathUnsafeCharacters(baseFile.Filename));
|
||||
|
||||
try
|
||||
{
|
||||
@@ -374,11 +372,8 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
outputStream.Dispose();
|
||||
|
||||
if (rom.ItemType == ItemType.Rom)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(rom.Date))
|
||||
File.SetCreationTime(fileName, DateTime.Parse(rom.Date));
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(baseFile.Date))
|
||||
File.SetCreationTime(fileName, DateTime.Parse(baseFile.Date));
|
||||
|
||||
success = true;
|
||||
}
|
||||
@@ -401,9 +396,9 @@ namespace SabreTools.Library.FileTypes
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public virtual bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <param name="baseFiles">BaseFiles representing the new information</param>
|
||||
/// <returns>True if the inputs were written properly, false otherwise</returns>
|
||||
public virtual bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -6,9 +6,6 @@ using System.Text.RegularExpressions;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Tools;
|
||||
using Compress;
|
||||
using Compress.gZip;
|
||||
@@ -57,11 +54,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
@@ -104,12 +97,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return encounteredErrors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
@@ -150,12 +138,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return realEntry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -196,10 +179,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
if (_children == null || _children.Count == 0)
|
||||
@@ -261,20 +241,14 @@ namespace SabreTools.Library.FileTypes
|
||||
return _children;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
// GZip files don't contain directories
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
// Check for the file existing first
|
||||
@@ -301,7 +275,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Check if the file is at least the minimum length
|
||||
if (filesize < 40 /* bytes */)
|
||||
{
|
||||
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {Utilities.GetBytesReadable(filesize)}");
|
||||
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {filesize}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -362,7 +336,7 @@ namespace SabreTools.Library.FileTypes
|
||||
// Check if the file is at least the minimum length
|
||||
if (filesize < 40 /* bytes */)
|
||||
{
|
||||
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {Utilities.GetBytesReadable(filesize)}");
|
||||
logger.Warning($"Possibly corrupt file '{Path.GetFullPath(this.Filename)}' with size {filesize}");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -415,15 +389,8 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent GZ file
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom = null)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile = null)
|
||||
{
|
||||
// Check that the input file exists
|
||||
if (!File.Exists(inputFile))
|
||||
@@ -435,18 +402,11 @@ namespace SabreTools.Library.FileTypes
|
||||
inputFile = Path.GetFullPath(inputFile);
|
||||
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to a torrent GZ file
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom = null)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile = null)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
@@ -461,10 +421,10 @@ namespace SabreTools.Library.FileTypes
|
||||
outDir = Path.GetFullPath(outDir);
|
||||
|
||||
// Now get the Rom info for the file so we have hashes and size
|
||||
rom = new Rom(GetInfo(inputStream, keepReadOpen: true));
|
||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, Depth));
|
||||
string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(Utilities.ByteArrayToString(baseFile.SHA1), Depth));
|
||||
|
||||
// Check to see if the folder needs to be created
|
||||
if (!Directory.Exists(Path.GetDirectoryName(outfile)))
|
||||
@@ -481,11 +441,11 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Write standard header and TGZ info
|
||||
byte[] data = Constants.TorrentGZHeader
|
||||
.Concat(Utilities.StringToByteArray(rom.MD5)) // MD5
|
||||
.Concat(Utilities.StringToByteArray(rom.CRC)) // CRC
|
||||
.Concat(baseFile.MD5) // MD5
|
||||
.Concat(baseFile.CRC) // CRC
|
||||
.ToArray();
|
||||
sw.Write(data);
|
||||
sw.Write((ulong)(rom.Size ?? 0)); // Long size (Unsigned, Mirrored)
|
||||
sw.Write((ulong)(baseFile.Size ?? 0)); // Long size (Unsigned, Mirrored)
|
||||
|
||||
// Now create a deflatestream from the input file
|
||||
ZlibBaseStream ds = new ZlibBaseStream(outputStream, CompressionMode.Compress, CompressionLevel.BestCompression, ZlibStreamFlavor.DEFLATE, true);
|
||||
@@ -502,8 +462,8 @@ namespace SabreTools.Library.FileTypes
|
||||
ds.Dispose();
|
||||
|
||||
// Now write the standard footer
|
||||
sw.Write(Utilities.StringToByteArray(rom.CRC).Reverse().ToArray());
|
||||
sw.Write((uint)(rom.Size ?? 0));
|
||||
sw.Write(baseFile.CRC.Reverse().ToArray());
|
||||
sw.Write((uint)(baseFile.Size ?? 0));
|
||||
|
||||
// Dispose of everything
|
||||
sw.Dispose();
|
||||
@@ -513,14 +473,8 @@ namespace SabreTools.Library.FileTypes
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrent GZ archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
@@ -39,33 +38,19 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -75,28 +60,19 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -106,40 +82,20 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent LRZip file
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to a torrent LRZip file
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrent LRZip archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
@@ -39,33 +38,19 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -75,28 +60,19 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -106,40 +82,20 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent LZ4 file
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile rom)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to a torrent LZ4 file
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile rom)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrent LZ4 archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SharpCompress.Archives;
|
||||
using SharpCompress.Archives.Rar;
|
||||
using SharpCompress.Readers;
|
||||
@@ -44,11 +42,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
@@ -86,12 +80,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return encounteredErrors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
@@ -132,12 +121,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return realEntry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -171,10 +155,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
@@ -222,11 +203,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
List<string> empties = new List<string>();
|
||||
@@ -262,9 +239,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return empties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -274,39 +249,21 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrentrar archive
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to a torrentrar archive
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrentrar archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> roms)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
using Compress;
|
||||
using Compress.SevenZip;
|
||||
@@ -46,11 +44,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
@@ -135,12 +129,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return encounteredErrors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
@@ -181,12 +170,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return realEntry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -255,10 +239,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
@@ -329,11 +310,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
List<string> empties = new List<string>();
|
||||
@@ -381,9 +358,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return empties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
SevenZ zf = new SevenZ();
|
||||
@@ -400,33 +375,21 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent7z archive
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent7z archive
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
if (inputStream == null || baseFile == null || baseFile.Filename == null)
|
||||
return success;
|
||||
|
||||
// If the stream is not readable, return
|
||||
@@ -437,7 +400,7 @@ namespace SabreTools.Library.FileTypes
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name) + (rom.Machine.Name.EndsWith(".7z") ? string.Empty : ".7z"));
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent.EndsWith(".7z") ? string.Empty : ".7z"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
@@ -461,14 +424,14 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, rom.Name.Replace('\\', '/'), istreamSize, 0, null, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -480,7 +443,7 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(rom.CRC));
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC);
|
||||
}
|
||||
|
||||
// Otherwise, sort the input files and write out in the correct order
|
||||
@@ -498,9 +461,9 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// If the old one doesn't contain the new file, then add it
|
||||
if (!oldZipFileContents.Contains(rom.Name.Replace('\\', '/')))
|
||||
if (!oldZipFileContents.Contains(baseFile.Filename.Replace('\\', '/')))
|
||||
{
|
||||
inputIndexMap.Add(rom.Name.Replace('\\', '/'), -1);
|
||||
inputIndexMap.Add(baseFile.Filename.Replace('\\', '/'), -1);
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
@@ -536,14 +499,14 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, rom.Name.Replace('\\', '/'), istreamSize, 0, null, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFile.Filename.Replace('\\', '/'), istreamSize, 0, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -555,7 +518,7 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(rom.CRC));
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
@@ -604,26 +567,20 @@ namespace SabreTools.Library.FileTypes
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrent7z archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either list of roms is null or empty, return
|
||||
if (inputFiles == null || roms == null || inputFiles.Count == 0 || roms.Count == 0)
|
||||
if (inputFiles == null || baseFiles == null || inputFiles.Count == 0 || baseFiles.Count == 0)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// If the number of inputs is less than the number of available roms, return
|
||||
if (inputFiles.Count < roms.Count)
|
||||
if (inputFiles.Count < baseFiles.Count)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
@@ -638,7 +595,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].Machine.Name) + (roms[0].Machine.Name.EndsWith(".7z") ? string.Empty : ".7z"));
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent.EndsWith(".7z") ? string.Empty : ".7z"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
@@ -663,7 +620,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), i);
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
|
||||
}
|
||||
|
||||
// Sort the keys in TZIP order
|
||||
@@ -681,14 +638,14 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[index].Name.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, roms[index].Name.Replace('\\', '/'), istreamSize, 0, null, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, 0, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -701,7 +658,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
freadStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(roms[index].CRC));
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[index].CRC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -722,12 +679,12 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// If the old one contains the new file, then just skip out
|
||||
if (oldZipFileContents.Contains(roms[i].Name.Replace('\\', '/')))
|
||||
if (oldZipFileContents.Contains(baseFiles[i].Filename.Replace('\\', '/')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), -(i + 1));
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), -(i + 1));
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
@@ -764,14 +721,14 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, 0, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, 0, null, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, 0, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -783,7 +740,7 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Flush();
|
||||
}
|
||||
freadStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(roms[-index - 1].CRC));
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[-index - 1].CRC);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
using Compress.ZipFile;
|
||||
using SharpCompress.Archives;
|
||||
@@ -17,7 +15,7 @@ using SharpCompress.Writers;
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a Torrent7zip archive for reading and writing
|
||||
/// Represents a Tape archive for reading and writing
|
||||
/// </summary>
|
||||
/// TODO: Don't try to read entries to MemoryStream during write
|
||||
public class TapeArchive : BaseArchive
|
||||
@@ -25,7 +23,7 @@ namespace SabreTools.Library.FileTypes
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a new TorrentTarArchive with no base file
|
||||
/// Create a new Tape archive with no base file
|
||||
/// </summary>
|
||||
public TapeArchive()
|
||||
: base()
|
||||
@@ -34,7 +32,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new TorrentTarArchive from the given file
|
||||
/// Create a new Tape archive from the given file
|
||||
/// </summary>
|
||||
/// <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>
|
||||
@@ -49,11 +47,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
@@ -91,12 +85,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return encounteredErrors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
@@ -137,12 +126,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return realEntry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -176,10 +160,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
@@ -227,11 +208,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
List<string> empties = new List<string>();
|
||||
@@ -267,9 +244,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return empties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -279,33 +254,21 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a tape archive
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to a tape archive
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
if (inputStream == null || baseFile == null || baseFile.Filename == null)
|
||||
return success;
|
||||
|
||||
// If the stream is not readable, return
|
||||
@@ -313,7 +276,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return success;
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name) + (rom.Machine.Name.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
|
||||
// Set internal variables
|
||||
TarArchive oldTarFile = TarArchive.Create();
|
||||
@@ -330,12 +293,12 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input stream to the output
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
tarFile.AddEntry(rom.Name, inputStream, size: rom.Size ?? 0, modified: usableDate);
|
||||
tarFile.AddEntry(baseFile.Filename, inputStream, size: baseFile.Size ?? 0, modified: usableDate);
|
||||
}
|
||||
|
||||
// Otherwise, sort the input files and write out in the correct order
|
||||
@@ -351,8 +314,8 @@ namespace SabreTools.Library.FileTypes
|
||||
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
|
||||
|
||||
// If the old one doesn't contain the new file, then add it
|
||||
if (!entries.Contains(rom.Name.Replace('\\', '/')))
|
||||
inputIndexMap.Add(rom.Name.Replace('\\', '/'), -1);
|
||||
if (!entries.Contains(baseFile.Filename.Replace('\\', '/')))
|
||||
inputIndexMap.Add(baseFile.Filename.Replace('\\', '/'), -1);
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < entries.Count; i++)
|
||||
@@ -379,7 +342,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// If we have the input file, add it now
|
||||
@@ -387,7 +350,7 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Copy the input file to the output
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
tarFile.AddEntry(rom.Name, inputStream, size: rom.Size ?? 0, modified: usableDate);
|
||||
tarFile.AddEntry(baseFile.Filename, inputStream, size: baseFile.Size ?? 0, modified: usableDate);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
@@ -429,26 +392,20 @@ namespace SabreTools.Library.FileTypes
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a tape archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either list of roms is null or empty, return
|
||||
if (inputFiles == null || roms == null || inputFiles.Count == 0 || roms.Count == 0)
|
||||
if (inputFiles == null || baseFiles == null || inputFiles.Count == 0 || baseFiles.Count == 0)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// If the number of inputs is less than the number of available roms, return
|
||||
if (inputFiles.Count < roms.Count)
|
||||
if (inputFiles.Count < baseFiles.Count)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
@@ -463,7 +420,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].Machine.Name) + (roms[0].Machine.Name.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent.EndsWith(".tar") ? string.Empty : ".tar"));
|
||||
|
||||
// Set internal variables
|
||||
TarArchive oldTarFile = TarArchive.Create();
|
||||
@@ -484,7 +441,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), i);
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
|
||||
}
|
||||
|
||||
// Sort the keys in TZIP order
|
||||
@@ -499,11 +456,11 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input stream to the output
|
||||
tarFile.AddEntry(roms[index].Name, File.OpenRead(inputFiles[index]), size: roms[index].Size ?? 0, modified: usableDate);
|
||||
tarFile.AddEntry(baseFiles[index].Filename, File.OpenRead(inputFiles[index]), size: baseFiles[index].Size ?? 0, modified: usableDate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -521,12 +478,12 @@ namespace SabreTools.Library.FileTypes
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
// If the old one contains the new file, then just skip out
|
||||
if (entries.Contains(roms[i].Name.Replace('\\', '/')))
|
||||
if (entries.Contains(baseFiles[i].Filename.Replace('\\', '/')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), -(i + 1));
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), -(i + 1));
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
@@ -557,11 +514,11 @@ namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
// Get temporary date-time if possible
|
||||
DateTime? usableDate = null;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out DateTime dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out DateTime dt))
|
||||
usableDate = dt;
|
||||
|
||||
// Copy the input file to the output
|
||||
tarFile.AddEntry(roms[-index - 1].Name, File.OpenRead(inputFiles[-index - 1]), size: roms[-index - 1].Size ?? 0, modified: usableDate);
|
||||
tarFile.AddEntry(baseFiles[-index - 1].Filename, File.OpenRead(inputFiles[-index - 1]), size: baseFiles[-index - 1].Size ?? 0, modified: usableDate);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
|
||||
@@ -5,9 +5,6 @@ using System.Text.RegularExpressions;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.IO;
|
||||
using SabreTools.Library.Tools;
|
||||
using SharpCompress.Compressors.Xz;
|
||||
|
||||
@@ -54,11 +51,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
@@ -98,12 +91,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return encounteredErrors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
@@ -144,12 +132,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return realEntry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -188,10 +171,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
if (_children == null || _children.Count == 0)
|
||||
@@ -249,20 +229,14 @@ namespace SabreTools.Library.FileTypes
|
||||
return _children;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
// XZ files don't contain directories
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
// Check for the file existing first
|
||||
@@ -315,15 +289,8 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent XZ file
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
// Check that the input file exists
|
||||
if (!File.Exists(inputFile))
|
||||
@@ -335,17 +302,11 @@ namespace SabreTools.Library.FileTypes
|
||||
inputFile = Path.GetFullPath(inputFile);
|
||||
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent XZ archive
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
@@ -360,10 +321,10 @@ namespace SabreTools.Library.FileTypes
|
||||
outDir = Path.GetFullPath(outDir);
|
||||
|
||||
// Now get the Rom info for the file so we have hashes and size
|
||||
rom = new Rom(GetInfo(inputStream, keepReadOpen: true));
|
||||
baseFile = GetInfo(inputStream, keepReadOpen: true);
|
||||
|
||||
// Get the output file name
|
||||
string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(rom.SHA1, Depth));
|
||||
string outfile = Path.Combine(outDir, PathExtensions.GetDepotPath(Utilities.ByteArrayToString(baseFile.SHA1), Depth));
|
||||
outfile = outfile.Replace(".gz", ".xz");
|
||||
|
||||
// Check to see if the folder needs to be created
|
||||
@@ -384,14 +345,8 @@ namespace SabreTools.Library.FileTypes
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrent XZ archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
@@ -39,33 +38,19 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -75,28 +60,19 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -106,40 +82,20 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent ZPAQ file
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to a torrent ZPAQ file
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrent ZPAQ archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.IO;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Tools;
|
||||
using Compress;
|
||||
using Compress.ZipFile;
|
||||
@@ -45,11 +43,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
bool encounteredErrors = true;
|
||||
@@ -136,12 +130,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return encounteredErrors;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
// Try to extract a stream using the given information
|
||||
@@ -182,12 +171,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return realEntry;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
@@ -256,10 +240,7 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
List<BaseFile> found = new List<BaseFile>();
|
||||
@@ -331,11 +312,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return found;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
List<string> empties = new List<string>();
|
||||
@@ -383,9 +360,7 @@ namespace SabreTools.Library.FileTypes
|
||||
return empties;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
ZipFile zf = new ZipFile();
|
||||
@@ -402,33 +377,21 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrentzip archive
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
// Get the file stream for the file and write out
|
||||
return Write(File.OpenRead(inputFile), outDir, rom);
|
||||
return Write(File.OpenRead(inputFile), outDir, baseFile);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to a torrentzip archive
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either input is null or empty, return
|
||||
if (inputStream == null || rom == null || rom.Name == null)
|
||||
if (inputStream == null || baseFile == null || baseFile.Filename == null)
|
||||
return success;
|
||||
|
||||
// If the stream is not readable, return
|
||||
@@ -439,7 +402,7 @@ namespace SabreTools.Library.FileTypes
|
||||
inputStream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(rom.Machine.Name) + (rom.Machine.Name.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(baseFile.Parent) + (baseFile.Parent.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
@@ -463,14 +426,14 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -482,7 +445,7 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(rom.CRC));
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC);
|
||||
}
|
||||
|
||||
// Otherwise, sort the input files and write out in the correct order
|
||||
@@ -500,8 +463,8 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// If the old one doesn't contain the new file, then add it
|
||||
if (!oldZipFileContents.Contains(rom.Name.Replace('\\', '/')))
|
||||
inputIndexMap.Add(rom.Name.Replace('\\', '/'), -1);
|
||||
if (!oldZipFileContents.Contains(baseFile.Filename.Replace('\\', '/')))
|
||||
inputIndexMap.Add(baseFile.Filename.Replace('\\', '/'), -1);
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
for (int i = 0; i < oldZipFile.LocalFilesCount(); i++)
|
||||
@@ -536,14 +499,14 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(inputStream.Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(rom.Date) && DateTime.TryParse(rom.Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFile.Date) && DateTime.TryParse(baseFile.Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, rom.Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFile.Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -555,7 +518,7 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Flush();
|
||||
}
|
||||
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(rom.CRC));
|
||||
zipFile.ZipFileCloseWriteStream(baseFile.CRC);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
@@ -605,26 +568,20 @@ namespace SabreTools.Library.FileTypes
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrentzip archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filenames to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">List of Rom representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
bool success = false;
|
||||
string tempFile = Path.Combine(outDir, $"tmp{Guid.NewGuid()}");
|
||||
|
||||
// If either list of roms is null or empty, return
|
||||
if (inputFiles == null || roms == null || inputFiles.Count == 0 || roms.Count == 0)
|
||||
if (inputFiles == null || baseFiles == null || inputFiles.Count == 0 || baseFiles.Count == 0)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
|
||||
// If the number of inputs is less than the number of available roms, return
|
||||
if (inputFiles.Count < roms.Count)
|
||||
if (inputFiles.Count < baseFiles.Count)
|
||||
{
|
||||
return success;
|
||||
}
|
||||
@@ -639,7 +596,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// Get the output archive name from the first rebuild rom
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(roms[0].Machine.Name) + (roms[0].Machine.Name.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
string archiveFileName = Path.Combine(outDir, Sanitizer.RemovePathUnsafeCharacters(baseFiles[0].Parent) + (baseFiles[0].Parent.EndsWith(".zip") ? string.Empty : ".zip"));
|
||||
|
||||
// Set internal variables
|
||||
Stream writeStream = null;
|
||||
@@ -664,7 +621,7 @@ namespace SabreTools.Library.FileTypes
|
||||
Dictionary<string, int> inputIndexMap = new Dictionary<string, int>();
|
||||
for (int i = 0; i < inputFiles.Count; i++)
|
||||
{
|
||||
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), i);
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), i);
|
||||
}
|
||||
|
||||
// Sort the keys in TZIP order
|
||||
@@ -682,14 +639,14 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[index]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(roms[index].Date) && DateTime.TryParse(roms[index].Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[index].Date) && DateTime.TryParse(baseFiles[index].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[index].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, roms[index].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[index].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -702,7 +659,7 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
freadStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(roms[index].CRC));
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[index].CRC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -723,12 +680,12 @@ namespace SabreTools.Library.FileTypes
|
||||
}
|
||||
|
||||
// If the old one contains the new file, then just skip out
|
||||
if (oldZipFileContents.Contains(roms[i].Name.Replace('\\', '/')))
|
||||
if (oldZipFileContents.Contains(baseFiles[i].Filename.Replace('\\', '/')))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
inputIndexMap.Add(roms[i].Name.Replace('\\', '/'), -(i + 1));
|
||||
inputIndexMap.Add(baseFiles[i].Filename.Replace('\\', '/'), -(i + 1));
|
||||
}
|
||||
|
||||
// Then add all of the old entries to it too
|
||||
@@ -765,14 +722,14 @@ namespace SabreTools.Library.FileTypes
|
||||
ulong istreamSize = (ulong)(new FileInfo(inputFiles[-index - 1]).Length);
|
||||
|
||||
DateTime dt = DateTime.Now;
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(roms[-index - 1].Date) && DateTime.TryParse(roms[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
if (UseDates && !string.IsNullOrWhiteSpace(baseFiles[-index - 1].Date) && DateTime.TryParse(baseFiles[-index - 1].Date.Replace('\\', '/'), out dt))
|
||||
{
|
||||
uint msDosDateTime = Utilities.ConvertDateTimeToMsDosTimeFormat(dt);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, false, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, msDosDateTime, out writeStream);
|
||||
}
|
||||
else
|
||||
{
|
||||
zipFile.ZipFileOpenWriteStream(false, true, roms[-index - 1].Name.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
zipFile.ZipFileOpenWriteStream(false, true, baseFiles[-index - 1].Filename.Replace('\\', '/'), istreamSize, (ushort)CompressionMethod.Deflated, null, out writeStream);
|
||||
}
|
||||
|
||||
// Copy the input stream to the output
|
||||
@@ -784,7 +741,7 @@ namespace SabreTools.Library.FileTypes
|
||||
writeStream.Flush();
|
||||
}
|
||||
freadStream.Dispose();
|
||||
zipFile.ZipFileCloseWriteStream(Utilities.StringToByteArray(roms[-index - 1].CRC));
|
||||
zipFile.ZipFileCloseWriteStream(baseFiles[-index - 1].CRC);
|
||||
}
|
||||
|
||||
// Otherwise, copy the file from the old archive
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using SabreTools.Data;
|
||||
using SabreTools.Library.DatItems;
|
||||
|
||||
namespace SabreTools.Library.FileTypes
|
||||
{
|
||||
@@ -39,33 +38,19 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Extraction
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file as an archive
|
||||
/// </summary>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>True if the extraction was a success, false otherwise</returns>
|
||||
/// <inheritdoc/>
|
||||
public override bool CopyAll(string outDir)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a file from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="outDir">Output directory for archive extraction</param>
|
||||
/// <returns>Name of the extracted file, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override string CopyToFile(string entryName, string outDir)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to extract a stream from an archive
|
||||
/// </summary>
|
||||
/// <param name="entryName">Name of the entry to be extracted</param>
|
||||
/// <param name="realEntry">Output representing the entry name that was found</param>
|
||||
/// <returns>MemoryStream representing the entry, null on error</returns>
|
||||
/// <inheritdoc/>
|
||||
public override (MemoryStream, string) CopyToStream(string entryName)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -75,28 +60,19 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of DatItem objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <returns>List of DatItem objects representing the found data</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<BaseFile> GetChildren()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of empty folders in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <returns>List of empty folders in the archive</returns>
|
||||
/// <inheritdoc/>
|
||||
public override List<string> GetEmptyFolders()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check whether the input file is a standardized format
|
||||
/// </summary>
|
||||
/// <inheritdoc/>
|
||||
public override bool IsTorrent()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
@@ -106,40 +82,20 @@ namespace SabreTools.Library.FileTypes
|
||||
|
||||
#region Writing
|
||||
|
||||
/// <summary>
|
||||
/// Write an input file to a torrent Zstd file
|
||||
/// </summary>
|
||||
/// <param name="inputFile">Input filename to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(string inputFile, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(string inputFile, string outDir, BaseFile baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write an input stream to a torrent Zstd file
|
||||
/// </summary>
|
||||
/// <param name="inputStream">Input stream to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <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>
|
||||
public override bool Write(Stream inputStream, string outDir, Rom rom)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(Stream inputStream, string outDir, BaseFile baseFile)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a set of input files to a torrent Zstd archive (assuming the same output archive name)
|
||||
/// </summary>
|
||||
/// <param name="inputFiles">Input files to be moved</param>
|
||||
/// <param name="outDir">Output directory to build to</param>
|
||||
/// <param name="rom">DatItem representing the new information</param>
|
||||
/// <returns>True if the archive was written properly, false otherwise</returns>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<Rom> roms)
|
||||
/// <inheritdoc/>
|
||||
public override bool Write(List<string> inputFiles, string outDir, List<BaseFile> baseFiles)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user