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