2016-10-24 12:58:57 -07:00
|
|
|
|
using System;
|
2016-09-02 13:59:25 -07:00
|
|
|
|
using System.Collections.Generic;
|
2016-10-10 10:51:19 -07:00
|
|
|
|
using System.Linq;
|
2016-10-24 12:58:57 -07:00
|
|
|
|
using Mono.Data.Sqlite;
|
|
|
|
|
|
|
|
|
|
|
|
using SabreTools.Helper;
|
|
|
|
|
|
using SabreTools.Helper.Data;
|
|
|
|
|
|
using SabreTools.Helper.Dats;
|
|
|
|
|
|
using SabreTools.Helper.Tools;
|
2016-09-02 13:59:25 -07:00
|
|
|
|
|
2016-10-28 21:49:29 -07:00
|
|
|
|
#if MONO
|
2016-10-27 11:35:17 -07:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
#else
|
2016-10-26 22:10:47 -07:00
|
|
|
|
using Alphaleonis.Win32.Filesystem;
|
2016-10-27 11:35:17 -07:00
|
|
|
|
#endif
|
2016-10-26 22:10:47 -07:00
|
|
|
|
|
2017-02-02 15:08:21 -08:00
|
|
|
|
namespace RombaSharp
|
2016-09-02 13:59:25 -07:00
|
|
|
|
{
|
|
|
|
|
|
public partial class RombaSharp
|
|
|
|
|
|
{
|
|
|
|
|
|
#region Init Methods
|
|
|
|
|
|
|
2016-09-02 14:08:34 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap adding files to the depots
|
|
|
|
|
|
/// </summary>
|
2016-10-10 10:51:19 -07:00
|
|
|
|
/// <param name="inputs">List of input folders to use</param>
|
|
|
|
|
|
/// <param name="onlyNeeded">True if only files in the database and don't exist are added, false otherwise</param>
|
2016-09-02 13:59:25 -07:00
|
|
|
|
private static void InitArchive(List<string> inputs, bool onlyNeeded)
|
|
|
|
|
|
{
|
2016-10-10 10:51:19 -07:00
|
|
|
|
// First we want to get just all directories from the inputs
|
|
|
|
|
|
List<string> onlyDirs = new List<string>();
|
|
|
|
|
|
foreach (string input in inputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Directory.Exists(input))
|
|
|
|
|
|
{
|
|
|
|
|
|
onlyDirs.Add(Path.GetFullPath(input));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Then process all of the input directories into an internal DAT
|
|
|
|
|
|
DatFile df = new DatFile();
|
|
|
|
|
|
foreach (string dir in onlyDirs)
|
|
|
|
|
|
{
|
2017-02-27 00:01:24 -08:00
|
|
|
|
df.PopulateFromDir(dir, Hash.SHA256 & Hash.SHA384 & Hash.SHA512, false, false, true, false, false, _tmpdir, false, null, _workers, _logger);
|
2016-10-19 13:34:44 -07:00
|
|
|
|
|
|
|
|
|
|
// If we're looking for only needed, consider the zipfiles themselves too
|
|
|
|
|
|
if (onlyNeeded)
|
|
|
|
|
|
{
|
2017-02-27 00:01:24 -08:00
|
|
|
|
df.PopulateFromDir(dir, Hash.SHA256 & Hash.SHA384 & Hash.SHA512, false, true, true, false, false, _tmpdir, false, null, _workers, _logger);
|
2016-10-19 13:34:44 -07:00
|
|
|
|
}
|
2016-10-10 10:51:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create an empty Dat for files that need to be rebuilt
|
|
|
|
|
|
DatFile need = new DatFile();
|
|
|
|
|
|
|
2016-10-17 11:04:07 -07:00
|
|
|
|
// Open the database connection
|
2016-10-10 10:51:19 -07:00
|
|
|
|
SqliteConnection dbc = new SqliteConnection(_connectionString);
|
2016-10-10 13:14:35 -07:00
|
|
|
|
dbc.Open();
|
|
|
|
|
|
|
|
|
|
|
|
// Now that we have the Dats, add the files to the database
|
2016-10-17 11:04:07 -07:00
|
|
|
|
string crcquery = "INSERT OR IGNORE INTO crc (crc) VALUES";
|
|
|
|
|
|
string md5query = "INSERT OR IGNORE INTO md5 (md5) VALUES";
|
2016-10-17 11:13:43 -07:00
|
|
|
|
string sha1query = "INSERT OR IGNORE INTO sha1 (sha1, depot) VALUES";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
string crcsha1query = "INSERT OR IGNORE INTO crcsha1 (crc, sha1) VALUES";
|
|
|
|
|
|
string md5sha1query = "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES";
|
|
|
|
|
|
|
2016-11-08 15:50:27 -08:00
|
|
|
|
foreach (string key in df.Keys)
|
2016-10-10 10:51:19 -07:00
|
|
|
|
{
|
2016-11-08 15:50:27 -08:00
|
|
|
|
List<DatItem> datItems = df[key];
|
2016-10-10 10:51:19 -07:00
|
|
|
|
foreach (Rom rom in datItems)
|
|
|
|
|
|
{
|
2016-10-17 11:04:07 -07:00
|
|
|
|
// If we care about if the file exists, check the databse first
|
|
|
|
|
|
if (onlyNeeded)
|
2016-10-10 10:51:19 -07:00
|
|
|
|
{
|
2016-10-17 11:04:07 -07:00
|
|
|
|
string query = "SELECT * FROM crcsha1 JOIN md5sha1 ON crcsha1.sha1=md5sha1.sha1"
|
2017-01-27 16:53:29 -08:00
|
|
|
|
+ " WHERE crcsha1.crc=\"" + rom.CRC + "\""
|
|
|
|
|
|
+ " OR md5sha1.md5=\"" + rom.MD5 + "\""
|
|
|
|
|
|
+ " OR md5sha1.sha1=\"" + rom.SHA1 + "\"";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
SqliteCommand slc = new SqliteCommand(query, dbc);
|
|
|
|
|
|
SqliteDataReader sldr = slc.ExecuteReader();
|
|
|
|
|
|
|
|
|
|
|
|
if (sldr.HasRows)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Add to the queries
|
|
|
|
|
|
if (!String.IsNullOrEmpty(rom.CRC))
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
crcquery += " (\"" + rom.CRC + "\"),";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (!String.IsNullOrEmpty(rom.MD5))
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
md5query += " (\"" + rom.MD5 + "\"),";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (!String.IsNullOrEmpty(rom.SHA1))
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
sha1query += " (\"" + rom.SHA1 + "\", \"" + _depots.Keys.ToList()[0] + "\"),";
|
2016-10-14 16:58:15 -07:00
|
|
|
|
|
2016-10-17 11:04:07 -07:00
|
|
|
|
if (!String.IsNullOrEmpty(rom.CRC))
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (!String.IsNullOrEmpty(rom.MD5))
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-10-14 16:58:15 -07:00
|
|
|
|
|
2016-10-17 11:04:07 -07:00
|
|
|
|
// Add to the Dat
|
2016-11-08 15:29:52 -08:00
|
|
|
|
need.Add(key, rom);
|
2016-10-17 11:04:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
// Otherwise, just add the file to the list
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
// Add to the queries
|
|
|
|
|
|
if (!String.IsNullOrEmpty(rom.CRC))
|
2016-10-10 10:51:19 -07:00
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
crcquery += " (\"" + rom.CRC + "\"),";
|
2016-10-14 16:58:15 -07:00
|
|
|
|
}
|
2016-10-17 11:04:07 -07:00
|
|
|
|
if (!String.IsNullOrEmpty(rom.MD5))
|
2016-10-14 16:58:15 -07:00
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
md5query += " (\"" + rom.MD5 + "\"),";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (!String.IsNullOrEmpty(rom.SHA1))
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
sha1query += " (\"" + rom.SHA1 + "\", \"" + _depots.Keys.ToList()[0] + "\"),";
|
2016-10-17 11:13:43 -07:00
|
|
|
|
|
2016-10-17 11:04:07 -07:00
|
|
|
|
if (!String.IsNullOrEmpty(rom.CRC))
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
crcsha1query += " (\"" + rom.CRC + "\", \"" + rom.SHA1 + "\"),";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
}
|
|
|
|
|
|
if (!String.IsNullOrEmpty(rom.MD5))
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
md5sha1query += " (\"" + rom.MD5 + "\", \"" + rom.SHA1 + "\"),";
|
2016-10-17 11:04:07 -07:00
|
|
|
|
}
|
2016-10-10 10:51:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-17 11:04:07 -07:00
|
|
|
|
// Add to the Dat
|
2016-11-08 15:29:52 -08:00
|
|
|
|
need.Add(key, rom);
|
2016-10-10 10:51:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-17 11:04:07 -07:00
|
|
|
|
// Now run the queries, if they're populated
|
|
|
|
|
|
if (crcquery != "INSERT OR IGNORE INTO crc (crc) VALUES")
|
|
|
|
|
|
{
|
|
|
|
|
|
SqliteCommand slc = new SqliteCommand(crcquery.TrimEnd(','), dbc);
|
|
|
|
|
|
slc.ExecuteNonQuery();
|
|
|
|
|
|
slc.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (md5query != "INSERT OR IGNORE INTO md5 (md5) VALUES")
|
|
|
|
|
|
{
|
|
|
|
|
|
SqliteCommand slc = new SqliteCommand(md5query.TrimEnd(','), dbc);
|
|
|
|
|
|
slc.ExecuteNonQuery();
|
|
|
|
|
|
slc.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (sha1query != "INSERT OR IGNORE INTO sha1 (sha1) VALUES")
|
|
|
|
|
|
{
|
|
|
|
|
|
SqliteCommand slc = new SqliteCommand(sha1query.TrimEnd(','), dbc);
|
|
|
|
|
|
slc.ExecuteNonQuery();
|
|
|
|
|
|
slc.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (crcsha1query != "INSERT OR IGNORE INTO crcsha1 (crc, sha1) VALUES")
|
|
|
|
|
|
{
|
|
|
|
|
|
SqliteCommand slc = new SqliteCommand(crcsha1query.TrimEnd(','), dbc);
|
|
|
|
|
|
slc.ExecuteNonQuery();
|
|
|
|
|
|
slc.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (md5sha1query != "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES")
|
|
|
|
|
|
{
|
|
|
|
|
|
SqliteCommand slc = new SqliteCommand(md5sha1query.TrimEnd(','), dbc);
|
|
|
|
|
|
slc.ExecuteNonQuery();
|
|
|
|
|
|
slc.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-10 10:51:19 -07:00
|
|
|
|
// Create the sorting object to use and rebuild the needed files
|
2016-10-19 13:30:20 -07:00
|
|
|
|
ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers((onlyNeeded ? 0 : 1), (onlyNeeded ? 0 : 1), (onlyNeeded ? 0 : 1), (onlyNeeded ? 0 : 1));
|
2017-01-31 23:18:41 -08:00
|
|
|
|
need.RebuildGeneric(onlyDirs, _depots.Keys.ToList()[0], _tmpdir, false /*quickScan*/, false /*date*/,
|
2017-01-18 10:20:00 -08:00
|
|
|
|
false /*delete*/, false /*inverse*/, OutputFormat.TorrentGzip, true /*romba*/, asl, false /*updateDat*/,
|
2017-03-01 20:43:27 -08:00
|
|
|
|
null /*headerToCheckAgainst*/, _workers /*maxDegreeOfParallelism*/, _logger);
|
2016-09-02 13:59:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-02 14:08:34 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap building all files from a set of DATs
|
|
|
|
|
|
/// </summary>
|
2016-10-12 15:40:06 -07:00
|
|
|
|
/// <param name="inputs">List of input DATs to rebuild from</param>
|
|
|
|
|
|
/// <param name="copy">True if files should be copied to output, false for rebuild</param>
|
|
|
|
|
|
private static void InitBuild(List<string> inputs, bool copy)
|
2016-09-02 13:59:25 -07:00
|
|
|
|
{
|
2016-09-08 17:42:53 -07:00
|
|
|
|
// Verify the filenames
|
|
|
|
|
|
Dictionary<string, string> foundDats = GetValidDats(inputs);
|
|
|
|
|
|
|
2016-10-12 14:40:21 -07:00
|
|
|
|
// Create a base output folder
|
|
|
|
|
|
if (!Directory.Exists("out"))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory("out");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-08 17:42:53 -07:00
|
|
|
|
// Now that we have the dictionary, we can loop through and output to a new folder for each
|
2016-10-12 14:40:21 -07:00
|
|
|
|
foreach (string key in foundDats.Keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Get the DAT file associated with the key
|
|
|
|
|
|
DatFile datFile = new DatFile();
|
2017-02-23 16:41:29 -08:00
|
|
|
|
datFile.Parse(Path.Combine(_dats, foundDats[key]), 0, 0, _logger);
|
2016-10-12 14:40:21 -07:00
|
|
|
|
|
|
|
|
|
|
// Create the new output directory if it doesn't exist
|
|
|
|
|
|
string outputFolder = Path.Combine("out", Path.GetFileNameWithoutExtension(foundDats[key]));
|
|
|
|
|
|
if (!Directory.Exists(outputFolder))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.CreateDirectory(outputFolder);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-10-17 11:04:07 -07:00
|
|
|
|
// Get all online depots
|
|
|
|
|
|
List<string> onlineDepots = _depots.Where(d => d.Value.Item2).Select(d => d.Key).ToList();
|
2016-10-14 16:58:15 -07:00
|
|
|
|
|
2016-10-17 11:04:07 -07:00
|
|
|
|
// Now scan all of those depots and rebuild
|
2016-10-19 13:21:43 -07:00
|
|
|
|
ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(1, 1, 1, 1);
|
2017-01-31 23:18:41 -08:00
|
|
|
|
datFile.RebuildDepot(onlineDepots, outputFolder, _tmpdir, false /*date*/,
|
2017-01-30 12:59:04 -08:00
|
|
|
|
false /*delete*/, false /*inverse*/, (copy ? OutputFormat.TorrentGzip : OutputFormat.TorrentZip), copy,
|
2017-03-01 20:43:27 -08:00
|
|
|
|
false /*updateDat*/, null /*headerToCheckAgainst*/, _workers /*maxDegreeOfParallelism*/, _logger);
|
2016-10-12 14:40:21 -07:00
|
|
|
|
}
|
2016-09-02 13:59:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-02 14:08:34 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap finding all files that are in both the database and a new Dat
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="newdat"></param>
|
2016-09-02 13:59:25 -07:00
|
|
|
|
private static void InitDiffDat(string newdat)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("This feature is not yet implemented: diffdat");
|
2016-09-08 17:42:53 -07:00
|
|
|
|
|
|
|
|
|
|
// First, we want to read in the DAT. Then for each file listed in the DAT, we check if it's in there or not.
|
|
|
|
|
|
// If it is in there, we add it to an output DAT. If it's not, we skip. Then we output the DAT.
|
2016-09-02 13:59:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-02 14:08:34 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap creating a Dat from a directory
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="inputs"></param>
|
2016-09-02 13:59:25 -07:00
|
|
|
|
private static void InitDir2Dat(List<string> inputs)
|
|
|
|
|
|
{
|
2016-09-02 14:13:44 -07:00
|
|
|
|
// Create a simple Dat output
|
2016-09-19 20:08:25 -07:00
|
|
|
|
DatFile datdata = new DatFile()
|
2016-09-02 14:13:44 -07:00
|
|
|
|
{
|
|
|
|
|
|
FileName = Path.GetFileName(inputs[0]) + " Dir2Dat",
|
|
|
|
|
|
Name = Path.GetFileName(inputs[0]) + " Dir2Dat",
|
|
|
|
|
|
Description = Path.GetFileName(inputs[0]) + " Dir2Dat",
|
2016-10-25 15:02:02 -07:00
|
|
|
|
DatFormat = DatFormat.Logiqx,
|
2016-09-02 14:13:44 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
2016-10-24 12:58:57 -07:00
|
|
|
|
Logger logger = new Logger();
|
2016-09-14 14:53:48 -07:00
|
|
|
|
foreach (string input in inputs)
|
|
|
|
|
|
{
|
2017-02-27 00:01:24 -08:00
|
|
|
|
datdata.PopulateFromDir(input, Hash.SHA256 & Hash.SHA384 & Hash.SHA512 /* omitFromScan */, true /* bare */, false /* archivesAsFiles */,
|
2016-10-10 11:28:27 -07:00
|
|
|
|
true /* enableGzip */, false /* addBlanks */, false /* addDate */, _tmpdir /* tempDir */, false /* copyFiles */,
|
2016-10-19 10:47:23 -07:00
|
|
|
|
null /* headerToCheckAgainst */, _workers /* maxDegreeOfParallelism */, _logger);
|
2017-03-01 20:43:27 -08:00
|
|
|
|
datdata.WriteToFile("", _workers, logger);
|
2016-09-14 14:53:48 -07:00
|
|
|
|
}
|
|
|
|
|
|
logger.Close();
|
2016-09-02 13:59:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-02 14:08:34 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap creating a fixdat for each Dat
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="inputs"></param>
|
2016-09-02 13:59:25 -07:00
|
|
|
|
private static void InitFixdat(List<string> inputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("This feature is not yet implemented: fixdat");
|
2016-09-08 17:42:53 -07:00
|
|
|
|
|
|
|
|
|
|
// Verify the filenames
|
|
|
|
|
|
Dictionary<string, string> foundDats = GetValidDats(inputs);
|
2016-09-08 17:52:02 -07:00
|
|
|
|
|
|
|
|
|
|
// Once we have each DAT, look up each associated hash based on the hash of the DATs.
|
|
|
|
|
|
// Then, for each rom, check to see if they exist in the folder. If they don't, add it
|
|
|
|
|
|
// to the fixDAT. Then output when the DAT is done, processing, moving on to the next...
|
|
|
|
|
|
// NOTE: This might share code with InitMiss
|
2016-09-02 13:59:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-02 22:06:20 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap importing CSVs into the database
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="inputs"></param>
|
|
|
|
|
|
private static void InitImport(List<string> inputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("This feature is not yet implemented: import");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-02 14:08:34 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap looking up if hashes exist in the database
|
|
|
|
|
|
/// </summary>
|
2016-10-10 10:51:19 -07:00
|
|
|
|
/// <param name="inputs">List of input strings representing hashes to check for</param>
|
2016-09-02 13:59:25 -07:00
|
|
|
|
private static void InitLookup(List<string> inputs)
|
|
|
|
|
|
{
|
2016-10-09 22:30:19 -07:00
|
|
|
|
// First, try to figure out what type of hash each is by length and clean it
|
2016-10-10 10:51:19 -07:00
|
|
|
|
List<string> crc = new List<string>();
|
|
|
|
|
|
List<string> md5 = new List<string>();
|
|
|
|
|
|
List<string> sha1 = new List<string>();
|
2016-10-09 22:30:19 -07:00
|
|
|
|
foreach (string input in inputs)
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
string temp = "";
|
2016-10-09 22:30:19 -07:00
|
|
|
|
if (input.Length == Constants.CRCLength)
|
|
|
|
|
|
{
|
|
|
|
|
|
temp = Style.CleanHashData(input, Constants.CRCLength);
|
2017-01-27 16:53:29 -08:00
|
|
|
|
if (temp != "")
|
2016-10-10 10:51:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
crc.Add(temp);
|
|
|
|
|
|
}
|
2016-10-09 22:30:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (input.Length == Constants.MD5Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
temp = Style.CleanHashData(input, Constants.MD5Length);
|
2017-01-27 16:53:29 -08:00
|
|
|
|
if (temp != "")
|
2016-10-10 10:51:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
md5.Add(temp);
|
|
|
|
|
|
}
|
2016-10-09 22:30:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
else if (input.Length == Constants.SHA1Length)
|
|
|
|
|
|
{
|
|
|
|
|
|
temp = Style.CleanHashData(input, Constants.SHA1Length);
|
2017-01-27 16:53:29 -08:00
|
|
|
|
if (temp != "")
|
2016-10-10 10:51:19 -07:00
|
|
|
|
{
|
|
|
|
|
|
sha1.Add(temp);
|
|
|
|
|
|
}
|
2016-10-09 22:30:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SqliteConnection dbc = new SqliteConnection(_connectionString);
|
2016-10-10 13:14:35 -07:00
|
|
|
|
dbc.Open();
|
|
|
|
|
|
|
|
|
|
|
|
// Now, search for each of them and return true or false for each
|
2016-10-10 10:51:19 -07:00
|
|
|
|
foreach (string input in crc)
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
string query = "SELECT * FROM crc WHERE crc=\"" + input + "\"";
|
2016-10-10 10:51:19 -07:00
|
|
|
|
SqliteCommand slc = new SqliteCommand(query, dbc);
|
|
|
|
|
|
SqliteDataReader sldr = slc.ExecuteReader();
|
|
|
|
|
|
if (sldr.HasRows)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("For hash '" + input + "' there were " + sldr.RecordsAffected + " matches in the database");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("Hash '" + input + "' had no matches in the database");
|
|
|
|
|
|
}
|
2016-10-09 22:30:19 -07:00
|
|
|
|
|
2016-10-10 10:51:19 -07:00
|
|
|
|
sldr.Dispose();
|
|
|
|
|
|
slc.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (string input in md5)
|
|
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
string query = "SELECT * FROM md5 WHERE md5=\"" + input + "\"";
|
2016-10-10 10:51:19 -07:00
|
|
|
|
SqliteCommand slc = new SqliteCommand(query, dbc);
|
|
|
|
|
|
SqliteDataReader sldr = slc.ExecuteReader();
|
|
|
|
|
|
if (sldr.HasRows)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("For hash '" + input + "' there were " + sldr.RecordsAffected + " matches in the database");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("Hash '" + input + "' had no matches in the database");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sldr.Dispose();
|
|
|
|
|
|
slc.Dispose();
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (string input in sha1)
|
2016-10-09 22:30:19 -07:00
|
|
|
|
{
|
2017-01-27 16:53:29 -08:00
|
|
|
|
string query = "SELECT * FROM sha1 WHERE sha1=\"" + input + "\"";
|
2016-10-09 22:30:19 -07:00
|
|
|
|
SqliteCommand slc = new SqliteCommand(query, dbc);
|
|
|
|
|
|
SqliteDataReader sldr = slc.ExecuteReader();
|
|
|
|
|
|
if (sldr.HasRows)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("For hash '" + input + "' there were " + sldr.RecordsAffected + " matches in the database");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("Hash '" + input + "' had no matches in the database");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sldr.Dispose();
|
|
|
|
|
|
slc.Dispose();
|
|
|
|
|
|
}
|
2016-09-08 17:52:02 -07:00
|
|
|
|
|
2016-10-09 22:30:19 -07:00
|
|
|
|
dbc.Dispose();
|
2016-09-02 13:59:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-02-02 21:57:34 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap merging an external depot into an existing one
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="inputs"></param>
|
|
|
|
|
|
/// <param name="depotPath"></param>
|
|
|
|
|
|
/// <param name="onlyNeeded"></param>
|
|
|
|
|
|
private static void InitMerge(List<string> inputs, string depotPath, bool onlyNeeded)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("This feature is not yet implemented: merge");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-09-02 14:08:34 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Wrap creating a havefile and a missfile for each Dat
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="inputs"></param>
|
2016-09-02 13:59:25 -07:00
|
|
|
|
private static void InitMiss(List<string> inputs)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.User("This feature is not yet implemented: miss");
|
2016-09-08 17:42:53 -07:00
|
|
|
|
|
|
|
|
|
|
// Verify the filenames
|
|
|
|
|
|
Dictionary<string, string> foundDats = GetValidDats(inputs);
|
2016-09-08 17:52:02 -07:00
|
|
|
|
|
|
|
|
|
|
// Once we have each DAT, look up each associated hash based on the hash of the DATs.
|
|
|
|
|
|
// Then, for each rom, check to see if they exist in the folder. If they do, add it
|
|
|
|
|
|
// to the have DAT, else wise go to the miss DAT. Then output both when the DAT is done
|
|
|
|
|
|
// processing, moving on to the next...
|
|
|
|
|
|
// NOTE: This might share code with InitFixdat
|
2016-09-02 13:59:25 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|