Compare commits
3 Commits
787721381d
...
v1.1.0
Author | SHA1 | Date | |
---|---|---|---|
1ee5114dab
|
|||
f403b77864
|
|||
42320ebf8d
|
@ -1,3 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using Microsoft.Data.Sqlite;
|
||||
@ -71,7 +72,7 @@ public class ChksumUtils {
|
||||
}
|
||||
|
||||
private Dictionary<string, string> CalculateChecksums(string[] filenames) {
|
||||
Dictionary<string, string> checksums = new Dictionary<string, string>();
|
||||
ConcurrentDictionary<string, string> checksums = new ConcurrentDictionary<string, string>();
|
||||
|
||||
Parallel.ForEach(filenames, (filename, state) => {
|
||||
using (var md5 = MD5.Create()) {
|
||||
@ -80,13 +81,13 @@ public class ChksumUtils {
|
||||
var checksum = BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
|
||||
|
||||
lock (checksums) {
|
||||
checksums.Add(filename, checksum);
|
||||
checksums.TryAdd(filename, checksum);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return checksums;
|
||||
return new Dictionary<string, string>(checksums);
|
||||
}
|
||||
|
||||
public void doTheThing() {
|
||||
@ -180,7 +181,7 @@ public class ChksumUtils {
|
||||
command2.Parameters.AddWithValue("$filehash", fileHash);
|
||||
command2.ExecuteNonQuery();
|
||||
|
||||
Console.WriteLine("File moved:");
|
||||
Console.WriteLine("File moved or is a duplicate:");
|
||||
Console.WriteLine($"\tfrom\t{pathToFile}");
|
||||
Console.WriteLine($"\tto \t{pathtofile}\n");
|
||||
wasMoved = true;
|
||||
@ -251,7 +252,6 @@ public class ChksumUtils {
|
||||
|
||||
public void compareDatabases(string filePathToOtherDatabase) {
|
||||
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) {
|
||||
using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadOnly")) {
|
||||
|
Reference in New Issue
Block a user