Create and use DatItems.FeatureType

This commit is contained in:
Matt Nadareski
2020-09-02 14:04:02 -07:00
parent 3d55e1462b
commit 26bb28afba
14 changed files with 347 additions and 199 deletions

View File

@@ -5,7 +5,6 @@ using System.Linq;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.FileTypes;
using SabreTools.Library.Help;
using Microsoft.Data.Sqlite;
namespace RombaSharp.Features
@@ -19,7 +18,7 @@ namespace RombaSharp.Features
Name = Value;
Flags = new List<string>() { "archive" };
Description = "Adds ROM files from the specified directories to the ROM archive.";
_featureType = FeatureType.Flag;
_featureType = SabreTools.Library.Help.FeatureType.Flag;
LongDescription = @"Adds ROM files from the specified directories to the ROM archive.
Traverses the specified directory trees looking for zip files and normal files.
Unpacked files will be stored as individual entries. Prior to unpacking a zip

View File

@@ -27,7 +27,7 @@ namespace RombaSharp.Features
CopyValue,
"-copy",
"Copy files to output instead of rebuilding",
FeatureType.Flag);
SabreTools.Library.Help.FeatureType.Flag);
}
} // Unique to RombaSharp
@@ -40,7 +40,7 @@ namespace RombaSharp.Features
FixdatOnlyValue,
"-fixdatOnly",
"only fix dats and don't generate torrentzips",
FeatureType.Flag);
SabreTools.Library.Help.FeatureType.Flag);
}
}
@@ -53,7 +53,7 @@ namespace RombaSharp.Features
LogOnlyValue,
"-log-only",
"Only write out actions to log",
FeatureType.Flag);
SabreTools.Library.Help.FeatureType.Flag);
}
}
@@ -66,7 +66,7 @@ namespace RombaSharp.Features
NoDbValue,
"-no-db",
"archive into depot but do not touch DB index and ignore only-needed flag",
FeatureType.Flag);
SabreTools.Library.Help.FeatureType.Flag);
}
}
@@ -79,7 +79,7 @@ namespace RombaSharp.Features
OnlyNeededValue,
"-only-needed",
"only archive ROM files actually referenced by DAT files from the DAT index",
FeatureType.Flag);
SabreTools.Library.Help.FeatureType.Flag);
}
}
@@ -92,7 +92,7 @@ namespace RombaSharp.Features
SkipInitialScanValue,
"-skip-initial-scan",
"skip the initial scan of the files to determine amount of work",
FeatureType.Flag);
SabreTools.Library.Help.FeatureType.Flag);
}
}
@@ -105,7 +105,7 @@ namespace RombaSharp.Features
UseGolangZipValue,
"-use-golang-zip",
"use go zip implementation instead of zlib",
FeatureType.Flag);
SabreTools.Library.Help.FeatureType.Flag);
}
}
@@ -122,7 +122,7 @@ namespace RombaSharp.Features
Include7ZipsInt32Value,
"-include-7zips",
"flag value == 0 means: add 7zip files themselves into the depot in addition to their contents, flag value == 2 means add 7zip files themselves but don't add content",
FeatureType.Int32);
SabreTools.Library.Help.FeatureType.Int32);
}
}
@@ -135,7 +135,7 @@ namespace RombaSharp.Features
IncludeGZipsInt32Value,
"-include-gzips",
"flag value == 0 means: add gzip files themselves into the depot in addition to their contents, flag value == 2 means add gzip files themselves but don't add content",
FeatureType.Int32);
SabreTools.Library.Help.FeatureType.Int32);
}
}
@@ -148,7 +148,7 @@ namespace RombaSharp.Features
IncludeZipsInt32Value,
"-include-zips",
"flag value == 0 means: add zip files themselves into the depot in addition to their contents, flag value == 2 means add zip files themselves but don't add content",
FeatureType.Int32);
SabreTools.Library.Help.FeatureType.Int32);
}
}
@@ -161,7 +161,7 @@ namespace RombaSharp.Features
SubworkersInt32Value,
"-subworkers",
"how many subworkers to launch for each worker",
FeatureType.Int32);
SabreTools.Library.Help.FeatureType.Int32);
}
} // Defaults to Workers count in config
@@ -174,7 +174,7 @@ namespace RombaSharp.Features
WorkersInt32Value,
"-workers",
"how many workers to launch for the job",
FeatureType.Int32);
SabreTools.Library.Help.FeatureType.Int32);
}
} // Defaults to Workers count in config
@@ -191,7 +191,7 @@ namespace RombaSharp.Features
SizeInt64Value,
"-size",
"size of the rom to lookup",
FeatureType.Int64);
SabreTools.Library.Help.FeatureType.Int64);
}
}
@@ -208,7 +208,7 @@ namespace RombaSharp.Features
DatsListStringValue,
"-dats",
"purge only roms declared in these dats",
FeatureType.List);
SabreTools.Library.Help.FeatureType.List);
}
}
@@ -221,7 +221,7 @@ namespace RombaSharp.Features
DepotListStringValue,
"-depot",
"work only on specified depot path",
FeatureType.List);
SabreTools.Library.Help.FeatureType.List);
}
}
@@ -238,7 +238,7 @@ namespace RombaSharp.Features
BackupStringValue,
"-backup",
"backup directory where backup files are moved to",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}
@@ -251,7 +251,7 @@ namespace RombaSharp.Features
DescriptionStringValue,
"-description",
"description value in DAT header",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}
@@ -264,7 +264,7 @@ namespace RombaSharp.Features
MissingSha1sStringValue,
"-missingSha1s",
"write paths of dats with missing sha1s into this file",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}
@@ -277,7 +277,7 @@ namespace RombaSharp.Features
NameStringValue,
"-name",
"name value in DAT header",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}
@@ -290,7 +290,7 @@ namespace RombaSharp.Features
NewStringValue,
"-new",
"new DAT file",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}
@@ -303,7 +303,7 @@ namespace RombaSharp.Features
OldStringValue,
"-old",
"old DAT file",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}
@@ -316,7 +316,7 @@ namespace RombaSharp.Features
OutStringValue,
"-out",
"output file",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}
@@ -329,7 +329,7 @@ namespace RombaSharp.Features
ResumeStringValue,
"-resume",
"resume a previously interrupted operation from the specified path",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}
@@ -342,7 +342,7 @@ namespace RombaSharp.Features
SourceStringValue,
"-source",
"source directory",
FeatureType.String);
SabreTools.Library.Help.FeatureType.String);
}
}

