Compare commits
4 Commits
7f6f4c5253
...
787721381d
Author | SHA1 | Date | |
---|---|---|---|
787721381d | |||
7d7e9bac6c | |||
2b4019d7cf | |||
be8180a60d |
@ -91,28 +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) {
|
||||||
Dictionary<string, string> fileHashes = CalculateChecksums(indexFiles());
|
return;
|
||||||
foreach (var file in fileHashes) {
|
}
|
||||||
string absolutePathToFile = file.Key;
|
connection.Open();
|
||||||
string fileName = Path.GetFileName(absolutePathToFile);
|
Dictionary<string, string> fileHashes = CalculateChecksums(indexFiles());
|
||||||
string pathToFile = Path.GetRelativePath(DatabaseRoot, absolutePathToFile);
|
|
||||||
string fileHash = file.Value;
|
|
||||||
|
|
||||||
if (checkIfFileMovedAndUpdatePathToFile(fileHash, fileName, pathToFile) == false && checkIfFileAlreadyExistsInDatabase(fileHash, fileName) == false) {
|
foreach (var file in fileHashes) {
|
||||||
connection.Open();
|
string absolutePathToFile = file.Key;
|
||||||
|
string fileName = Path.GetFileName(absolutePathToFile);
|
||||||
|
string pathToFile = Path.GetRelativePath(DatabaseRoot, absolutePathToFile);
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -184,8 +185,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() {
|
||||||
@ -204,19 +205,20 @@ 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)) {
|
||||||
var deleteCommand = connection.CreateCommand();
|
continue;
|
||||||
deleteCommand.CommandText =
|
|
||||||
@"
|
|
||||||
DELETE FROM file
|
|
||||||
WHERE pathtofile = $pathtofile
|
|
||||||
";
|
|
||||||
deleteCommand.Parameters.AddWithValue("$pathtofile", pathToFile);
|
|
||||||
deleteCommand.ExecuteNonQuery();
|
|
||||||
|
|
||||||
Console.WriteLine("File deleted:");
|
|
||||||
Console.WriteLine($"\t{pathToFile}\n");
|
|
||||||
}
|
}
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user