mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[RombaSharp] Write code for "build"
This commit is contained in:
@@ -268,7 +268,7 @@ namespace SabreTools
|
||||
_logger.User("Total SHA1s: " + (long)slc.ExecuteScalar());
|
||||
|
||||
// Total number of DATs
|
||||
query = "SELECT COUNT(*) FROM dats";
|
||||
query = "SELECT COUNT(*) FROM dats GROUP BY hash";
|
||||
slc = new SqliteCommand(query, dbc);
|
||||
_logger.User("Total DATs: " + (long)slc.ExecuteScalar());
|
||||
|
||||
@@ -498,13 +498,14 @@ namespace SabreTools
|
||||
private static Dictionary<string, string> GetValidDats(List<string> inputs)
|
||||
{
|
||||
// Get a dictionary of filenames that actually exist in the DATRoot, logging which ones are not
|
||||
List<string> datRootDats = Directory.EnumerateFiles(_dats, "*", SearchOption.AllDirectories).ToList().ConvertAll(i => i.ToLowerInvariant());
|
||||
List<string> datRootDats = Directory.EnumerateFiles(_dats, "*", SearchOption.AllDirectories).ToList();
|
||||
List<string> lowerCaseDats = datRootDats.ConvertAll(i => Path.GetFileName(i).ToLowerInvariant());
|
||||
Dictionary<string, string> foundDats = new Dictionary<string, string>();
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
if (datRootDats.Contains(input.ToLowerInvariant()))
|
||||
if (lowerCaseDats.Contains(input.ToLowerInvariant()))
|
||||
{
|
||||
string fullpath = Path.GetFullPath(datRootDats[datRootDats.IndexOf(input.ToLowerInvariant())]);
|
||||
string fullpath = Path.GetFullPath(datRootDats[lowerCaseDats.IndexOf(input.ToLowerInvariant())]);
|
||||
string sha1 = FileTools.GetFileInfo(fullpath, _logger).SHA1;
|
||||
foundDats.Add(sha1, fullpath);
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ namespace SabreTools
|
||||
List<DatItem> datItems = df.Files[key];
|
||||
foreach (Rom rom in datItems)
|
||||
{
|
||||
string query = "SELECT id FROM data WHERE size=" + rom.Size + " AND ("
|
||||
+ "(crc=\"" + rom.CRC + "\" OR value=\"null\")"
|
||||
+ " AND (md5=\"" + rom.MD5 + "\" OR value=\"null\")"
|
||||
+ " AND (sha1=\"" + rom.SHA1 + "\" OR value=\"null\")"
|
||||
string query = "SELECT id FROM data WHERE size=" + rom.Size
|
||||
+ " AND (crc=\"" + rom.CRC + "\" OR crc=\"null\")"
|
||||
+ " AND (md5=\"" + rom.MD5 + "\" OR md5=\"null\")"
|
||||
+ " AND (sha1=\"" + rom.SHA1 + "\" OR sha1=\"null\")"
|
||||
+ " AND indepot=0";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
SqliteDataReader sldr = slc.ExecuteReader();
|
||||
@@ -119,13 +119,69 @@ namespace SabreTools
|
||||
/// <param name="inputs"></param>
|
||||
private static void InitBuild(List<string> inputs)
|
||||
{
|
||||
_logger.User("This feature is not yet implemented: build");
|
||||
|
||||
// Verify the filenames
|
||||
Dictionary<string, string> foundDats = GetValidDats(inputs);
|
||||
|
||||
// Now that we have the dictionary, we can loop through and output to a new folder for each
|
||||
// Create a base output folder
|
||||
if (!Directory.Exists("out"))
|
||||
{
|
||||
Directory.CreateDirectory("out");
|
||||
}
|
||||
|
||||
// Open the database
|
||||
SqliteConnection dbc = new SqliteConnection(_connectionString);
|
||||
dbc.Open();
|
||||
|
||||
// Now that we have the dictionary, we can loop through and output to a new folder for each
|
||||
foreach (string key in foundDats.Keys)
|
||||
{
|
||||
// Get the DAT file associated with the key
|
||||
DatFile datFile = new DatFile();
|
||||
datFile.Parse(Path.Combine(_dats, foundDats[key]), 0, 0, _logger, softlist: true);
|
||||
ArchiveScanLevel asl = ArchiveTools.GetArchiveScanLevelFromNumbers(0, 0, 0, 0);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Then get all hashes associated with this DAT
|
||||
string query = "SELECT sha1 FROM dats JOIN data ON dats.id=data.id WHERE hash=\"" + key + "\"";
|
||||
SqliteCommand slc = new SqliteCommand(query, dbc);
|
||||
SqliteDataReader sldr = slc.ExecuteReader();
|
||||
if (sldr.HasRows)
|
||||
{
|
||||
while (sldr.Read())
|
||||
{
|
||||
string sha1 = sldr.GetString(0);
|
||||
string filename = Path.Combine(sha1.Substring(0, 2), sha1.Substring(2, 2), sha1.Substring(4, 2), sha1.Substring(6, 2), sha1 + ".gz");
|
||||
|
||||
// Find the first depot that contains the folder
|
||||
foreach (string depot in _depots.Keys)
|
||||
{
|
||||
// If the depot is online, check it
|
||||
if (_depots[depot].Item2)
|
||||
{
|
||||
if (File.Exists(Path.Combine(depot, filename)))
|
||||
{
|
||||
ArchiveTools.ExtractArchive(Path.Combine(depot, filename), _tmpdir, asl, _logger);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now that we have extracted everything, we rebuild to the output folder
|
||||
List<string> temp = new List<string>();
|
||||
temp.Add(_tmpdir);
|
||||
SimpleSort ss = new SimpleSort(datFile, temp, outputFolder, "", false, false, false, true, false, false, asl, false, _logger);
|
||||
ss.StartProcessing();
|
||||
}
|
||||
|
||||
dbc.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -155,19 +155,9 @@ namespace SabreTools
|
||||
{
|
||||
outdat = temparg.Split('=')[1];
|
||||
}
|
||||
else if (File.Exists(temparg) || Directory.Exists(temparg))
|
||||
{
|
||||
inputs.Add(temparg);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Error("Invalid input detected: " + arg);
|
||||
Console.WriteLine();
|
||||
Build.Help();
|
||||
Console.WriteLine();
|
||||
_logger.Error("Invalid input detected: " + arg);
|
||||
_logger.Close();
|
||||
return;
|
||||
inputs.Add(temparg);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -5380,9 +5380,18 @@ namespace SabreTools.Helper
|
||||
|
||||
// Add the file information to the DAT
|
||||
lock (Files)
|
||||
{
|
||||
if (Files.ContainsKey(key))
|
||||
{
|
||||
Files[key].Add(datItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<DatItem> temp = new List<DatItem>();
|
||||
temp.Add(datItem);
|
||||
Files.Add(key, temp);
|
||||
}
|
||||
}
|
||||
|
||||
logger.User("File added: " + romname + Environment.NewLine);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ namespace SabreTools.Helper
|
||||
/// Process the DAT and verify the output directory
|
||||
/// </summary>
|
||||
/// <returns>True if verification was a success, false otherwise</returns>
|
||||
public bool VerifyDirectory()
|
||||
private bool VerifyDirectory()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
@@ -194,7 +194,7 @@ namespace SabreTools.Helper
|
||||
///
|
||||
/// This is actually rather slow and inefficient. See below for more correct implemenation
|
||||
/// </remarks>
|
||||
public bool RebuildToOutput()
|
||||
private bool RebuildToOutput()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
@@ -232,6 +232,14 @@ namespace SabreTools.Helper
|
||||
{
|
||||
FileTools.CleanDirectory(_tempDir);
|
||||
}
|
||||
if (success && _delete)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(files[i]);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
// Now one final delete of the temp directory
|
||||
@@ -615,7 +623,7 @@ namespace SabreTools.Helper
|
||||
/// 4) Order by output game
|
||||
/// 5) Rebuild all files
|
||||
/// </remarks>
|
||||
public bool RebuiltToOutputAlternate()
|
||||
private bool RebuiltToOutputAlternate()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
@@ -781,7 +789,7 @@ namespace SabreTools.Helper
|
||||
/// <param name="matchdat">Reference to the Dat to add to</param>
|
||||
/// <param name="logger">Logger object for file and console output</param>
|
||||
/// <returns>True if the file could be added, false otherwise</returns>
|
||||
public bool RebuildToOutputAlternateParseRomHelper(string file, ref DatFile matchdat, Logger logger)
|
||||
private bool RebuildToOutputAlternateParseRomHelper(string file, ref DatFile matchdat, Logger logger)
|
||||
{
|
||||
Rom rom = FileTools.GetFileInfo(file, logger);
|
||||
|
||||
@@ -851,7 +859,7 @@ namespace SabreTools.Helper
|
||||
/// </summary>
|
||||
/// <returns>True if the cleaning succeeded, false otherwise</returns>
|
||||
/// <remarks>This method is incomplete, it need to be finished before it can be used</remarks>
|
||||
public bool InplaceRebuild()
|
||||
private bool InplaceRebuild()
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user