Compare commits
4 Commits
7f6f4c5253
...
787721381d
Author | SHA1 | Date | |
---|---|---|---|
787721381d | |||
7d7e9bac6c | |||
2b4019d7cf | |||
be8180a60d |
@ -91,8 +91,12 @@ 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;
|
||||||
|
}
|
||||||
|
connection.Open();
|
||||||
Dictionary<string, string> fileHashes = CalculateChecksums(indexFiles());
|
Dictionary<string, string> fileHashes = CalculateChecksums(indexFiles());
|
||||||
|
|
||||||
foreach (var file in fileHashes) {
|
foreach (var file in fileHashes) {
|
||||||
string absolutePathToFile = file.Key;
|
string absolutePathToFile = file.Key;
|
||||||
string fileName = Path.GetFileName(absolutePathToFile);
|
string fileName = Path.GetFileName(absolutePathToFile);
|
||||||
@ -100,8 +104,6 @@ public class ChksumUtils {
|
|||||||
string fileHash = file.Value;
|
string fileHash = file.Value;
|
||||||
|
|
||||||
if (checkIfFileMovedAndUpdatePathToFile(fileHash, fileName, pathToFile) == false && checkIfFileAlreadyExistsInDatabase(fileHash, fileName) == false) {
|
if (checkIfFileMovedAndUpdatePathToFile(fileHash, fileName, pathToFile) == false && checkIfFileAlreadyExistsInDatabase(fileHash, fileName) == false) {
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
command.CommandText =
|
command.CommandText =
|
||||||
@"
|
@"
|
||||||
@ -116,7 +118,6 @@ public class ChksumUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private bool checkIfFileAlreadyExistsInDatabase(string fileHash, string pathToFile) {
|
private bool checkIfFileAlreadyExistsInDatabase(string fileHash, string pathToFile) {
|
||||||
string filehash = string.Empty;
|
string filehash = string.Empty;
|
||||||
@ -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,7 +205,9 @@ 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();
|
var deleteCommand = connection.CreateCommand();
|
||||||
deleteCommand.CommandText =
|
deleteCommand.CommandText =
|
||||||
@"
|
@"
|
||||||
@ -220,7 +223,6 @@ public class ChksumUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private List<string> getFilehashesFromDatabase(string connectionString) {
|
private List<string> getFilehashesFromDatabase(string connectionString) {
|
||||||
List<string> filehashesFromDatabase = new List<string>();
|
List<string> filehashesFromDatabase = new List<string>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user