private string last = string.Empty;
private void Watcher_Changes(object sender, FileSystemEventArgs e) {
try {
var info = new FileInfo(e.FullPath);
var size = info.Length;
string output = $ "[*] {e.ChangeType}: \"{e.FullPath}\": \"{size}\"";
if (last.Equals(output))
return;
Println(output);
last = output;
} catch (Exception ex) {
PrintErr(ex);
}
}
Now i'm just showing the file size either if changed or not. but i want that only if the file size has changed then show the size in the output string :
string output = $"[*] {e.ChangeType}: \"{e.FullPath}\": \"{size}\"";
What i'm trying to do is to use MD5 but not sure how to use it next. This is what i did so far.
I added a new method :
private byte[] CheckSize(string filename)
{
using (MD5 md5 = MD5.Create())
{
using (var stream = File.OpenRead(filename))
{
return md5.ComputeHash(stream);
}
}
}
Then in the changes event :
byte[] checkedsize = CheckSize(e.FullPath);
but not sure what to do with the byte array next ?
private void Watcher_Changes(object sender, FileSystemEventArgs e)
{
try
{
var info = new FileInfo(e.FullPath);
var size = info.Length;
byte[] checkedsize = CheckSize(e.FullPath);
string output = $"[*] {e.ChangeType}: \"{e.FullPath}\": \"{size}\"";
if (last.Equals(output))
return;
Println(output);
last = output;
}
catch (Exception ex)
{
PrintErr(ex);
}
}