mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Reduce redundant code
This commit is contained in:
@@ -2362,21 +2362,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// Now we want to get forcepack flag if it's not overridden
|
||||
if (outputFormat == OutputFormat.Folder && Header.ForcePacking != PackingFlag.None)
|
||||
{
|
||||
switch (Header.ForcePacking)
|
||||
{
|
||||
case PackingFlag.Zip:
|
||||
outputFormat = OutputFormat.TorrentZip;
|
||||
break;
|
||||
case PackingFlag.Unzip:
|
||||
case PackingFlag.Partial:
|
||||
outputFormat = OutputFormat.Folder;
|
||||
break;
|
||||
case PackingFlag.Flat:
|
||||
outputFormat = OutputFormat.ParentFolder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
outputFormat = Header.ForcePacking.AsOutputFormat();
|
||||
|
||||
// Preload the Skipper list
|
||||
Transform.Init();
|
||||
@@ -2387,38 +2373,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
#region Rebuild from depots in order
|
||||
|
||||
string format = string.Empty;
|
||||
switch (outputFormat)
|
||||
{
|
||||
case OutputFormat.Folder:
|
||||
case OutputFormat.ParentFolder:
|
||||
format = "directory";
|
||||
break;
|
||||
case OutputFormat.TapeArchive:
|
||||
format = "TAR";
|
||||
break;
|
||||
case OutputFormat.Torrent7Zip:
|
||||
format = "Torrent7Z";
|
||||
break;
|
||||
case OutputFormat.TorrentGzip:
|
||||
case OutputFormat.TorrentGzipRomba:
|
||||
format = "TorrentGZ";
|
||||
break;
|
||||
case OutputFormat.TorrentLRZip:
|
||||
format = "TorrentLRZ";
|
||||
break;
|
||||
case OutputFormat.TorrentRar:
|
||||
format = "TorrentRAR";
|
||||
break;
|
||||
case OutputFormat.TorrentXZ:
|
||||
case OutputFormat.TorrentXZRomba:
|
||||
format = "TorrentXZ";
|
||||
break;
|
||||
case OutputFormat.TorrentZip:
|
||||
format = "TorrentZip";
|
||||
break;
|
||||
}
|
||||
|
||||
string format = outputFormat.FromOutputFormat() ?? string.Empty;
|
||||
InternalStopwatch watch = new InternalStopwatch($"Rebuilding all files to {format}");
|
||||
|
||||
// Now loop through and get only directories from the input paths
|
||||
@@ -2560,21 +2515,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
// Now we want to get forcepack flag if it's not overridden
|
||||
if (outputFormat == OutputFormat.Folder && Header.ForcePacking != PackingFlag.None)
|
||||
{
|
||||
switch (Header.ForcePacking)
|
||||
{
|
||||
case PackingFlag.Zip:
|
||||
outputFormat = OutputFormat.TorrentZip;
|
||||
break;
|
||||
case PackingFlag.Unzip:
|
||||
case PackingFlag.Partial:
|
||||
outputFormat = OutputFormat.Folder;
|
||||
break;
|
||||
case PackingFlag.Flat:
|
||||
outputFormat = OutputFormat.ParentFolder;
|
||||
break;
|
||||
}
|
||||
}
|
||||
outputFormat = Header.ForcePacking.AsOutputFormat();
|
||||
|
||||
// Preload the Skipper list
|
||||
Transform.Init();
|
||||
@@ -2585,38 +2526,7 @@ namespace SabreTools.Library.DatFiles
|
||||
|
||||
#region Rebuild from sources in order
|
||||
|
||||
string format = string.Empty;
|
||||
switch (outputFormat)
|
||||
{
|
||||
case OutputFormat.Folder:
|
||||
case OutputFormat.ParentFolder:
|
||||
format = "directory";
|
||||
break;
|
||||
case OutputFormat.TapeArchive:
|
||||
format = "TAR";
|
||||
break;
|
||||
case OutputFormat.Torrent7Zip:
|
||||
format = "Torrent7Z";
|
||||
break;
|
||||
case OutputFormat.TorrentGzip:
|
||||
case OutputFormat.TorrentGzipRomba:
|
||||
format = "TorrentGZ";
|
||||
break;
|
||||
case OutputFormat.TorrentLRZip:
|
||||
format = "TorrentLRZ";
|
||||
break;
|
||||
case OutputFormat.TorrentRar:
|
||||
format = "TorrentRAR";
|
||||
break;
|
||||
case OutputFormat.TorrentXZ:
|
||||
case OutputFormat.TorrentXZRomba:
|
||||
format = "TorrentXZ";
|
||||
break;
|
||||
case OutputFormat.TorrentZip:
|
||||
format = "TorrentZip";
|
||||
break;
|
||||
}
|
||||
|
||||
string format = outputFormat.FromOutputFormat() ?? string.Empty;
|
||||
InternalStopwatch watch = new InternalStopwatch($"Rebuilding all files to {format}");
|
||||
|
||||
// Now loop through all of the files in all of the inputs
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.Reports;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using SabreTools.Library.DatFiles;
|
||||
using SabreTools.Library.DatItems;
|
||||
using SabreTools.Library.FileTypes;
|
||||
using SabreTools.Library.Reports;
|
||||
|
||||
namespace SabreTools.Library.Tools
|
||||
{
|
||||
public static class Converters
|
||||
@@ -38,6 +41,28 @@ namespace SabreTools.Library.Tools
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the default OutputFormat associated with each PackingFlag
|
||||
/// </summary>
|
||||
/// <param name="packing"></param>
|
||||
/// <returns></returns>
|
||||
public static OutputFormat AsOutputFormat(this PackingFlag packing)
|
||||
{
|
||||
switch (packing)
|
||||
{
|
||||
case PackingFlag.Zip:
|
||||
return OutputFormat.TorrentZip;
|
||||
case PackingFlag.Unzip:
|
||||
case PackingFlag.Partial:
|
||||
return OutputFormat.Folder;
|
||||
case PackingFlag.Flat:
|
||||
return OutputFormat.ParentFolder;
|
||||
case PackingFlag.None:
|
||||
default:
|
||||
return OutputFormat.Folder;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region String to Enum
|
||||
@@ -2079,6 +2104,57 @@ namespace SabreTools.Library.Tools
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input OutputFormat
|
||||
/// </summary>
|
||||
/// <param name="itemType">OutputFormat to get value from</param>
|
||||
/// <returns>String value corresponding to the OutputFormat</returns>
|
||||
public static string FromOutputFormat(this OutputFormat itemType)
|
||||
{
|
||||
#if NET_FRAMEWORK
|
||||
switch (itemType)
|
||||
{
|
||||
case OutputFormat.Folder:
|
||||
case OutputFormat.ParentFolder:
|
||||
return "directory";
|
||||
case OutputFormat.TapeArchive:
|
||||
return "TAR";
|
||||
case OutputFormat.Torrent7Zip:
|
||||
return "Torrent7Z";
|
||||
case OutputFormat.TorrentGzip:
|
||||
case OutputFormat.TorrentGzipRomba:
|
||||
return "TorrentGZ";
|
||||
case OutputFormat.TorrentLRZip:
|
||||
return "TorrentLRZ";
|
||||
case OutputFormat.TorrentRar:
|
||||
return "TorrentRAR";
|
||||
case OutputFormat.TorrentXZ:
|
||||
case OutputFormat.TorrentXZRomba:
|
||||
return "TorrentXZ";
|
||||
case OutputFormat.TorrentZip:
|
||||
return "TorrentZip";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
#else
|
||||
return itemType switch
|
||||
{
|
||||
OutputFormat.Folder => "directory",
|
||||
OutputFormat.ParentFolder => "directory",
|
||||
OutputFormat.TapeArchive => "TAR",
|
||||
OutputFormat.Torrent7Zip => "Torrent7Z",
|
||||
OutputFormat.TorrentGzip => "TorrentGZ",
|
||||
OutputFormat.TorrentGzipRomba => "TorrentGZ",
|
||||
OutputFormat.TorrentLRZip => "TorrentLRZ",
|
||||
OutputFormat.TorrentRar => "TorrentRAR",
|
||||
OutputFormat.TorrentXZ => "TorrentXZ",
|
||||
OutputFormat.TorrentXZRomba => "TorrentXZ",
|
||||
OutputFormat.TorrentZip => "TorrentZip",
|
||||
_ => null,
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get string value from input PackingFlag
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user