[Utilities, SabreTools] Add flag conversion methods

This commit is contained in:
Matt Nadareski
2017-12-01 11:03:58 -08:00
parent de7d144e00
commit 3a6f673bf1
2 changed files with 63 additions and 76 deletions

View File

@@ -303,6 +303,65 @@ namespace SabreTools.Library.Tools
return hash;
}
/// <summary>
/// Get ForceMerging value from input string
/// </summary>
/// <param name="forcemerge">String to get value from</param>
/// <returns>ForceMerging value corresponding to the string</returns>
public static ForceMerging GetForceMerging(string forcemerge)
{
switch (forcemerge?.ToLowerInvariant())
{
case "none":
default:
return ForceMerging.None;
case "split":
return ForceMerging.Split;
case "full":
return ForceMerging.Full;
}
}
/// <summary>
/// Get ForceNodump value from input string
/// </summary>
/// <param name="forcend">String to get value from</param>
/// <returns>ForceNodump value corresponding to the string</returns>
public static ForceNodump GetForceNodump(string forcend)
{
switch (forcend?.ToLowerInvariant())
{
case "none":
default:
return ForceNodump.None;
case "obsolete":
return ForceNodump.Obsolete;
case "required":
return ForceNodump.Required;
case "ignore":
return ForceNodump.Ignore;
}
}
/// <summary>
/// Get ForcePacking value from input string
/// </summary>
/// <param name="forcepack">String to get value from</param>
/// <returns>ForcePacking value corresponding to the string</returns>
public static ForcePacking GetForcePacking(string forcepack)
{
switch (forcepack?.ToLowerInvariant())
{
case "none":
default:
return ForcePacking.None;
case "zip":
return ForcePacking.Zip;
case "unzip":
return ForcePacking.Unzip;
}
}
/// <summary>
/// Replace accented characters
/// </summary>

View File

@@ -87,20 +87,7 @@ namespace SabreTools
string headerToCheckAgainst,
bool chdsAsFiles)
{
ForcePacking fp = ForcePacking.None;
switch (forcepack?.ToLowerInvariant())
{
case "none":
default:
fp = ForcePacking.None;
break;
case "zip":
fp = ForcePacking.Zip;
break;
case "unzip":
fp = ForcePacking.Unzip;
break;
}
ForcePacking fp = Utilities.GetForcePacking(forcepack);
// Create a new DATFromDir object and process the inputs
DatFile basedat = new DatFile
@@ -394,68 +381,9 @@ namespace SabreTools
Hash stripHash)
{
// Set the special flags
ForceMerging fm = ForceMerging.None;
if (!String.IsNullOrWhiteSpace(forcemerge))
{
switch (forcemerge.ToLowerInvariant())
{
case "none":
fm = ForceMerging.None;
break;
case "split":
fm = ForceMerging.Split;
break;
case "full":
fm = ForceMerging.Full;
break;
default:
Globals.Logger.Warning("{0} is not a valid merge flag", forcemerge);
break;
}
}
ForceNodump fn = ForceNodump.None;
if (!String.IsNullOrWhiteSpace(forcend))
{
switch (forcend.ToLowerInvariant())
{
case "none":
fn = ForceNodump.None;
break;
case "obsolete":
fn = ForceNodump.Obsolete;
break;
case "required":
fn = ForceNodump.Required;
break;
case "ignore":
fn = ForceNodump.Ignore;
break;
default:
Globals.Logger.Warning("{0} is not a valid nodump flag", forcend);
break;
}
}
ForcePacking fp = ForcePacking.None;
if (!String.IsNullOrWhiteSpace(forcepack))
{
switch (forcepack.ToLowerInvariant())
{
case "none":
fp = ForcePacking.None;
break;
case "zip":
fp = ForcePacking.Zip;
break;
case "unzip":
fp = ForcePacking.Unzip;
break;
default:
Globals.Logger.Warning("{0} is not a valid packing flag", forcepack);
break;
}
}
ForceMerging fm = Utilities.GetForceMerging(forcemerge);
ForceNodump fn = Utilities.GetForceNodump(forcend);
ForcePacking fp = Utilities.GetForcePacking(forcepack);
// Normalize the extensions
addext = (addext == "" || addext.StartsWith(".") ? addext : "." + addext);