From d36cff2f9b4ee9af07f93c80a20cdd99e86be4a8 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 15 Feb 2018 23:52:57 -0800 Subject: [PATCH] [FileTypes] Rename methods to fit better --- SabreTools.Library/DatFiles/DatFile.cs | 6 ++--- SabreTools.Library/FileTypes/BaseArchive.cs | 12 +++++----- SabreTools.Library/FileTypes/Folder.cs | 23 +++++++++---------- SabreTools.Library/FileTypes/GZipArchive.cs | 8 +++---- SabreTools.Library/FileTypes/LRZipArchive.cs | 6 ++--- SabreTools.Library/FileTypes/LZ4Archive.cs | 6 ++--- SabreTools.Library/FileTypes/RarArchive.cs | 8 +++---- .../FileTypes/SevenZipArchive.cs | 8 +++---- SabreTools.Library/FileTypes/TapeArchive.cs | 8 +++---- .../FileTypes/TorrentZipArchive.cs | 8 +++---- SabreTools.Library/FileTypes/XZArchive.cs | 8 +++---- SabreTools.Library/FileTypes/ZPAQArchive.cs | 6 ++--- SabreTools.Library/FileTypes/ZstdArchive.cs | 6 ++--- 13 files changed, 56 insertions(+), 57 deletions(-) diff --git a/SabreTools.Library/DatFiles/DatFile.cs b/SabreTools.Library/DatFiles/DatFile.cs index 1ebc9521..ea0477ac 100644 --- a/SabreTools.Library/DatFiles/DatFile.cs +++ b/SabreTools.Library/DatFiles/DatFile.cs @@ -4403,7 +4403,7 @@ namespace SabreTools.Library.DatFiles Folder archive = Utilities.GetArchive(file); if (archive != null) { - (fileStream, realName) = archive.ExtractEntryStream(datItem.Name); + (fileStream, realName) = archive.CopyToStream(datItem.Name); } } // Otherwise, just open the filestream @@ -4487,7 +4487,7 @@ namespace SabreTools.Library.DatFiles Folder archive = Utilities.GetArchive(file); if (archive != null) { - (fileStream, realName) = archive.ExtractEntryStream(datItem.Name); + (fileStream, realName) = archive.CopyToStream(datItem.Name); } } // Otherwise, just open the filestream @@ -4577,7 +4577,7 @@ namespace SabreTools.Library.DatFiles Folder archive = Utilities.GetArchive(file); if (archive != null) { - (fileStream, realName) = archive.ExtractEntryStream(datItem.Name); + (fileStream, realName) = archive.CopyToStream(datItem.Name); } } // Otherwise, just open the filestream diff --git a/SabreTools.Library/FileTypes/BaseArchive.cs b/SabreTools.Library/FileTypes/BaseArchive.cs index 99043f95..e8797b89 100644 --- a/SabreTools.Library/FileTypes/BaseArchive.cs +++ b/SabreTools.Library/FileTypes/BaseArchive.cs @@ -48,7 +48,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public new abstract bool ExtractAll(string outDir); + public override abstract bool CopyAll(string outDir); /// /// Attempt to extract an entry from an archive @@ -56,7 +56,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public new abstract string ExtractEntry(string entryName, string outDir); + public override abstract string CopyToFile(string entryName, string outDir); /// /// Attempt to extract a stream from an archive @@ -64,7 +64,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public new abstract (MemoryStream, string) ExtractEntryStream(string entryName); + public override abstract (MemoryStream, string) CopyToStream(string entryName); #endregion @@ -104,7 +104,7 @@ namespace SabreTools.Library.FileTypes /// True if the date from the DAT should be used if available, false otherwise (default) /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public abstract bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false); + public override abstract bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false); /// /// Write an input stream to an archive @@ -115,7 +115,7 @@ namespace SabreTools.Library.FileTypes /// True if the date from the DAT should be used if available, false otherwise (default) /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public abstract bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false); + public override abstract bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false); /// /// Write a set of input files to an archive (assuming the same output archive name) @@ -126,7 +126,7 @@ namespace SabreTools.Library.FileTypes /// True if the date from the DAT should be used if available, false otherwise (default) /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public abstract bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false); + public override abstract bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false); #endregion } diff --git a/SabreTools.Library/FileTypes/Folder.cs b/SabreTools.Library/FileTypes/Folder.cs index 0b7d2a95..cf8e9ca1 100644 --- a/SabreTools.Library/FileTypes/Folder.cs +++ b/SabreTools.Library/FileTypes/Folder.cs @@ -20,7 +20,6 @@ using SearchOption = System.IO.SearchOption; using SeekOrigin = System.IO.SeekOrigin; using Stream = System.IO.Stream; #endif -using SharpCompress.Common; namespace SabreTools.Library.FileTypes { @@ -66,7 +65,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public bool ExtractAll(string outDir) + public virtual bool CopyAll(string outDir) { // Copy all files from the current folder to the output directory recursively try @@ -92,7 +91,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public string ExtractEntry(string entryName, string outDir) + public virtual string CopyToFile(string entryName, string outDir) { string realentry = null; @@ -131,7 +130,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public (MemoryStream, string) ExtractEntryStream(string entryName) + public virtual (MemoryStream, string) CopyToStream(string entryName) { MemoryStream ms = new MemoryStream(); string realentry = null; @@ -175,7 +174,7 @@ namespace SabreTools.Library.FileTypes /// True if entry dates should be included, false otherwise (default) /// List of BaseFile objects representing the found data /// TODO: All instances of Hash.DeepHashes should be made into 0x0 eventually - public List GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false) + public virtual List GetChildren(Hash omitFromScan = Hash.DeepHashes, bool date = false) { if (_children == null || _children.Count == 0) { @@ -200,7 +199,7 @@ namespace SabreTools.Library.FileTypes /// /// Input file to get data from /// List of empty folders in the folder - public List GetEmptyFolders() + public virtual List GetEmptyFolders() { return Utilities.GetEmptyDirectories(_filename).ToList(); } @@ -210,7 +209,7 @@ namespace SabreTools.Library.FileTypes #region Writing /// - /// Write an input file to a torrent LRZip file + /// Write an input file to an output folder /// /// Input filename to be moved /// Output directory to build to @@ -219,13 +218,13 @@ namespace SabreTools.Library.FileTypes /// True if files should be output in Romba depot folders, false otherwise /// True if the write was a success, false otherwise /// 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. - public bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false) + public virtual bool Write(string inputFile, string outDir, Rom rom, bool date = false, bool romba = false) { throw new NotImplementedException(); } /// - /// Write an input stream to a torrent LRZip file + /// Write an input stream to an output folder /// /// Input stream to be moved /// Output directory to build to @@ -234,7 +233,7 @@ namespace SabreTools.Library.FileTypes /// True if files should be output in Romba depot folders, false otherwise /// True if the write was a success, false otherwise /// 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. - public bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false) + public virtual bool Write(Stream inputStream, string outDir, Rom rom, bool date = false, bool romba = false) { bool success = false; @@ -308,7 +307,7 @@ namespace SabreTools.Library.FileTypes } /// - /// Write a set of input files to a torrent LRZip archive (assuming the same output archive name) + /// Write a set of input files to an output folder (assuming the same output archive name) /// /// Input files to be moved /// Output directory to build to @@ -316,7 +315,7 @@ namespace SabreTools.Library.FileTypes /// True if the date from the DAT should be used if available, false otherwise (default) /// True if files should be output in Romba depot folders, false otherwise /// True if the archive was written properly, false otherwise - public bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) + public virtual bool Write(List inputFiles, string outDir, List roms, bool date = false, bool romba = false) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/GZipArchive.cs b/SabreTools.Library/FileTypes/GZipArchive.cs index f1a98333..1f92e721 100644 --- a/SabreTools.Library/FileTypes/GZipArchive.cs +++ b/SabreTools.Library/FileTypes/GZipArchive.cs @@ -60,7 +60,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { bool encounteredErrors = true; @@ -103,10 +103,10 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { // Try to extract a stream using the given information - (MemoryStream ms, string realEntry) = ExtractEntryStream(entryName); + (MemoryStream ms, string realEntry) = CopyToStream(entryName); // If the memory stream and the entry name are both non-null, we write to file if (ms != null && realEntry != null) @@ -149,7 +149,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { MemoryStream ms = new MemoryStream(); string realEntry = null; diff --git a/SabreTools.Library/FileTypes/LRZipArchive.cs b/SabreTools.Library/FileTypes/LRZipArchive.cs index 03515601..35b53a81 100644 --- a/SabreTools.Library/FileTypes/LRZipArchive.cs +++ b/SabreTools.Library/FileTypes/LRZipArchive.cs @@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { throw new NotImplementedException(); } @@ -60,7 +60,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { throw new NotImplementedException(); } @@ -71,7 +71,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/LZ4Archive.cs b/SabreTools.Library/FileTypes/LZ4Archive.cs index 474b2add..7d8ac92f 100644 --- a/SabreTools.Library/FileTypes/LZ4Archive.cs +++ b/SabreTools.Library/FileTypes/LZ4Archive.cs @@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { throw new NotImplementedException(); } @@ -60,7 +60,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { throw new NotImplementedException(); } @@ -71,7 +71,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/RarArchive.cs b/SabreTools.Library/FileTypes/RarArchive.cs index fca749b0..c748de60 100644 --- a/SabreTools.Library/FileTypes/RarArchive.cs +++ b/SabreTools.Library/FileTypes/RarArchive.cs @@ -60,7 +60,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { bool encounteredErrors = true; @@ -101,10 +101,10 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { // Try to extract a stream using the given information - (MemoryStream ms, string realEntry) = ExtractEntryStream(entryName); + (MemoryStream ms, string realEntry) = CopyToStream(entryName); // If the memory stream and the entry name are both non-null, we write to file if (ms != null && realEntry != null) @@ -147,7 +147,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { MemoryStream ms = new MemoryStream(); string realEntry = null; diff --git a/SabreTools.Library/FileTypes/SevenZipArchive.cs b/SabreTools.Library/FileTypes/SevenZipArchive.cs index b80cf491..542d6948 100644 --- a/SabreTools.Library/FileTypes/SevenZipArchive.cs +++ b/SabreTools.Library/FileTypes/SevenZipArchive.cs @@ -63,7 +63,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { bool encounteredErrors = true; @@ -104,10 +104,10 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { // Try to extract a stream using the given information - (MemoryStream ms, string realEntry) = ExtractEntryStream(entryName); + (MemoryStream ms, string realEntry) = CopyToStream(entryName); // If the memory stream and the entry name are both non-null, we write to file if (ms != null && realEntry != null) @@ -150,7 +150,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { MemoryStream ms = new MemoryStream(); string realEntry = null; diff --git a/SabreTools.Library/FileTypes/TapeArchive.cs b/SabreTools.Library/FileTypes/TapeArchive.cs index c68addad..02d81f69 100644 --- a/SabreTools.Library/FileTypes/TapeArchive.cs +++ b/SabreTools.Library/FileTypes/TapeArchive.cs @@ -63,7 +63,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { bool encounteredErrors = true; @@ -104,10 +104,10 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { // Try to extract a stream using the given information - (MemoryStream ms, string realEntry) = ExtractEntryStream(entryName); + (MemoryStream ms, string realEntry) = CopyToStream(entryName); // If the memory stream and the entry name are both non-null, we write to file if (ms != null && realEntry != null) @@ -150,7 +150,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { MemoryStream ms = new MemoryStream(); string realEntry = null; diff --git a/SabreTools.Library/FileTypes/TorrentZipArchive.cs b/SabreTools.Library/FileTypes/TorrentZipArchive.cs index b04232f1..77cbf1e2 100644 --- a/SabreTools.Library/FileTypes/TorrentZipArchive.cs +++ b/SabreTools.Library/FileTypes/TorrentZipArchive.cs @@ -59,7 +59,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { bool encounteredErrors = true; @@ -147,10 +147,10 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { // Try to extract a stream using the given information - (MemoryStream ms, string realEntry) = ExtractEntryStream(entryName); + (MemoryStream ms, string realEntry) = CopyToStream(entryName); // If the memory stream and the entry name are both non-null, we write to file if (ms != null && realEntry != null) @@ -193,7 +193,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { MemoryStream ms = new MemoryStream(); string realEntry = null; diff --git a/SabreTools.Library/FileTypes/XZArchive.cs b/SabreTools.Library/FileTypes/XZArchive.cs index 74173c43..8ddd00b6 100644 --- a/SabreTools.Library/FileTypes/XZArchive.cs +++ b/SabreTools.Library/FileTypes/XZArchive.cs @@ -63,7 +63,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { bool encounteredErrors = true; @@ -104,10 +104,10 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { // Try to extract a stream using the given information - (MemoryStream ms, string realEntry) = ExtractEntryStream(entryName); + (MemoryStream ms, string realEntry) = CopyToStream(entryName); // If the memory stream and the entry name are both non-null, we write to file if (ms != null && realEntry != null) @@ -150,7 +150,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { MemoryStream ms = new MemoryStream(); string realEntry = null; diff --git a/SabreTools.Library/FileTypes/ZPAQArchive.cs b/SabreTools.Library/FileTypes/ZPAQArchive.cs index 0664a3bb..7fd012bf 100644 --- a/SabreTools.Library/FileTypes/ZPAQArchive.cs +++ b/SabreTools.Library/FileTypes/ZPAQArchive.cs @@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { throw new NotImplementedException(); } @@ -60,7 +60,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { throw new NotImplementedException(); } @@ -71,7 +71,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { throw new NotImplementedException(); } diff --git a/SabreTools.Library/FileTypes/ZstdArchive.cs b/SabreTools.Library/FileTypes/ZstdArchive.cs index b712f46a..09343096 100644 --- a/SabreTools.Library/FileTypes/ZstdArchive.cs +++ b/SabreTools.Library/FileTypes/ZstdArchive.cs @@ -49,7 +49,7 @@ namespace SabreTools.Library.FileTypes /// /// Output directory for archive extraction /// True if the extraction was a success, false otherwise - public override bool ExtractAll(string outDir) + public override bool CopyAll(string outDir) { throw new NotImplementedException(); } @@ -60,7 +60,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output directory for archive extraction /// Name of the extracted file, null on error - public override string ExtractEntry(string entryName, string outDir) + public override string CopyToFile(string entryName, string outDir) { throw new NotImplementedException(); } @@ -71,7 +71,7 @@ namespace SabreTools.Library.FileTypes /// Name of the entry to be extracted /// Output representing the entry name that was found /// MemoryStream representing the entry, null on error - public override (MemoryStream, string) ExtractEntryStream(string entryName) + public override (MemoryStream, string) CopyToStream(string entryName) { throw new NotImplementedException(); }