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:
Stanley Dimant
2022-06-14 21:53:41 +02:00
parent c0de781421
commit da2b2701e8
12 changed files with 379 additions and 232 deletions

View File

@@ -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("-", "");
}
}
}