Files
ClubPenguinClient/MareSynchronos/Factories/FileCacheFactory.cs
Stanley Dimant da2b2701e8 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
2022-06-14 21:53:41 +02:00

29 lines
836 B
C#

using System.IO;
using MareSynchronos.FileCacheDB;
using MareSynchronos.Utils;
namespace MareSynchronos.Factories
{
public class FileCacheFactory
{
public FileCache Create(string file)
{
FileInfo fileInfo = new(file);
string sha1Hash = Crypto.GetFileHash(fileInfo.FullName);
return new FileCache()
{
Filepath = fileInfo.FullName,
Hash = sha1Hash,
LastModifiedDate = fileInfo.LastWriteTimeUtc.Ticks.ToString(),
};
}
public void UpdateFileCache(FileCache cache)
{
FileInfo fileInfo = new(cache.Filepath);
cache.Hash = Crypto.GetFileHash(cache.Filepath);
cache.LastModifiedDate = fileInfo.LastWriteTimeUtc.Ticks.ToString();
}
}
}