[DatFile, Utilities] Rename factory functions

This commit is contained in:
Matt Nadareski
2017-11-17 15:51:09 -08:00
parent 6826996574
commit 68e30cd7d8
2 changed files with 42 additions and 41 deletions

View File

@@ -3056,7 +3056,7 @@ namespace SabreTools.Library.DatFiles
// Now parse the correct type of DAT // Now parse the correct type of DAT
try try
{ {
Utilities.CreateDatFileFromTypeAndBase(Utilities.GetDatFormat(filename), this)?.ParseFile(filename, sysid, srcid, keep, clean, remUnicode); Utilities.GetDatFile(Utilities.GetDatFormat(filename), this)?.ParseFile(filename, sysid, srcid, keep, clean, remUnicode);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -3488,7 +3488,7 @@ namespace SabreTools.Library.DatFiles
if (!archivesAsFiles) if (!archivesAsFiles)
{ {
// Get the base archive first // Get the base archive first
BaseArchive archive = Utilities.CreateArchiveFromExistingInput(newItem); BaseArchive archive = Utilities.GetArchive(newItem);
// Now get all extracted items from the archive // Now get all extracted items from the archive
if (archive != null) if (archive != null)
@@ -3527,7 +3527,7 @@ namespace SabreTools.Library.DatFiles
List<string> empties = new List<string>(); List<string> empties = new List<string>();
// Get the base archive first // Get the base archive first
BaseArchive archive = Utilities.CreateArchiveFromExistingInput(newItem); BaseArchive archive = Utilities.GetArchive(newItem);
// Now get all blank folders from the archive // Now get all blank folders from the archive
if (archive != null) if (archive != null)
@@ -4068,7 +4068,7 @@ namespace SabreTools.Library.DatFiles
bool isTorrentGzip = tgz.IsTorrent(); bool isTorrentGzip = tgz.IsTorrent();
// Get the base archive first // Get the base archive first
BaseArchive archive = Utilities.CreateArchiveFromExistingInput(file); BaseArchive archive = Utilities.GetArchive(file);
// Now get all extracted items from the archive // Now get all extracted items from the archive
if (archive != null) if (archive != null)
@@ -4197,7 +4197,7 @@ namespace SabreTools.Library.DatFiles
if (isZip != null) if (isZip != null)
{ {
string realName = null; string realName = null;
BaseArchive archive = Utilities.CreateArchiveFromExistingInput(file); BaseArchive archive = Utilities.GetArchive(file);
if (archive != null) if (archive != null)
{ {
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name); (fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
@@ -4225,7 +4225,7 @@ namespace SabreTools.Library.DatFiles
foreach (DatItem item in dupes) foreach (DatItem item in dupes)
{ {
// Get the output archive, if possible // Get the output archive, if possible
BaseArchive outputArchive = Utilities.CreateArchiveFromOutputFormat(outputFormat); BaseArchive outputArchive = Utilities.GetArchive(outputFormat);
// Now rebuild to the output file // Now rebuild to the output file
outputArchive.Write(fileStream, outDir, (Rom)item, date: date, romba: romba); outputArchive.Write(fileStream, outDir, (Rom)item, date: date, romba: romba);
@@ -4279,7 +4279,7 @@ namespace SabreTools.Library.DatFiles
if (isZip != null) if (isZip != null)
{ {
string realName = null; string realName = null;
BaseArchive archive = Utilities.CreateArchiveFromExistingInput(file); BaseArchive archive = Utilities.GetArchive(file);
if (archive != null) if (archive != null)
{ {
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name); (fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
@@ -4312,7 +4312,7 @@ namespace SabreTools.Library.DatFiles
Globals.Logger.User("No matches found for '{0}', rebuilding accordingly from inverse flag...", Path.GetFileName(datItem.Name)); Globals.Logger.User("No matches found for '{0}', rebuilding accordingly from inverse flag...", Path.GetFileName(datItem.Name));
// Get the output archive, if possible // Get the output archive, if possible
BaseArchive outputArchive = Utilities.CreateArchiveFromOutputFormat(outputFormat); BaseArchive outputArchive = Utilities.GetArchive(outputFormat);
// Now rebuild to the output file // Now rebuild to the output file
if (outputArchive == null) if (outputArchive == null)
@@ -4369,7 +4369,7 @@ namespace SabreTools.Library.DatFiles
if (isZip != null) if (isZip != null)
{ {
string realName = null; string realName = null;
BaseArchive archive = Utilities.CreateArchiveFromExistingInput(file); BaseArchive archive = Utilities.GetArchive(file);
if (archive != null) if (archive != null)
{ {
(fileStream, realName) = archive.ExtractEntryStream(datItem.Name); (fileStream, realName) = archive.ExtractEntryStream(datItem.Name);
@@ -4429,7 +4429,7 @@ namespace SabreTools.Library.DatFiles
bool eitherSuccess = false; bool eitherSuccess = false;
// Get the output archive, if possible // Get the output archive, if possible
BaseArchive outputArchive = Utilities.CreateArchiveFromOutputFormat(outputFormat); BaseArchive outputArchive = Utilities.GetArchive(outputFormat);
// Now rebuild to the output file // Now rebuild to the output file
eitherSuccess |= outputArchive.Write(transformStream, outDir, (Rom)item, date: date, romba: romba); eitherSuccess |= outputArchive.Write(transformStream, outDir, (Rom)item, date: date, romba: romba);
@@ -5426,7 +5426,7 @@ namespace SabreTools.Library.DatFiles
string outfile = outfiles[datFormat]; string outfile = outfiles[datFormat];
try try
{ {
Utilities.CreateDatFileFromTypeAndBase(datFormat, this)?.WriteToFile(outfile, ignoreblanks); Utilities.GetDatFile(datFormat, this)?.WriteToFile(outfile, ignoreblanks);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -5702,7 +5702,7 @@ namespace SabreTools.Library.DatFiles
// Loop through and output based on the inputs // Loop through and output based on the inputs
foreach (KeyValuePair<StatReportFormat, string> kvp in outputs) foreach (KeyValuePair<StatReportFormat, string> kvp in outputs)
{ {
reports.Add(Utilities.CreateBaseReportFromType(kvp.Key, kvp.Value, baddumpCol, nodumpCol)); reports.Add(Utilities.GetBaseReport(kvp.Key, kvp.Value, baddumpCol, nodumpCol));
} }
// Write the header, if any // Write the header, if any

View File

@@ -441,7 +441,7 @@ namespace SabreTools.Library.Tools
/// </summary> /// </summary>
/// <param name="input">Name of the file to create the archive from</param> /// <param name="input">Name of the file to create the archive from</param>
/// <returns>Archive object representing the inputs</returns> /// <returns>Archive object representing the inputs</returns>
public static BaseArchive CreateArchiveFromExistingInput(string input) public static BaseArchive GetArchive(string input)
{ {
BaseArchive archive = null; BaseArchive archive = null;
@@ -483,7 +483,7 @@ namespace SabreTools.Library.Tools
/// </summary> /// </summary>
/// <param name="archiveType">SharpCompress.Common.ArchiveType representing the archive to create</param> /// <param name="archiveType">SharpCompress.Common.ArchiveType representing the archive to create</param>
/// <returns>Archive object representing the inputs</returns> /// <returns>Archive object representing the inputs</returns>
public static BaseArchive CreateArchiveFromArchiveType(ArchiveType archiveType) public static BaseArchive GetArchive(ArchiveType archiveType)
{ {
switch (archiveType) switch (archiveType)
{ {
@@ -507,7 +507,7 @@ namespace SabreTools.Library.Tools
/// </summary> /// </summary>
/// <param name="archiveType">SabreTools.Library.Data.SharpCompress.OutputFormat representing the archive to create</param> /// <param name="archiveType">SabreTools.Library.Data.SharpCompress.OutputFormat representing the archive to create</param>
/// <returns>Archive object representing the inputs</returns> /// <returns>Archive object representing the inputs</returns>
public static BaseArchive CreateArchiveFromOutputFormat(OutputFormat outputFormat) public static BaseArchive GetArchive(OutputFormat outputFormat)
{ {
switch (outputFormat) switch (outputFormat)
{ {
@@ -538,13 +538,39 @@ namespace SabreTools.Library.Tools
} }
} }
/// <summary>
/// Create a specific type of BaseReport to be used based on a format and user inputs
/// </summary>
/// <param name="statReportFormat">Format of the Statistics Report to be created</param>
/// <param name="filename">Name of the file to write out to</param>
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param>
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param>
/// <returns>BaseReport of the specific internal type that corresponds to the inputs</returns>
public static BaseReport GetBaseReport(StatReportFormat statReportFormat, string filename, bool baddumpCol, bool nodumpCol)
{
switch (statReportFormat)
{
case StatReportFormat.Textfile:
return new Textfile(null, filename, baddumpCol, nodumpCol);
case StatReportFormat.CSV:
return new Reports.SeparatedValue(null, filename, ',', baddumpCol, nodumpCol);
case StatReportFormat.HTML:
return new Html(null, filename, baddumpCol, nodumpCol);
case StatReportFormat.TSV:
return new Reports.SeparatedValue(null, filename, '\t', baddumpCol, nodumpCol);
}
return null;
}
/// <summary> /// <summary>
/// Create a specific type of DatFile to be used based on a format and a base DAT /// Create a specific type of DatFile to be used based on a format and a base DAT
/// </summary> /// </summary>
/// <param name="datFormat">Format of the DAT to be created</param> /// <param name="datFormat">Format of the DAT to be created</param>
/// <param name="baseDat">DatFile containing the information to use in specific operations</param> /// <param name="baseDat">DatFile containing the information to use in specific operations</param>
/// <returns>DatFile of the specific internal type that corresponds to the inputs</returns> /// <returns>DatFile of the specific internal type that corresponds to the inputs</returns>
public static DatFile CreateDatFileFromTypeAndBase(DatFormat datFormat, DatFile baseDat) public static DatFile GetDatFile(DatFormat datFormat, DatFile baseDat)
{ {
switch (datFormat) switch (datFormat)
{ {
@@ -589,31 +615,6 @@ namespace SabreTools.Library.Tools
return null; return null;
} }
/// <summary>
/// Create a specific type of BaseReport to be used based on a format and user inputs
/// </summary>
/// <param name="statReportFormat">Format of the Statistics Report to be created</param>
/// <param name="filename">Name of the file to write out to</param>
/// <param name="baddumpCol">True if baddumps should be included in output, false otherwise</param>
/// <param name="nodumpCol">True if nodumps should be included in output, false otherwise</param>
/// <returns>BaseReport of the specific internal type that corresponds to the inputs</returns>
public static BaseReport CreateBaseReportFromType(StatReportFormat statReportFormat, string filename, bool baddumpCol, bool nodumpCol)
{
switch (statReportFormat)
{
case StatReportFormat.Textfile:
return new Textfile(null, filename, baddumpCol, nodumpCol);
case StatReportFormat.CSV:
return new Reports.SeparatedValue(null, filename, ',', baddumpCol, nodumpCol);
case StatReportFormat.HTML:
return new Html(null, filename, baddumpCol, nodumpCol);
case StatReportFormat.TSV:
return new Reports.SeparatedValue(null, filename, '\t', baddumpCol, nodumpCol);
}
return null;
}
#endregion #endregion
#region File Information #region File Information