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,36 +1,34 @@
using Dalamud.Game.ClientState;
using Dalamud.Plugin;
using Dalamud.Plugin.Ipc;
using MareSynchronos.FileCacheDB;
using MareSynchronos.Managers;
using MareSynchronos.Models;
namespace MareSynchronos.Factories
{
public class FileReplacementFactory
{
private readonly IpcManager ipcManager;
private readonly ClientState clientState;
private ICallGateSubscriber<string, string, string> resolvePath;
private string penumbraDirectory;
public FileReplacementFactory(DalamudPluginInterface pluginInterface, ClientState clientState)
public FileReplacementFactory(IpcManager ipcManager, ClientState clientState)
{
resolvePath = pluginInterface.GetIpcSubscriber<string, string, string>("Penumbra.ResolveCharacterPath");
penumbraDirectory = pluginInterface.GetIpcSubscriber<string>("Penumbra.GetModDirectory").InvokeFunc().ToLower() + '\\';
this.ipcManager = ipcManager;
this.clientState = clientState;
}
public FileReplacement Create(string gamePath, bool resolve = true)
{
var fileReplacement = new FileReplacement(gamePath, penumbraDirectory);
var fileReplacement = new FileReplacement(gamePath, ipcManager.PenumbraModDirectory()!);
if (!resolve) return fileReplacement;
fileReplacement.SetResolvedPath(resolvePath.InvokeFunc(gamePath, clientState.LocalPlayer!.Name.ToString()));
string playerName = clientState.LocalPlayer!.Name.ToString();
fileReplacement.SetResolvedPath(ipcManager.PenumbraResolvePath(gamePath, playerName)!);
if (!fileReplacement.HasFileReplacement)
{
// try to resolve path with --filename instead?
string[] tempGamePath = gamePath.Split('/');
tempGamePath[tempGamePath.Length - 1] = "--" + tempGamePath[tempGamePath.Length - 1];
string newTempGamePath = string.Join('/', tempGamePath);
var resolvedPath = resolvePath.InvokeFunc(newTempGamePath, clientState.LocalPlayer!.Name.ToString());
var resolvedPath = ipcManager.PenumbraResolvePath(newTempGamePath, playerName)!;
if (resolvedPath != newTempGamePath)
{
fileReplacement.SetResolvedPath(resolvedPath);