mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[RomManipulation] Uncomment and fix cleaning code, add cleaning flag
This commit is contained in:
@@ -73,8 +73,10 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="srcid">Source ID for the DAT</param>
|
/// <param name="srcid">Source ID for the DAT</param>
|
||||||
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
||||||
/// <param name="logger">Logger object for console and/or file output</param>
|
/// <param name="logger">Logger object for console and/or file output</param>
|
||||||
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||||
|
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
||||||
/// <returns>DatData object representing the read-in data</returns>
|
/// <returns>DatData object representing the read-in data</returns>
|
||||||
public static DatData Parse(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false)
|
public static DatData Parse(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false, bool clean = false)
|
||||||
{
|
{
|
||||||
// If the output filename isn't set already, get the internal filename
|
// If the output filename isn't set already, get the internal filename
|
||||||
if (String.IsNullOrEmpty(datdata.FileName))
|
if (String.IsNullOrEmpty(datdata.FileName))
|
||||||
@@ -100,10 +102,10 @@ namespace SabreTools.Helper
|
|||||||
case OutputFormat.ClrMamePro:
|
case OutputFormat.ClrMamePro:
|
||||||
return ParseCMP(filename, sysid, srcid, datdata, logger, keep);
|
return ParseCMP(filename, sysid, srcid, datdata, logger, keep);
|
||||||
case OutputFormat.RomCenter:
|
case OutputFormat.RomCenter:
|
||||||
return ParseRC(filename, sysid, srcid, datdata, logger, keep);
|
return ParseRC(filename, sysid, srcid, datdata, logger);
|
||||||
case OutputFormat.SabreDat:
|
case OutputFormat.SabreDat:
|
||||||
case OutputFormat.Xml:
|
case OutputFormat.Xml:
|
||||||
return ParseXML(filename, sysid, srcid, datdata, logger, keep);
|
return ParseXML(filename, sysid, srcid, datdata, logger, keep, clean);
|
||||||
default:
|
default:
|
||||||
return datdata;
|
return datdata;
|
||||||
}
|
}
|
||||||
@@ -117,6 +119,7 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="srcid">Source ID for the DAT</param>
|
/// <param name="srcid">Source ID for the DAT</param>
|
||||||
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
||||||
/// <param name="logger">Logger object for console and/or file output</param>
|
/// <param name="logger">Logger object for console and/or file output</param>
|
||||||
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||||
/// <returns>DatData object representing the read-in data</returns>
|
/// <returns>DatData object representing the read-in data</returns>
|
||||||
public static DatData ParseCMP(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false)
|
public static DatData ParseCMP(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false)
|
||||||
{
|
{
|
||||||
@@ -378,7 +381,7 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
||||||
/// <param name="logger">Logger object for console and/or file output</param>
|
/// <param name="logger">Logger object for console and/or file output</param>
|
||||||
/// <returns>DatData object representing the read-in data</returns>
|
/// <returns>DatData object representing the read-in data</returns>
|
||||||
public static DatData ParseRC(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false)
|
public static DatData ParseRC(string filename, int sysid, int srcid, DatData datdata, Logger logger)
|
||||||
{
|
{
|
||||||
// Read the input file, if possible
|
// Read the input file, if possible
|
||||||
logger.Log("Attempting to read file: \"" + filename + "\"");
|
logger.Log("Attempting to read file: \"" + filename + "\"");
|
||||||
@@ -526,8 +529,10 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="srcid">Source ID for the DAT</param>
|
/// <param name="srcid">Source ID for the DAT</param>
|
||||||
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
/// <param name="datdata">The DatData object representing found roms to this point</param>
|
||||||
/// <param name="logger">Logger object for console and/or file output</param>
|
/// <param name="logger">Logger object for console and/or file output</param>
|
||||||
|
/// <param name="keep">True if full pathnames are to be kept, false otherwise (default)</param>
|
||||||
|
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
||||||
/// <returns>DatData object representing the read-in data</returns>
|
/// <returns>DatData object representing the read-in data</returns>
|
||||||
public static DatData ParseXML(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false)
|
public static DatData ParseXML(string filename, int sysid, int srcid, DatData datdata, Logger logger, bool keep = false, bool clean = false)
|
||||||
{
|
{
|
||||||
// Prepare all internal variables
|
// Prepare all internal variables
|
||||||
XmlReader subreader, headreader, flagreader;
|
XmlReader subreader, headreader, flagreader;
|
||||||
@@ -550,11 +555,14 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
string tempgame = String.Join("\\", parent);
|
string tempgame = String.Join("\\", parent);
|
||||||
|
|
||||||
/*
|
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same if in clean mode
|
||||||
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same
|
if (clean)
|
||||||
tempgame = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(tempgame).Groups[1].Value;
|
{
|
||||||
tempgame = tempgame.TrimStart().TrimEnd();
|
string[] splitgame = tempgame.Split(Path.DirectorySeparatorChar);
|
||||||
*/
|
splitgame[splitgame.Length - 1] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(splitgame[splitgame.Length - 1]).Groups[1].Value;
|
||||||
|
tempgame = String.Join(Path.DirectorySeparatorChar.ToString(), splitgame);
|
||||||
|
tempgame = tempgame.TrimStart().TrimEnd();
|
||||||
|
}
|
||||||
|
|
||||||
RomData rom = new RomData
|
RomData rom = new RomData
|
||||||
{
|
{
|
||||||
@@ -970,16 +978,22 @@ namespace SabreTools.Helper
|
|||||||
nodump = true;
|
nodump = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// If we're in clean mode, sanitize the game name
|
||||||
///Run the name through the filters to make sure that it's correct
|
if (clean)
|
||||||
tempname = Style.NormalizeChars(tempname);
|
{
|
||||||
tempname = Style.RussianToLatin(tempname);
|
string[] splitgame = tempname.Split(Path.DirectorySeparatorChar);
|
||||||
tempname = Style.SearchPattern(tempname);
|
string intname = splitgame[splitgame.Length - 1];
|
||||||
|
|
||||||
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same
|
///Run the name through the filters to make sure that it's correct
|
||||||
tempname = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(tempname).Groups[1].Value;
|
intname = Style.NormalizeChars(intname);
|
||||||
tempname = tempname.TrimStart().TrimEnd();
|
intname = Style.RussianToLatin(intname);
|
||||||
*/
|
intname = Style.SearchPattern(intname);
|
||||||
|
|
||||||
|
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same if in clean mode
|
||||||
|
splitgame[splitgame.Length - 1] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(intname).Groups[1].Value;
|
||||||
|
tempname = String.Join(Path.DirectorySeparatorChar.ToString(), splitgame);
|
||||||
|
tempname = tempname.TrimStart().TrimEnd();
|
||||||
|
}
|
||||||
|
|
||||||
// Only add the rom if there's useful information in it
|
// Only add the rom if there's useful information in it
|
||||||
if (!(crc == "" && md5 == "" && sha1 == "") || nodump)
|
if (!(crc == "" && md5 == "" && sha1 == "") || nodump)
|
||||||
@@ -1035,11 +1049,14 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
tempname = (parent.Count > 0 ? String.Join("\\", parent) + Path.DirectorySeparatorChar : "") + tempname;
|
tempname = (parent.Count > 0 ? String.Join("\\", parent) + Path.DirectorySeparatorChar : "") + tempname;
|
||||||
|
|
||||||
/*
|
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same if in clean mode
|
||||||
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same
|
if (clean)
|
||||||
tempname = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(tempname).Groups[1].Value;
|
{
|
||||||
tempname = tempname.TrimEnd().TrimStart();
|
string[] splitgame = tempname.Split(Path.DirectorySeparatorChar);
|
||||||
*/
|
splitgame[splitgame.Length - 1] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(splitgame[splitgame.Length - 1]).Groups[1].Value;
|
||||||
|
tempname = String.Join(Path.DirectorySeparatorChar.ToString(), splitgame);
|
||||||
|
tempname = tempname.TrimStart().TrimEnd();
|
||||||
|
}
|
||||||
|
|
||||||
RomData rom = new RomData
|
RomData rom = new RomData
|
||||||
{
|
{
|
||||||
@@ -1200,11 +1217,14 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same if in clean mode
|
||||||
// WoD gets rid of anything past the first "(" or "[" as the name, we will do the same
|
if (clean)
|
||||||
tempname = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(tempname).Groups[1].Value;
|
{
|
||||||
tempname = tempname.TrimEnd().TrimStart();
|
string[] splitgame = tempname.Split(Path.DirectorySeparatorChar);
|
||||||
*/
|
splitgame[splitgame.Length - 1] = new Regex(@"(([[(].*[\)\]] )?([^([]+))").Match(splitgame[splitgame.Length - 1]).Groups[1].Value;
|
||||||
|
tempname = String.Join(Path.DirectorySeparatorChar.ToString(), splitgame);
|
||||||
|
tempname = tempname.TrimStart().TrimEnd();
|
||||||
|
}
|
||||||
|
|
||||||
// Only add the rom if there's useful information in it
|
// Only add the rom if there's useful information in it
|
||||||
if (!(crc == "" && md5 == "" && sha1 == "") || nodump)
|
if (!(crc == "" && md5 == "" && sha1 == "") || nodump)
|
||||||
|
|||||||
Reference in New Issue
Block a user