mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-15 04:14:15 +01:00
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:
parent
c0de781421
commit
da2b2701e8
12 changed files with 379 additions and 232 deletions
|
|
@ -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("-", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue