mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Add a little more safety to Skippers
This commit is contained in:
@@ -60,9 +60,6 @@ namespace SabreTools.DatFiles
|
|||||||
if (outputFormat == OutputFormat.Folder && datFile.Header.ForcePacking != PackingFlag.None)
|
if (outputFormat == OutputFormat.Folder && datFile.Header.ForcePacking != PackingFlag.None)
|
||||||
outputFormat = GetOutputFormat(datFile.Header.ForcePacking);
|
outputFormat = GetOutputFormat(datFile.Header.ForcePacking);
|
||||||
|
|
||||||
// Preload the Skipper list
|
|
||||||
SkipperMatch.Init();
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
bool success = true;
|
bool success = true;
|
||||||
@@ -202,8 +199,6 @@ namespace SabreTools.DatFiles
|
|||||||
if (outputFormat == OutputFormat.Folder && datFile.Header.ForcePacking != PackingFlag.None)
|
if (outputFormat == OutputFormat.Folder && datFile.Header.ForcePacking != PackingFlag.None)
|
||||||
outputFormat = GetOutputFormat(datFile.Header.ForcePacking);
|
outputFormat = GetOutputFormat(datFile.Header.ForcePacking);
|
||||||
|
|
||||||
// Preload the Skipper list
|
|
||||||
SkipperMatch.Init();
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -419,6 +414,7 @@ namespace SabreTools.DatFiles
|
|||||||
if (datFile.Header.HeaderSkipper != null)
|
if (datFile.Header.HeaderSkipper != null)
|
||||||
{
|
{
|
||||||
// Check to see if we have a matching header first
|
// Check to see if we have a matching header first
|
||||||
|
SkipperMatch.Init();
|
||||||
SkipperRule rule = SkipperMatch.GetMatchingRule(fileStream, Path.GetFileNameWithoutExtension(datFile.Header.HeaderSkipper));
|
SkipperRule rule = SkipperMatch.GetMatchingRule(fileStream, Path.GetFileNameWithoutExtension(datFile.Header.HeaderSkipper));
|
||||||
|
|
||||||
// If there's a match, create the new file to write
|
// If there's a match, create the new file to write
|
||||||
|
|||||||
@@ -295,6 +295,7 @@ namespace SabreTools.FileTypes
|
|||||||
// Try to match the supplied header skipper
|
// Try to match the supplied header skipper
|
||||||
if (header != null)
|
if (header != null)
|
||||||
{
|
{
|
||||||
|
SkipperMatch.Init();
|
||||||
var rule = SkipperMatch.GetMatchingRule(input, Path.GetFileNameWithoutExtension(header));
|
var rule = SkipperMatch.GetMatchingRule(input, Path.GetFileNameWithoutExtension(header));
|
||||||
|
|
||||||
// If there's a match, transform the stream before getting info
|
// If there's a match, transform the stream before getting info
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace SabreTools.Skippers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Header skippers represented by a list of skipper objects
|
/// Header skippers represented by a list of skipper objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private static List<SkipperFile> List;
|
private static List<SkipperFile> Skippers = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Local paths
|
/// Local paths
|
||||||
@@ -45,13 +45,24 @@ namespace SabreTools.Skippers
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize static fields
|
/// Initialize static fields
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Init()
|
/// <param name="experimental">True to enable internal header skipper generation, false to use file-based generation (default)</param>
|
||||||
|
public static void Init(bool experimental = false)
|
||||||
{
|
{
|
||||||
PopulateSkippers();
|
// If the list is populated, don't add to it
|
||||||
|
if (Skippers != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// If we're using internal skipper generation
|
||||||
|
if (experimental)
|
||||||
|
PopulateSkippersInternal();
|
||||||
|
|
||||||
|
// If we're using file-based skipper generation
|
||||||
|
else
|
||||||
|
PopulateSkippers();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Populate the entire list of header Skippers
|
/// Populate the entire list of header skippers from physical files
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// http://mamedev.emulab.it/clrmamepro/docs/xmlheaders.txt
|
/// http://mamedev.emulab.it/clrmamepro/docs/xmlheaders.txt
|
||||||
@@ -60,18 +71,18 @@ namespace SabreTools.Skippers
|
|||||||
private static void PopulateSkippers()
|
private static void PopulateSkippers()
|
||||||
{
|
{
|
||||||
// Ensure the list exists
|
// Ensure the list exists
|
||||||
if (List == null)
|
if (Skippers == null)
|
||||||
List = new List<SkipperFile>();
|
Skippers = new List<SkipperFile>();
|
||||||
|
|
||||||
// Get skippers for each known header type
|
// Get skippers for each known header type
|
||||||
foreach (string skipperFile in Directory.EnumerateFiles(LocalPath, "*", SearchOption.AllDirectories))
|
foreach (string skipperFile in Directory.EnumerateFiles(LocalPath, "*", SearchOption.AllDirectories))
|
||||||
{
|
{
|
||||||
List.Add(new SkipperFile(Path.GetFullPath(skipperFile)));
|
Skippers.Add(new SkipperFile(Path.GetFullPath(skipperFile)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Populate the entire list of header skippers
|
/// Populate the entire list of header skippers from generated objects
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// http://mamedev.emulab.it/clrmamepro/docs/xmlheaders.txt
|
/// http://mamedev.emulab.it/clrmamepro/docs/xmlheaders.txt
|
||||||
@@ -80,19 +91,19 @@ namespace SabreTools.Skippers
|
|||||||
private static void PopulateSkippersInternal()
|
private static void PopulateSkippersInternal()
|
||||||
{
|
{
|
||||||
// Ensure the list exists
|
// Ensure the list exists
|
||||||
if (List == null)
|
if (Skippers == null)
|
||||||
List = new List<SkipperFile>();
|
Skippers = new List<SkipperFile>();
|
||||||
|
|
||||||
// Get skippers for each known header type
|
// Get skippers for each known header type
|
||||||
List.Add(GetAtari7800());
|
Skippers.Add(GetAtari7800());
|
||||||
List.Add(GetAtariLynx());
|
Skippers.Add(GetAtariLynx());
|
||||||
List.Add(GetCommodorePSID());
|
Skippers.Add(GetCommodorePSID());
|
||||||
List.Add(GetNECPCEngine());
|
Skippers.Add(GetNECPCEngine());
|
||||||
List.Add(GetNintendo64());
|
Skippers.Add(GetNintendo64());
|
||||||
List.Add(GetNintendoEntertainmentSystem());
|
Skippers.Add(GetNintendoEntertainmentSystem());
|
||||||
List.Add(GetNintendoFamicomDiskSystem());
|
Skippers.Add(GetNintendoFamicomDiskSystem());
|
||||||
List.Add(GetSuperNintendoEntertainmentSystem());
|
Skippers.Add(GetSuperNintendoEntertainmentSystem());
|
||||||
List.Add(GetSuperFamicomSPC());
|
Skippers.Add(GetSuperFamicomSPC());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -132,7 +143,7 @@ namespace SabreTools.Skippers
|
|||||||
// Loop through and find a Skipper that has the right name
|
// Loop through and find a Skipper that has the right name
|
||||||
logger.Verbose("Beginning search for matching header skip rules");
|
logger.Verbose("Beginning search for matching header skip rules");
|
||||||
List<SkipperFile> tempList = new List<SkipperFile>();
|
List<SkipperFile> tempList = new List<SkipperFile>();
|
||||||
tempList.AddRange(List);
|
tempList.AddRange(Skippers);
|
||||||
|
|
||||||
// Loop through all known SkipperFiles
|
// Loop through all known SkipperFiles
|
||||||
foreach (SkipperFile skipper in tempList)
|
foreach (SkipperFile skipper in tempList)
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ The following systems have headers that this program can work with:
|
|||||||
logger.User($"\nGetting skipper information for '{file}'");
|
logger.User($"\nGetting skipper information for '{file}'");
|
||||||
|
|
||||||
// Get the skipper rule that matches the file, if any
|
// Get the skipper rule that matches the file, if any
|
||||||
|
SkipperMatch.Init();
|
||||||
SkipperRule rule = SkipperMatch.GetMatchingRule(file, string.Empty);
|
SkipperRule rule = SkipperMatch.GetMatchingRule(file, string.Empty);
|
||||||
|
|
||||||
// If we have an empty rule, return false
|
// If we have an empty rule, return false
|
||||||
|
|||||||
Reference in New Issue
Block a user