[RombaSharp] Fix deleting dats

- Only try to remove dats if some exist to remove
- Lump all deletes into a single statement
This commit is contained in:
Matt Nadareski
2018-02-09 11:41:22 -08:00
parent 8073368bfb
commit 6d21a37857

View File

@@ -217,10 +217,10 @@ namespace RombaSharp
// Verify the filenames // Verify the filenames
Dictionary<string, string> foundDats = GetValidDats(inputs); Dictionary<string, string> foundDats = GetValidDats(inputs);
// Create a base output folder // Ensure the output directory is set
if (!Directory.Exists("out")) if (String.IsNullOrWhiteSpace(outdat))
{ {
Directory.CreateDirectory("out"); outdat = "out";
} }
// Now that we have the dictionary, we can loop through and output to a new folder for each // Now that we have the dictionary, we can loop through and output to a new folder for each
@@ -231,11 +231,8 @@ namespace RombaSharp
datFile.Parse(Path.Combine(_dats, foundDats[key]), 0, 0); datFile.Parse(Path.Combine(_dats, foundDats[key]), 0, 0);
// Create the new output directory if it doesn't exist // Create the new output directory if it doesn't exist
string outputFolder = Path.Combine("out", Path.GetFileNameWithoutExtension(foundDats[key])); string outputFolder = Path.Combine(outdat, Path.GetFileNameWithoutExtension(foundDats[key]));
if (!Directory.Exists(outputFolder)) Utilities.EnsureOutputDirectory(outputFolder, create: true);
{
Directory.CreateDirectory(outputFolder);
}
// Get all online depots // Get all online depots
List<string> onlineDepots = _depots.Where(d => d.Value.Item2).Select(d => d.Key).ToList(); List<string> onlineDepots = _depots.Where(d => d.Value.Item2).Select(d => d.Key).ToList();
@@ -776,17 +773,23 @@ namespace RombaSharp
watch.Stop(); watch.Stop();
// Now loop through and remove all references to old Dats // Now loop through and remove all references to old Dats
watch.Start("Removing unmatched DAT information"); if (unneeded.Count > 0)
foreach (string dathash in unneeded)
{ {
query = "DELETE FROM dat WHERE hash=\"" + dathash + "\""; watch.Start("Removing unmatched DAT information");
query = "DELETE FROM dat WHERE";
foreach (string dathash in unneeded)
{
query += " OR hash=\"" + dathash + "\"";
}
query = query.Replace("WHERE OR", "WHERE");
slc = new SqliteCommand(query, dbc); slc = new SqliteCommand(query, dbc);
slc.ExecuteNonQuery(); slc.ExecuteNonQuery();
slc.Dispose(); slc.Dispose();
}
watch.Stop(); watch.Stop();
}
dbc.Dispose(); dbc.Dispose();
} }