Compare commits
2 Commits
8aec649781
...
b899c4c5b6
Author | SHA1 | Date | |
---|---|---|---|
b899c4c5b6 | |||
2d42842fb2 |
15
README.md
15
README.md
@ -39,19 +39,8 @@ Go to the publish folder
|
|||||||
cd src/Chksum/bin/Release/net7.0/linux-x64/publish
|
cd src/Chksum/bin/Release/net7.0/linux-x64/publish
|
||||||
```
|
```
|
||||||
|
|
||||||
Copy the libe_sqlite3.so to your /usr/local/lib or /usr/lib
|
|
||||||
```bash
|
|
||||||
cp libe_sqlite3.so /usr/local/lib
|
|
||||||
```
|
|
||||||
|
|
||||||
Run executable
|
Run executable
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
LD_LIBRARY_PATH=/usr/local/lib ./Chksum
|
./Chksum
|
||||||
```
|
```
|
||||||
|
|
||||||
Info
|
|
||||||
|
|
||||||
LD_LIBRARY_PATH=/usr/local/lib is needed to tell the executable where the library is located
|
|
||||||
|
|
||||||
Alternately you can put the libe_sqlite3.so into the same folder as the executable
|
|
@ -39,6 +39,10 @@ public class Program {
|
|||||||
case "createDB":
|
case "createDB":
|
||||||
utils.initializeDB();
|
utils.initializeDB();
|
||||||
break;
|
break;
|
||||||
|
case "checkIfFileWasDeleted":
|
||||||
|
Console.ResetColor();
|
||||||
|
utils.checkIfFileWasDeleted();
|
||||||
|
break;
|
||||||
case "help":
|
case "help":
|
||||||
PrintAvailableOptions();
|
PrintAvailableOptions();
|
||||||
break;
|
break;
|
||||||
@ -57,6 +61,7 @@ public class Program {
|
|||||||
"checksum",
|
"checksum",
|
||||||
"compareChecksums",
|
"compareChecksums",
|
||||||
"createDB",
|
"createDB",
|
||||||
|
"checkIfFileWasDeleted",
|
||||||
"help"
|
"help"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ public class ChksumUtils {
|
|||||||
string pathToFile = Path.GetRelativePath(DatabaseRoot, absolutePathToFile);
|
string pathToFile = Path.GetRelativePath(DatabaseRoot, absolutePathToFile);
|
||||||
string fileHash = CalculateMD5(fileName);
|
string fileHash = CalculateMD5(fileName);
|
||||||
|
|
||||||
if (checkIfFileMovedAndUpdatePathToFile(fileHash, fileName, pathToFile) == false && checkIfFileAlreadyExists(fileHash, fileName) == false) {
|
if (checkIfFileMovedAndUpdatePathToFile(fileHash, fileName, pathToFile) == false && checkIfFileAlreadyExistsInDatabase(fileHash, fileName) == false) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
@ -104,12 +104,12 @@ public class ChksumUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool checkIfFileAlreadyExists(string fileHash, string pathToFile) {
|
private bool checkIfFileAlreadyExistsInDatabase(string fileHash, string pathToFile) {
|
||||||
string filehash = string.Empty;
|
string filehash = string.Empty;
|
||||||
string pathtofile = string.Empty;
|
string pathtofile = string.Empty;
|
||||||
bool doesExist = false;
|
bool doesExist = false;
|
||||||
|
|
||||||
using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadWrite")) {
|
using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadOnly")) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
var command = connection.CreateCommand();
|
var command = connection.CreateCommand();
|
||||||
@ -128,9 +128,6 @@ public class ChksumUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fileHash == filehash) {
|
if (fileHash == filehash) {
|
||||||
Console.WriteLine("Duplicate files found:");
|
|
||||||
Console.WriteLine($"\toriginal\t{pathToFile}");
|
|
||||||
Console.WriteLine($"\tduplicate\t{pathtofile}\n");
|
|
||||||
doesExist = true;
|
doesExist = true;
|
||||||
}
|
}
|
||||||
return doesExist;
|
return doesExist;
|
||||||
@ -177,7 +174,41 @@ public class ChksumUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void compareChecksums() {
|
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())) {
|
foreach (var directory in Directory.GetDirectories(Directory.GetCurrentDirectory())) {
|
||||||
Directory.SetCurrentDirectory(directory); // Set new root
|
Directory.SetCurrentDirectory(directory); // Set new root
|
||||||
if (getFileCount() >= 1) {
|
if (getFileCount() >= 1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user