View File

@@ -4,7 +4,6 @@ using System.IO;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.Help;
using SabreTools.Library.Tools;
using Microsoft.Data.Sqlite;
@@ -19,7 +18,7 @@ namespace RombaSharp.Features
Name = Value;
Flags = new List<string>() { "refresh-dats" };
Description = "Refreshes the DAT index from the files in the DAT master directory tree.";
_featureType = FeatureType.Flag;
_featureType = SabreTools.Library.Help.FeatureType.Flag;
LongDescription = @"Refreshes the DAT index from the files in the DAT master directory tree.
Detects any changes in the DAT master directory tree and updates the DAT index
accordingly, marking deleted or overwritten dats as orphaned and updating

View File

@@ -4,7 +4,6 @@ using System.IO;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.Help;
using Microsoft.Data.Sqlite;
namespace RombaSharp.Features
@@ -19,7 +18,7 @@ namespace RombaSharp.Features
Name = Value;
Flags = new List<string>() { "depot-rescan" };
Description = "Rescan a specific depot to get new information";
_featureType = FeatureType.Flag;
_featureType = SabreTools.Library.Help.FeatureType.Flag;
LongDescription = "Rescan a specific depot to get new information";
Features = new Dictionary<string, SabreTools.Library.Help.Feature>();
}

View File

@@ -292,7 +292,7 @@ namespace SabreTools.Library.DatFiles
case "feature":
datItems.Add(new Feature
{
Type = reader.GetAttribute("type"),
Type = reader.GetAttribute("type").AsFeatureType(),
Status = reader.GetAttribute("status"),
Overall = reader.GetAttribute("overall"),
});
@@ -1569,7 +1569,7 @@ namespace SabreTools.Library.DatFiles
case ItemType.Feature:
var feature = datItem as Feature;
xtw.WriteStartElement("feature");
xtw.WriteOptionalAttributeString("type", feature.Type);
xtw.WriteOptionalAttributeString("type", feature.Type.FromFeatureType());
xtw.WriteOptionalAttributeString("status", feature.Status);
xtw.WriteOptionalAttributeString("overall", feature.Overall);
xtw.WriteEndElement();

View File

@@ -1393,7 +1393,7 @@ namespace SabreTools.Library.DatFiles
var feature = datItem as Feature;
xtw.WriteStartElement("file");
xtw.WriteAttributeString("type", "feature");
xtw.WriteOptionalAttributeString("type", feature.Type);
xtw.WriteOptionalAttributeString("type", feature.Type.FromFeatureType());
xtw.WriteOptionalAttributeString("status", feature.Status);
xtw.WriteOptionalAttributeString("overall", feature.Overall);
xtw.WriteEndElement();

View File

