Compare commits

..

No commits in common. "787721381d33cbf456e7e794fdfbd2466ec3ac6a" and "7f6f4c5253fd2d6c2edfe77dea201133161958db" have entirely different histories.

View File

@ -91,29 +91,28 @@ public class ChksumUtils {
public void doTheThing() { public void doTheThing() {
using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadWrite")) { using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadWrite")) {
if (getTotalFileCount() < 1) { if (getTotalFileCount() >= 1) {
return; Dictionary<string, string> fileHashes = CalculateChecksums(indexFiles());
} foreach (var file in fileHashes) {
connection.Open(); string absolutePathToFile = file.Key;
Dictionary<string, string> fileHashes = CalculateChecksums(indexFiles()); string fileName = Path.GetFileName(absolutePathToFile);
string pathToFile = Path.GetRelativePath(DatabaseRoot, absolutePathToFile);
foreach (var file in fileHashes) { string fileHash = file.Value;
string absolutePathToFile = file.Key;
string fileName = Path.GetFileName(absolutePathToFile); if (checkIfFileMovedAndUpdatePathToFile(fileHash, fileName, pathToFile) == false && checkIfFileAlreadyExistsInDatabase(fileHash, fileName) == false) {
string pathToFile = Path.GetRelativePath(DatabaseRoot, absolutePathToFile); connection.Open();
string fileHash = file.Value;
var command = connection.CreateCommand();
if (checkIfFileMovedAndUpdatePathToFile(fileHash, fileName, pathToFile) == false && checkIfFileAlreadyExistsInDatabase(fileHash, fileName) == false) { command.CommandText =
var command = connection.CreateCommand(); @"
command.CommandText = INSERT INTO file (filehash, filename, pathtofile)
@" VALUES ($filehash, $filename, $pathtofile)
INSERT INTO file (filehash, filename, pathtofile) ";
VALUES ($filehash, $filename, $pathtofile) command.Parameters.AddWithValue("$filehash", fileHash);
"; command.Parameters.AddWithValue("$filename", fileName);
command.Parameters.AddWithValue("$filehash", fileHash); command.Parameters.AddWithValue("$pathtofile", pathToFile);
command.Parameters.AddWithValue("$filename", fileName); command.ExecuteNonQuery();
command.Parameters.AddWithValue("$pathtofile", pathToFile); }
command.ExecuteNonQuery();
} }
} }
} }
@ -185,8 +184,8 @@ public class ChksumUtils {
Console.WriteLine($"\tto \t{pathtofile}\n"); Console.WriteLine($"\tto \t{pathtofile}\n");
wasMoved = true; wasMoved = true;
} }
return wasMoved;
} }
return wasMoved;
} }
public void checkIfFileWasDeleted() { public void checkIfFileWasDeleted() {
@ -205,20 +204,19 @@ public class ChksumUtils {
while (reader.Read()) { while (reader.Read()) {
pathToFile = reader.GetString(0); pathToFile = reader.GetString(0);
if (File.Exists(pathToFile)) { if (!File.Exists(pathToFile)) {
continue; var deleteCommand = connection.CreateCommand();
} deleteCommand.CommandText =
var deleteCommand = connection.CreateCommand(); @"
deleteCommand.CommandText = DELETE FROM file
@" WHERE pathtofile = $pathtofile
DELETE FROM file ";
WHERE pathtofile = $pathtofile deleteCommand.Parameters.AddWithValue("$pathtofile", pathToFile);
"; deleteCommand.ExecuteNonQuery();
deleteCommand.Parameters.AddWithValue("$pathtofile", pathToFile);
deleteCommand.ExecuteNonQuery();
Console.WriteLine("File deleted:"); Console.WriteLine("File deleted:");
Console.WriteLine($"\t{pathToFile}\n"); Console.WriteLine($"\t{pathToFile}\n");
}
} }
} }
} }