[ALL] Start work on restructuring based on hashes (will not compile)

This set of changes is the start of turning over to a Hash based system instead of a Rom/Dat based system. It's a long process but it will be worth it in the end.
This commit is contained in:
Matt Nadareski
2016-08-29 16:33:07 -07:00
parent a5dae7e693
commit 0b97b046c8
18 changed files with 2094 additions and 226 deletions

View File

@@ -92,7 +92,7 @@ namespace SabreTools
flag = false;
break;
default:
if (System.IO.File.Exists(temparg) || Directory.Exists(temparg))
if (File.Exists(temparg) || Directory.Exists(temparg))
{
input = temparg;
}
@@ -164,7 +164,7 @@ namespace SabreTools
if (_flag)
{
// If it's a single file, just check it
if (System.IO.File.Exists(_input))
if (File.Exists(_input))
{
DetectSkipperAndTransform(_input);
}
@@ -183,7 +183,7 @@ namespace SabreTools
else
{
// If it's a single file, just check it
if (System.IO.File.Exists(_input))
if (File.Exists(_input))
{
ReplaceHeader(_input);
}
@@ -224,7 +224,7 @@ namespace SabreTools
// Now take care of the header and new output file
string hstr = string.Empty;
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(file)))
using (BinaryReader br = new BinaryReader(File.OpenRead(file)))
{
// Extract the header as a string for the database
byte[] hbin = br.ReadBytes(headerSize);
@@ -248,13 +248,13 @@ namespace SabreTools
Skippers.TransformFile(file, newfile, rule, _logger);
// If the output file doesn't exist, return false
if (!System.IO.File.Exists(newfile))
if (!File.Exists(newfile))
{
return false;
}
// Now add the information to the database if it's not already there
Helper.Rom rom = RomTools.GetSingleFileInfo(newfile);
Rom rom = RomTools.GetSingleFileInfo(newfile);
AddHeaderToDatabase(hstr, rom.HashData.SHA1, type);
}
@@ -309,7 +309,7 @@ namespace SabreTools
public bool ReplaceHeader(string file)
{
// First, get the SHA-1 hash of the file
Helper.Rom rom = RomTools.GetSingleFileInfo(file);
Rom rom = RomTools.GetSingleFileInfo(file);
// Then try to pull the corresponding headers from the database
string header = "";

View File

@@ -14,16 +14,22 @@ namespace SabreTools.Helper
public static long SizeZero = 0;
public static string CRCZero = "00000000";
public static byte[] CRCZeroBytes = new byte[] { 0x00, 0x00, 0x00, 0x00 };
public static string MD5Zero = "d41d8cd98f00b204e9800998ecf8427e";
public static byte[] MD5ZeroBytes = new byte[] { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e };
public static string SHA1Zero = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
public static byte[] SHA1ZeroBytes = new byte[] { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 };
#endregion
#region Hash string length constants
public static int CRCLength = 8;
public static int CRCBytesLength = 4;
public static int MD5Length = 32;
public static int MD5BytesLength = 16;
public static int SHA1Length = 40;
public static int SHA1BytesLength = 20;
#endregion

View File

@@ -28,9 +28,9 @@ namespace SabreTools.Helper
public struct HashData
{
public long Size;
public string CRC;
public string MD5;
public string SHA1;
public byte[] CRC;
public byte[] MD5;
public byte[] SHA1;
public List<RomData> Roms;
}
@@ -43,7 +43,8 @@ namespace SabreTools.Helper
public ItemType Type;
public bool Nodump;
public string Date;
public List<MachineData> Machines;
public DupeType DupeType;
public MachineData Machine;
}
/// <summary>
@@ -51,6 +52,7 @@ namespace SabreTools.Helper
/// </summary>
public struct MachineData
{
// Data specific to Machine/Game
public string Name;
public string Comment;
public string Description;
@@ -64,6 +66,12 @@ namespace SabreTools.Helper
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>
@@ -91,6 +99,7 @@ namespace SabreTools.Helper
public ForcePacking ForcePacking;
public OutputFormat OutputFormat;
public bool MergeRoms;
public List<HashData> Hashes;
// Data specific to the Miss DAT type
public bool UseGame;

View File

@@ -70,7 +70,7 @@ namespace SabreTools.Helper
try
{
_log = new StreamWriter(System.IO.File.Open(_basepath + _filename, FileMode.OpenOrCreate | FileMode.Append));
_log = new StreamWriter(File.Open(_basepath + _filename, FileMode.OpenOrCreate | FileMode.Append));
_log.WriteLine("Logging started " + DateTime.Now);
_log.Flush();
}

View File

@@ -58,7 +58,7 @@ namespace SabreTools.Helper
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(System.IO.File.ReadAllText(Path.Combine(_remappersPath, mapping + ".xml")));
doc.LoadXml(File.ReadAllText(Path.Combine(_remappersPath, mapping + ".xml")));
}
catch (XmlException ex)
{

View File

@@ -74,7 +74,7 @@ namespace SabreTools.Helper
Rules = new List<SkipperRule>(),
};
if (!System.IO.File.Exists(filename))
if (!File.Exists(filename))
{
return skipper;
}
@@ -319,7 +319,7 @@ namespace SabreTools.Helper
SkipperRule skipperRule = new SkipperRule();
// If the file doesn't exist, return a blank skipper rule
if (!System.IO.File.Exists(input))
if (!File.Exists(input))
{
logger.Error("The file '" + input + "' does not exist so it cannot be tested");
return skipperRule;
@@ -332,7 +332,7 @@ namespace SabreTools.Helper
if (String.IsNullOrEmpty(skippername) || (!String.IsNullOrEmpty(skipper.Name) && skippername.ToLowerInvariant() == skipper.Name.ToLowerInvariant()))
{
// Loop through the rules until one is found that works
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(input)))
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
{
foreach (SkipperRule rule in skipper.Rules)
{
@@ -495,7 +495,7 @@ namespace SabreTools.Helper
bool success = true;
// If the input file doesn't exist, fail
if (!System.IO.File.Exists(input))
if (!File.Exists(input))
{
logger.Error("I'm sorry but '" + input + "' doesn't exist!");
return false;
@@ -521,8 +521,8 @@ namespace SabreTools.Helper
try
{
logger.User("Applying found rule to file '" + input + "'");
using (BinaryWriter bw = new BinaryWriter(System.IO.File.OpenWrite(output)))
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(input)))
using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(output)))
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
{
// Seek to the beginning offset
if (rule.StartOffset == null)
@@ -619,7 +619,7 @@ namespace SabreTools.Helper
{
try
{
System.IO.File.Delete(output);
File.Delete(output);
}
catch
{
@@ -663,7 +663,7 @@ namespace SabreTools.Helper
XmlDocument doc = new XmlDocument();
try
{
doc.LoadXml(System.IO.File.ReadAllText(System.IO.Path.Combine(Path, skipper + ".xml")));
doc.LoadXml(File.ReadAllText(System.IO.Path.Combine(Path, skipper + ".xml")));
}
catch (XmlException ex)
{
@@ -726,7 +726,7 @@ namespace SabreTools.Helper
public static HeaderType GetFileHeaderType(string input, out int hs, Logger logger)
{
// Open the file in read mode
BinaryReader br = new BinaryReader(System.IO.File.OpenRead(input));
BinaryReader br = new BinaryReader(File.OpenRead(input));
// Extract the first 1024 bytes of the file
byte[] hbin = br.ReadBytes(1024);

View File

@@ -23,10 +23,10 @@ namespace SabreTools.Helper
{
string archiveFileName = Path.Combine(output, rom.Machine + ".zip");
System.IO.Compression.ZipArchive outarchive = null;
ZipArchive outarchive = null;
try
{
if (!System.IO.File.Exists(archiveFileName))
if (!File.Exists(archiveFileName))
{
outarchive = ZipFile.Open(archiveFileName, ZipArchiveMode.Create);
}
@@ -35,7 +35,7 @@ namespace SabreTools.Helper
outarchive = ZipFile.Open(archiveFileName, ZipArchiveMode.Update);
}
if (System.IO.File.Exists(input))
if (File.Exists(input))
{
if (outarchive.Mode == ZipArchiveMode.Create || outarchive.GetEntry(rom.Name) == null)
{
@@ -74,13 +74,13 @@ namespace SabreTools.Helper
string archiveFileName = Path.Combine(output, rom.Machine + ".zip");
// Delete an empty file first
if (System.IO.File.Exists(archiveFileName) && new FileInfo(archiveFileName).Length == 0)
if (File.Exists(archiveFileName) && new FileInfo(archiveFileName).Length == 0)
{
System.IO.File.Delete(archiveFileName);
File.Delete(archiveFileName);
}
// Get if the file should be written out
bool newfile = System.IO.File.Exists(archiveFileName) && new FileInfo(archiveFileName).Length != 0;
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
@@ -88,7 +88,7 @@ namespace SabreTools.Helper
{
try
{
if (System.IO.File.Exists(input))
if (File.Exists(input))
{
archive.AddEntry(rom.Name, input);
}
@@ -105,10 +105,10 @@ namespace SabreTools.Helper
}
}
if (System.IO.File.Exists(archiveFileName + ".tmp"))
if (File.Exists(archiveFileName + ".tmp"))
{
System.IO.File.Delete(archiveFileName);
System.IO.File.Move(archiveFileName + ".tmp", archiveFileName);
File.Delete(archiveFileName);
File.Move(archiveFileName + ".tmp", archiveFileName);
}
}
@@ -172,7 +172,7 @@ namespace SabreTools.Helper
{
if (at == ArchiveType.SevenZip && sevenzip != ArchiveScanLevel.External)
{
sza = SevenZipArchive.Open(System.IO.File.OpenRead(input));
sza = SevenZipArchive.Open(File.OpenRead(input));
logger.Log("Found archive of type: " + at);
// Create the temp directory
@@ -189,9 +189,9 @@ namespace SabreTools.Helper
// Create the temp directory
Directory.CreateDirectory(tempdir);
using (FileStream itemstream = System.IO.File.OpenRead(input))
using (FileStream itemstream = File.OpenRead(input))
{
using (FileStream outstream = System.IO.File.Create(Path.Combine(tempdir, Path.GetFileNameWithoutExtension(input))))
using (FileStream outstream = File.Create(Path.Combine(tempdir, Path.GetFileNameWithoutExtension(input))))
{
using (GZipStream gzstream = new GZipStream(itemstream, CompressionMode.Decompress))
{
@@ -203,7 +203,7 @@ namespace SabreTools.Helper
}
else
{
reader = ReaderFactory.Open(System.IO.File.OpenRead(input));
reader = ReaderFactory.Open(File.OpenRead(input));
logger.Log("Found archive of type: " + at);
if ((at == ArchiveType.Zip && zip != ArchiveScanLevel.External) ||
@@ -265,7 +265,7 @@ namespace SabreTools.Helper
IReader reader = null;
try
{
reader = ReaderFactory.Open(System.IO.File.OpenRead(input));
reader = ReaderFactory.Open(File.OpenRead(input));
if (at == ArchiveType.Zip || at == ArchiveType.SevenZip || at == ArchiveType.Rar)
{
@@ -291,9 +291,9 @@ namespace SabreTools.Helper
// Dispose the original reader
reader.Dispose();
using(FileStream itemstream = System.IO.File.OpenRead(input))
using(FileStream itemstream = File.OpenRead(input))
{
using (FileStream outstream = System.IO.File.Create(Path.Combine(tempdir, Path.GetFileNameWithoutExtension(input))))
using (FileStream outstream = File.Create(Path.Combine(tempdir, Path.GetFileNameWithoutExtension(input))))
{
using (GZipStream gzstream = new GZipStream(itemstream, CompressionMode.Decompress))
{
@@ -333,7 +333,7 @@ namespace SabreTools.Helper
// First get the archive types
ArchiveType? iat = GetCurrentArchiveType(inputArchive, logger);
ArchiveType? oat = (System.IO.File.Exists(outputArchive) ? GetCurrentArchiveType(outputArchive, logger) : ArchiveType.Zip);
ArchiveType? oat = (File.Exists(outputArchive) ? GetCurrentArchiveType(outputArchive, logger) : ArchiveType.Zip);
// If we got back null (or the output is not a Zipfile), then it's not an archive, so we we return
if (iat == null || (oat == null || oat != ArchiveType.Zip) || inputArchive == outputArchive)
@@ -342,10 +342,10 @@ namespace SabreTools.Helper
}
IReader reader = null;
System.IO.Compression.ZipArchive outarchive = null;
ZipArchive outarchive = null;
try
{
reader = ReaderFactory.Open(System.IO.File.OpenRead(inputArchive));
reader = ReaderFactory.Open(File.OpenRead(inputArchive));
if (iat == ArchiveType.Zip || iat == ArchiveType.SevenZip || iat == ArchiveType.Rar)
{
@@ -354,7 +354,7 @@ namespace SabreTools.Helper
logger.Log("Current entry name: '" + reader.Entry.Key + "'");
if (reader.Entry != null && reader.Entry.Key.Contains(sourceEntryName))
{
if (!System.IO.File.Exists(outputArchive))
if (!File.Exists(outputArchive))
{
outarchive = ZipFile.Open(outputArchive, ZipArchiveMode.Create);
}
@@ -365,7 +365,7 @@ namespace SabreTools.Helper
if (outarchive.Mode == ZipArchiveMode.Create || outarchive.GetEntry(destEntryName) == null)
{
System.IO.Compression.ZipArchiveEntry iae = outarchive.CreateEntry(destEntryName, CompressionLevel.Optimal) as System.IO.Compression.ZipArchiveEntry;
ZipArchiveEntry iae = outarchive.CreateEntry(destEntryName, CompressionLevel.Optimal) as ZipArchiveEntry;
using (Stream iaestream = iae.Open())
{
@@ -407,7 +407,7 @@ namespace SabreTools.Helper
// First get the archive types
ArchiveType? iat = GetCurrentArchiveType(inputArchive, logger);
ArchiveType? oat = (System.IO.File.Exists(outputArchive) ? GetCurrentArchiveType(outputArchive, logger) : ArchiveType.Zip);
ArchiveType? oat = (File.Exists(outputArchive) ? GetCurrentArchiveType(outputArchive, logger) : ArchiveType.Zip);
// If we got back null (or the output is not a Zipfile), then it's not an archive, so we we return
if (iat == null || (oat == null || oat != ArchiveType.Zip) || inputArchive == outputArchive)
@@ -417,7 +417,7 @@ namespace SabreTools.Helper
try
{
using (IReader reader = ReaderFactory.Open(System.IO.File.OpenRead(inputArchive)))
using (IReader reader = ReaderFactory.Open(File.OpenRead(inputArchive)))
{
if (iat == ArchiveType.Zip || iat == ArchiveType.SevenZip || iat == ArchiveType.Rar)
{
@@ -427,7 +427,7 @@ namespace SabreTools.Helper
if (reader.Entry != null && reader.Entry.Key.Contains(sourceEntryName))
{
// Get if the file should be written out
bool newfile = System.IO.File.Exists(outputArchive) && new FileInfo(outputArchive).Length != 0;
bool newfile = File.Exists(outputArchive) && new FileInfo(outputArchive).Length != 0;
using (SharpCompress.Archive.Zip.ZipArchive archive = (newfile
? ArchiveFactory.Open(outputArchive, Options.LookForHeader) as SharpCompress.Archive.Zip.ZipArchive
@@ -447,10 +447,10 @@ namespace SabreTools.Helper
}
}
if (System.IO.File.Exists(outputArchive + ".tmp"))
if (File.Exists(outputArchive + ".tmp"))
{
System.IO.File.Delete(outputArchive);
System.IO.File.Move(outputArchive + ".tmp", outputArchive);
File.Delete(outputArchive);
File.Move(outputArchive + ".tmp", outputArchive);
}
success = true;
@@ -512,7 +512,7 @@ namespace SabreTools.Helper
if (at == ArchiveType.GZip)
{
// Get the CRC and size from the file
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(input)))
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
{
br.BaseStream.Seek(-8, SeekOrigin.End);
byte[] headercrc = br.ReadBytes(4);
@@ -522,7 +522,7 @@ namespace SabreTools.Helper
}
}
reader = ReaderFactory.Open(System.IO.File.OpenRead(input));
reader = ReaderFactory.Open(File.OpenRead(input));
if (at != ArchiveType.Tar)
{
@@ -594,7 +594,7 @@ namespace SabreTools.Helper
byte[] headermd5; // MD5
byte[] headercrc; // CRC
byte[] headersz; // Int64 size
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(input)))
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
{
header = br.ReadBytes(12);
headermd5 = br.ReadBytes(16);
@@ -650,7 +650,7 @@ namespace SabreTools.Helper
public static bool WriteTorrentGZ(string input, string outdir, bool romba, Logger logger)
{
// Check that the input file exists
if (!System.IO.File.Exists(input))
if (!File.Exists(input))
{
logger.Warning("File " + input + " does not exist!");
return false;
@@ -670,7 +670,7 @@ namespace SabreTools.Helper
// If it doesn't exist, create the output file and then write
string outfile = Path.Combine(outdir, rom.HashData.SHA1 + ".gz");
using (FileStream inputstream = new FileStream(input, FileMode.Open))
using (GZipStream output = new GZipStream(System.IO.File.Open(outfile, FileMode.Create, FileAccess.Write), CompressionMode.Compress))
using (GZipStream output = new GZipStream(File.Open(outfile, FileMode.Create, FileAccess.Write), CompressionMode.Compress))
{
inputstream.CopyTo(output);
}
@@ -678,7 +678,7 @@ namespace SabreTools.Helper
// Now that it's ready, inject the header info
using (BinaryWriter sw = new BinaryWriter(new MemoryStream()))
{
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(outfile)))
using (BinaryReader br = new BinaryReader(File.OpenRead(outfile)))
{
// Write standard header and TGZ info
byte[] data = Constants.TorrentGZHeader
@@ -698,7 +698,7 @@ namespace SabreTools.Helper
}
}
using (BinaryWriter bw = new BinaryWriter(System.IO.File.Open(outfile, FileMode.Create)))
using (BinaryWriter bw = new BinaryWriter(File.Open(outfile, FileMode.Create)))
{
// Now write the new file over the original
sw.BaseStream.Seek(0, SeekOrigin.Begin);
@@ -719,12 +719,12 @@ namespace SabreTools.Helper
try
{
System.IO.File.Move(outfile, Path.Combine(outdir, Path.GetFileName(outfile)));
File.Move(outfile, Path.Combine(outdir, Path.GetFileName(outfile)));
}
catch (Exception ex)
{
logger.Warning(ex.ToString());
System.IO.File.Delete(outfile);
File.Delete(outfile);
}
}
@@ -754,7 +754,7 @@ namespace SabreTools.Helper
try
{
byte[] magic = new byte[8];
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(input)))
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
{
magic = br.ReadBytes(8);
}
@@ -851,5 +851,295 @@ namespace SabreTools.Helper
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}
#region Hash-to-Dat functions
// 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, int machineIndex)
{
string archiveFileName = Path.Combine(output, rom.Machines[machineIndex] + ".zip");
ZipArchive outarchive = null;
try
{
if (!File.Exists(archiveFileName))
{
outarchive = ZipFile.Open(archiveFileName, ZipArchiveMode.Create);
}
else
{
outarchive = 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, int machineIndex)
{
string archiveFileName = Path.Combine(output, rom.Machines[machineIndex] + ".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);
}
}
/// <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 = 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));
MachineData tempmachine = new MachineData
{
Name = gamename,
Description = gamename,
};
RomData temprom = new RomData
{
Type = ItemType.Rom,
Name = reader.Entry.Key,
Machines = new List<MachineData>(),
};
temprom.Machines.Add(tempmachine);
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);
MachineData tempmachine = new MachineData
{
Name = sha1,
Description = sha1,
};
RomData temprom = new RomData
{
Type = ItemType.Rom,
Name = sha1,
Machines = new List<MachineData>(),
};
temprom.Machines.Add(tempmachine);
HashData temphash = new HashData
{
Size = extractedsize,
CRC = headercrc,
MD5 = headermd5,
SHA1 = StringToByteArray(sha1),
Roms = new List<RomData>(),
};
temphash.Roms.Add(temprom);
return temphash;
}
#endregion
}
}

View File

@@ -17,7 +17,7 @@ namespace SabreTools.Helper
public static void EnsureDatabase(string db, string connectionString)
{
// Make sure the file exists
if (!System.IO.File.Exists(db))
if (!File.Exists(db))
{
SqliteConnection.CreateFile(db);
}

File diff suppressed because it is too large Load Diff

View File

@@ -85,7 +85,7 @@ namespace SabreTools.Helper
try
{
FileStream fs = System.IO.File.Create(outfile);
FileStream fs = File.Create(outfile);
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
// Write out the header
@@ -619,7 +619,7 @@ namespace SabreTools.Helper
{
try
{
System.IO.File.Delete(file);
File.Delete(file);
}
catch { }
}
@@ -643,14 +643,14 @@ namespace SabreTools.Helper
public static void RemoveBytesFromFile(string input, string output, long bytesToRemoveFromHead, long bytesToRemoveFromTail)
{
// If any of the inputs are invalid, skip
if (!System.IO.File.Exists(input) || new FileInfo(input).Length <= (bytesToRemoveFromHead + bytesToRemoveFromTail))
if (!File.Exists(input) || new FileInfo(input).Length <= (bytesToRemoveFromHead + bytesToRemoveFromTail))
{
return;
}
// Read the input file and write to the fail
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(input)))
using (BinaryWriter bw = new BinaryWriter(System.IO.File.OpenWrite(output)))
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(output)))
{
int bufferSize = 1024;
long adjustedLength = br.BaseStream.Length - bytesToRemoveFromTail;
@@ -708,13 +708,13 @@ namespace SabreTools.Helper
public static void AppendBytesToFile(string input, string output, byte[] bytesToAddToHead, byte[] bytesToAddToTail)
{
// If any of the inputs are invalid, skip
if (!System.IO.File.Exists(input))
if (!File.Exists(input))
{
return;
}
using (BinaryReader br = new BinaryReader(System.IO.File.OpenRead(input)))
using (BinaryWriter bw = new BinaryWriter(System.IO.File.OpenWrite(output)))
using (BinaryReader br = new BinaryReader(File.OpenRead(input)))
using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(output)))
{
if (bytesToAddToHead.Count() > 0)
{
@@ -751,13 +751,13 @@ namespace SabreTools.Helper
/// <param name="output">Output filename</param>
public static void CopyFileToNewLocation(string input, string output)
{
if (System.IO.File.Exists(input) && !System.IO.File.Exists(output))
if (File.Exists(input) && !File.Exists(output))
{
if (!Directory.Exists(Path.GetDirectoryName(output)))
{
Directory.CreateDirectory(Path.GetDirectoryName(output));
}
System.IO.File.Copy(input, output);
File.Copy(input, output);
}
}
}

View File

@@ -21,7 +21,7 @@ namespace SabreTools.Helper
public static Rom GetSingleFileInfo(string input, bool noMD5 = false, bool noSHA1 = false, long offset = 0)
{
// Add safeguard if file doesn't exist
if (!System.IO.File.Exists(input))
if (!File.Exists(input))
{
return new Rom();
}
@@ -44,7 +44,7 @@ namespace SabreTools.Helper
using (Crc32 crc = new Crc32())
using (MD5 md5 = MD5.Create())
using (SHA1 sha1 = SHA1.Create())
using (FileStream fs = System.IO.File.OpenRead(input))
using (FileStream fs = File.OpenRead(input))
{
// Seek to the starting position, if one is set
if (offset > 0)
@@ -186,6 +186,104 @@ namespace SabreTools.Helper
return outroms;
}
/// <summary>
/// Merge an arbitrary set of ROMs based on the supplied information
/// </summary>
/// <param name="inhashes">List of HashData objects representing the roms to be merged</param>
/// <param name="logger">Logger object for console and/or file output</param>
/// <returns>A List of HashData objects representing the merged roms</returns>
public static List<HashData> Merge(List<HashData> inhashes, Logger logger)
{
// Create output list
List<HashData> outroms = new List<HashData>();
// Check for null or blank roms first
if (inhashes == null || inhashes.Count == 0)
{
return outroms;
}
// Then deduplicate them by checking to see if data matches previous saved roms
foreach (HashData hash in inhashes)
{
// If it's a nodump, add and skip
if (hash.Roms[0].Nodump)
{
outroms.Add(hash);
continue;
}
// If it's the first rom in the list, don't touch it
if (outroms.Count != 0)
{
// Check if the rom is a duplicate
DupeType dupetype = DupeType.None;
HashData savedHash = new HashData();
int pos = -1;
for (int i = 0; i < outroms.Count; i++)
{
HashData lastrom = outroms[i];
RomData savedRom = savedHash.Roms[0];
MachineData savedMachine = savedRom.Machine;
// Get the duplicate status
dupetype = GetDuplicateStatus(hash, lastrom, logger);
// If it's a duplicate, skip adding it to the output but add any missing information
if (dupetype != DupeType.None)
{
savedHash = lastrom;
pos = i;
savedHash.CRC = (savedHash.CRC == null && hash.CRC != null ? hash.CRC : savedHash.CRC);
savedHash.MD5 = (savedHash.MD5 == null && hash.MD5 != null ? hash.MD5 : savedHash.MD5);
savedHash.SHA1 = (savedHash.SHA1 == null && hash.SHA1 != null ? hash.SHA1 : savedHash.SHA1);
savedRom.DupeType = dupetype;
// If the current system has a lower ID than the previous, set the system accordingly
if (hash.Roms[0].Machine.SystemID < savedMachine.SystemID)
{
savedMachine.SystemID = hash.Roms[0].Machine.SystemID;
savedMachine.System = hash.Roms[0].Machine.System;
savedMachine.Name = hash.Roms[0].Machine.Name;
savedRom.Name = hash.Roms[0].Name;
}
// If the current source has a lower ID than the previous, set the source accordingly
if (hash.Roms[0].Machine.SourceID < savedMachine.SourceID)
{
savedMachine.SourceID = hash.Roms[0].Machine.SourceID;
savedMachine.Source = hash.Roms[0].Machine.Source;
savedMachine.Name = hash.Roms[0].Machine.Name;
savedRom.Name = hash.Roms[0].Name;
}
break;
}
}
// If no duplicate is found, add it to the list
if (dupetype == DupeType.None)
{
outroms.Add(hash);
}
// Otherwise, if a new rom information is found, add that
else
{
outroms.RemoveAt(pos);
outroms.Insert(pos, savedHash);
}
}
else
{
outroms.Add(hash);
}
}
// Then return the result
return outroms;
}
/// <summary>
/// List all duplicates found in a DAT based on a rom
/// </summary>
@@ -348,5 +446,51 @@ namespace SabreTools.Helper
return hash;
}
/// <summary>
/// Clean a hash byte array and pad to the correct size
/// </summary>
/// <param name="hash">Hash byte array to sanitize</param>
/// <param name="padding">Amount of bytes to pad to</param>
/// <returns>Cleaned byte array</returns>
public static byte[] CleanHashData(byte[] hash, int padding)
{
// If we have a null hash or a <=0 padding, return the hash
if (hash == null || padding <= 0)
{
return hash;
}
// If we have a hash longer than the padding, trim and return
if (hash.Length > padding)
{
return hash.Take(padding).ToArray();
}
// If we have a hash of the correct length, return
if (hash.Length == padding)
{
return hash;
}
// Otherwise get the output byte array of the correct length
byte[] newhash = new byte[padding];
// Then write the proper number of empty bytes
int padNeeded = padding - hash.Length;
int index = 0;
for (index = 0; index < padNeeded; index++)
{
newhash[index] = 0x00;
}
// Now add the original hash
for (int i = 0; i < hash.Length; i++)
{
newhash[index + i] = hash[index];
}
return newhash;
}
}
}

View File

@@ -71,7 +71,7 @@ namespace SabreTools
public bool Start()
{
// Double check to see what it needs to be named
_basePath = (_inputs.Count > 0 ? (System.IO.File.Exists(_inputs[0]) ? _inputs[0] : _inputs[0] + Path.DirectorySeparatorChar) : "");
_basePath = (_inputs.Count > 0 ? (File.Exists(_inputs[0]) ? _inputs[0] : _inputs[0] + Path.DirectorySeparatorChar) : "");
_basePath = (_basePath != "" ? Path.GetFullPath(_basePath) : "");
// If the description is defined but not the name, set the name from the description
@@ -115,7 +115,7 @@ namespace SabreTools
else
{
// Create and open the output file for writing
FileStream fs = System.IO.File.Create(Style.CreateOutfileName(Environment.CurrentDirectory, _datdata));
FileStream fs = File.Create(Style.CreateOutfileName(Environment.CurrentDirectory, _datdata));
sw = new StreamWriter(fs, Encoding.UTF8);
sw.AutoFlush = true;
}
@@ -128,11 +128,11 @@ namespace SabreTools
foreach (string path in _inputs)
{
// Set local paths and vars
_basePath = (System.IO.File.Exists(path) ? path : path + Path.DirectorySeparatorChar);
_basePath = (File.Exists(path) ? path : path + Path.DirectorySeparatorChar);
_basePath = Path.GetFullPath(_basePath);
// This is where the main loop would go
if (System.IO.File.Exists(_basePath))
if (File.Exists(_basePath))
{
lastparent = ProcessPossibleArchive(_basePath, sw, lastparent);
}
@@ -152,7 +152,7 @@ namespace SabreTools
{
if (_datdata.Type != "SuperDAT")
{
_basePath = (System.IO.File.Exists(item) ? item : item + Path.DirectorySeparatorChar);
_basePath = (File.Exists(item) ? item : item + Path.DirectorySeparatorChar);
_basePath = Path.GetFullPath(_basePath);
}
@@ -170,7 +170,7 @@ namespace SabreTools
if (!items)
{
string actualroot = item.Remove(0, basePathBackup.Length);
Helper.Rom rom = new Helper.Rom
Rom rom = new Rom
{
Name = "null",
Machine = new Machine
@@ -197,7 +197,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
_datdata.Files.Add(key, temp);
}
@@ -209,7 +209,7 @@ namespace SabreTools
if (Directory.EnumerateFiles(subdir, "*", SearchOption.AllDirectories).Count() == 0)
{
string actualroot = subdir.Remove(0, basePathBackup.Length);
Helper.Rom rom = new Helper.Rom
Rom rom = new Rom
{
Name = "null",
Machine = new Machine
@@ -236,7 +236,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
_datdata.Files.Add(key, temp);
}
@@ -259,10 +259,10 @@ namespace SabreTools
List<string> keys = _datdata.Files.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> roms = _datdata.Files[key];
List<Rom> roms = _datdata.Files[key];
for (int i = 0; i < roms.Count; i++)
{
Helper.Rom rom = roms[i];
Rom rom = roms[i];
// If we're in a mode that doesn't allow for actual empty folders, add the blank info
if (_datdata.OutputFormat != OutputFormat.SabreDat && _datdata.OutputFormat != OutputFormat.MissFile)
@@ -284,7 +284,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
_datdata.Files.Add(inkey, temp);
}
@@ -318,7 +318,7 @@ namespace SabreTools
// If we had roms but not blanks (and not in Romba mode), create an artifical rom for the purposes of outputting
if (lastparent != null && _datdata.Files.Count == 0)
{
_datdata.Files.Add("temp", new List<Helper.Rom>());
_datdata.Files.Add("temp", new List<Rom>());
}
}
@@ -346,7 +346,7 @@ namespace SabreTools
// Special case for if we are in Romba mode (all names are supposed to be SHA-1 hashes)
if (_datdata.Romba)
{
Helper.Rom rom = ArchiveTools.GetTorrentGZFileInfo(item, _logger);
Rom rom = ArchiveTools.GetTorrentGZFileInfo(item, _logger);
// If the rom is valid, write it out
if (rom.Name != null)
@@ -362,7 +362,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
_datdata.Files.Add(key, temp);
}
@@ -391,8 +391,8 @@ namespace SabreTools
// If we have an archive, scan it
if (type != null)
{
List<Helper.Rom> extracted = ArchiveTools.GetArchiveFileInfo(item, _logger);
foreach (Helper.Rom rom in extracted)
List<Rom> extracted = ArchiveTools.GetArchiveFileInfo(item, _logger);
foreach (Rom rom in extracted)
{
lastparent = ProcessFileHelper(item, rom, sw, _basePath,
Path.Combine((Path.GetDirectoryName(Path.GetFullPath(item)) + Path.DirectorySeparatorChar).Remove(0, _basePath.Length) +
@@ -401,7 +401,7 @@ namespace SabreTools
}
}
// Otherwise, just get the info on the file itself
else if (!Directory.Exists(item) && System.IO.File.Exists(item))
else if (!Directory.Exists(item) && File.Exists(item))
{
lastparent = ProcessFile(item, sw, _basePath, "", _datdata, lastparent);
}
@@ -440,7 +440,7 @@ namespace SabreTools
}
}
// Otherwise, just get the info on the file itself
else if (!Directory.Exists(item) && System.IO.File.Exists(item))
else if (!Directory.Exists(item) && File.Exists(item))
{
lastparent = ProcessFile(item, sw, _basePath, "", _datdata, lastparent);
}
@@ -462,7 +462,7 @@ namespace SabreTools
private string ProcessFile(string item, StreamWriter sw, string basepath, string parent, Dat datdata, string lastparent)
{
_logger.Log(Path.GetFileName(item) + " treated like a file");
Helper.Rom rom = RomTools.GetSingleFileInfo(item, _noMD5, _noSHA1);
Rom rom = RomTools.GetSingleFileInfo(item, _noMD5, _noSHA1);
return ProcessFileHelper(item, rom, sw, basepath, parent, datdata, lastparent);
}
@@ -478,7 +478,7 @@ namespace SabreTools
/// <param name="datdata">DatData object with output information</param>
/// <param name="lastparent">Last known parent game name</param>
/// <returns>New last known parent game name</returns>
private string ProcessFileHelper(string item, Helper.Rom rom, StreamWriter sw, string basepath, string parent, Dat datdata, string lastparent)
private string ProcessFileHelper(string item, Rom rom, StreamWriter sw, string basepath, string parent, Dat datdata, string lastparent)
{
try
{
@@ -537,7 +537,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
_datdata.Files.Add(key, temp);
}

View File

@@ -163,7 +163,7 @@ namespace SabreTools
foreach (string file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
{
string hash = "";
using (FileStream fs = System.IO.File.Open(file, FileMode.Open))
using (FileStream fs = File.Open(file, FileMode.Open))
{
hash = BitConverter.ToString(sha1.ComputeHash(fs)).Replace("-", "");
}
@@ -188,11 +188,11 @@ namespace SabreTools
List<string> keys = datdata.Files.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Helper.Rom> newroms = datdata.Files[key];
List<Rom> temp = new List<Rom>();
List<Rom> newroms = datdata.Files[key];
for (int i = 0; i < newroms.Count; i++)
{
Helper.Rom rom = newroms[i];
Rom rom = newroms[i];
// In the case that the RomData is incomplete, skip it
if (rom.Name == null || rom.Machine.Name == null)

View File

@@ -39,15 +39,15 @@ namespace SabreTools
public bool Process()
{
// Check all of the files for validity and break if one doesn't exist
if (_currentAllMerged != "" && !System.IO.File.Exists(_currentAllMerged))
if (_currentAllMerged != "" && !File.Exists(_currentAllMerged))
{
return false;
}
if (_currentMissingMerged != "" && !System.IO.File.Exists(_currentMissingMerged))
if (_currentMissingMerged != "" && !File.Exists(_currentMissingMerged))
{
return false;
}
if (_currentNewMerged != "" && !System.IO.File.Exists(_currentNewMerged))
if (_currentNewMerged != "" && !File.Exists(_currentNewMerged))
{
return false;
}
@@ -63,11 +63,11 @@ namespace SabreTools
// Now get Net New output dictionary [(currentNewMerged)-(currentAllMerged)]
_logger.User("Creating and populating Net New dictionary");
Dictionary<string, List<Helper.Rom>> netNew = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> netNew = new Dictionary<string, List<Rom>>();
foreach (string key in completeDats.Files.Keys)
{
List<Helper.Rom> templist = RomTools.Merge(completeDats.Files[key], _logger);
foreach (Helper.Rom rom in templist)
List<Rom> templist = RomTools.Merge(completeDats.Files[key], _logger);
foreach (Rom rom in templist)
{
if (rom.Dupe == DupeType.None && rom.Metadata.System == _currentNewMerged)
{
@@ -77,7 +77,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
netNew.Add(key, temp);
}
@@ -87,11 +87,11 @@ namespace SabreTools
// Now create the Unneeded dictionary [(currentAllMerged)-(currentNewMerged)]
_logger.User("Creating and populating Uneeded dictionary");
Dictionary<string, List<Helper.Rom>> unneeded = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> unneeded = new Dictionary<string, List<Rom>>();
foreach (string key in completeDats.Files.Keys)
{
List<Helper.Rom> templist = RomTools.Merge(completeDats.Files[key], _logger);
foreach (Helper.Rom rom in templist)
List<Rom> templist = RomTools.Merge(completeDats.Files[key], _logger);
foreach (Rom rom in templist)
{
if (rom.Dupe == DupeType.None && rom.Metadata.System == _currentAllMerged)
{
@@ -101,7 +101,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
unneeded.Add(key, temp);
}
@@ -124,11 +124,11 @@ namespace SabreTools
midMissing.Files.Add(key, unneeded[key]);
}
}
Dictionary<string, List<Helper.Rom>> newMissing = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> newMissing = new Dictionary<string, List<Rom>>();
foreach (string key in midMissing.Files.Keys)
{
List<Helper.Rom> templist = RomTools.Merge(midMissing.Files[key], _logger);
foreach (Helper.Rom rom in templist)
List<Rom> templist = RomTools.Merge(midMissing.Files[key], _logger);
foreach (Rom rom in templist)
{
if (rom.Dupe == DupeType.None && rom.Metadata.System == _currentMissingMerged)
{
@@ -138,7 +138,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
newMissing.Add(key, temp);
}
@@ -159,7 +159,7 @@ namespace SabreTools
// Now create the Have dictionary [(currentNewMerged)-(c)]
_logger.User("Creating and populating Have dictionary");
Dictionary<string, List<Helper.Rom>> midHave = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> midHave = new Dictionary<string, List<Rom>>();
foreach (string key in newMissing.Keys)
{
if (midHave.ContainsKey(key))
@@ -175,7 +175,7 @@ namespace SabreTools
{
if (midHave.ContainsKey(key))
{
foreach (Helper.Rom rom in completeDats.Files[key])
foreach (Rom rom in completeDats.Files[key])
{
if (rom.Metadata.System == _currentNewMerged)
{
@@ -185,8 +185,8 @@ namespace SabreTools
}
else
{
List<Helper.Rom> roms = new List<Helper.Rom>();
foreach (Helper.Rom rom in completeDats.Files[key])
List<Rom> roms = new List<Rom>();
foreach (Rom rom in completeDats.Files[key])
{
if (rom.Metadata.System == _currentNewMerged)
{
@@ -196,11 +196,11 @@ namespace SabreTools
midHave.Add(key, roms);
}
}
Dictionary<string, List<Helper.Rom>> have = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> have = new Dictionary<string, List<Rom>>();
foreach (string key in midHave.Keys)
{
List<Helper.Rom> templist = RomTools.Merge(midHave[key], _logger);
foreach (Helper.Rom rom in templist)
List<Rom> templist = RomTools.Merge(midHave[key], _logger);
foreach (Rom rom in templist)
{
if (rom.Dupe == DupeType.None && rom.Metadata.System == _currentNewMerged)
{
@@ -210,7 +210,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
have.Add(key, temp);
}
@@ -225,11 +225,11 @@ namespace SabreTools
List<string> keys = netNew.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Helper.Rom> roms = netNew[key];
List<Rom> temp = new List<Rom>();
List<Rom> roms = netNew[key];
for (int i = 0; i < roms.Count; i++)
{
Helper.Rom rom = roms[i];
Rom rom = roms[i];
rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero;
rom.HashData.MD5 = Constants.MD5Zero;
@@ -243,11 +243,11 @@ namespace SabreTools
keys = unneeded.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Helper.Rom> roms = unneeded[key];
List<Rom> temp = new List<Rom>();
List<Rom> roms = unneeded[key];
for (int i = 0; i < roms.Count; i++)
{
Helper.Rom rom = roms[i];
Rom rom = roms[i];
rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero;
rom.HashData.MD5 = Constants.MD5Zero;
@@ -261,11 +261,11 @@ namespace SabreTools
keys = newMissing.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Helper.Rom> roms = newMissing[key];
List<Rom> temp = new List<Rom>();
List<Rom> roms = newMissing[key];
for (int i = 0; i < roms.Count; i++)
{
Helper.Rom rom = roms[i];
Rom rom = roms[i];
rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero;
rom.HashData.MD5 = Constants.MD5Zero;
@@ -279,11 +279,11 @@ namespace SabreTools
keys = have.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Helper.Rom> roms = have[key];
List<Rom> temp = new List<Rom>();
List<Rom> roms = have[key];
for (int i = 0; i < roms.Count; i++)
{
Helper.Rom rom = roms[i];
Rom rom = roms[i];
rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero;
rom.HashData.MD5 = Constants.MD5Zero;
@@ -364,11 +364,11 @@ namespace SabreTools
Dat midHave = new Dat();
midHave = DatTools.Parse(_currentMissingMerged, 0, 0, midHave, _logger);
midHave = DatTools.Parse(_currentAllMerged, 0, 0, midHave, _logger);
Dictionary<string, List<Helper.Rom>> have = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> have = new Dictionary<string, List<Rom>>();
foreach (string key in midHave.Files.Keys)
{
List<Helper.Rom> templist = RomTools.Merge(midHave.Files[key], _logger);
foreach (Helper.Rom rom in templist)
List<Rom> templist = RomTools.Merge(midHave.Files[key], _logger);
foreach (Rom rom in templist)
{
if (rom.Dupe == DupeType.None && rom.Metadata.System == _currentAllMerged)
{
@@ -378,7 +378,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
have.Add(key, temp);
}
@@ -393,11 +393,11 @@ namespace SabreTools
List<string> keys = have.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Helper.Rom> roms = have[key];
List<Rom> temp = new List<Rom>();
List<Rom> roms = have[key];
for (int i = 0; i < roms.Count; i++)
{
Helper.Rom rom = roms[i];
Rom rom = roms[i];
rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero;
rom.HashData.MD5 = Constants.MD5Zero;
@@ -434,11 +434,11 @@ namespace SabreTools
Dat midHave = new Dat();
midHave = DatTools.Parse(_currentMissingMerged, 0, 0, midHave, _logger);
midHave = DatTools.Parse(_currentNewMerged, 0, 0, midHave, _logger);
Dictionary<string, List<Helper.Rom>> have = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> have = new Dictionary<string, List<Rom>>();
foreach (string key in midHave.Files.Keys)
{
List<Helper.Rom> templist = RomTools.Merge(midHave.Files[key], _logger);
foreach (Helper.Rom rom in templist)
List<Rom> templist = RomTools.Merge(midHave.Files[key], _logger);
foreach (Rom rom in templist)
{
if (rom.Dupe == DupeType.None && rom.Metadata.System == _currentNewMerged)
{
@@ -448,7 +448,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
have.Add(key, temp);
}
@@ -463,11 +463,11 @@ namespace SabreTools
List<string> keys = have.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Helper.Rom> roms = have[key];
List<Rom> temp = new List<Rom>();
List<Rom> roms = have[key];
for (int i = 0; i < roms.Count; i++)
{
Helper.Rom rom = roms[i];
Rom rom = roms[i];
rom.HashData.Size = Constants.SizeZero;
rom.HashData.CRC = Constants.CRCZero;
rom.HashData.MD5 = Constants.MD5Zero;

View File

@@ -411,7 +411,7 @@ namespace SabreTools
OutputFormat = (old ? OutputFormat.ClrMamePro : OutputFormat.Xml),
Romba = romba,
Type = (superdat ? "SuperDAT" : ""),
Files = new Dictionary<string, List<Helper.Rom>>(),
Files = new Dictionary<string, List<Rom>>(),
};
DATFromDir dfd = new DATFromDir(inputs, datdata, noMD5, noSHA1, bare, archivesAsFiles, enableGzip, tempDir, _logger);
bool success = dfd.Start();
@@ -436,7 +436,7 @@ namespace SabreTools
// Verify the input files
foreach (string input in inputs)
{
if (!System.IO.File.Exists(input) && !Directory.Exists(input))
if (!File.Exists(input) && !Directory.Exists(input))
{
_logger.Error(input + " is not a valid file or folder!");
Console.WriteLine();
@@ -464,7 +464,7 @@ namespace SabreTools
// Verify the input files
foreach (string input in inputs)
{
if (!System.IO.File.Exists(input) && !Directory.Exists(input))
if (!File.Exists(input) && !Directory.Exists(input))
{
_logger.Error(input + " is not a valid file or folder!");
Console.WriteLine();
@@ -506,7 +506,7 @@ namespace SabreTools
foreach (string input in inputs)
{
if (System.IO.File.Exists(input))
if (File.Exists(input))
{
newinputs.Add(input);
}

View File

@@ -80,7 +80,7 @@ namespace SabreTools
foreach (string input in _inputs)
{
// If it's a file, run the proper split on the file
if (System.IO.File.Exists(input))
if (File.Exists(input))
{
if (_hash)
{
@@ -155,7 +155,7 @@ namespace SabreTools
ForcePacking = datdata.ForcePacking,
OutputFormat = outputFormat,
MergeRoms = datdata.MergeRoms,
Files = new Dictionary<string, List<Helper.Rom>>(),
Files = new Dictionary<string, List<Rom>>(),
};
Dat sha1 = new Dat
{
@@ -177,7 +177,7 @@ namespace SabreTools
ForcePacking = datdata.ForcePacking,
OutputFormat = outputFormat,
MergeRoms = datdata.MergeRoms,
Files = new Dictionary<string, List<Helper.Rom>>(),
Files = new Dictionary<string, List<Rom>>(),
};
Dat md5 = new Dat
{
@@ -199,7 +199,7 @@ namespace SabreTools
ForcePacking = datdata.ForcePacking,
OutputFormat = outputFormat,
MergeRoms = datdata.MergeRoms,
Files = new Dictionary<string, List<Helper.Rom>>(),
Files = new Dictionary<string, List<Rom>>(),
};
Dat crc = new Dat
{
@@ -221,15 +221,15 @@ namespace SabreTools
ForcePacking = datdata.ForcePacking,
OutputFormat = outputFormat,
MergeRoms = datdata.MergeRoms,
Files = new Dictionary<string, List<Helper.Rom>>(),
Files = new Dictionary<string, List<Rom>>(),
};
// Now populate each of the DAT objects in turn
List<string> keys = datdata.Files.Keys.ToList();
foreach (string key in keys)
{
List<Helper.Rom> roms = datdata.Files[key];
foreach (Helper.Rom rom in roms)
List<Rom> roms = datdata.Files[key];
foreach (Rom rom in roms)
{
// If the file is a nodump
if (rom.Nodump)
@@ -240,7 +240,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
nodump.Files.Add(key, temp);
}
@@ -254,7 +254,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
sha1.Files.Add(key, temp);
}
@@ -268,7 +268,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
md5.Files.Add(key, temp);
}
@@ -282,7 +282,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
crc.Files.Add(key, temp);
}
@@ -351,7 +351,7 @@ namespace SabreTools
Homepage = datdata.Homepage,
Url = datdata.Url,
Comment = datdata.Comment,
Files = new Dictionary<string, List<Helper.Rom>>(),
Files = new Dictionary<string, List<Rom>>(),
OutputFormat = outputFormat,
};
Dat datdataB = new Dat
@@ -367,7 +367,7 @@ namespace SabreTools
Homepage = datdata.Homepage,
Url = datdata.Url,
Comment = datdata.Comment,
Files = new Dictionary<string, List<Helper.Rom>>(),
Files = new Dictionary<string, List<Rom>>(),
OutputFormat = outputFormat,
};
@@ -380,7 +380,7 @@ namespace SabreTools
// Now separate the roms accordingly
foreach (string key in datdata.Files.Keys)
{
foreach (Helper.Rom rom in datdata.Files[key])
foreach (Rom rom in datdata.Files[key])
{
if (_extA.Contains(Path.GetExtension(rom.Name.ToUpperInvariant())))
{
@@ -390,7 +390,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
datdataA.Files.Add(key, temp);
}
@@ -403,7 +403,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
datdataB.Files.Add(key, temp);
}
@@ -416,7 +416,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
datdataA.Files.Add(key, temp);
}
@@ -426,7 +426,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
datdataB.Files.Add(key, temp);
}

View File

@@ -69,7 +69,7 @@ namespace SabreTools
_cursorLeft = Console.CursorLeft;
_matched = new Dat
{
Files = new Dictionary<string, List<Helper.Rom>>(),
Files = new Dictionary<string, List<Rom>>(),
};
}
@@ -167,7 +167,7 @@ namespace SabreTools
else if (temparg.StartsWith("-dat=") || temparg.StartsWith("--dat="))
{
string datfile = temparg.Split('=')[1];
if (!System.IO.File.Exists(datfile))
if (!File.Exists(datfile))
{
logger.Error("DAT must be a valid file: " + datfile);
Console.WriteLine();
@@ -206,7 +206,7 @@ namespace SabreTools
zip = 0;
}
}
else if (System.IO.File.Exists(temparg) || Directory.Exists(temparg))
else if (File.Exists(temparg) || Directory.Exists(temparg))
{
inputs.Add(temparg);
}
@@ -358,7 +358,7 @@ namespace SabreTools
// Setup the fixdat
_matched = (Dat)_datdata.CloneHeader();
_matched.Files = new Dictionary<string, List<Helper.Rom>>();
_matched.Files = new Dictionary<string, List<Rom>>();
_matched.FileName = "fixDat_" + _matched.FileName;
_matched.Name = "fixDat_" + _matched.Name;
_matched.Description = "fixDat_" + _matched.Description;
@@ -366,10 +366,10 @@ namespace SabreTools
// Now that all files are parsed, get only files found in directory
bool found = false;
foreach (List<Helper.Rom> roms in _datdata.Files.Values)
foreach (List<Rom> roms in _datdata.Files.Values)
{
List<Helper.Rom> newroms = RomTools.Merge(roms, _logger);
foreach (Helper.Rom rom in newroms)
List<Rom> newroms = RomTools.Merge(roms, _logger);
foreach (Rom rom in newroms)
{
if (rom.Metadata.SourceID == 99)
{
@@ -381,7 +381,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(rom);
_matched.Files.Add(key, temp);
}
@@ -414,7 +414,7 @@ namespace SabreTools
List<string> files = new List<string>();
foreach (string input in _inputs)
{
if (System.IO.File.Exists(input))
if (File.Exists(input))
{
_logger.Log("File found: '" + input + "'");
files.Add(Path.GetFullPath(input));
@@ -492,7 +492,7 @@ namespace SabreTools
// Hash and match the external files
if (shouldExternalScan)
{
Helper.Rom rom = RomTools.GetSingleFileInfo(input);
Rom rom = RomTools.GetSingleFileInfo(input);
// If we have a blank RomData, it's an error
if (rom.Name == null)
@@ -501,9 +501,9 @@ namespace SabreTools
}
// Try to find the matches to the file that was found
List<Helper.Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger, true);
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger, true);
_logger.Log("File '" + input + "' had " + foundroms.Count + " matches in the DAT!");
foreach (Helper.Rom found in foundroms)
foreach (Rom found in foundroms)
{
_logger.Log("Matched name: " + found.Name);
@@ -515,7 +515,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(found);
_matched.Files.Add(key, temp);
}
@@ -532,7 +532,7 @@ namespace SabreTools
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_tgz ? found.HashData.SHA1 : found.Name) + "'");
try
{
System.IO.File.Copy(input, Path.Combine(gamedir, Path.GetFileName(found.Name)));
File.Copy(input, Path.Combine(gamedir, Path.GetFileName(found.Name)));
}
catch { }
}
@@ -558,7 +558,7 @@ namespace SabreTools
// Otherwise, apply the rule ot the file
string newinput = input + ".new";
Skippers.TransformFile(input, newinput, rule, _logger);
Helper.Rom drom = RomTools.GetSingleFileInfo(newinput);
Rom drom = RomTools.GetSingleFileInfo(newinput);
// If we have a blank RomData, it's an error
if (drom.Name == null)
@@ -567,9 +567,9 @@ namespace SabreTools
}
// Try to find the matches to the file that was found
List<Helper.Rom> founddroms = RomTools.GetDuplicates(drom, _datdata, _logger, true);
List<Rom> founddroms = RomTools.GetDuplicates(drom, _datdata, _logger, true);
_logger.Log("File '" + newinput + "' had " + founddroms.Count + " matches in the DAT!");
foreach (Helper.Rom found in founddroms)
foreach (Rom found in founddroms)
{
// Add rom to the matched list
string key = found.HashData.Size + "-" + found.HashData.CRC;
@@ -579,7 +579,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(found);
_matched.Files.Add(key, temp);
}
@@ -599,7 +599,7 @@ namespace SabreTools
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + (_tgz ? found.HashData.SHA1 : found.Name) + "'");
try
{
System.IO.File.Copy(newinput, Path.Combine(gamedir, Path.GetFileName(found.Name)));
File.Copy(newinput, Path.Combine(gamedir, Path.GetFileName(found.Name)));
}
catch { }
}
@@ -616,7 +616,7 @@ namespace SabreTools
}
// Then output the headered rom (renamed)
Helper.Rom newfound = found;
Rom newfound = found;
newfound.Name = Path.GetFileNameWithoutExtension(newfound.Name) + " (" + rom.HashData.CRC + ")" + Path.GetExtension(newfound.Name);
// Add rom to the matched list
@@ -627,7 +627,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(newfound);
_matched.Files.Add(key, temp);
}
@@ -644,7 +644,7 @@ namespace SabreTools
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + newfound.Name + "'");
try
{
System.IO.File.Copy(input, Path.Combine(gamedir, Path.GetFileName(newfound.Name)));
File.Copy(input, Path.Combine(gamedir, Path.GetFileName(newfound.Name)));
}
catch { }
}
@@ -665,7 +665,7 @@ namespace SabreTools
// Now remove this temporary file
try
{
System.IO.File.Delete(newinput);
File.Delete(newinput);
}
catch
{
@@ -681,18 +681,18 @@ namespace SabreTools
if (_quickScan)
{
_logger.Log("Beginning quick scan of contents from '" + input + "'");
List<Helper.Rom> internalRomData = ArchiveTools.GetArchiveFileInfo(input, _logger);
List<Rom> internalRomData = ArchiveTools.GetArchiveFileInfo(input, _logger);
_logger.Log(internalRomData.Count + " entries found in '" + input + "'");
// If the list is populated, then the file was a filled archive
if (internalRomData.Count > 0)
{
foreach (Helper.Rom rom in internalRomData)
foreach (Rom rom in internalRomData)
{
// Try to find the matches to the file that was found
List<Helper.Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger, true);
List<Rom> foundroms = RomTools.GetDuplicates(rom, _datdata, _logger, true);
_logger.Log("File '" + rom.Name + "' had " + foundroms.Count + " matches in the DAT!");
foreach (Helper.Rom found in foundroms)
foreach (Rom found in foundroms)
{
// Add rom to the matched list
string key = found.HashData.Size + "-" + found.HashData.CRC;
@@ -702,7 +702,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> temp = new List<Helper.Rom>();
List<Rom> temp = new List<Rom>();
temp.Add(found);
_matched.Files.Add(key, temp);
}
@@ -712,7 +712,7 @@ namespace SabreTools
// Copy file to output directory
_logger.Log("Rebuilding file '" + Path.GetFileName(rom.Name) + "' to '" + found.Name + "'");
string outfile = ArchiveTools.ExtractSingleItemFromArchive(input, rom.Name, _tempdir, _logger);
if (System.IO.File.Exists(outfile))
if (File.Exists(outfile))
{
string gamedir = Path.Combine(_outdir, found.Machine.Name);
if (!Directory.Exists(gamedir))
@@ -722,7 +722,7 @@ namespace SabreTools
try
{
System.IO.File.Move(outfile, Path.Combine(gamedir, Path.GetFileName(found.Name)));
File.Move(outfile, Path.Combine(gamedir, Path.GetFileName(found.Name)));
}
catch { }
}
@@ -735,7 +735,7 @@ namespace SabreTools
if (Build.MonoEnvironment || _tgz)
{
string outfile = ArchiveTools.ExtractSingleItemFromArchive(input, rom.Name, _tempdir, _logger);
if (System.IO.File.Exists(outfile))
if (File.Exists(outfile))
{
if (_tgz)
{
@@ -748,7 +748,7 @@ namespace SabreTools
try
{
System.IO.File.Delete(outfile);
File.Delete(outfile);
}
catch { }
}
@@ -773,7 +773,7 @@ namespace SabreTools
{
try
{
System.IO.File.Delete(input);
File.Delete(input);
}
catch (Exception)
{
@@ -825,11 +825,11 @@ namespace SabreTools
}
// Now process the inputs (assumed that it's archived sets as of right now
Dictionary<string, List<Helper.Rom>> scanned = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> scanned = new Dictionary<string, List<Rom>>();
foreach (string archive in Directory.EnumerateFiles(_outdir, "*", SearchOption.AllDirectories))
{
// If we are in quickscan, get the list of roms that way
List<Helper.Rom> roms = new List<Helper.Rom>();
List<Rom> roms = new List<Rom>();
if (_quickScan)
{
roms = ArchiveTools.GetArchiveFileInfo(Path.GetFullPath(archive), _logger);
@@ -849,7 +849,7 @@ namespace SabreTools
}
// Then add each of the found files to the new dictionary
foreach (Helper.Rom rom in roms)
foreach (Rom rom in roms)
{
string key = rom.HashData.Size + "-" + rom.HashData.CRC;
if (scanned.ContainsKey(key))
@@ -858,7 +858,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> templist = new List<Helper.Rom>();
List<Rom> templist = new List<Rom>();
templist.Add(rom);
scanned.Add(key, templist);
}
@@ -872,7 +872,7 @@ namespace SabreTools
}
// Now that we have all of the from DAT and from folder roms, we try to match them, removing the perfect matches
Dictionary<string, List<Helper.Rom>> remove = new Dictionary<string, List<Helper.Rom>>();
Dictionary<string, List<Rom>> remove = new Dictionary<string, List<Rom>>();
foreach (string key in scanned.Keys)
{
// If the key doesn't even exist in the DAT, then mark the entire key for removal
@@ -890,9 +890,9 @@ namespace SabreTools
// Otherwise check each of the values individually
else
{
List<Helper.Rom> romsList = _datdata.Files[key];
List<Helper.Rom> scannedList = scanned[key];
foreach (Helper.Rom rom in scannedList)
List<Rom> romsList = _datdata.Files[key];
List<Rom> scannedList = scanned[key];
foreach (Rom rom in scannedList)
{
if (!romsList.Contains(rom))
{
@@ -902,7 +902,7 @@ namespace SabreTools
}
else
{
List<Helper.Rom> templist = new List<Helper.Rom>();
List<Rom> templist = new List<Rom>();
templist.Add(rom);
remove.Add(key, templist);
}

View File

@@ -152,7 +152,7 @@ namespace SabreTools
zip = 0;
}
}
else if (System.IO.File.Exists(temparg) || Directory.Exists(temparg))
else if (File.Exists(temparg) || Directory.Exists(temparg))
{
inputs.Add(temparg);
}
@@ -223,7 +223,7 @@ namespace SabreTools
List<string> newinputs = new List<string>();
foreach (string input in inputs)
{
if (System.IO.File.Exists(input))
if (File.Exists(input))
{
newinputs.Add(Path.GetFullPath(input));
}
@@ -305,7 +305,7 @@ namespace SabreTools
try
{
_logger.User("Attempting to delete " + input);
System.IO.File.Delete(input);
File.Delete(input);
}
catch (Exception ex)
{
@@ -329,7 +329,7 @@ namespace SabreTools
}
// If we're in romba mode and the size file doesn't exist, create it
if (_romba && !System.IO.File.Exists(Path.Combine(_outdir, ".romba_size")))
if (_romba && !File.Exists(Path.Combine(_outdir, ".romba_size")))
{
// Get the size of all of the files in the output folder
long size = 0;
@@ -340,8 +340,8 @@ namespace SabreTools
}
// Write out the value to each of the romba depot files
using (StreamWriter tw = new StreamWriter(System.IO.File.Open(Path.Combine(_outdir, ".romba_size"), FileMode.Create, FileAccess.Write)))
using (StreamWriter twb = new StreamWriter(System.IO.File.Open(Path.Combine(_outdir, ".romba_size.backup"), FileMode.Create, FileAccess.Write)))
using (StreamWriter tw = new StreamWriter(File.Open(Path.Combine(_outdir, ".romba_size"), FileMode.Create, FileAccess.Write)))
using (StreamWriter twb = new StreamWriter(File.Open(Path.Combine(_outdir, ".romba_size.backup"), FileMode.Create, FileAccess.Write)))
{
tw.Write(size);
twb.Write(size);