[SabreTools, DatFile, Utilities] Add "output-type" flag (not hooked up)

This commit is contained in:
Matt Nadareski
2018-01-23 11:39:35 -08:00
parent 6e47a1d809
commit a0d585d994
4 changed files with 98 additions and 4 deletions

View File

@@ -3222,7 +3222,7 @@ namespace SabreTools.Library.DatFiles
FileName = (String.IsNullOrWhiteSpace(FileName) ? (keepext ? Path.GetFileName(filename) : Path.GetFileNameWithoutExtension(filename)) : FileName);
// If the output type isn't set already, get the internal output type
DatFormat = (DatFormat == 0 ? Utilities.GetDatFormat(filename) : DatFormat);
DatFormat = (DatFormat == 0 ? Utilities.GetDatFormatFromFile(filename) : DatFormat);
// Now parse the correct type of DAT
try

View File

@@ -595,7 +595,7 @@ namespace SabreTools.Library.Tools
/// <returns>DatFile of the specific internal type that corresponds to the inputs</returns>
public static DatFile GetDatFile(string input, DatFile baseDat)
{
DatFormat datFormat = GetDatFormat(input);
DatFormat datFormat = GetDatFormatFromFile(input);
return GetDatFile(datFormat, baseDat);
}
@@ -681,6 +681,69 @@ namespace SabreTools.Library.Tools
}
}
/// <summary>
/// Get DatFormat value from input string
/// </summary>
/// <param name="input">String to get value from</param>
/// <returns>DatFormat value corresponding to the string</returns>
public static DatFormat GetDatFormat(string input)
{
switch (input?.ToLowerInvariant())
{
case "all":
return DatFormat.ALL;
case "am":
case "attractmode":
return DatFormat.AttractMode;
case "cmp":
case "clrmamepro":
return DatFormat.ClrMamePro;
case "csv":
return DatFormat.CSV;
case "dc":
case "doscenter":
return DatFormat.DOSCenter;
case "lr":
case "listrom":
return DatFormat.Listrom;
case "lx":
case "listxml":
return DatFormat.Listxml;
case "miss":
case "missfile":
return DatFormat.MissFile;
case "md5":
return DatFormat.RedumpMD5;
case "ol":
case "offlinelist":
return DatFormat.OfflineList;
case "rc":
case "romcenter":
return DatFormat.RomCenter;
case "sd":
case "sabredat":
return DatFormat.SabreDat;
case "sfv":
return DatFormat.RedumpSFV;
case "sha1":
return DatFormat.RedumpSHA1;
case "sha256":
return DatFormat.RedumpSHA256;
case "sha384":
return DatFormat.RedumpSHA384;
case "sha512":
return DatFormat.RedumpSHA512;
case "sl":
case "softwarelist":
return DatFormat.SoftwareList;
case "xml":
case "logiqx":
return DatFormat.Logiqx;
default:
return DatFormat.Logiqx; // TODO: Placeholder until DatFormat.None
}
}
/// <summary>
/// Get ForceMerging value from input string
/// </summary>
@@ -1048,7 +1111,7 @@ namespace SabreTools.Library.Tools
/// </summary>
/// <param name="filename">Name of the file to be parsed</param>
/// <returns>The DatFormat corresponding to the DAT</returns>
public static DatFormat GetDatFormat(string filename)
public static DatFormat GetDatFormatFromFile(string filename)
{
// Limit the output formats based on extension
if (!HasValidDatExtension(filename))

View File

@@ -1616,6 +1616,26 @@ namespace SabreTools
});
}
}
private static Feature outputTypeListInput
{
get
{
return new Feature(
new List<string>() { "-ot", "--output-type" },
"Output DATs to a given type or types",
FeatureType.List,
new List<string>()
{
" Supported values are:",
" all, am/attractmode, cmp/clrmamepro, csv,",
" dc/doscenter, lr/listrom, lx/listxml,",
" miss/missfile, md5, ol/offlinelist,",
" rc/romcenter, sd/sabredat, sfv, sha1,",
" sha256, sha384, sha512, sl/softwarelist",
" xml/logiqx",
});
}
}
private static Feature sha1ListInput
{
get

View File

@@ -388,7 +388,7 @@ namespace SabreTools
if ((datHeader.DatFormat & DatFormat.LogiqxDepreciated) == 0)
{
datHeader.DatFormat |= DatFormat.Logiqx;
}
}
break;
case "quick":
quickScan = true;
@@ -652,6 +652,17 @@ namespace SabreTools
filter.NotItemStatuses |= Utilities.GetItemStatus(nstat);
}
break;
case "output-type":
foreach (string ot in (List<string>)feat.Value.GetValue())
{
DatFormat dftemp = Utilities.GetDatFormat(ot);
if (dftemp != DatFormat.Logiqx
|| (dftemp == DatFormat.Logiqx && (datHeader.DatFormat & DatFormat.LogiqxDepreciated) == 0))
{
datHeader.DatFormat |= dftemp;
}
}
break;
case "sha1":
filter.SHA1s.AddRange((List<string>)feat.Value.GetValue());
break;