mirror of
https://github.com/n00mkrad/flowframes.git
synced 2025-12-16 16:37:48 +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.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Flowframes.Data
|
namespace Flowframes.Data
|
||||||
@@ -8,6 +10,16 @@ namespace Flowframes.Data
|
|||||||
{
|
{
|
||||||
public static string GetHash(string path, bool b64 = true)
|
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);
|
var file = new FileInfo(path);
|
||||||
string hash = $"{file.Name}{file.Length}{file.LastWriteTime.ToString("yyyyMMddHHmmss")}";
|
string hash = $"{file.Name}{file.Length}{file.LastWriteTime.ToString("yyyyMMddHHmmss")}";
|
||||||
return b64 ? Convert.ToBase64String(Encoding.UTF8.GetBytes(hash)).TrimEnd('=') : hash;
|
return b64 ? Convert.ToBase64String(Encoding.UTF8.GetBytes(hash)).TrimEnd('=') : hash;
|
||||||
|
|||||||
Reference in New Issue
Block a user