mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-15 16:07:45 +01:00
PseudoHash directory support
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using Flowframes.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Flowframes.Data
|
||||
@@ -8,6 +10,16 @@ namespace Flowframes.Data
|
||||
{
|
||||
public static string GetHash(string path, bool b64 = true)
|
||||
{
|
||||
bool isDir = Directory.Exists(path);
|
||||
|
||||
if (isDir)
|
||||
{
|
||||
var dir = new DirectoryInfo(path);
|
||||
var files = IoUtils.GetFileInfosSorted(path);
|
||||
string dirHash = $"{dir.Name}{files.Sum(f => f.Length)}{dir.LastWriteTime.ToString("yyyyMMddHHmmss")}";
|
||||
return b64 ? Convert.ToBase64String(Encoding.UTF8.GetBytes(dirHash)).TrimEnd('=') : dirHash;
|
||||
}
|
||||
|
||||
var file = new FileInfo(path);
|
||||
string hash = $"{file.Name}{file.Length}{file.LastWriteTime.ToString("yyyyMMddHHmmss")}";
|
||||
return b64 ? Convert.ToBase64String(Encoding.UTF8.GetBytes(hash)).TrimEnd('=') : hash;
|
||||
|
||||
Reference in New Issue
Block a user