Reduce redundant code

This commit is contained in:
Matt Nadareski
2020-08-28 22:21:35 -07:00
parent 165f06ceba
commit b5107a8a2e
2 changed files with 83 additions and 97 deletions

View File

@@ -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>