@@ -17,6 +17,33 @@ namespace SabreTools.Library.DatItems
External = 1 << 3,
}
/// <summary>
/// Determine the feature type
/// </summary>
[Flags]
public enum FeatureType
{
/// <summary>
/// This is a fake flag that is used for filter only
/// </summary>
NULL = 0,
Protection = 1 << 0,
Palette = 1 << 1,
Graphics = 1 << 2,
Sound = 1 << 3,
Controls = 1 << 4,
Keyboard = 1 << 5,
Mouse = 1 << 6,
Microphone = 1 << 7,
Camera = 1 << 8,
Disk = 1 << 9,
Printer = 1 << 10,
Lan = 1 << 11,
Wan = 1 << 12,
Timing = 1 << 13,
}
/// <summary>
/// List of valid field types within a DatItem/Machine
/// </summary>

View File

@@ -3,6 +3,7 @@ using System.Linq;
using SabreTools.Library.Filtering;
using Newtonsoft.Json;
using SabreTools.Library.Tools;
namespace SabreTools.Library.DatItems
{
@@ -18,7 +19,7 @@ namespace SabreTools.Library.DatItems
/// Type of feature
/// </summary>
[JsonProperty("type")]
public string Type { get; set; } // TODO: (protection|palette|graphics|sound|controls|keyboard|mouse|microphone|camera|disk|printer|lan|wan|timing)
public FeatureType Type { get; set; }
/// <summary>
/// Emulation status
@@ -47,7 +48,7 @@ namespace SabreTools.Library.DatItems
// Handle Feature-specific fields
if (mappings.Keys.Contains(Field.DatItem_FeatureType))
Type = mappings[Field.DatItem_FeatureType];
Type = mappings[Field.DatItem_FeatureType].AsFeatureType();
if (mappings.Keys.Contains(Field.DatItem_FeatureStatus))
Status = mappings[Field.DatItem_FeatureStatus];
@@ -140,9 +141,9 @@ namespace SabreTools.Library.DatItems
return false;
// Filter on type
if (filter.DatItem_FeatureType.MatchesPositiveSet(Type) == false)
if (filter.DatItem_FeatureType.MatchesPositive(FeatureType.NULL, Type) == false)
return false;
if (filter.DatItem_FeatureType.MatchesNegativeSet(Type) == true)
if (filter.DatItem_FeatureType.MatchesNegative(FeatureType.NULL, Type) == true)
return false;
// Filter on status
@@ -171,7 +172,7 @@ namespace SabreTools.Library.DatItems
// Remove the fields
if (fields.Contains(Field.DatItem_FeatureType))
Type = null;
Type = FeatureType.NULL;
if (fields.Contains(Field.DatItem_FeatureStatus))
Status = null;

View File

@@ -295,7 +295,7 @@ namespace SabreTools.Library.Filtering
public FilterItem<bool?> DatItem_Value_Default { get; private set; } = new FilterItem<bool?>() { Neutral = null };
// Feature
public FilterItem<string> DatItem_FeatureType { get; private set; } = new FilterItem<string>();
public FilterItem<FeatureType> DatItem_FeatureType { get; private set; } = new FilterItem<FeatureType>() { Positive = FeatureType.NULL, Negative = FeatureType.NULL };
public FilterItem<string> DatItem_FeatureStatus { get; private set; } = new FilterItem<string>();
public FilterItem<string> DatItem_FeatureOverall { get; private set; } = new FilterItem<string>();
@@ -1700,9 +1700,9 @@ namespace SabreTools.Library.Filtering
// Feature
case Field.DatItem_FeatureType:
if (negate)
DatItem_FeatureType.NegativeSet.Add(value);
DatItem_FeatureType.Negative |= value.AsFeatureType();
else
DatItem_FeatureType.PositiveSet.Add(value);
DatItem_FeatureType.Positive |= value.AsFeatureType();
break;
case Field.DatItem_FeatureStatus:

View File

@@ -145,6 +145,69 @@ namespace SabreTools.Library.Tools
}
}
/// <summary>
/// Get FeatureType value from input string
/// </summary>
/// <param name="featureType">String to get value from</param>
/// <returns>FeatureType value corresponding to the string</returns>
public static FeatureType AsFeatureType(this string featureType)
{
#if NET_FRAMEWORK
switch (featureType?.ToLowerInvariant())
{
case "protection":
return FeatureType.Protection;
case "palette":
return FeatureType.Palette;
case "graphics":
return FeatureType.Graphics;
case "sound":
return FeatureType.Sound;
case "controls":
return FeatureType.Controls;
case "keyboard":
return FeatureType.Keyboard;
case "mouse":
return FeatureType.Mouse;
case "microphone":
return FeatureType.Microphone;
case "camera":
return FeatureType.Camera;
case "disk":
return FeatureType.Disk;
case "printer":
return FeatureType.Printer;
case "lan":
return FeatureType.Lan;
case "wan":
return FeatureType.Wan;
case "timing":
return FeatureType.Timing;
default:
return FeatureType.NULL;
}
#else
return featureType?.ToLowerInvariant() switch
{
"protection" => FeatureType.Protection,
"palette" => FeatureType.Palette,
"graphics" => FeatureType.Graphics,
"sound" => FeatureType.Sound,
"controls" => FeatureType.Controls,
"keyboard" => FeatureType.Keyboard,
"mouse" => FeatureType.Mouse,
"microphone" => FeatureType.Microphone,
"camera" => FeatureType.Camera,
"disk" => FeatureType.Disk,
"printer" => FeatureType.Printer,
"lan" => FeatureType.Lan,
"wan" => FeatureType.Wan,
"timing" => FeatureType.Timing,
_ => FeatureType.NULL,
};
#endif
}
/// <summary>
/// Get Field value from input string
/// </summary>
@@ -1955,6 +2018,69 @@ namespace SabreTools.Library.Tools
// TODO: DatFormat -> string
// TODO: Field -> string
/// <summary>
/// Get string value from input FeatureType
/// </summary>
/// <param name="featureType">FeatureType to get value from</param>
/// <returns>String value corresponding to the FeatureType</returns>
public static string FromFeatureType(this FeatureType featureType)
{
#if NET_FRAMEWORK
switch (featureType)
{
case FeatureType.Protection:
return "protection";
case FeatureType.Palette:
return "palette";
case FeatureType.Graphics:
return "graphics";
case FeatureType.Sound:
return "sound";
case FeatureType.Controls:
return "controls";
case FeatureType.Keyboard:
return "keyboard";
case FeatureType.Mouse:
return "mouse";
case FeatureType.Microphone:
return "microphone";
case FeatureType.Camera:
return "camera";
case FeatureType.Disk:
return "disk";
case FeatureType.Printer:
return "printer";
case FeatureType.Lan:
return "lan";
case FeatureType.Wan:
return "wan";
case FeatureType.Timing:
return "timing";
default:
return null;
}
#else
return featureType switch
{
FeatureType.Protection => "protection",
FeatureType.Palette => "palette",
FeatureType.Graphics => "graphics",
FeatureType.Sound => "sound",
FeatureType.Controls => "controls",
FeatureType.Keyboard => "keyboard",
FeatureType.Mouse => "mouse",
FeatureType.Microphone => "microphone",
FeatureType.Camera => "camera",
FeatureType.Disk => "disk",
FeatureType.Printer => "printer",
FeatureType.Lan => "lan",
FeatureType.Wan => "wan",
FeatureType.Timing => "timing",
_ => null,
};
#endif
}
/// <summary>
/// Get string value from input ItemStatus
/// </summary>

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,6 @@ using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.Filtering;
using SabreTools.Library.IO;
using SabreTools.Library.Help;
using SabreTools.Library.Tools;
namespace SabreTools.Features
@@ -23,7 +22,7 @@ namespace SabreTools.Features
Name = Value;
Flags = new List<string>() { "-bt", "--batch" };
Description = "Enable batch mode";
_featureType = FeatureType.Flag;
_featureType = SabreTools.Library.Help.FeatureType.Flag;
LongDescription = @"Run a special mode that takes input files as lists of batch commands to run sequentially. Each command has to be its own line and must be followed by a semicolon (`;`). Commented lines may start with either `REM` or `#`. Multiple batch files are allowed but they will be run independently from each other.
The following commands are currently implemented:

