parent
a6c994fa65
commit
f99ca8bb26
@ -1,4 +1,4 @@
|
|||||||
public class Program {
|
public class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
@ -11,8 +11,6 @@ public class Program {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Chksum.getBaseDir();
|
|
||||||
|
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
switch (args[0]) {
|
switch (args[0]) {
|
||||||
case "checksum":
|
case "checksum":
|
||||||
@ -48,9 +46,6 @@ public class Program {
|
|||||||
|
|
||||||
Chksum.compareChecksums();
|
Chksum.compareChecksums();
|
||||||
break;
|
break;
|
||||||
case "createDB":
|
|
||||||
Chksum.initializeDB();
|
|
||||||
break;
|
|
||||||
case "help":
|
case "help":
|
||||||
PrintAvailableOptions();
|
PrintAvailableOptions();
|
||||||
break;
|
break;
|
||||||
@ -68,7 +63,6 @@ public class Program {
|
|||||||
"countmd5",
|
"countmd5",
|
||||||
"deletemd5",
|
"deletemd5",
|
||||||
"compareChecksums",
|
"compareChecksums",
|
||||||
"createDB",
|
|
||||||
"help"
|
"help"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
49
chksum.cs
49
chksum.cs
@ -1,10 +1,7 @@
|
|||||||
using Microsoft.Data.Sqlite;
|
|
||||||
|
|
||||||
// Go into folder
|
// Go into folder
|
||||||
// Check if any file is in there
|
// Check if any file is in there
|
||||||
// If there is a file. Calculate md5sum > filename.md5
|
// If there is a file. Calculate md5sum > filename.md5
|
||||||
// If there is no file. Repeat
|
// If there is no file. Repeat
|
||||||
|
|
||||||
public class Chksum {
|
public class Chksum {
|
||||||
|
|
||||||
// int getDirectoryCount() {
|
// int getDirectoryCount() {
|
||||||
@ -22,30 +19,6 @@ public class Chksum {
|
|||||||
// return parentFolder;
|
// return parentFolder;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public static string DatabaseRoot { get; set; }
|
|
||||||
public static void getBaseDir() {
|
|
||||||
DatabaseRoot = AppDomain.CurrentDomain.BaseDirectory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initializeDB() {
|
|
||||||
using (var connection = new SqliteConnection("Data Source=chksum.db")) {
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
var command = connection.CreateCommand();
|
|
||||||
command.CommandText =
|
|
||||||
@"
|
|
||||||
CREATE TABLE file (
|
|
||||||
filehash TEXT NOT NULL PRIMARY KEY,
|
|
||||||
filename TEXT NOT NULL,
|
|
||||||
pathtofile TEXT NOT NULL,
|
|
||||||
artist TEXT,
|
|
||||||
playbacklength INTEGER
|
|
||||||
);
|
|
||||||
";
|
|
||||||
command.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string CalculateMD5(string filename) {
|
private static string CalculateMD5(string filename) {
|
||||||
using (var md5 = System.Security.Cryptography.MD5.Create()) {
|
using (var md5 = System.Security.Cryptography.MD5.Create()) {
|
||||||
using (var stream = File.OpenRead(filename)) {
|
using (var stream = File.OpenRead(filename)) {
|
||||||
@ -63,24 +36,10 @@ public class Chksum {
|
|||||||
FileInfo[] files = dir.GetFiles();
|
FileInfo[] files = dir.GetFiles();
|
||||||
foreach (FileInfo file in files) {
|
foreach (FileInfo file in files) {
|
||||||
string fileName = file.Name;
|
string fileName = file.Name;
|
||||||
string absolutePathToFile = Path.GetFullPath(fileName);
|
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
|
||||||
string pathToFile = Path.GetRelativePath(DatabaseRoot, absolutePathToFile);
|
string checksumFile = Directory.GetCurrentDirectory() + "/" + fileNameWithoutExtension + ".md5";
|
||||||
string fileHash = CalculateMD5(fileName);
|
File.AppendAllText(checksumFile, CalculateMD5(fileName) + " " + fileName);
|
||||||
|
Console.WriteLine(checksumFile);
|
||||||
using (var connection = new SqliteConnection("Data Source=" + DatabaseRoot + "chksum.db;Mode=ReadWrite")) {
|
|
||||||
connection.Open();
|
|
||||||
|
|
||||||
var command = connection.CreateCommand();
|
|
||||||
command.CommandText =
|
|
||||||
@"
|
|
||||||
INSERT INTO file (filehash, filename, pathtofile)
|
|
||||||
VALUES ($filehash, $filename, $pathtofile)
|
|
||||||
";
|
|
||||||
command.Parameters.AddWithValue("$filehash", fileHash);
|
|
||||||
command.Parameters.AddWithValue("$filename", fileName);
|
|
||||||
command.Parameters.AddWithValue("$pathtofile", pathToFile);
|
|
||||||
command.ExecuteNonQuery();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
doTheThing();
|
doTheThing();
|
||||||
|
@ -11,8 +11,4 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Data.Sqlite" Version="7.0.8" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
Loading…
Reference in New Issue
Block a user