mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ALL] Convert Dat from a struct to an object
This effectively doesn't do much for the time being since there's only one "Dat type" that's being used. Realistically, this is probably the best bet since a given DAT should not be restricted to an output type as much as an ItemType is bound to its data. This also removes the experimental classes that won't be in use for forever. More work still might need to be done but it is unknown at this point.
This commit is contained in:
@@ -33,7 +33,7 @@ namespace SabreTools
|
||||
Dictionary<string, Tuple<long, bool>> depots = new Dictionary<string, Tuple<long, bool>>();
|
||||
|
||||
// Get the XML text reader for the configuration file, if possible
|
||||
XmlTextReader xtr = DatTools.GetXmlTextReader(_config, _logger);
|
||||
XmlTextReader xtr = DatFile.GetXmlTextReader(_config, _logger);
|
||||
|
||||
// Now parse the XML file for settings
|
||||
if (xtr != null)
|
||||
@@ -357,8 +357,8 @@ namespace SabreTools
|
||||
foreach (string key in toscan.Keys)
|
||||
{
|
||||
// Parse the Dat if possible
|
||||
Dat tempdat = new Dat();
|
||||
DatTools.Parse(toscan[key], 0, 0, ref tempdat, _logger);
|
||||
DatFile tempdat = new DatFile();
|
||||
DatFile.Parse(toscan[key], 0, 0, ref tempdat, _logger);
|
||||
|
||||
// If the Dat wasn't empty, add the information
|
||||
if (tempdat.Files.Count != 0)
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace SabreTools
|
||||
private static void InitDir2Dat(List<string> inputs)
|
||||
{
|
||||
// Create a simple Dat output
|
||||
Dat datdata = new Dat()
|
||||
DatFile datdata = new DatFile()
|
||||
{
|
||||
FileName = Path.GetFileName(inputs[0]) + " Dir2Dat",
|
||||
Name = Path.GetFileName(inputs[0]) + " Dir2Dat",
|
||||
@@ -73,7 +73,7 @@ namespace SabreTools
|
||||
DATFromDir dfd = new DATFromDir(input, datdata, false /* noMD5 */, false /* noSHA1 */, true /* bare */, false /* archivesAsFiles */,
|
||||
true /* enableGzip */, false /* addBlanks */, false /* addDate */, "__temp__" /* tempDir */, 4 /* maxDegreeOfParallelism */, _logger);
|
||||
dfd.Start();
|
||||
DatTools.WriteDatfile(dfd.DatData, "", logger);
|
||||
DatFile.WriteDatfile(dfd.DatData, "", logger);
|
||||
}
|
||||
logger.Close();
|
||||
}
|
||||
|
||||
@@ -3,154 +3,6 @@ using System.Collections.Generic;
|
||||
|
||||
namespace SabreTools.Helper
|
||||
{
|
||||
#region Hash-to-Dat structs [Currently Unused]
|
||||
|
||||
/* Thought experiment
|
||||
|
||||
So, here's a connundrum: Should the internal structure of how DATs work (down to the hash level) mirror
|
||||
how people see it (Dat to multiple games, game to multiple roms, rom to single hash) or
|
||||
should it more closely mirror real life (Hash to multiple roms, rom to multiple games, game to single DAT)
|
||||
|
||||
If I use the "how people see it":
|
||||
Things are pretty much how they are now with redundant data and the like
|
||||
It makes sense to write things out to file, though. And life is easier when output is easier.
|
||||
No code changes (big plus!)
|
||||
|
||||
If I use the "how it is":
|
||||
Less data is likely to be mirrored
|
||||
Refs to DAT files are possible so that there aren't duplicates
|
||||
A lot of code will have to change...
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Intermediate struct for holding and processing Hash data (NEW SYSTEM)
|
||||
/// </summary>
|
||||
public struct HashData : IEquatable<HashData>
|
||||
{
|
||||
public long Size;
|
||||
public byte[] CRC;
|
||||
public byte[] MD5;
|
||||
public byte[] SHA1;
|
||||
public List<RomData> Roms;
|
||||
|
||||
public bool Equals(HashData other)
|
||||
{
|
||||
return this.Equals(other, false);
|
||||
}
|
||||
|
||||
public bool Equals(HashData other, bool IsDisk)
|
||||
{
|
||||
bool equals = false;
|
||||
|
||||
if (!IsDisk &&
|
||||
((this.MD5 == null || other.MD5 == null) || this.MD5 == other.MD5) &&
|
||||
((this.SHA1 == null || other.SHA1 == null) || this.SHA1 == other.SHA1))
|
||||
{
|
||||
equals = true;
|
||||
}
|
||||
else if (!IsDisk &&
|
||||
(this.Size == other.Size) &&
|
||||
((this.CRC == null || other.CRC != null) || this.CRC == other.CRC) &&
|
||||
((this.MD5 == null || other.MD5 == null) || this.MD5 == other.MD5) &&
|
||||
((this.SHA1 == null || other.SHA1 == null) || this.SHA1 == other.SHA1))
|
||||
{
|
||||
equals = true;
|
||||
}
|
||||
|
||||
return equals;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intermediate struct for holding and processing Rom data (NEW SYSTEM)
|
||||
/// </summary>
|
||||
public struct RomData
|
||||
{
|
||||
public string Name;
|
||||
public ItemType Type;
|
||||
public bool Nodump;
|
||||
public string Date;
|
||||
public DupeType DupeType;
|
||||
public MachineData Machine;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intermediate struct for holding and processing Game/Machine data (NEW SYSTEM)
|
||||
/// </summary>
|
||||
public struct MachineData
|
||||
{
|
||||
// Data specific to Machine/Game
|
||||
public string Name;
|
||||
public string Comment;
|
||||
public string Description;
|
||||
public string Year;
|
||||
public string Manufacturer;
|
||||
public string RomOf;
|
||||
public string CloneOf;
|
||||
public string SampleOf;
|
||||
public string SourceFile;
|
||||
public bool IsBios;
|
||||
public string Board;
|
||||
public string RebuildTo;
|
||||
public bool TorrentZipped;
|
||||
|
||||
// Data specific to the source of the Machine/Game
|
||||
public int SystemID;
|
||||
public string System;
|
||||
public int SourceID;
|
||||
public string Source;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intermediate struct for holding and processing DAT data (NEW SYSTEM)
|
||||
/// </summary>
|
||||
public struct DatData
|
||||
{
|
||||
// Data common to most DAT types
|
||||
public string FileName;
|
||||
public string Name;
|
||||
public string Description;
|
||||
public string RootDir;
|
||||
public string Category;
|
||||
public string Version;
|
||||
public string Date;
|
||||
public string Author;
|
||||
public string Email;
|
||||
public string Homepage;
|
||||
public string Url;
|
||||
public string Comment;
|
||||
public string Header;
|
||||
public string Type; // Generally only used for SuperDAT
|
||||
public ForceMerging ForceMerging;
|
||||
public ForceNodump ForceNodump;
|
||||
public ForcePacking ForcePacking;
|
||||
public OutputFormat OutputFormat;
|
||||
public bool MergeRoms;
|
||||
public List<HashData> Hashes;
|
||||
|
||||
// Data specific to the Miss DAT type
|
||||
public bool UseGame;
|
||||
public string Prefix;
|
||||
public string Postfix;
|
||||
public bool Quotes;
|
||||
public string RepExt;
|
||||
public string AddExt;
|
||||
public bool GameName;
|
||||
public bool Romba;
|
||||
public bool? XSV; // true for tab-deliminated output, false for comma-deliminated output
|
||||
|
||||
// Statistical data related to the DAT
|
||||
public long RomCount;
|
||||
public long DiskCount;
|
||||
public long TotalSize;
|
||||
public long CRCCount;
|
||||
public long MD5Count;
|
||||
public long SHA1Count;
|
||||
public long NodumpCount;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Dat-to-Hash structs
|
||||
|
||||
/// <summary>
|
||||
@@ -191,136 +43,6 @@ namespace SabreTools.Helper
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Intermediate struct for holding DAT information
|
||||
/// </summary>
|
||||
public struct Dat : ICloneable
|
||||
{
|
||||
// Data common to most DAT types
|
||||
public string FileName;
|
||||
public string Name;
|
||||
public string Description;
|
||||
public string RootDir;
|
||||
public string Category;
|
||||
public string Version;
|
||||
public string Date;
|
||||
public string Author;
|
||||
public string Email;
|
||||
public string Homepage;
|
||||
public string Url;
|
||||
public string Comment;
|
||||
public string Header;
|
||||
public string Type; // Generally only used for SuperDAT
|
||||
public ForceMerging ForceMerging;
|
||||
public ForceNodump ForceNodump;
|
||||
public ForcePacking ForcePacking;
|
||||
public OutputFormat OutputFormat;
|
||||
public bool MergeRoms;
|
||||
public Dictionary<string, List<DatItem>> Files;
|
||||
|
||||
// Data specific to the Miss DAT type
|
||||
public bool UseGame;
|
||||
public string Prefix;
|
||||
public string Postfix;
|
||||
public bool Quotes;
|
||||
public string RepExt;
|
||||
public string AddExt;
|
||||
public bool RemExt;
|
||||
public bool GameName;
|
||||
public bool Romba;
|
||||
public bool? XSV; // true for tab-deliminated output, false for comma-deliminated output
|
||||
|
||||
// Statistical data related to the DAT
|
||||
public long RomCount;
|
||||
public long DiskCount;
|
||||
public long TotalSize;
|
||||
public long CRCCount;
|
||||
public long MD5Count;
|
||||
public long SHA1Count;
|
||||
public long NodumpCount;
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new Dat
|
||||
{
|
||||
FileName = this.FileName,
|
||||
Name = this.Name,
|
||||
Description = this.Description,
|
||||
RootDir = this.RootDir,
|
||||
Category = this.Category,
|
||||
Version = this.Version,
|
||||
Date = this.Date,
|
||||
Author = this.Author,
|
||||
Email = this.Email,
|
||||
Homepage = this.Homepage,
|
||||
Url = this.Url,
|
||||
Comment = this.Comment,
|
||||
Header = this.Header,
|
||||
Type = this.Type,
|
||||
ForceMerging = this.ForceMerging,
|
||||
ForceNodump = this.ForceNodump,
|
||||
ForcePacking = this.ForcePacking,
|
||||
OutputFormat = this.OutputFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = this.Files,
|
||||
UseGame = this.UseGame,
|
||||
Prefix = this.Prefix,
|
||||
Postfix = this.Postfix,
|
||||
Quotes = this.Quotes,
|
||||
RepExt = this.RepExt,
|
||||
AddExt = this.AddExt,
|
||||
RemExt = this.RemExt,
|
||||
GameName = this.GameName,
|
||||
Romba = this.Romba,
|
||||
XSV = this.XSV,
|
||||
RomCount = this.RomCount,
|
||||
DiskCount = this.DiskCount,
|
||||
TotalSize = this.TotalSize,
|
||||
CRCCount = this.CRCCount,
|
||||
MD5Count = this.MD5Count,
|
||||
SHA1Count = this.SHA1Count,
|
||||
NodumpCount = this.NodumpCount,
|
||||
};
|
||||
}
|
||||
|
||||
public object CloneHeader()
|
||||
{
|
||||
return new Dat
|
||||
{
|
||||
FileName = this.FileName,
|
||||
Name = this.Name,
|
||||
Description = this.Description,
|
||||
RootDir = this.RootDir,
|
||||
Category = this.Category,
|
||||
Version = this.Version,
|
||||
Date = this.Date,
|
||||
Author = this.Author,
|
||||
Email = this.Email,
|
||||
Homepage = this.Homepage,
|
||||
Url = this.Url,
|
||||
Comment = this.Comment,
|
||||
Header = this.Header,
|
||||
Type = this.Type,
|
||||
ForceMerging = this.ForceMerging,
|
||||
ForceNodump = this.ForceNodump,
|
||||
ForcePacking = this.ForcePacking,
|
||||
OutputFormat = this.OutputFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
UseGame = this.UseGame,
|
||||
Prefix = this.Prefix,
|
||||
Postfix = this.Postfix,
|
||||
Quotes = this.Quotes,
|
||||
RepExt = this.RepExt,
|
||||
AddExt = this.AddExt,
|
||||
RemExt = this.RemExt,
|
||||
GameName = this.GameName,
|
||||
Romba = this.Romba,
|
||||
XSV = this.XSV,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Skipper structs
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace SabreTools
|
||||
private string _tempDir;
|
||||
|
||||
// User specified inputs
|
||||
private Dat _datdata;
|
||||
private DatFile _datdata;
|
||||
private bool _noMD5;
|
||||
private bool _noSHA1;
|
||||
private bool _bare;
|
||||
@@ -32,7 +32,7 @@ namespace SabreTools
|
||||
private Logger _logger;
|
||||
|
||||
// Public variables
|
||||
public Dat DatData
|
||||
public DatFile DatData
|
||||
{
|
||||
get { return _datdata; }
|
||||
}
|
||||
@@ -52,7 +52,7 @@ namespace SabreTools
|
||||
/// <param name="tempDir">Name of the directory to create a temp folder in (blank is current directory)</param>
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logger object for console and file output</param>
|
||||
public DATFromDir(string basePath, Dat datdata, bool noMD5, bool noSHA1, bool bare, bool archivesAsFiles,
|
||||
public DATFromDir(string basePath, DatFile datdata, bool noMD5, bool noSHA1, bool bare, bool archivesAsFiles,
|
||||
bool enableGzip, bool addBlanks, bool addDate, string tempDir, int maxDegreeOfParallelism, Logger logger)
|
||||
{
|
||||
_basePath = Path.GetFullPath(basePath);
|
||||
|
||||
@@ -10,11 +10,464 @@ using System.Xml;
|
||||
|
||||
namespace SabreTools.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// DAT manipulation tools that rely on Rom and related structs
|
||||
/// </summary>
|
||||
public class DatTools
|
||||
public class DatFile : ICloneable
|
||||
{
|
||||
#region Private instance variables
|
||||
|
||||
// Data common to most DAT types
|
||||
private string _fileName;
|
||||
private string _name;
|
||||
private string _description;
|
||||
private string _rootDir;
|
||||
private string _category;
|
||||
private string _version;
|
||||
private string _date;
|
||||
private string _author;
|
||||
private string _email;
|
||||
private string _homepage;
|
||||
private string _url;
|
||||
private string _comment;
|
||||
private string _header;
|
||||
private string _type; // Generally only used for SuperDAT
|
||||
private ForceMerging _forceMerging;
|
||||
private ForceNodump _forceNodump;
|
||||
private ForcePacking _forcePacking;
|
||||
private OutputFormat _outputFormat;
|
||||
private bool _mergeRoms;
|
||||
private Dictionary<string, List<DatItem>> _files;
|
||||
|
||||
// Data specific to the Miss DAT type
|
||||
private bool _useGame;
|
||||
private string _prefix;
|
||||
private string _postfix;
|
||||
private bool _quotes;
|
||||
private string _repExt;
|
||||
private string _addExt;
|
||||
private bool _remExt;
|
||||
private bool _gameName;
|
||||
private bool _romba;
|
||||
private bool? _xsv; // true for tab-deliminated output, false for comma-deliminated output
|
||||
|
||||
// Statistical data related to the DAT
|
||||
private long _romCount;
|
||||
private long _diskCount;
|
||||
private long _totalSize;
|
||||
private long _crcCount;
|
||||
private long _md5Count;
|
||||
private long _sha1Count;
|
||||
private long _nodumpCount;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Publicly facing variables
|
||||
|
||||
// Data common to most DAT types
|
||||
public string FileName
|
||||
{
|
||||
get { return _fileName; }
|
||||
set { _fileName = value; }
|
||||
}
|
||||
public string Name
|
||||
{
|
||||
get { return _name; }
|
||||
set { _name = value; }
|
||||
}
|
||||
public string Description
|
||||
{
|
||||
get { return _description; }
|
||||
set { _description = value; }
|
||||
}
|
||||
public string RootDir
|
||||
{
|
||||
get { return _rootDir; }
|
||||
set { _rootDir = value; }
|
||||
}
|
||||
public string Category
|
||||
{
|
||||
get { return _category; }
|
||||
set { _category = value; }
|
||||
}
|
||||
public string Version
|
||||
{
|
||||
get { return _version; }
|
||||
set { _version = value; }
|
||||
}
|
||||
public string Date
|
||||
{
|
||||
get { return _date; }
|
||||
set { _date = value; }
|
||||
}
|
||||
public string Author
|
||||
{
|
||||
get { return _author; }
|
||||
set { _author = value; }
|
||||
}
|
||||
public string Email
|
||||
{
|
||||
get { return _email; }
|
||||
set { _email = value; }
|
||||
}
|
||||
public string Homepage
|
||||
{
|
||||
get { return _homepage; }
|
||||
set { _homepage = value; }
|
||||
}
|
||||
public string Url
|
||||
{
|
||||
get { return _url; }
|
||||
set { _url = value; }
|
||||
}
|
||||
public string Comment
|
||||
{
|
||||
get { return _comment; }
|
||||
set { _comment = value; }
|
||||
}
|
||||
public string Header
|
||||
{
|
||||
get { return _header; }
|
||||
set { _header = value; }
|
||||
}
|
||||
public string Type // Generally only used for SuperDAT
|
||||
{
|
||||
get { return _type; }
|
||||
set { _type = value; }
|
||||
}
|
||||
public ForceMerging ForceMerging
|
||||
{
|
||||
get { return _forceMerging; }
|
||||
set { _forceMerging = value; }
|
||||
}
|
||||
public ForceNodump ForceNodump
|
||||
{
|
||||
get { return _forceNodump; }
|
||||
set { _forceNodump = value; }
|
||||
}
|
||||
public ForcePacking ForcePacking
|
||||
{
|
||||
get { return _forcePacking; }
|
||||
set { _forcePacking = value; }
|
||||
}
|
||||
public OutputFormat OutputFormat
|
||||
{
|
||||
get { return _outputFormat; }
|
||||
set { _outputFormat = value; }
|
||||
}
|
||||
public bool MergeRoms
|
||||
{
|
||||
get { return _mergeRoms; }
|
||||
set { _mergeRoms = value; }
|
||||
}
|
||||
public Dictionary<string, List<DatItem>> Files
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_files == null)
|
||||
{
|
||||
_files = new Dictionary<string, List<DatItem>>();
|
||||
}
|
||||
return _files;
|
||||
}
|
||||
set
|
||||
{
|
||||
_files = value;
|
||||
}
|
||||
}
|
||||
|
||||
// Data specific to the Miss DAT type
|
||||
public bool UseGame
|
||||
{
|
||||
get { return _useGame; }
|
||||
set { _useGame = value; }
|
||||
}
|
||||
public string Prefix
|
||||
{
|
||||
get { return _prefix; }
|
||||
set { _prefix = value; }
|
||||
}
|
||||
public string Postfix
|
||||
{
|
||||
get { return _postfix; }
|
||||
set { _postfix = value; }
|
||||
}
|
||||
public bool Quotes
|
||||
{
|
||||
get { return _quotes; }
|
||||
set { _quotes = value; }
|
||||
}
|
||||
public string RepExt
|
||||
{
|
||||
get { return _repExt; }
|
||||
set { _repExt = value; }
|
||||
}
|
||||
public string AddExt
|
||||
{
|
||||
get { return _addExt; }
|
||||
set { _addExt = value; }
|
||||
}
|
||||
public bool RemExt
|
||||
{
|
||||
get { return _remExt; }
|
||||
set { _remExt = value; }
|
||||
}
|
||||
public bool GameName
|
||||
{
|
||||
get { return _gameName; }
|
||||
set { _gameName = value; }
|
||||
}
|
||||
public bool Romba
|
||||
{
|
||||
get { return _romba; }
|
||||
set { _romba = value; }
|
||||
}
|
||||
public bool? XSV // true for tab-deliminated output, false for comma-deliminated output
|
||||
{
|
||||
get { return _xsv; }
|
||||
set { _xsv = value; }
|
||||
}
|
||||
|
||||
// Statistical data related to the DAT
|
||||
public long RomCount
|
||||
{
|
||||
get { return _romCount; }
|
||||
set { _romCount = value; }
|
||||
}
|
||||
public long DiskCount
|
||||
{
|
||||
get { return _diskCount; }
|
||||
set { _diskCount = value; }
|
||||
}
|
||||
public long TotalSize
|
||||
{
|
||||
get { return _totalSize; }
|
||||
set { _totalSize = value; }
|
||||
}
|
||||
public long CRCCount
|
||||
{
|
||||
get { return _crcCount; }
|
||||
set { _crcCount = value; }
|
||||
}
|
||||
public long MD5Count
|
||||
{
|
||||
get { return _md5Count; }
|
||||
set { _md5Count = value; }
|
||||
}
|
||||
public long SHA1Count
|
||||
{
|
||||
get { return _sha1Count; }
|
||||
set { _sha1Count = value; }
|
||||
}
|
||||
public long NodumpCount
|
||||
{
|
||||
get { return _nodumpCount; }
|
||||
set { _nodumpCount = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Create a default, empty Dat object
|
||||
/// </summary>
|
||||
public DatFile()
|
||||
{
|
||||
// Nothing needs to be done
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new Dat object with the included information (standard Dats)
|
||||
/// </summary>
|
||||
/// <param name="filename">New filename</param>
|
||||
/// <param name="name">New name</param>
|
||||
/// <param name="description">New description</param>
|
||||
/// <param name="rootdir">New rootdir</param>
|
||||
/// <param name="category">New category</param>
|
||||
/// <param name="version">New version</param>
|
||||
/// <param name="date">New date</param>
|
||||
/// <param name="author">New author</param>
|
||||
/// <param name="email">New email</param>
|
||||
/// <param name="homepage">New homepage</param>
|
||||
/// <param name="url">New URL</param>
|
||||
/// <param name="comment">New comment</param>
|
||||
/// <param name="header">New header</param>
|
||||
/// <param name="superdat">True to set SuperDAT type, false otherwise</param>
|
||||
/// <param name="forcemerge">None, Split, Full</param>
|
||||
/// <param name="forcend">None, Obsolete, Required, Ignore</param>
|
||||
/// <param name="forcepack">None, Zip, Unzip</param>
|
||||
/// <param name="outputFormat">Non-zero flag for output format, zero otherwise for default</param>
|
||||
/// <param name="mergeRoms">True to dedupe the roms in the DAT, false otherwise (default)</param>
|
||||
/// <param name="files">Dictionary of lists of DatItem objects</param>
|
||||
public DatFile(string fileName, string name, string description, string rootDir, string category, string version, string date,
|
||||
string author, string email, string homepage, string url, string comment, string header, string type, ForceMerging forceMerging,
|
||||
ForceNodump forceNodump, ForcePacking forcePacking, OutputFormat outputFormat, bool mergeRoms, Dictionary<string, List<DatItem>> files)
|
||||
{
|
||||
_fileName = fileName;
|
||||
_name = name;
|
||||
_description = description;
|
||||
_rootDir = rootDir;
|
||||
_category = category;
|
||||
_version = version;
|
||||
_date = date;
|
||||
_author = author;
|
||||
_email = email;
|
||||
_homepage = homepage;
|
||||
_url = url;
|
||||
_comment = comment;
|
||||
_header = header;
|
||||
_type = type;
|
||||
_forceMerging = forceMerging;
|
||||
_forceNodump = forceNodump;
|
||||
_forcePacking = forcePacking;
|
||||
_outputFormat = outputFormat;
|
||||
_mergeRoms = mergeRoms;
|
||||
_files = files;
|
||||
|
||||
_romCount = 0;
|
||||
_diskCount = 0;
|
||||
_totalSize = 0;
|
||||
_crcCount = 0;
|
||||
_md5Count = 0;
|
||||
_sha1Count = 0;
|
||||
_nodumpCount = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new Dat object with the included information (missfile)
|
||||
/// </summary>
|
||||
/// <param name="filename">New filename</param>
|
||||
/// <param name="name">New name</param>
|
||||
/// <param name="description">New description</param>
|
||||
/// <param name="outputFormat">Non-zero flag for output format, zero otherwise for default</param>
|
||||
/// <param name="mergeRoms">True to dedupe the roms in the DAT, false otherwise (default)</param>
|
||||
/// <param name="files">Dictionary of lists of DatItem objects</param>
|
||||
/// <param name="useGame">True if games are to be used in output, false if roms are</param>
|
||||
/// <param name="prefix">Generic prefix to be added to each line</param>
|
||||
/// <param name="postfix">Generic postfix to be added to each line</param>
|
||||
/// <param name="quotes">Add quotes to each item</param>
|
||||
/// <param name="repExt">Replace all extensions with another</param>
|
||||
/// <param name="addExt">Add an extension to all items</param>
|
||||
/// <param name="remExt">Remove all extensions</param>
|
||||
/// <param name="gameName">Add the dat name as a directory prefix</param>
|
||||
/// <param name="romba">Output files in romba format</param>
|
||||
/// <param name="xsv">True to output files in TSV format, false to output files in CSV format, null otherwise</param>
|
||||
public DatFile(string fileName, string name, string description, OutputFormat outputFormat, bool mergeRoms,
|
||||
Dictionary<string, List<DatItem>> files, bool useGame, string prefix, string postfix, bool quotes,
|
||||
string repExt, string addExt, bool remExt, bool gameName, bool romba, bool? xsv)
|
||||
{
|
||||
_fileName = fileName;
|
||||
_name = name;
|
||||
_description = description;
|
||||
_outputFormat = outputFormat;
|
||||
_mergeRoms = mergeRoms;
|
||||
_files = files;
|
||||
|
||||
_useGame = useGame;
|
||||
_prefix = prefix;
|
||||
_postfix = postfix;
|
||||
_quotes = quotes;
|
||||
_repExt = repExt;
|
||||
_addExt = addExt;
|
||||
_remExt = remExt;
|
||||
_gameName = gameName;
|
||||
_romba = romba;
|
||||
_xsv = xsv;
|
||||
|
||||
_romCount = 0;
|
||||
_diskCount = 0;
|
||||
_totalSize = 0;
|
||||
_crcCount = 0;
|
||||
_md5Count = 0;
|
||||
_sha1Count = 0;
|
||||
_nodumpCount = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Cloning Methods
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new DatFile
|
||||
{
|
||||
FileName = this.FileName,
|
||||
Name = this.Name,
|
||||
Description = this.Description,
|
||||
RootDir = this.RootDir,
|
||||
Category = this.Category,
|
||||
Version = this.Version,
|
||||
Date = this.Date,
|
||||
Author = this.Author,
|
||||
Email = this.Email,
|
||||
Homepage = this.Homepage,
|
||||
Url = this.Url,
|
||||
Comment = this.Comment,
|
||||
Header = this.Header,
|
||||
Type = this.Type,
|
||||
ForceMerging = this.ForceMerging,
|
||||
ForceNodump = this.ForceNodump,
|
||||
ForcePacking = this.ForcePacking,
|
||||
OutputFormat = this.OutputFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = this.Files,
|
||||
UseGame = this.UseGame,
|
||||
Prefix = this.Prefix,
|
||||
Postfix = this.Postfix,
|
||||
Quotes = this.Quotes,
|
||||
RepExt = this.RepExt,
|
||||
AddExt = this.AddExt,
|
||||
RemExt = this.RemExt,
|
||||
GameName = this.GameName,
|
||||
Romba = this.Romba,
|
||||
XSV = this.XSV,
|
||||
RomCount = this.RomCount,
|
||||
DiskCount = this.DiskCount,
|
||||
TotalSize = this.TotalSize,
|
||||
CRCCount = this.CRCCount,
|
||||
MD5Count = this.MD5Count,
|
||||
SHA1Count = this.SHA1Count,
|
||||
NodumpCount = this.NodumpCount,
|
||||
};
|
||||
}
|
||||
|
||||
public object CloneHeader()
|
||||
{
|
||||
return new DatFile
|
||||
{
|
||||
FileName = this.FileName,
|
||||
Name = this.Name,
|
||||
Description = this.Description,
|
||||
RootDir = this.RootDir,
|
||||
Category = this.Category,
|
||||
Version = this.Version,
|
||||
Date = this.Date,
|
||||
Author = this.Author,
|
||||
Email = this.Email,
|
||||
Homepage = this.Homepage,
|
||||
Url = this.Url,
|
||||
Comment = this.Comment,
|
||||
Header = this.Header,
|
||||
Type = this.Type,
|
||||
ForceMerging = this.ForceMerging,
|
||||
ForceNodump = this.ForceNodump,
|
||||
ForcePacking = this.ForcePacking,
|
||||
OutputFormat = this.OutputFormat,
|
||||
MergeRoms = this.MergeRoms,
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
UseGame = this.UseGame,
|
||||
Prefix = this.Prefix,
|
||||
Postfix = this.Postfix,
|
||||
Quotes = this.Quotes,
|
||||
RepExt = this.RepExt,
|
||||
AddExt = this.AddExt,
|
||||
RemExt = this.RemExt,
|
||||
GameName = this.GameName,
|
||||
Romba = this.Romba,
|
||||
XSV = this.XSV,
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region DAT Parsing
|
||||
|
||||
/// <summary>
|
||||
@@ -103,7 +556,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="clean">True if game names are sanitized, false otherwise (default)</param>
|
||||
/// <param name="softlist">True if SL XML names should be kept, false otherwise (default)</param>
|
||||
/// <param name="keepext">True if original extension should be kept, false otherwise (default)</param>
|
||||
public static void Parse(string filename, int sysid, int srcid, ref Dat datdata, Logger logger, bool keep = false, bool clean = false, bool softlist = false, bool keepext = false)
|
||||
public static void Parse(string filename, int sysid, int srcid, ref DatFile datdata, Logger logger, bool keep = false, bool clean = false, bool softlist = false, bool keepext = false)
|
||||
{
|
||||
Parse(filename, sysid, srcid, ref datdata, null, null, null, -1, -1, -1, null, null, null, null, false, false, "", logger, keep, clean, softlist, keepext);
|
||||
}
|
||||
@@ -138,7 +591,7 @@ namespace SabreTools.Helper
|
||||
string filename,
|
||||
int sysid,
|
||||
int srcid,
|
||||
ref Dat datdata,
|
||||
ref DatFile datdata,
|
||||
|
||||
// Rom filtering
|
||||
string gamename,
|
||||
@@ -229,7 +682,7 @@ namespace SabreTools.Helper
|
||||
string filename,
|
||||
int sysid,
|
||||
int srcid,
|
||||
ref Dat datdata,
|
||||
ref DatFile datdata,
|
||||
|
||||
// Rom filtering
|
||||
string gamename,
|
||||
@@ -674,7 +1127,7 @@ namespace SabreTools.Helper
|
||||
string filename,
|
||||
int sysid,
|
||||
int srcid,
|
||||
ref Dat datdata,
|
||||
ref DatFile datdata,
|
||||
|
||||
// Rom filtering
|
||||
string gamename,
|
||||
@@ -840,7 +1293,7 @@ namespace SabreTools.Helper
|
||||
string filename,
|
||||
int sysid,
|
||||
int srcid,
|
||||
ref Dat datdata,
|
||||
ref DatFile datdata,
|
||||
|
||||
// Rom filtering
|
||||
string gamename,
|
||||
@@ -1574,7 +2027,7 @@ namespace SabreTools.Helper
|
||||
/// <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">Logger object for console and/or file output</param>
|
||||
private static void ParseAddHelper(DatItem item, ref Dat datdata, string gamename, string romname, string romtype, long sgt, long slt,
|
||||
private static void ParseAddHelper(DatItem item, ref DatFile datdata, string gamename, string romname, string romtype, long sgt, long slt,
|
||||
long seq, string crc, string md5, string sha1, bool? nodump, bool trim, bool single, string root, bool clean, Logger logger, out string key)
|
||||
{
|
||||
key = "";
|
||||
@@ -1805,7 +2258,7 @@ namespace SabreTools.Helper
|
||||
{
|
||||
logger.User("A total of " + count + " file hashes will be written out to file");
|
||||
}
|
||||
|
||||
|
||||
return sortable;
|
||||
}
|
||||
|
||||
@@ -1843,7 +2296,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="root">String representing root directory to compare against for length calculation</param>
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
public static void Update(List<string> inputFileNames, Dat datdata, OutputFormat outputFormat, string outDir, bool merge,
|
||||
public static void Update(List<string> inputFileNames, DatFile datdata, OutputFormat outputFormat, string outDir, bool merge,
|
||||
DiffMode diff, bool? cascade, bool inplace, bool skip, bool bare, bool clean, bool softlist, string gamename, string romname, string romtype,
|
||||
long sgt, long slt, long seq, string crc, string md5, string sha1, bool? nodump, bool trim, bool single, string root, int maxDegreeOfParallelism,
|
||||
Logger logger)
|
||||
@@ -1897,8 +2350,8 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Create a dictionary of all ROMs from the input DATs
|
||||
Dat userData;
|
||||
List<Dat> datHeaders = PopulateUserData(newInputFileNames, inplace, clean, softlist,
|
||||
DatFile userData;
|
||||
List<DatFile> datHeaders = PopulateUserData(newInputFileNames, inplace, clean, softlist,
|
||||
outDir, datdata, out userData, gamename, romname, romtype, sgt, slt, seq,
|
||||
crc, md5, sha1, nodump, trim, single, root, maxDegreeOfParallelism, logger);
|
||||
|
||||
@@ -1924,53 +2377,53 @@ namespace SabreTools.Helper
|
||||
Parallel.ForEach(inputFileNames,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
|
||||
inputFileName =>
|
||||
{
|
||||
// Clean the input string
|
||||
if (inputFileName != "")
|
||||
{
|
||||
inputFileName = Path.GetFullPath(inputFileName);
|
||||
}
|
||||
|
||||
if (File.Exists(inputFileName))
|
||||
{
|
||||
Dat innerDatdata = (Dat)datdata.CloneHeader();
|
||||
logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\"");
|
||||
Parse(inputFileName, 0, 0, ref innerDatdata, gamename, romname,
|
||||
romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single,
|
||||
root, logger, true, clean, softlist, keepext: (innerDatdata.XSV != null));
|
||||
|
||||
// If we have roms, output them
|
||||
if (innerDatdata.Files.Count != 0)
|
||||
// Clean the input string
|
||||
if (inputFileName != "")
|
||||
{
|
||||
WriteDatfile(innerDatdata, (outDir == "" ? Path.GetDirectoryName(inputFileName) : outDir), logger, overwrite: (outDir != ""));
|
||||
inputFileName = Path.GetFullPath(inputFileName);
|
||||
}
|
||||
}
|
||||
else if (Directory.Exists(inputFileName))
|
||||
{
|
||||
inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar;
|
||||
|
||||
Parallel.ForEach(Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories),
|
||||
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
|
||||
file =>
|
||||
if (File.Exists(inputFileName))
|
||||
{
|
||||
logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\"");
|
||||
Dat innerDatdata = (Dat)datdata.Clone();
|
||||
innerDatdata.Files = null;
|
||||
Parse(file, 0, 0, ref innerDatdata, gamename, romname, romtype, sgt,
|
||||
slt, seq, crc, md5, sha1, nodump, trim, single, root, logger, true, clean, keepext: (datdata.XSV != null));
|
||||
DatFile innerDatdata = (DatFile)datdata.CloneHeader();
|
||||
logger.User("Processing \"" + Path.GetFileName(inputFileName) + "\"");
|
||||
Parse(inputFileName, 0, 0, ref innerDatdata, gamename, romname,
|
||||
romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single,
|
||||
root, logger, true, clean, softlist, keepext: (innerDatdata.XSV != null));
|
||||
|
||||
// If we have roms, output them
|
||||
if (innerDatdata.Files != null && innerDatdata.Files.Count != 0)
|
||||
if (innerDatdata.Files.Count != 0)
|
||||
{
|
||||
WriteDatfile(innerDatdata, (outDir == "" ? Path.GetDirectoryName(file) : outDir + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), logger, overwrite: (outDir != ""));
|
||||
WriteDatfile(innerDatdata, (outDir == "" ? Path.GetDirectoryName(inputFileName) : outDir), logger, overwrite: (outDir != ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("I'm sorry but " + inputFileName + " doesn't exist!");
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (Directory.Exists(inputFileName))
|
||||
{
|
||||
inputFileName = Path.GetFullPath(inputFileName) + Path.DirectorySeparatorChar;
|
||||
|
||||
Parallel.ForEach(Directory.EnumerateFiles(inputFileName, "*", SearchOption.AllDirectories),
|
||||
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
|
||||
file =>
|
||||
{
|
||||
logger.User("Processing \"" + Path.GetFullPath(file).Remove(0, inputFileName.Length) + "\"");
|
||||
DatFile innerDatdata = (DatFile)datdata.Clone();
|
||||
innerDatdata.Files = null;
|
||||
Parse(file, 0, 0, ref innerDatdata, gamename, romname, romtype, sgt,
|
||||
slt, seq, crc, md5, sha1, nodump, trim, single, root, logger, true, clean, keepext: (datdata.XSV != null));
|
||||
|
||||
// If we have roms, output them
|
||||
if (innerDatdata.Files != null && innerDatdata.Files.Count != 0)
|
||||
{
|
||||
WriteDatfile(innerDatdata, (outDir == "" ? Path.GetDirectoryName(file) : outDir + Path.GetDirectoryName(file).Remove(0, inputFileName.Length - 1)), logger, overwrite: (outDir != ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("I'm sorry but " + inputFileName + " doesn't exist!");
|
||||
}
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1995,11 +2448,11 @@ namespace SabreTools.Helper
|
||||
/// <param name="maxDegreeOfParallelism">Integer representing the maximum amount of parallelization to be used</param>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
/// <returns>List of DatData objects representing headers</returns>
|
||||
private static List<Dat> PopulateUserData(List<string> inputs, bool inplace, bool clean, bool softlist, string outDir,
|
||||
Dat inputDat, out Dat userData, string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc,
|
||||
private static List<DatFile> PopulateUserData(List<string> inputs, bool inplace, bool clean, bool softlist, string outDir,
|
||||
DatFile inputDat, out DatFile userData, string gamename, string romname, string romtype, long sgt, long slt, long seq, string crc,
|
||||
string md5, string sha1, bool? nodump, bool trim, bool single, string root, int maxDegreeOfParallelism, Logger logger)
|
||||
{
|
||||
Dat[] datHeaders = new Dat[inputs.Count];
|
||||
DatFile[] datHeaders = new DatFile[inputs.Count];
|
||||
DateTime start = DateTime.Now;
|
||||
logger.User("Processing individual DATs");
|
||||
|
||||
@@ -2007,24 +2460,24 @@ namespace SabreTools.Helper
|
||||
inputs.Count,
|
||||
new ParallelOptions { MaxDegreeOfParallelism = maxDegreeOfParallelism },
|
||||
i =>
|
||||
{
|
||||
string input = inputs[i];
|
||||
logger.User("Adding DAT: " + input.Split('¬')[0]);
|
||||
datHeaders[i] = new Dat
|
||||
{
|
||||
OutputFormat = (inputDat.OutputFormat != 0 ? inputDat.OutputFormat: 0),
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
MergeRoms = inputDat.MergeRoms,
|
||||
};
|
||||
string input = inputs[i];
|
||||
logger.User("Adding DAT: " + input.Split('¬')[0]);
|
||||
datHeaders[i] = new DatFile
|
||||
{
|
||||
OutputFormat = (inputDat.OutputFormat != 0 ? inputDat.OutputFormat : 0),
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
MergeRoms = inputDat.MergeRoms,
|
||||
};
|
||||
|
||||
Parse(input.Split('¬')[0], i, 0, ref datHeaders[i], gamename, romname, romtype, sgt, slt, seq,
|
||||
crc, md5, sha1, nodump, trim, single, root, logger, true, clean, softlist);
|
||||
});
|
||||
Parse(input.Split('¬')[0], i, 0, ref datHeaders[i], gamename, romname, romtype, sgt, slt, seq,
|
||||
crc, md5, sha1, nodump, trim, single, root, logger, true, clean, softlist);
|
||||
});
|
||||
|
||||
logger.User("Processing complete in " + DateTime.Now.Subtract(start).ToString(@"hh\:mm\:ss\.fffff"));
|
||||
|
||||
logger.User("Populating internal DAT");
|
||||
userData = (Dat)inputDat.CloneHeader();
|
||||
userData = (DatFile)inputDat.CloneHeader();
|
||||
userData.Files = new Dictionary<string, List<DatItem>>();
|
||||
for (int i = 0; i < inputs.Count; i++)
|
||||
{
|
||||
@@ -2057,21 +2510,21 @@ namespace SabreTools.Helper
|
||||
/// <param name="userData">Main DatData to draw information from</param>
|
||||
/// <param name="inputs">List of inputs to write out from</param>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
public static void DiffNoCascade(DiffMode diff, string outDir, Dat userData, List<string> inputs, Logger logger)
|
||||
public static void DiffNoCascade(DiffMode diff, string outDir, DatFile userData, List<string> inputs, Logger logger)
|
||||
{
|
||||
DateTime start = DateTime.Now;
|
||||
logger.User("Initializing all output DATs");
|
||||
|
||||
// Default vars for use
|
||||
string post = "";
|
||||
Dat outerDiffData = new Dat();
|
||||
Dat dupeData = new Dat();
|
||||
DatFile outerDiffData = new DatFile();
|
||||
DatFile dupeData = new DatFile();
|
||||
|
||||
// Don't have External dupes
|
||||
if ((diff & DiffMode.NoDupes) != 0)
|
||||
{
|
||||
post = " (No Duplicates)";
|
||||
outerDiffData = (Dat)userData.CloneHeader();
|
||||
outerDiffData = (DatFile)userData.CloneHeader();
|
||||
outerDiffData.FileName += post;
|
||||
outerDiffData.Name += post;
|
||||
outerDiffData.Description += post;
|
||||
@@ -2082,7 +2535,7 @@ namespace SabreTools.Helper
|
||||
if ((diff & DiffMode.Dupes) != 0)
|
||||
{
|
||||
post = " (Duplicates)";
|
||||
dupeData = (Dat)userData.CloneHeader();
|
||||
dupeData = (DatFile)userData.CloneHeader();
|
||||
dupeData.FileName += post;
|
||||
dupeData.Name += post;
|
||||
dupeData.Description += post;
|
||||
@@ -2090,17 +2543,17 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Create a list of DatData objects representing individual output files
|
||||
List<Dat> outDats = new List<Dat>();
|
||||
List<DatFile> outDats = new List<DatFile>();
|
||||
|
||||
// Loop through each of the inputs and get or create a new DatData object
|
||||
if ((diff & DiffMode.Individuals) != 0)
|
||||
{
|
||||
Dat[] outDatsArray = new Dat[inputs.Count];
|
||||
DatFile[] outDatsArray = new DatFile[inputs.Count];
|
||||
|
||||
Parallel.For(0, inputs.Count, j =>
|
||||
{
|
||||
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
|
||||
Dat diffData = (Dat)userData.CloneHeader();
|
||||
DatFile diffData = (DatFile)userData.CloneHeader();
|
||||
diffData.FileName += innerpost;
|
||||
diffData.Name += innerpost;
|
||||
diffData.Description += innerpost;
|
||||
@@ -2233,23 +2686,23 @@ namespace SabreTools.Helper
|
||||
/// <param name="datHeaders">Dat headers used optionally</param>
|
||||
/// <param name="skip">True if the first cascaded diff file should be skipped on output, false otherwise</param>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
public static void DiffCascade(string outDir, bool inplace, Dat userData, List<string> inputs, List<Dat> datHeaders, bool skip, Logger logger)
|
||||
public static void DiffCascade(string outDir, bool inplace, DatFile userData, List<string> inputs, List<DatFile> datHeaders, bool skip, Logger logger)
|
||||
{
|
||||
string post = "";
|
||||
|
||||
// Create a list of DatData objects representing output files
|
||||
List<Dat> outDats = new List<Dat>();
|
||||
List<DatFile> outDats = new List<DatFile>();
|
||||
|
||||
// Loop through each of the inputs and get or create a new DatData object
|
||||
DateTime start = DateTime.Now;
|
||||
logger.User("Initializing all output DATs");
|
||||
|
||||
Dat[] outDatsArray = new Dat[inputs.Count];
|
||||
DatFile[] outDatsArray = new DatFile[inputs.Count];
|
||||
|
||||
Parallel.For(0, inputs.Count, j =>
|
||||
{
|
||||
string innerpost = " (" + Path.GetFileNameWithoutExtension(inputs[j].Split('¬')[0]) + " Only)";
|
||||
Dat diffData;
|
||||
DatFile diffData;
|
||||
|
||||
// If we're in inplace mode, take the appropriate DatData object already stored
|
||||
if (inplace || !String.IsNullOrEmpty(outDir))
|
||||
@@ -2258,7 +2711,7 @@ namespace SabreTools.Helper
|
||||
}
|
||||
else
|
||||
{
|
||||
diffData = (Dat)userData.CloneHeader();
|
||||
diffData = (DatFile)userData.CloneHeader();
|
||||
diffData.FileName += post;
|
||||
diffData.Name += post;
|
||||
diffData.Description += post;
|
||||
@@ -2278,7 +2731,7 @@ namespace SabreTools.Helper
|
||||
|
||||
foreach (string key in keys)
|
||||
{
|
||||
List< DatItem> roms = DatItem.Merge(userData.Files[key], logger);
|
||||
List<DatItem> roms = DatItem.Merge(userData.Files[key], logger);
|
||||
|
||||
if (roms != null && roms.Count > 0)
|
||||
{
|
||||
@@ -2332,7 +2785,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="userData">Main DatData to draw information from</param>
|
||||
/// <param name="datHeaders">Dat headers used optionally</param>
|
||||
/// <param name="logger">Logging object for console and file output</param>
|
||||
public static void MergeNoDiff(string outDir, Dat userData, List<string> inputs, List<Dat> datHeaders, Logger logger)
|
||||
public static void MergeNoDiff(string outDir, DatFile userData, List<string> inputs, List<DatFile> datHeaders, Logger logger)
|
||||
{
|
||||
// If we're in SuperDAT mode, prefix all games with their respective DATs
|
||||
if (userData.Type == "SuperDAT")
|
||||
@@ -2384,7 +2837,7 @@ namespace SabreTools.Helper
|
||||
/// The following features have been requested for file output:
|
||||
/// - Have the ability to strip special (non-ASCII) characters from rom information
|
||||
/// </remarks>
|
||||
public static bool WriteDatfile(Dat datdata, string outDir, Logger logger, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true)
|
||||
public static bool WriteDatfile(DatFile datdata, string outDir, Logger logger, bool norename = true, bool stats = false, bool ignoreblanks = false, bool overwrite = true)
|
||||
{
|
||||
// If there's nothing there, abort
|
||||
if (datdata.Files == null || datdata.Files.Count == 0)
|
||||
@@ -2571,7 +3024,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="datdata">DatData object representing DAT information</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
public static bool WriteHeader(StreamWriter sw, OutputFormat outputFormat, Dat datdata, Logger logger)
|
||||
public static bool WriteHeader(StreamWriter sw, OutputFormat outputFormat, DatFile datdata, Logger logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -2668,7 +3121,7 @@ namespace SabreTools.Helper
|
||||
(!String.IsNullOrEmpty(datdata.Comment) ? "\t\t<comment>" + HttpUtility.HtmlEncode(datdata.Comment) + "</comment>\n" : "") +
|
||||
(!String.IsNullOrEmpty(datdata.Type) ? "\t\t<type>" + HttpUtility.HtmlEncode(datdata.Type) + "</type>\n" : "") +
|
||||
(datdata.ForcePacking != ForcePacking.None || datdata.ForceMerging != ForceMerging.None || datdata.ForceNodump != ForceNodump.None ?
|
||||
"\t\t<clrmamepro" +
|
||||
"\t\t<clrmamepro" +
|
||||
(datdata.ForcePacking == ForcePacking.Unzip ? " forcepacking=\"unzip\"" : "") +
|
||||
(datdata.ForcePacking == ForcePacking.Zip ? " forcepacking=\"zip\"" : "") +
|
||||
(datdata.ForceMerging == ForceMerging.Full ? " forcemerging=\"full\"" : "") +
|
||||
@@ -2852,7 +3305,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <param name="ignoreblanks">True if blank roms should be skipped on output, false otherwise (default)</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
public static bool WriteRomData(StreamWriter sw, OutputFormat outputFormat, DatItem rom, string lastgame, Dat datdata, int depth, Logger logger, bool ignoreblanks = false)
|
||||
public static bool WriteRomData(StreamWriter sw, OutputFormat outputFormat, DatItem rom, string lastgame, DatFile datdata, int depth, Logger logger, bool ignoreblanks = false)
|
||||
{
|
||||
// If we are in ignore blanks mode AND we have a blank (0-size) rom, skip
|
||||
if (ignoreblanks
|
||||
@@ -2914,7 +3367,7 @@ namespace SabreTools.Helper
|
||||
+ " )\n";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case OutputFormat.MissFile:
|
||||
// Missfile should only output Rom and Disk
|
||||
@@ -2998,7 +3451,7 @@ namespace SabreTools.Helper
|
||||
{
|
||||
string inline = "\"" + datdata.FileName + "\""
|
||||
+ separator + "\"" + datdata.Name + "\""
|
||||
+ separator + "\"" + datdata.Description+ "\""
|
||||
+ separator + "\"" + datdata.Description + "\""
|
||||
+ separator + "\"" + rom.MachineName + "\""
|
||||
+ separator + "\"" + rom.MachineDescription + "\""
|
||||
+ separator + "\"rom\""
|
||||
@@ -3110,7 +3563,7 @@ namespace SabreTools.Helper
|
||||
"¬" + HttpUtility.HtmlEncode(rom.Name) +
|
||||
"¬¬¬¬¬\n";
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case OutputFormat.SabreDat:
|
||||
string prefix = "";
|
||||
@@ -3241,7 +3694,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="depth">Current depth to output file at (SabreDAT only)</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <returns>True if the data was written, false on error</returns>
|
||||
public static bool WriteFooter(StreamWriter sw, OutputFormat outputFormat, Dat datdata, int depth, Logger logger)
|
||||
public static bool WriteFooter(StreamWriter sw, OutputFormat outputFormat, DatFile datdata, int depth, Logger logger)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -3337,11 +3790,11 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Get the file data to be split
|
||||
Dat datdata = new Dat();
|
||||
Parse(filename, 0, 0, ref datdata, logger, softlist:true);
|
||||
DatFile datdata = new DatFile();
|
||||
Parse(filename, 0, 0, ref datdata, logger, softlist: true);
|
||||
|
||||
// Set all of the appropriate outputs for each of the subsets
|
||||
Dat datdataA = new Dat
|
||||
DatFile datdataA = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (" + newExtAString + ")",
|
||||
Name = datdata.Name + " (" + newExtAString + ")",
|
||||
@@ -3357,7 +3810,7 @@ namespace SabreTools.Helper
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
OutputFormat = outputFormat,
|
||||
};
|
||||
Dat datdataB = new Dat
|
||||
DatFile datdataB = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (" + newExtBString + ")",
|
||||
Name = datdata.Name + " (" + newExtBString + ")",
|
||||
@@ -3475,12 +3928,12 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Get the file data to be split
|
||||
Dat datdata = new Dat();
|
||||
Parse(filename, 0, 0, ref datdata, logger, true, softlist:true);
|
||||
DatFile datdata = new DatFile();
|
||||
Parse(filename, 0, 0, ref datdata, logger, true, softlist: true);
|
||||
|
||||
// Create each of the respective output DATs
|
||||
logger.User("Creating and populating new DATs");
|
||||
Dat nodump = new Dat
|
||||
DatFile nodump = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (Nodump)",
|
||||
Name = datdata.Name + " (Nodump)",
|
||||
@@ -3502,7 +3955,7 @@ namespace SabreTools.Helper
|
||||
MergeRoms = datdata.MergeRoms,
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
};
|
||||
Dat sha1 = new Dat
|
||||
DatFile sha1 = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (SHA-1)",
|
||||
Name = datdata.Name + " (SHA-1)",
|
||||
@@ -3524,7 +3977,7 @@ namespace SabreTools.Helper
|
||||
MergeRoms = datdata.MergeRoms,
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
};
|
||||
Dat md5 = new Dat
|
||||
DatFile md5 = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (MD5)",
|
||||
Name = datdata.Name + " (MD5)",
|
||||
@@ -3546,7 +3999,7 @@ namespace SabreTools.Helper
|
||||
MergeRoms = datdata.MergeRoms,
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
};
|
||||
Dat crc = new Dat
|
||||
DatFile crc = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (CRC)",
|
||||
Name = datdata.Name + " (CRC)",
|
||||
@@ -3569,7 +4022,7 @@ namespace SabreTools.Helper
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
};
|
||||
|
||||
Dat other = new Dat
|
||||
DatFile other = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (Other)",
|
||||
Name = datdata.Name + " (Other)",
|
||||
@@ -3735,12 +4188,12 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Get the file data to be split
|
||||
Dat datdata = new Dat();
|
||||
Parse(filename, 0, 0, ref datdata, logger, true, softlist:true);
|
||||
DatFile datdata = new DatFile();
|
||||
Parse(filename, 0, 0, ref datdata, logger, true, softlist: true);
|
||||
|
||||
// Create each of the respective output DATs
|
||||
logger.User("Creating and populating new DATs");
|
||||
Dat romdat = new Dat
|
||||
DatFile romdat = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (ROM)",
|
||||
Name = datdata.Name + " (ROM)",
|
||||
@@ -3762,7 +4215,7 @@ namespace SabreTools.Helper
|
||||
MergeRoms = datdata.MergeRoms,
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
};
|
||||
Dat diskdat = new Dat
|
||||
DatFile diskdat = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (Disk)",
|
||||
Name = datdata.Name + " (Disk)",
|
||||
@@ -3784,7 +4237,7 @@ namespace SabreTools.Helper
|
||||
MergeRoms = datdata.MergeRoms,
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
};
|
||||
Dat sampledat = new Dat
|
||||
DatFile sampledat = new DatFile
|
||||
{
|
||||
FileName = datdata.FileName + " (Sample)",
|
||||
Name = datdata.Name + " (Sample)",
|
||||
@@ -166,7 +166,7 @@ namespace SabreTools
|
||||
string intname = systemname + " (" + sourcename + ")";
|
||||
string datname = systemname + " (" + sourcename + " " + version + ")";
|
||||
|
||||
Dat datdata = new Dat
|
||||
DatFile datdata = new DatFile
|
||||
{
|
||||
Name = intname,
|
||||
Description = datname,
|
||||
@@ -179,7 +179,7 @@ namespace SabreTools
|
||||
Files = dict,
|
||||
};
|
||||
|
||||
return DatTools.WriteDatfile(datdata, _outDir, _logger);
|
||||
return DatFile.WriteDatfile(datdata, _outDir, _logger);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -144,7 +144,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Create the output DatData object
|
||||
Dat datdata = new Dat
|
||||
DatFile datdata = new DatFile
|
||||
{
|
||||
FileName = description,
|
||||
Name = name,
|
||||
@@ -173,7 +173,7 @@ namespace SabreTools
|
||||
{
|
||||
Int32.TryParse(sourcemap[hash], out tempSrcId);
|
||||
}
|
||||
DatTools.Parse(file, 0, tempSrcId, ref datdata, _logger);
|
||||
DatFile.Parse(file, 0, tempSrcId, ref datdata, _logger);
|
||||
}
|
||||
|
||||
// If the dictionary is empty for any reason, tell the user and exit
|
||||
@@ -238,7 +238,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Then write out the file
|
||||
DatTools.WriteDatfile(datdata, _outroot, _logger, _norename);
|
||||
DatFile.WriteDatfile(datdata, _outroot, _logger, _norename);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -366,8 +366,8 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Get all roms that are found in the DAT to see what needs to be added
|
||||
Dat datdata = new Dat();
|
||||
DatTools.Parse(_filepath, sysid, srcid, ref datdata, _logger);
|
||||
DatFile datdata = new DatFile();
|
||||
DatFile.Parse(_filepath, sysid, srcid, ref datdata, _logger);
|
||||
|
||||
// Sort inputted roms into games
|
||||
SortedDictionary<string, List<DatItem>> sortable = new SortedDictionary<string, List<DatItem>>();
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace SabreTools.Helper
|
||||
public class SimpleSort
|
||||
{
|
||||
// Private instance variables
|
||||
private Dat _datdata;
|
||||
private DatFile _datdata;
|
||||
private List<string> _inputs;
|
||||
private string _outDir;
|
||||
private string _tempDir;
|
||||
@@ -30,7 +30,7 @@ namespace SabreTools.Helper
|
||||
// Other private variables
|
||||
private int _cursorTop;
|
||||
private int _cursorLeft;
|
||||
private Dat _matched;
|
||||
private DatFile _matched;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new SimpleSort object
|
||||
@@ -51,7 +51,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="zip">Integer representing the archive handling level for Zip</param>
|
||||
/// <param name="updateDat">True if the updated DAT should be output, false otherwise</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
public SimpleSort(Dat datdata, List<string> inputs, string outDir, string tempDir,
|
||||
public SimpleSort(DatFile datdata, List<string> inputs, string outDir, string tempDir,
|
||||
bool quickScan, bool toFolder, bool verify, bool delete, bool? torrentX, bool romba, int sevenzip,
|
||||
int gz, int rar, int zip, bool updateDat, Logger logger)
|
||||
{
|
||||
@@ -74,7 +74,7 @@ namespace SabreTools.Helper
|
||||
|
||||
_cursorTop = Console.CursorTop;
|
||||
_cursorLeft = Console.CursorLeft;
|
||||
_matched = new Dat
|
||||
_matched = new DatFile
|
||||
{
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
};
|
||||
@@ -144,7 +144,7 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Setup the fixdat
|
||||
_matched = (Dat)_datdata.CloneHeader();
|
||||
_matched = (DatFile)_datdata.CloneHeader();
|
||||
_matched.Files = new Dictionary<string, List<DatItem>>();
|
||||
_matched.FileName = "fixDat_" + _matched.FileName;
|
||||
_matched.Name = "fixDat_" + _matched.Name;
|
||||
@@ -179,7 +179,7 @@ namespace SabreTools.Helper
|
||||
// Now output the fixdat to the main folder
|
||||
if (found)
|
||||
{
|
||||
DatTools.WriteDatfile(_matched, "", _logger, stats: true);
|
||||
DatFile.WriteDatfile(_matched, "", _logger, stats: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -273,7 +273,7 @@ namespace SabreTools.Helper
|
||||
_datdata.Name = "fixDat_" + _datdata.Name;
|
||||
_datdata.Description = "fixDat_" + _datdata.Description;
|
||||
_datdata.OutputFormat = OutputFormat.Xml;
|
||||
DatTools.WriteDatfile(_datdata, "", _logger);
|
||||
DatFile.WriteDatfile(_datdata, "", _logger);
|
||||
}
|
||||
|
||||
return success;
|
||||
@@ -341,7 +341,7 @@ namespace SabreTools.Helper
|
||||
|
||||
// Now loop through all of the files and check them, DFD style
|
||||
_logger.User("Getting source file information...");
|
||||
Dat matchdat = new Dat
|
||||
DatFile matchdat = new DatFile
|
||||
{
|
||||
Files = new Dictionary<string, List<DatItem>>(),
|
||||
};
|
||||
@@ -429,7 +429,7 @@ namespace SabreTools.Helper
|
||||
}
|
||||
|
||||
// Then bucket the keys by game for better output
|
||||
SortedDictionary<string, List<DatItem>> keysByGame = DatTools.BucketByGame(toFromMap.Keys.ToList(), false, true, _logger);
|
||||
SortedDictionary<string, List<DatItem>> keysByGame = DatFile.BucketByGame(toFromMap.Keys.ToList(), false, true, _logger);
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -456,7 +456,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="file">Name of the file to attempt to add</param>
|
||||
/// <param name="matchdat">Reference to the Dat to add to</param>
|
||||
/// <returns>True if the file could be added, false otherwise</returns>
|
||||
public bool RebuildToOutputAlternateParseRomHelper(string file, ref Dat matchdat)
|
||||
public bool RebuildToOutputAlternateParseRomHelper(string file, ref DatFile matchdat)
|
||||
{
|
||||
Rom rom = FileTools.GetSingleFileInfo(file);
|
||||
|
||||
|
||||
@@ -47,9 +47,9 @@ namespace SabreTools.Helper
|
||||
{
|
||||
_logger.Log("Beginning stat collection for '" + filename + "'");
|
||||
List<String> games = new List<String>();
|
||||
Dat datdata = new Dat();
|
||||
DatTools.Parse(filename, 0, 0, ref datdata, _logger);
|
||||
SortedDictionary<string, List<DatItem>> newroms = DatTools.BucketByGame(datdata.Files, false, true, _logger, false);
|
||||
DatFile datdata = new DatFile();
|
||||
DatFile.Parse(filename, 0, 0, ref datdata, _logger);
|
||||
SortedDictionary<string, List<DatItem>> newroms = DatFile.BucketByGame(datdata.Files, false, true, _logger, false);
|
||||
|
||||
// Output single DAT stats (if asked)
|
||||
if (_single)
|
||||
@@ -76,7 +76,7 @@ namespace SabreTools.Helper
|
||||
|
||||
// Output total DAT stats
|
||||
if (!_single) { _logger.User(""); }
|
||||
Dat totaldata = new Dat
|
||||
DatFile totaldata = new DatFile
|
||||
{
|
||||
TotalSize = totalSize,
|
||||
RomCount = totalRom,
|
||||
@@ -102,7 +102,7 @@ Please check the log folder if the stats scrolled offscreen");
|
||||
/// <param name="logger">Logger object for file and console writing</param>
|
||||
/// <param name="recalculate">True if numbers should be recalculated for the DAT, false otherwise (default)</param>
|
||||
/// <param name="game">Number of games to use, -1 means recalculate games (default)</param>
|
||||
public static void OutputStats(Dat datdata, Logger logger, bool recalculate = false, long game = -1)
|
||||
public static void OutputStats(DatFile datdata, Logger logger, bool recalculate = false, long game = -1)
|
||||
{
|
||||
if (recalculate)
|
||||
{
|
||||
@@ -131,7 +131,7 @@ Please check the log folder if the stats scrolled offscreen");
|
||||
}
|
||||
}
|
||||
|
||||
SortedDictionary<string, List<DatItem>> newroms = DatTools.BucketByGame(datdata.Files, false, true, logger, false);
|
||||
SortedDictionary<string, List<DatItem>> newroms = DatFile.BucketByGame(datdata.Files, false, true, logger, false);
|
||||
if (datdata.TotalSize < 0)
|
||||
{
|
||||
datdata.TotalSize = Int64.MaxValue + datdata.TotalSize;
|
||||
|
||||
@@ -103,6 +103,7 @@
|
||||
<Compile Include="Objects\DATFromDir.cs" />
|
||||
<Compile Include="Objects\DatObjects\Archive.cs" />
|
||||
<Compile Include="Objects\DatObjects\BiosSet.cs" />
|
||||
<Compile Include="Objects\DatObjects\DatFile.cs" />
|
||||
<Compile Include="Objects\DatObjects\DatItem.cs" />
|
||||
<Compile Include="Objects\DatObjects\Disk.cs" />
|
||||
<Compile Include="Objects\DatObjects\Release.cs" />
|
||||
@@ -145,9 +146,7 @@
|
||||
<Compile Include="Objects\Logger.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Mappings\Mappings.cs" />
|
||||
<Compile Include="Tools\DatTools.cs" />
|
||||
<Compile Include="Data\Structs.cs" />
|
||||
<Compile Include="Tools\FileToolsHash.cs" />
|
||||
<Compile Include="Objects\Stats.cs" />
|
||||
<Compile Include="Tools\Style.cs" />
|
||||
<Compile Include="Data\Build.cs" />
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace SabreTools.Helper
|
||||
|
||||
Logger logger = new Logger(false, "");
|
||||
logger.Start();
|
||||
XmlTextReader xtr = DatTools.GetXmlTextReader(filename, logger);
|
||||
XmlTextReader xtr = DatFile.GetXmlTextReader(filename, logger);
|
||||
|
||||
if (xtr == null)
|
||||
{
|
||||
|
||||
@@ -1,305 +0,0 @@
|
||||
using SharpCompress.Archive;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Reader;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SabreTools.Helper
|
||||
{
|
||||
public class FileToolsHash
|
||||
{
|
||||
#region Archive Writing
|
||||
|
||||
// All things in this region are direct ports and do not take advantage of the multiple rom per hash that comes with the new system
|
||||
|
||||
/// <summary>
|
||||
/// Copy a file to an output archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input filename to be moved</param>
|
||||
/// <param name="output">Output directory to build to</param>
|
||||
/// <param name="hash">RomData representing the new information</param>
|
||||
/// <remarks>This uses the new system that is not implemented anywhere yet</remarks>
|
||||
public static void WriteToArchive(string input, string output, RomData rom)
|
||||
{
|
||||
string archiveFileName = Path.Combine(output, rom.Machine + ".zip");
|
||||
|
||||
ZipArchive outarchive = null;
|
||||
try
|
||||
{
|
||||
if (!File.Exists(archiveFileName))
|
||||
{
|
||||
outarchive = System.IO.Compression.ZipFile.Open(archiveFileName, ZipArchiveMode.Create);
|
||||
}
|
||||
else
|
||||
{
|
||||
outarchive = System.IO.Compression.ZipFile.Open(archiveFileName, ZipArchiveMode.Update);
|
||||
}
|
||||
|
||||
if (File.Exists(input))
|
||||
{
|
||||
if (outarchive.Mode == ZipArchiveMode.Create || outarchive.GetEntry(rom.Name) == null)
|
||||
{
|
||||
outarchive.CreateEntryFromFile(input, rom.Name, CompressionLevel.Optimal);
|
||||
}
|
||||
}
|
||||
else if (Directory.Exists(input))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
if (outarchive.Mode == ZipArchiveMode.Create || outarchive.GetEntry(file) == null)
|
||||
{
|
||||
outarchive.CreateEntryFromFile(file, file, CompressionLevel.Optimal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
outarchive?.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy a file to an output archive using SharpCompress
|
||||
/// </summary>
|
||||
/// <param name="input">Input filename to be moved</param>
|
||||
/// <param name="output">Output directory to build to</param>
|
||||
/// <param name="rom">RomData representing the new information</param>
|
||||
/// <remarks>This uses the new system that is not implemented anywhere yet</remarks>
|
||||
public static void WriteToManagedArchive(string input, string output, RomData rom)
|
||||
{
|
||||
string archiveFileName = Path.Combine(output, rom.Machine + ".zip");
|
||||
|
||||
// Delete an empty file first
|
||||
if (File.Exists(archiveFileName) && new FileInfo(archiveFileName).Length == 0)
|
||||
{
|
||||
File.Delete(archiveFileName);
|
||||
}
|
||||
|
||||
// Get if the file should be written out
|
||||
bool newfile = File.Exists(archiveFileName) && new FileInfo(archiveFileName).Length != 0;
|
||||
|
||||
using (SharpCompress.Archive.Zip.ZipArchive archive = (newfile
|
||||
? ArchiveFactory.Open(archiveFileName, Options.LookForHeader) as SharpCompress.Archive.Zip.ZipArchive
|
||||
: ArchiveFactory.Create(ArchiveType.Zip) as SharpCompress.Archive.Zip.ZipArchive))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (File.Exists(input))
|
||||
{
|
||||
archive.AddEntry(rom.Name, input);
|
||||
}
|
||||
else if (Directory.Exists(input))
|
||||
{
|
||||
archive.AddAllFromDirectory(input, "*", SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
archive.SaveTo(archiveFileName + ".tmp", CompressionType.Deflate);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Don't log archive write errors
|
||||
}
|
||||
}
|
||||
|
||||
if (File.Exists(archiveFileName + ".tmp"))
|
||||
{
|
||||
File.Delete(archiveFileName);
|
||||
File.Move(archiveFileName + ".tmp", archiveFileName);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region File Information
|
||||
|
||||
/// <summary>
|
||||
/// Generate a list of HashData objects from the header values in an archive
|
||||
/// </summary>
|
||||
/// <param name="input">Input file to get data from</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <returns>List of HashData objects representing the found data</returns>
|
||||
/// <remarks>This uses the new system that is not implemented anywhere yet</remarks>
|
||||
public static List<HashData> GetArchiveFileHashes(string input, Logger logger)
|
||||
{
|
||||
List<HashData> hashes = new List<HashData>();
|
||||
string gamename = Path.GetFileNameWithoutExtension(input);
|
||||
|
||||
// First get the archive type
|
||||
ArchiveType? at = FileTools.GetCurrentArchiveType(input, logger);
|
||||
|
||||
// If we got back null, then it's not an archive, so we we return
|
||||
if (at == null)
|
||||
{
|
||||
return hashes;
|
||||
}
|
||||
|
||||
// If we got back GZip, try to get TGZ info first
|
||||
else if (at == ArchiveType.GZip)
|
||||
{
|
||||
HashData possibleTgz = GetTorrentGZFileHash(input, logger);
|
||||
|
||||
// If it was, then add it to the outputs and continue
|
||||
if (possibleTgz.Size != -1)
|
||||
{
|
||||
hashes.Add(possibleTgz);
|
||||
return hashes;
|
||||
}
|
||||
}
|
||||
|
||||
IReader reader = null;
|
||||
try
|
||||
{
|
||||
logger.Log("Found archive of type: " + at);
|
||||
long size = 0;
|
||||
byte[] crc = null;
|
||||
|
||||
// If we have a gzip file, get the crc directly
|
||||
if (at == ArchiveType.GZip)
|
||||
{
|
||||
// Get the CRC and size from the file
|
||||
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
|
||||
{
|
||||
br.BaseStream.Seek(-8, SeekOrigin.End);
|
||||
crc = br.ReadBytes(4).Reverse().ToArray();
|
||||
byte[] headersize = br.ReadBytes(4);
|
||||
size = BitConverter.ToInt32(headersize.Reverse().ToArray(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
reader = ReaderFactory.Open(File.OpenRead(input));
|
||||
|
||||
if (at != ArchiveType.Tar)
|
||||
{
|
||||
while (reader.MoveToNextEntry())
|
||||
{
|
||||
if (reader.Entry != null && !reader.Entry.IsDirectory)
|
||||
{
|
||||
logger.Log("Entry found: '" + reader.Entry.Key + "': "
|
||||
+ (size == 0 ? reader.Entry.Size : size) + ", "
|
||||
+ (crc == null ? BitConverter.GetBytes(reader.Entry.Crc) : crc));
|
||||
|
||||
RomData temprom = new RomData
|
||||
{
|
||||
Type = ItemType.Rom,
|
||||
Name = reader.Entry.Key,
|
||||
Machine = new MachineData
|
||||
{
|
||||
Name = gamename,
|
||||
Description = gamename,
|
||||
},
|
||||
};
|
||||
HashData temphash = new HashData
|
||||
{
|
||||
Size = (size == 0 ? reader.Entry.Size : size),
|
||||
CRC = (crc == null ? BitConverter.GetBytes(reader.Entry.Crc) : crc),
|
||||
MD5 = null,
|
||||
SHA1 = null,
|
||||
Roms = new List<RomData>(),
|
||||
};
|
||||
temphash.Roms.Add(temprom);
|
||||
hashes.Add(temphash);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
reader?.Dispose();
|
||||
}
|
||||
|
||||
return hashes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve file information for a single torrent GZ file
|
||||
/// </summary>
|
||||
/// <param name="input">Filename to get information from</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <returns>Populated HashData object if success, empty one on error</returns>
|
||||
/// <remarks>This uses the new system that is not implemented anywhere yet</remarks>
|
||||
public static HashData GetTorrentGZFileHash(string input, Logger logger)
|
||||
{
|
||||
string datum = Path.GetFileName(input).ToLowerInvariant();
|
||||
string sha1 = Path.GetFileNameWithoutExtension(input).ToLowerInvariant();
|
||||
long filesize = new FileInfo(input).Length;
|
||||
|
||||
// Check if the name is the right length
|
||||
if (!Regex.IsMatch(datum, @"^[0-9a-f]{40}\.gz"))
|
||||
{
|
||||
logger.Warning("Non SHA-1 filename found, skipping: '" + datum + "'");
|
||||
return new HashData();
|
||||
}
|
||||
|
||||
// Check if the file is at least the minimum length
|
||||
if (filesize < 40 /* bytes */)
|
||||
{
|
||||
logger.Warning("Possibly corrupt file '" + input + "' with size " + Style.GetBytesReadable(filesize));
|
||||
return new HashData();
|
||||
}
|
||||
|
||||
// Get the Romba-specific header data
|
||||
byte[] header; // Get preamble header for checking
|
||||
byte[] headermd5; // MD5
|
||||
byte[] headercrc; // CRC
|
||||
byte[] headersz; // Int64 size
|
||||
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
|
||||
{
|
||||
header = br.ReadBytes(12);
|
||||
headermd5 = br.ReadBytes(16);
|
||||
headercrc = br.ReadBytes(4);
|
||||
headersz = br.ReadBytes(8);
|
||||
}
|
||||
|
||||
// If the header is not correct, return a blank rom
|
||||
bool correct = true;
|
||||
for (int i = 0; i < header.Length; i++)
|
||||
{
|
||||
correct &= (header[i] == Constants.TorrentGZHeader[i]);
|
||||
}
|
||||
if (!correct)
|
||||
{
|
||||
return new HashData();
|
||||
}
|
||||
|
||||
// Now convert the size and get the right position
|
||||
long extractedsize = (long)BitConverter.ToUInt64(headersz.Reverse().ToArray(), 0);
|
||||
|
||||
RomData temprom = new RomData
|
||||
{
|
||||
Type = ItemType.Rom,
|
||||
Name = sha1,
|
||||
Machine = new MachineData
|
||||
{
|
||||
Name = sha1,
|
||||
Description = sha1,
|
||||
},
|
||||
};
|
||||
HashData temphash = new HashData
|
||||
{
|
||||
Size = extractedsize,
|
||||
CRC = headercrc,
|
||||
MD5 = headermd5,
|
||||
SHA1 = Style.StringToByteArray(sha1),
|
||||
Roms = new List<RomData>(),
|
||||
};
|
||||
temphash.Roms.Add(temprom);
|
||||
|
||||
return temphash;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -154,7 +154,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="datdata">DAT information</param>
|
||||
/// <param name="overwrite">True if we ignore existing files (default), false otherwise</param>
|
||||
/// <returns>Dictionary of output formats mapped to file names</returns>
|
||||
public static Dictionary<OutputFormat, string> CreateOutfileNames(string outDir, Dat datdata, bool overwrite = true)
|
||||
public static Dictionary<OutputFormat, string> CreateOutfileNames(string outDir, DatFile datdata, bool overwrite = true)
|
||||
{
|
||||
// Create the output dictionary
|
||||
Dictionary<OutputFormat, string> outfileNames = new Dictionary<OutputFormat, string>();
|
||||
@@ -214,7 +214,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="datdata">DAT information</param>
|
||||
/// <param name="overwrite">True if we ignore existing files, false otherwise</param>
|
||||
/// <returns>String containing the new filename</returns>
|
||||
private static string CreateOutfileNamesHelper(string outDir, string extension, Dat datdata, bool overwrite)
|
||||
private static string CreateOutfileNamesHelper(string outDir, string extension, DatFile datdata, bool overwrite)
|
||||
{
|
||||
string filename = (String.IsNullOrEmpty(datdata.FileName) ? datdata.Description : datdata.FileName);
|
||||
string outfile = outDir + filename + extension;
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace SabreTools
|
||||
}
|
||||
}
|
||||
|
||||
SimpleSort ss = new SimpleSort(new Dat(), newinputs, outDir, tempDir, false, false, false, delete, false, romba, sevenzip, gz, rar, zip, false, logger);
|
||||
SimpleSort ss = new SimpleSort(new DatFile(), newinputs, outDir, tempDir, false, false, false, delete, false, romba, sevenzip, gz, rar, zip, false, logger);
|
||||
return ss.Convert();
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace SabreTools
|
||||
int maxDegreeOfParallelism)
|
||||
{
|
||||
// Create a new DATFromDir object and process the inputs
|
||||
Dat basedat = new Dat
|
||||
DatFile basedat = new DatFile
|
||||
{
|
||||
FileName = filename,
|
||||
Name = name,
|
||||
@@ -149,7 +149,7 @@ namespace SabreTools
|
||||
if (Directory.Exists(path))
|
||||
{
|
||||
// Clone the base Dat for information
|
||||
Dat datdata = (Dat)basedat.Clone();
|
||||
DatFile datdata = (DatFile)basedat.Clone();
|
||||
datdata.Files = new Dictionary<string, List<DatItem>>();
|
||||
|
||||
string basePath = Path.GetFullPath(path);
|
||||
@@ -159,7 +159,7 @@ namespace SabreTools
|
||||
// If it was a success, write the DAT out
|
||||
if (success)
|
||||
{
|
||||
DatTools.WriteDatfile(dfd.DatData, "", _logger);
|
||||
DatFile.WriteDatfile(dfd.DatData, "", _logger);
|
||||
}
|
||||
|
||||
// Otherwise, show the help
|
||||
@@ -190,13 +190,13 @@ namespace SabreTools
|
||||
{
|
||||
if (File.Exists(input))
|
||||
{
|
||||
DatTools.SplitByExt(Path.GetFullPath(input), outDir, Path.GetDirectoryName(input), extaList, extbList, _logger);
|
||||
DatFile.SplitByExt(Path.GetFullPath(input), outDir, Path.GetDirectoryName(input), extaList, extbList, _logger);
|
||||
}
|
||||
else if (Directory.Exists(input))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
DatTools.SplitByExt(file, outDir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), extaList, extbList, _logger);
|
||||
DatFile.SplitByExt(file, outDir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), extaList, extbList, _logger);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -271,13 +271,13 @@ namespace SabreTools
|
||||
{
|
||||
if (File.Exists(input))
|
||||
{
|
||||
DatTools.SplitByHash(Path.GetFullPath(input), outDir, Path.GetDirectoryName(input), _logger);
|
||||
DatFile.SplitByHash(Path.GetFullPath(input), outDir, Path.GetDirectoryName(input), _logger);
|
||||
}
|
||||
else if (Directory.Exists(input))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
DatTools.SplitByHash(file, outDir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger);
|
||||
DatFile.SplitByHash(file, outDir, (input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar), _logger);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -384,10 +384,10 @@ namespace SabreTools
|
||||
bool toFolder, bool verify, bool delete, bool? torrentX, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, Logger logger)
|
||||
{
|
||||
// Add all of the input DATs into one huge internal DAT
|
||||
Dat datdata = new Dat();
|
||||
DatFile datdata = new DatFile();
|
||||
foreach (string datfile in datfiles)
|
||||
{
|
||||
DatTools.Parse(datfile, 99, 99, ref datdata, logger);
|
||||
DatFile.Parse(datfile, 99, 99, ref datdata, logger);
|
||||
}
|
||||
|
||||
SimpleSort ss = new SimpleSort(datdata, inputs, outDir, tempDir, quickScan, toFolder, verify,
|
||||
@@ -438,13 +438,13 @@ namespace SabreTools
|
||||
{
|
||||
if (File.Exists(input))
|
||||
{
|
||||
DatTools.SplitByType(Path.GetFullPath(input), outDir, Path.GetFullPath(Path.GetDirectoryName(input)), _logger);
|
||||
DatFile.SplitByType(Path.GetFullPath(input), outDir, Path.GetFullPath(Path.GetDirectoryName(input)), _logger);
|
||||
}
|
||||
else if (Directory.Exists(input))
|
||||
{
|
||||
foreach (string file in Directory.EnumerateFiles(input, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
DatTools.SplitByType(file, outDir, Path.GetFullPath((input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar)), _logger);
|
||||
DatFile.SplitByType(file, outDir, Path.GetFullPath((input.EndsWith(Path.DirectorySeparatorChar.ToString()) ? input : input + Path.DirectorySeparatorChar)), _logger);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -671,7 +671,7 @@ namespace SabreTools
|
||||
}
|
||||
|
||||
// Populate the DatData object
|
||||
Dat userInputDat = new Dat
|
||||
DatFile userInputDat = new DatFile
|
||||
{
|
||||
FileName = filename,
|
||||
Name = name,
|
||||
@@ -705,7 +705,7 @@ namespace SabreTools
|
||||
XSV = tsv,
|
||||
};
|
||||
|
||||
DatTools.Update(inputs, userInputDat, outputFormat, outDir, merge, diffMode, cascade, inplace, skip, bare, clean, softlist,
|
||||
DatFile.Update(inputs, userInputDat, outputFormat, outDir, merge, diffMode, cascade, inplace, skip, bare, clean, softlist,
|
||||
gamename, romname, romtype, sgt, slt, seq, crc, md5, sha1, nodump, trim, single, root, maxDegreeOfParallelism, _logger);
|
||||
}
|
||||
|
||||
|
||||
@@ -251,10 +251,10 @@ namespace SabreTools
|
||||
bool toFolder, bool verify, bool delete, bool? torrentX, bool romba, int sevenzip, int gz, int rar, int zip, bool updateDat, Logger logger)
|
||||
{
|
||||
// Add all of the input DATs into one huge internal DAT
|
||||
Dat datdata = new Dat();
|
||||
DatFile datdata = new DatFile();
|
||||
foreach (string datfile in datfiles)
|
||||
{
|
||||
DatTools.Parse(datfile, 99, 99, ref datdata, logger, keep: true, softlist: true);
|
||||
DatFile.Parse(datfile, 99, 99, ref datdata, logger, keep: true, softlist: true);
|
||||
}
|
||||
|
||||
SimpleSort ss = new SimpleSort(datdata, inputs, outDir, tempDir, quickScan, toFolder, verify,
|
||||
@@ -295,7 +295,7 @@ namespace SabreTools
|
||||
}
|
||||
}
|
||||
|
||||
SimpleSort ss = new SimpleSort(new Dat(), newinputs, outDir, tempDir, false, false, false,
|
||||
SimpleSort ss = new SimpleSort(new DatFile(), newinputs, outDir, tempDir, false, false, false,
|
||||
delete, false, romba, sevenzip, gz, rar, zip, false, logger);
|
||||
return ss.Convert();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user