actually start to bring structure into the project
make it resilent against restarts/reloads remove all user interaction for resource gathering compute hashes on first time file resolving and on updates of said file on resolving
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using MareSynchronos.FileCacheDB;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
using MareSynchronos.Utils;
|
||||
|
||||
namespace MareSynchronos.Factories
|
||||
{
|
||||
public class FileCacheFactory
|
||||
{
|
||||
public FileCacheFactory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public FileCache Create(string file)
|
||||
{
|
||||
FileInfo fileInfo = new(file);
|
||||
string sha1Hash = GetHash(fileInfo.FullName);
|
||||
string sha1Hash = Crypto.GetFileHash(fileInfo.FullName);
|
||||
return new FileCache()
|
||||
{
|
||||
Filepath = fileInfo.FullName,
|
||||
@@ -28,14 +21,8 @@ namespace MareSynchronos.Factories
|
||||
public void UpdateFileCache(FileCache cache)
|
||||
{
|
||||
FileInfo fileInfo = new(cache.Filepath);
|
||||
cache.Hash = GetHash(cache.Filepath);
|
||||
cache.Hash = Crypto.GetFileHash(cache.Filepath);
|
||||
cache.LastModifiedDate = fileInfo.LastWriteTimeUtc.Ticks.ToString();
|
||||
}
|
||||
|
||||
private string GetHash(string filePath)
|
||||
{
|
||||
using SHA1CryptoServiceProvider cryptoProvider = new();
|
||||
return BitConverter.ToString(cryptoProvider.ComputeHash(File.ReadAllBytes(filePath))).Replace("-", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user