feature/multi-threading #2

Merged
ProfessionalUwU merged 10 commits from feature/multi-threading into main 2023-06-29 02:15:11 +02:00
Showing only changes of commit 787721381d - Show all commits

View File

@ -91,27 +91,29 @@ 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) {
connection.Open(); 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);
var command = connection.CreateCommand(); string fileHash = file.Value;
command.CommandText =
@" if (checkIfFileMovedAndUpdatePathToFile(fileHash, fileName, pathToFile) == false && checkIfFileAlreadyExistsInDatabase(fileHash, fileName) == false) {
INSERT INTO file (filehash, filename, pathtofile) var command = connection.CreateCommand();
VALUES ($filehash, $filename, $pathtofile) command.CommandText =
"; @"
command.Parameters.AddWithValue("$filehash", fileHash); INSERT INTO file (filehash, filename, pathtofile)
command.Parameters.AddWithValue("$filename", fileName); VALUES ($filehash, $filename, $pathtofile)
command.Parameters.AddWithValue("$pathtofile", pathToFile); ";
command.ExecuteNonQuery(); command.Parameters.AddWithValue("$filehash", fileHash);
} command.Parameters.AddWithValue("$filename", fileName);
command.Parameters.AddWithValue("$pathtofile", pathToFile);
command.ExecuteNonQuery();
} }
} }
} }