2025-06-28 22:34:47 +02:00
|
|
|
|
using Flowframes.IO;
|
|
|
|
|
|
using System;
|
2025-03-23 19:36:57 +01:00
|
|
|
|
using System.IO;
|
2025-06-28 22:34:47 +02:00
|
|
|
|
using System.Linq;
|
2025-03-23 19:36:57 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.Data
|
|
|
|
|
|
{
|
|
|
|
|
|
internal class PseudoHash
|
|
|
|
|
|
{
|
|
|
|
|
|
public static string GetHash(string path, bool b64 = true)
|
|
|
|
|
|
{
|
2025-06-28 22:34:47 +02:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-23 19:36:57 +01:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|