mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[SabreTools] Merge TrimMerge into Update
This commit is contained in:
@@ -125,10 +125,6 @@ Options:
|
|||||||
-source= Source ID
|
-source= Source ID
|
||||||
-st, --stats Get statistics on all input DATs
|
-st, --stats Get statistics on all input DATs
|
||||||
-si, --single Show individual statistics
|
-si, --single Show individual statistics
|
||||||
-tm, --trim-merge Consolidate DAT into a single game and trim entries
|
|
||||||
-rd=, --root-dir= Set the root directory for trimming calculation
|
|
||||||
-nr, --no-rename Keep game names instead of using '!'
|
|
||||||
-df, --disable-force Disable forceunzipping
|
|
||||||
-ud, --update Update a DAT file
|
-ud, --update Update a DAT file
|
||||||
-oc, --output-cmp Output in CMP format
|
-oc, --output-cmp Output in CMP format
|
||||||
-om, --output-miss Output in Missfile format
|
-om, --output-miss Output in Missfile format
|
||||||
@@ -167,6 +163,9 @@ Options:
|
|||||||
Supported values are:
|
Supported values are:
|
||||||
None, Zip, Unzip
|
None, Zip, Unzip
|
||||||
-clean Clean game names according to WoD standards
|
-clean Clean game names according to WoD standards
|
||||||
|
-trim Trim file names to fit NTFS length
|
||||||
|
-rd=, --root-dir= Set the root directory for calc
|
||||||
|
-si, --single All game names replaced by '!'
|
||||||
-dd, --dedup Enable deduping in the created DAT
|
-dd, --dedup Enable deduping in the created DAT
|
||||||
-m, --merge Merge the input DATs
|
-m, --merge Merge the input DATs
|
||||||
-b, --bare Don't include date in automatic name
|
-b, --bare Don't include date in automatic name
|
||||||
|
|||||||
@@ -1521,10 +1521,13 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
|
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
|
||||||
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
|
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
|
||||||
/// <param name="nodump">Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump)</param>
|
/// <param name="nodump">Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump)</param>
|
||||||
|
/// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param>
|
||||||
|
/// <param name="single">True if all games should be replaced by '!', false otherwise</param>
|
||||||
|
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||||
/// <param name="logger">Logging object for console and file output</param>
|
/// <param name="logger">Logging object for console and file output</param>
|
||||||
public static void Update(List<string> inputFileNames, Dat datdata, string outputDirectory, bool merge, bool diff, bool cascade, bool inplace,
|
public static void Update(List<string> inputFileNames, Dat datdata, string outputDirectory, bool merge, bool diff, bool cascade, bool inplace,
|
||||||
bool bare, bool clean, string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc, string md5,
|
bool bare, bool clean, string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc, string md5,
|
||||||
string sha1, bool? nodump, Logger logger)
|
string sha1, bool? nodump, bool trim, bool single, string root, Logger logger)
|
||||||
{
|
{
|
||||||
// If we're in merging or diffing mode, use the full list of inputs
|
// If we're in merging or diffing mode, use the full list of inputs
|
||||||
if (merge || diff)
|
if (merge || diff)
|
||||||
@@ -1535,7 +1538,13 @@ namespace SabreTools.Helper
|
|||||||
List<Dat> datHeaders = PopulateUserData(inputFileNames, inplace, clean, outputDirectory, datdata, out userData, logger);
|
List<Dat> datHeaders = PopulateUserData(inputFileNames, inplace, clean, outputDirectory, datdata, out userData, logger);
|
||||||
|
|
||||||
// If we want to filter, apply it to the userData now
|
// If we want to filter, apply it to the userData now
|
||||||
userData = Filter(userData, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
|
userData = Filter(userData, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, logger);
|
||||||
|
|
||||||
|
// If we're trimming, apply it to the userData now
|
||||||
|
if (trim)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Modify the Dictionary if necessary and output the results
|
// Modify the Dictionary if necessary and output the results
|
||||||
if (diff && !cascade)
|
if (diff && !cascade)
|
||||||
@@ -1570,7 +1579,7 @@ namespace SabreTools.Helper
|
|||||||
{
|
{
|
||||||
logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\"");
|
logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\"");
|
||||||
datdata = Parse(inputFileName, 0, 0, datdata, logger, true, clean);
|
datdata = Parse(inputFileName, 0, 0, datdata, logger, true, clean);
|
||||||
datdata = Filter(datdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
|
datdata = Filter(datdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, logger);
|
||||||
|
|
||||||
// If the extension matches, append ".new" to the filename
|
// If the extension matches, append ".new" to the filename
|
||||||
string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat");
|
string extension = (datdata.OutputFormat == OutputFormat.Xml || datdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat");
|
||||||
@@ -1591,7 +1600,7 @@ namespace SabreTools.Helper
|
|||||||
Dat innerDatdata = (Dat)datdata.Clone();
|
Dat innerDatdata = (Dat)datdata.Clone();
|
||||||
innerDatdata.Roms = null;
|
innerDatdata.Roms = null;
|
||||||
innerDatdata = Parse(file, 0, 0, innerDatdata, logger, true, clean);
|
innerDatdata = Parse(file, 0, 0, innerDatdata, logger, true, clean);
|
||||||
innerDatdata = Filter(innerDatdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, logger);
|
innerDatdata = Filter(innerDatdata, gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, logger);
|
||||||
|
|
||||||
// If the extension matches, append ".new" to the filename
|
// If the extension matches, append ".new" to the filename
|
||||||
string extension = (innerDatdata.OutputFormat == OutputFormat.Xml || innerDatdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat");
|
string extension = (innerDatdata.OutputFormat == OutputFormat.Xml || innerDatdata.OutputFormat == OutputFormat.SabreDat ? ".xml" : ".dat");
|
||||||
@@ -1672,10 +1681,13 @@ namespace SabreTools.Helper
|
|||||||
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
|
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
|
||||||
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
|
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
|
||||||
/// <param name="nodump">Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump)</param>
|
/// <param name="nodump">Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump)</param>
|
||||||
|
/// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param>
|
||||||
|
/// <param name="single">True if all games should be replaced by '!', false otherwise</param>
|
||||||
|
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||||
/// <param name="logger">Logging object for console and file output</param>
|
/// <param name="logger">Logging object for console and file output</param>
|
||||||
/// <returns>Returns filtered DatData object</returns>
|
/// <returns>Returns filtered DatData object</returns>
|
||||||
public static Dat Filter(Dat datdata, string gamename, string romname, string romtype, long sgt,
|
public static Dat Filter(Dat datdata, string gamename, string romname, string romtype, long sgt,
|
||||||
long slt, long seq, string crc, string md5, string sha1, bool? nodump, Logger logger)
|
long slt, long seq, string crc, string md5, string sha1, bool? nodump, bool trim, bool single, string root, Logger logger)
|
||||||
{
|
{
|
||||||
// Now loop through and create a new Rom dictionary using filtered values
|
// Now loop through and create a new Rom dictionary using filtered values
|
||||||
Dictionary<string, List<Rom>> dict = new Dictionary<string, List<Rom>>();
|
Dictionary<string, List<Rom>> dict = new Dictionary<string, List<Rom>>();
|
||||||
@@ -1683,8 +1695,10 @@ namespace SabreTools.Helper
|
|||||||
foreach (string key in keys)
|
foreach (string key in keys)
|
||||||
{
|
{
|
||||||
List<Rom> roms = datdata.Roms[key];
|
List<Rom> roms = datdata.Roms[key];
|
||||||
foreach (Rom rom in roms)
|
for (int i = 0; i < roms.Count; i++)
|
||||||
{
|
{
|
||||||
|
Rom rom = roms[i];
|
||||||
|
|
||||||
// Filter on nodump status
|
// Filter on nodump status
|
||||||
if (nodump == true && !rom.Nodump)
|
if (nodump == true && !rom.Nodump)
|
||||||
{
|
{
|
||||||
@@ -1803,6 +1817,25 @@ namespace SabreTools.Helper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we are in single game mode, rename all games
|
||||||
|
if (single)
|
||||||
|
{
|
||||||
|
rom.Game = "!";
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we are in NTFS trim mode, trim the game name
|
||||||
|
if (trim)
|
||||||
|
{
|
||||||
|
// Windows max name length is 260
|
||||||
|
int usableLength = 260 - rom.Game.Length - root.Length;
|
||||||
|
if (rom.Name.Length > usableLength)
|
||||||
|
{
|
||||||
|
string ext = Path.GetExtension(rom.Name);
|
||||||
|
rom.Name = rom.Name.Substring(0, usableLength - ext.Length);
|
||||||
|
rom.Name += ext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If it made it this far, add the rom to the output dictionary
|
// If it made it this far, add the rom to the output dictionary
|
||||||
if (dict.ContainsKey(key))
|
if (dict.ContainsKey(key))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -124,6 +124,10 @@ namespace SabreTools
|
|||||||
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
|
/// <param name="md5">MD5 of the rom to match (can use asterisk-partials)</param>
|
||||||
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
|
/// <param name="sha1">SHA-1 of the rom to match (can use asterisk-partials)</param>
|
||||||
/// <param name="nodump">Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump)</param>
|
/// <param name="nodump">Select roms with nodump status as follows: null (match all), true (match Nodump only), false (exclude Nodump)</param>
|
||||||
|
/// /* Trimming info */
|
||||||
|
/// <param name="trim">True if we are supposed to trim names to NTFS length, false otherwise</param>
|
||||||
|
/// <param name="single">True if all games should be replaced by '!', false otherwise</param>
|
||||||
|
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||||
/// /* Output DAT info */
|
/// /* Output DAT info */
|
||||||
/// <param name="outdir">Optional param for output directory</param>
|
/// <param name="outdir">Optional param for output directory</param>
|
||||||
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
/// <param name="clean">True to clean the game names to WoD standard, false otherwise (default)</param>
|
||||||
@@ -182,6 +186,11 @@ namespace SabreTools
|
|||||||
string sha1,
|
string sha1,
|
||||||
bool? nodump,
|
bool? nodump,
|
||||||
|
|
||||||
|
/* Trimming info */
|
||||||
|
bool trim,
|
||||||
|
bool single,
|
||||||
|
string root,
|
||||||
|
|
||||||
/* Output DAT info */
|
/* Output DAT info */
|
||||||
string outdir,
|
string outdir,
|
||||||
bool clean,
|
bool clean,
|
||||||
@@ -302,36 +311,36 @@ namespace SabreTools
|
|||||||
{
|
{
|
||||||
userInputDat.OutputFormat = OutputFormat.ClrMamePro;
|
userInputDat.OutputFormat = OutputFormat.ClrMamePro;
|
||||||
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
||||||
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger);
|
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, _logger);
|
||||||
}
|
}
|
||||||
if (outputMiss)
|
if (outputMiss)
|
||||||
{
|
{
|
||||||
userInputDat.OutputFormat = OutputFormat.MissFile;
|
userInputDat.OutputFormat = OutputFormat.MissFile;
|
||||||
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
||||||
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger);
|
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, _logger);
|
||||||
}
|
}
|
||||||
if (outputRC)
|
if (outputRC)
|
||||||
{
|
{
|
||||||
userInputDat.OutputFormat = OutputFormat.RomCenter;
|
userInputDat.OutputFormat = OutputFormat.RomCenter;
|
||||||
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
||||||
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger);
|
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, _logger);
|
||||||
}
|
}
|
||||||
if (outputSD)
|
if (outputSD)
|
||||||
{
|
{
|
||||||
userInputDat.OutputFormat = OutputFormat.SabreDat;
|
userInputDat.OutputFormat = OutputFormat.SabreDat;
|
||||||
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
||||||
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger);
|
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, _logger);
|
||||||
}
|
}
|
||||||
if (outputXML)
|
if (outputXML)
|
||||||
{
|
{
|
||||||
userInputDat.OutputFormat = OutputFormat.Xml;
|
userInputDat.OutputFormat = OutputFormat.Xml;
|
||||||
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
||||||
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger);
|
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, _logger);
|
||||||
}
|
}
|
||||||
if (!outputCMP && !outputMiss && !outputRC && !outputSD && !outputXML)
|
if (!outputCMP && !outputMiss && !outputRC && !outputSD && !outputXML)
|
||||||
{
|
{
|
||||||
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
DatTools.Update(inputs, userInputDat, outdir, merge, diff, cascade, inplace, bare, clean,
|
||||||
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, _logger);
|
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, _logger);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -400,23 +409,6 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Wrap trimming and merging a single DAT
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="input">Input file or folder to be converted</param>
|
|
||||||
/// <param name="root">Root directory to base path lengths on</param>
|
|
||||||
/// <param name="rename">True is games should not be renamed</param>
|
|
||||||
/// <param name="force">True if forcepacking="unzip" should be included</param>
|
|
||||||
private static void InitTrimMerge(string input, string root, bool rename, bool force)
|
|
||||||
{
|
|
||||||
if (input != "" && (File.Exists(input) || Directory.Exists(input)))
|
|
||||||
{
|
|
||||||
TrimMerge sg = new TrimMerge(input, root, rename, force, _logger);
|
|
||||||
sg.Process();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Wrap splitting a DAT by 2 extensions
|
/// Wrap splitting a DAT by 2 extensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -361,8 +361,7 @@ namespace SabreTools
|
|||||||
case "--skip":
|
case "--skip":
|
||||||
skip = true;
|
skip = true;
|
||||||
break;
|
break;
|
||||||
case "-tm":
|
case "-trim":
|
||||||
case "--trim-merge":
|
|
||||||
trim = true;
|
trim = true;
|
||||||
break;
|
break;
|
||||||
case "-tsv":
|
case "-tsv":
|
||||||
@@ -585,8 +584,8 @@ namespace SabreTools
|
|||||||
|
|
||||||
// If more than one switch is enabled, show the help screen
|
// If more than one switch is enabled, show the help screen
|
||||||
if (!(add ^ datfromdir ^ extsplit ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^
|
if (!(add ^ datfromdir ^ extsplit ^ generate ^ genall ^ hashsplit ^ import ^ listsrc ^ listsys ^
|
||||||
(merge || diff) ^ (update || outputCMP || outputRC || outputSD || outputXML || outputMiss) ^
|
(merge || diff || update || outputCMP || outputRC || outputSD || outputXML || outputMiss || trim) ^
|
||||||
offlineMerge ^ rem ^ stats ^ trim))
|
offlineMerge ^ rem ^ stats))
|
||||||
{
|
{
|
||||||
_logger.Error("Only one feature switch is allowed at a time");
|
_logger.Error("Only one feature switch is allowed at a time");
|
||||||
Build.Help();
|
Build.Help();
|
||||||
@@ -644,7 +643,7 @@ namespace SabreTools
|
|||||||
InitUpdate(inputs, filename, name, description, category, version, date, author, email, homepage, url, comment, header,
|
InitUpdate(inputs, filename, name, description, category, version, date, author, email, homepage, url, comment, header,
|
||||||
superdat, forcemerge, forcend, forcepack, outputCMP, outputMiss, outputRC, outputSD, outputXML, usegame, prefix,
|
superdat, forcemerge, forcend, forcepack, outputCMP, outputMiss, outputRC, outputSD, outputXML, usegame, prefix,
|
||||||
postfix, quotes, repext, addext, datprefix, romba, tsv, merge, diff, cascade, inplace, bare, gamename, romname,
|
postfix, quotes, repext, addext, datprefix, romba, tsv, merge, diff, cascade, inplace, bare, gamename, romname,
|
||||||
romtype, sgt, slt, seq, crc, md5, sha1, nodump, outdir, clean, dedup);
|
romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, outdir, clean, dedup);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a source or system
|
// Add a source or system
|
||||||
@@ -681,15 +680,6 @@ namespace SabreTools
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Consolodate and trim DAT
|
|
||||||
else if (trim)
|
|
||||||
{
|
|
||||||
foreach (string input in inputs)
|
|
||||||
{
|
|
||||||
InitTrimMerge(input, root, !norename, !disableForce);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Split a DAT by extension
|
// Split a DAT by extension
|
||||||
else if (extsplit)
|
else if (extsplit)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -110,7 +110,6 @@
|
|||||||
<Compile Include="Partials\SabreTools_Inits.cs" />
|
<Compile Include="Partials\SabreTools_Inits.cs" />
|
||||||
<Compile Include="Partials\SabreTools_Menus.cs" />
|
<Compile Include="Partials\SabreTools_Menus.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TrimMerge.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config" />
|
||||||
|
|||||||
@@ -1,139 +0,0 @@
|
|||||||
using SabreTools.Helper;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace SabreTools
|
|
||||||
{
|
|
||||||
public class TrimMerge
|
|
||||||
{
|
|
||||||
// Instance variables
|
|
||||||
private string _filename;
|
|
||||||
private string _path;
|
|
||||||
private bool _rename;
|
|
||||||
private bool _forceunpack;
|
|
||||||
private Logger _logger;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Create a new TrimMerge object
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Name of the file or folder to be processed</param>
|
|
||||||
/// <param name="path">Root path to use for trimming</param>
|
|
||||||
/// <param name="rename">True if games should be renamed into a uniform string, false otherwise</param>
|
|
||||||
/// <param name="forceunpack">True if forcepacking="unzip" should be set on the output, false otherwise</param>
|
|
||||||
/// <param name="logger">Logger object for console and file output</param>
|
|
||||||
public TrimMerge(string filename, string path, bool rename, bool forceunpack, Logger logger)
|
|
||||||
{
|
|
||||||
_filename = filename;
|
|
||||||
_path = path;
|
|
||||||
_rename = rename;
|
|
||||||
_forceunpack = forceunpack;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Trim and process the given DAT or folder of DATs
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>True if the DAT could be updated, false otherwise</returns>
|
|
||||||
public bool Process()
|
|
||||||
{
|
|
||||||
// If file doesn't exist, error and return
|
|
||||||
if (!File.Exists(_filename) && !Directory.Exists(_filename))
|
|
||||||
{
|
|
||||||
_logger.Error("File or folder '" + _filename + "' doesn't exist");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We want the full path of the file, just in case
|
|
||||||
_filename = Path.GetFullPath(_filename);
|
|
||||||
|
|
||||||
// If it's a single file, handle it as such
|
|
||||||
if (!Directory.Exists(_filename) && File.Exists(_filename))
|
|
||||||
{
|
|
||||||
_logger.Log("File found: " + _filename);
|
|
||||||
ProcessDAT(_filename, _path, _rename);
|
|
||||||
}
|
|
||||||
// If it's a directory, loop through the files and see if any are DATs
|
|
||||||
else if (Directory.Exists(_filename))
|
|
||||||
{
|
|
||||||
// Make sure the path ends with the proper character
|
|
||||||
if (!_filename.EndsWith(Path.DirectorySeparatorChar.ToString()))
|
|
||||||
{
|
|
||||||
_filename += Path.DirectorySeparatorChar;
|
|
||||||
}
|
|
||||||
|
|
||||||
_logger.Log("Directory found: " + _filename);
|
|
||||||
foreach (string file in Directory.EnumerateFiles(_filename, "*", SearchOption.AllDirectories))
|
|
||||||
{
|
|
||||||
_logger.Log("File found: " + file);
|
|
||||||
ProcessDAT(file, _path, _rename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Import the existing DAT(s)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="filename">Name of the file to be processed</param>
|
|
||||||
/// <param name="path">The base path to be used for comparison</param>
|
|
||||||
/// <param name="rename">True if roms are to be renamed</param>
|
|
||||||
private void ProcessDAT(string filename, string path, bool rename)
|
|
||||||
{
|
|
||||||
Dat datdata = new Dat
|
|
||||||
{
|
|
||||||
ForcePacking = (_forceunpack ? ForcePacking.Unzip : ForcePacking.None),
|
|
||||||
OutputFormat = DatTools.GetOutputFormat(filename),
|
|
||||||
};
|
|
||||||
datdata = DatTools.Parse(filename, 0, 0, datdata, _logger);
|
|
||||||
|
|
||||||
// Trim all file names according to the path that's set
|
|
||||||
List<string> keys = datdata.Roms.Keys.ToList();
|
|
||||||
foreach (string key in keys)
|
|
||||||
{
|
|
||||||
List<Rom> newroms = new List<Rom>();
|
|
||||||
foreach (Rom rom in datdata.Roms[key])
|
|
||||||
{
|
|
||||||
Rom newrom = rom;
|
|
||||||
|
|
||||||
// If we are in single game mode, rename all games
|
|
||||||
if (rename)
|
|
||||||
{
|
|
||||||
newrom.Game = "!";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Windows max name length is 260
|
|
||||||
int usableLength = 260 - newrom.Game.Length - _path.Length;
|
|
||||||
if (newrom.Name.Length > usableLength)
|
|
||||||
{
|
|
||||||
string ext = Path.GetExtension(newrom.Name);
|
|
||||||
newrom.Name = newrom.Name.Substring(0, usableLength - ext.Length);
|
|
||||||
newrom.Name += ext;
|
|
||||||
}
|
|
||||||
|
|
||||||
newroms.Add(newrom);
|
|
||||||
}
|
|
||||||
datdata.Roms[key] = newroms;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now write the file out accordingly
|
|
||||||
Output.WriteDatfile(datdata, Path.GetDirectoryName(filename), _logger);
|
|
||||||
|
|
||||||
// Remove the original file if different and inform the user
|
|
||||||
if (filename != Style.CreateOutfileName(" ", datdata).Remove(0, 1))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
File.Delete(filename);
|
|
||||||
_logger.Log("Original file \"" + filename + "\" deleted");
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.Error(ex.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user