experimental first iteration of persistent transient resources on startup
This commit is contained in:
@@ -5,16 +5,20 @@ using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using System.Text.RegularExpressions;
|
||||
using MareSynchronos.FileCache;
|
||||
using MareSynchronos.Managers;
|
||||
using System;
|
||||
|
||||
namespace MareSynchronos.Models;
|
||||
|
||||
public class FileReplacement
|
||||
{
|
||||
private readonly FileCacheManager fileDbManager;
|
||||
private readonly IpcManager ipcManager;
|
||||
|
||||
public FileReplacement(FileCacheManager fileDbManager)
|
||||
public FileReplacement(FileCacheManager fileDbManager, IpcManager ipcManager)
|
||||
{
|
||||
this.fileDbManager = fileDbManager;
|
||||
this.ipcManager = ipcManager;
|
||||
}
|
||||
|
||||
public bool Computed => IsFileSwap || !HasFileReplacement || !string.IsNullOrEmpty(Hash);
|
||||
@@ -29,7 +33,7 @@ public class FileReplacement
|
||||
|
||||
public string ResolvedPath { get; set; } = string.Empty;
|
||||
|
||||
public void SetResolvedPath(string path)
|
||||
private void SetResolvedPath(string path)
|
||||
{
|
||||
ResolvedPath = path.ToLowerInvariant().Replace('\\', '/');
|
||||
if (!HasFileReplacement || IsFileSwap) return;
|
||||
@@ -43,10 +47,18 @@ public class FileReplacement
|
||||
|
||||
public bool Verify()
|
||||
{
|
||||
var cache = fileDbManager.GetFileCacheByPath(ResolvedPath);
|
||||
if (cache == null) return false;
|
||||
Hash = cache.Hash;
|
||||
return true;
|
||||
if (!IsFileSwap)
|
||||
{
|
||||
var cache = fileDbManager.GetFileCacheByPath(ResolvedPath);
|
||||
if (cache == null) return false;
|
||||
Hash = cache.Hash;
|
||||
return true;
|
||||
}
|
||||
|
||||
var resolvedPath = fileDbManager.ResolveFileReplacement(GamePaths.First());
|
||||
ResolvedPath = resolvedPath.ToLowerInvariant();
|
||||
|
||||
return IsFileSwap;
|
||||
}
|
||||
|
||||
public FileReplacementDto ToFileReplacementDto()
|
||||
@@ -58,10 +70,23 @@ public class FileReplacement
|
||||
FileSwapPath = IsFileSwap ? ResolvedPath : string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
builder.AppendLine($"Modded: {HasFileReplacement} - {string.Join(",", GamePaths)} => {ResolvedPath}");
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
internal void ReverseResolvePath(string path)
|
||||
{
|
||||
GamePaths = ipcManager.PenumbraReverseResolvePlayer(path).ToList();
|
||||
SetResolvedPath(path);
|
||||
}
|
||||
|
||||
internal void ResolvePath(string path)
|
||||
{
|
||||
GamePaths = new List<string> { path };
|
||||
SetResolvedPath(ipcManager.PenumbraResolvePath(path));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user