Refactor getFilehashesFromDatabase

This commit is contained in:
ProfessionalUwU 2023-06-26 18:20:47 +02:00
parent 944b61a1ac
commit 836b850f3f
Signed by: ProfessionalUwU
GPG Key ID: 9F28CB1645C4BFB5

View File

@ -208,9 +208,10 @@ public class ChksumUtils {
}
}
private List<string> getFilehashesOfOriginDatabase() {
List<string> filehashesOfOriginDatabase = new List<string>();
using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadOnly")) {
private List<string> getFilehashesFromDatabase(string connectionString) {
List<string> filehashesFromDatabase = new List<string>();
using (var connection = new SqliteConnection(connectionString)) {
string filehash = string.Empty;
connection.Open();
@ -224,40 +225,16 @@ public class ChksumUtils {
using (var reader = selectCommand.ExecuteReader()) {
while (reader.Read()) {
filehash = reader.GetString(0);
filehashesOfOriginDatabase.Add(filehash);
filehashesFromDatabase.Add(filehash);
}
}
}
return filehashesOfOriginDatabase;
}
private List<string> getFilehashesOfRemoteDatabase(string filePathToOtherDatabase) {
List<string> filehashesOfRemoteDatabase = new List<string>();
using (var connection = new SqliteConnection("Data Source=" + filePathToOtherDatabase + ";Mode=ReadOnly")) {
string filehash = string.Empty;
connection.Open();
var selectCommand = connection.CreateCommand();
selectCommand.CommandText =
@"
Select filehash FROM file
";
using (var reader = selectCommand.ExecuteReader()) {
while (reader.Read()) {
filehash = reader.GetString(0);
filehashesOfRemoteDatabase.Add(filehash);
}
}
}
return filehashesOfRemoteDatabase;
return filehashesFromDatabase;
}
public void compareDatabases(string filePathToOtherDatabase) {
List<string> filesThatDoNotExistsInTheRemote = getFilehashesOfOriginDatabase().Except(getFilehashesOfRemoteDatabase(filePathToOtherDatabase)).ToList();
List<string> filesThatDoNotExistsInTheRemote = getFilehashesFromDatabase("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadOnly").Except(getFilehashesFromDatabase("Data Source=" + filePathToOtherDatabase + ";Mode=ReadOnly")).ToList();
//List<string> filesThatDoNotExistsInTheOrigin = filehashesOfRemoteDatabase.Except(filehashesOfOriginDatabase).ToList();
foreach (string file in filesThatDoNotExistsInTheRemote) {