View File

@@ -4,7 +4,6 @@ using System.Threading.Tasks;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.Help;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
@@ -19,7 +18,7 @@ namespace SabreTools.Features
Name = Value;
Flags = new List<string>() { "-sp", "--split" };
Description = "Split input DATs by a given criteria";
_featureType = FeatureType.Flag;
_featureType = SabreTools.Library.Help.FeatureType.Flag;
LongDescription = "This feature allows the user to split input DATs by a number of different possible criteria. See the individual input information for details. More than one split type is allowed at a time.";
Features = new Dictionary<string, Library.Help.Feature>();

View File

@@ -6,7 +6,6 @@ using System.Threading.Tasks;
using SabreTools.Library.Data;
using SabreTools.Library.DatFiles;
using SabreTools.Library.DatItems;
using SabreTools.Library.Help;
using SabreTools.Library.IO;
using SabreTools.Library.Tools;
@@ -21,7 +20,7 @@ namespace SabreTools.Features
Name = Value;
Flags = new List<string>() { "-ud", "--update" };
Description = "Update and manipulate DAT(s)";
_featureType = FeatureType.Flag;
_featureType = SabreTools.Library.Help.FeatureType.Flag;
LongDescription = "This is the multitool part of the program, allowing for almost every manipulation to a DAT, or set of DATs. This is also a combination of many different programs that performed DAT manipulation that work better together.";
Features = new Dictionary<string, Library.Help.Feature>();