feature/SQlite #1
@ -39,6 +39,10 @@ public class Program {
|
|||||||
case "createDB":
|
case "createDB":
|
||||||
utils.initializeDB();
|
utils.initializeDB();
|
||||||
break;
|
break;
|
||||||
|
case "checkIfFileWasDeleted":
|
||||||
|
Console.ResetColor();
|
||||||
|
utils.checkIfFileWasDeleted();
|
||||||
|
break;
|
||||||
case "help":
|
case "help":
|
||||||
PrintAvailableOptions();
|
PrintAvailableOptions();
|
||||||
break;
|
break;
|
||||||
@ -57,6 +61,7 @@ public class Program {
|
|||||||
"checksum",
|
"checksum",
|
||||||
"compareChecksums",
|
"compareChecksums",
|
||||||
"createDB",
|
"createDB",
|
||||||
|
"checkIfFileWasDeleted",
|
||||||
"help"
|
"help"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -174,6 +174,40 @@ public class ChksumUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkIfFileWasDeleted() {
|
||||||
|
string pathToFile = string.Empty;
|
||||||
|
|
||||||
|
using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadWrite")) {
|
||||||
|
connection.Open();
|
||||||
|
|
||||||
|
var selectCommand = connection.CreateCommand();
|
||||||
|
selectCommand.CommandText =
|
||||||
|
@"
|
||||||
|
Select pathtofile FROM file
|
||||||
|
";
|
||||||
|
|
||||||
|
using (var reader = selectCommand.ExecuteReader()) {
|
||||||
|
while (reader.Read()) {
|
||||||
|
pathToFile = reader.GetString(0);
|
||||||
|
|
||||||
|
if (!File.Exists(pathToFile)) {
|
||||||
|
var deleteCommand = connection.CreateCommand();
|
||||||
|
deleteCommand.CommandText =
|
||||||
|
@"
|
||||||
|
DELETE FROM file
|
||||||
|
WHERE pathtofile = $pathtofile
|
||||||
|
";
|
||||||
|
deleteCommand.Parameters.AddWithValue("$pathtofile", pathToFile);
|
||||||
|
deleteCommand.ExecuteNonQuery();
|
||||||
|
|
||||||
|
Console.WriteLine("File deleted:");
|
||||||
|
Console.WriteLine($"\t{pathToFile}\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void compareChecksums() { // reuse for database comparison
|
public void compareChecksums() { // reuse for database comparison
|
||||||
foreach (var directory in Directory.GetDirectories(Directory.GetCurrentDirectory())) {
|
foreach (var directory in Directory.GetDirectories(Directory.GetCurrentDirectory())) {
|
||||||
Directory.SetCurrentDirectory(directory); // Set new root
|
Directory.SetCurrentDirectory(directory); // Set new root
|
||||||
|
Loading…
x
Reference in New Issue
Block a user