calculate and display local cache size on cache changes, add clear cache button

This commit is contained in:
Stanley Dimant
2022-06-24 18:53:56 +02:00
parent cc0af38b31
commit f8919abea8
7 changed files with 87 additions and 68 deletions

View File

@@ -1,6 +1,5 @@
using System.Diagnostics;
using System.Threading;
using Dalamud.Game.ClientState;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using FFXIVClientStructs.FFXIV.Client.System.Resource;

View File

@@ -1,48 +0,0 @@
using System;
using System.IO;
using System.Threading;
using MareSynchronos.FileCacheDB;
using MareSynchronos.Utils;
namespace MareSynchronos.Factories
{
public class FileCacheFactory
{
public FileCache Create(string file)
{
FileInfo fileInfo = new(file);
if (IsFileLocked(fileInfo))
{
throw new FileLoadException();
}
var 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();
}
private bool IsFileLocked(FileInfo file)
{
try
{
using var fs = file.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch
{
return true;
}
return false;
}
}
}