Add option to check for deleted files
This commit is contained in:
parent
2d42842fb2
commit
b899c4c5b6
@ -39,6 +39,10 @@ public class Program {
|
||||
case "createDB":
|
||||
utils.initializeDB();
|
||||
break;
|
||||
case "checkIfFileWasDeleted":
|
||||
Console.ResetColor();
|
||||
utils.checkIfFileWasDeleted();
|
||||
break;
|
||||
case "help":
|
||||
PrintAvailableOptions();
|
||||
break;
|
||||
@ -57,6 +61,7 @@ public class Program {
|
||||
"checksum",
|
||||
"compareChecksums",
|
||||
"createDB",
|
||||
"checkIfFileWasDeleted",
|
||||
"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
|
||||
foreach (var directory in Directory.GetDirectories(Directory.GetCurrentDirectory())) {
|
||||
Directory.SetCurrentDirectory(directory); // Set new root
|
||||
|
Loading…
Reference in New Issue
Block a user