potentially fix pets and summons
This commit is contained in:
@@ -49,7 +49,7 @@ namespace MareSynchronos.Managers
|
||||
|
||||
public string WatchedPenumbraDirectory => (_penumbraDirWatcher?.EnableRaisingEvents ?? false) ? _penumbraDirWatcher!.Path : "Not watched";
|
||||
|
||||
public FileCache? Create(string file, CancellationToken token)
|
||||
public FileCache? Create(string file, CancellationToken? token)
|
||||
{
|
||||
FileInfo fileInfo = new(file);
|
||||
int attempt = 0;
|
||||
@@ -57,7 +57,7 @@ namespace MareSynchronos.Managers
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
Logger.Debug("Waiting for file release " + fileInfo.FullName + " attempt " + attempt);
|
||||
token.ThrowIfCancellationRequested();
|
||||
token?.ThrowIfCancellationRequested();
|
||||
}
|
||||
|
||||
if (attempt >= 10) return null;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.FileCacheDB;
|
||||
using MareSynchronos.Models;
|
||||
using MareSynchronos.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MareSynchronos.Managers
|
||||
{
|
||||
@@ -15,16 +14,26 @@ namespace MareSynchronos.Managers
|
||||
{
|
||||
private readonly IpcManager manager;
|
||||
private readonly DalamudUtil dalamudUtil;
|
||||
|
||||
public event TransientResourceLoadedEvent? TransientResourceLoaded;
|
||||
|
||||
private Dictionary<IntPtr, HashSet<string>> TransientResources { get; } = new();
|
||||
private Dictionary<ObjectKind, HashSet<string>> SemiTransientResources { get; } = new();
|
||||
private Dictionary<ObjectKind, HashSet<FileReplacement>> SemiTransientResources { get; } = new();
|
||||
public TransientResourceManager(IpcManager manager, DalamudUtil dalamudUtil)
|
||||
{
|
||||
manager.PenumbraResourceLoadEvent += Manager_PenumbraResourceLoadEvent;
|
||||
this.manager = manager;
|
||||
this.dalamudUtil = dalamudUtil;
|
||||
dalamudUtil.FrameworkUpdate += DalamudUtil_FrameworkUpdate;
|
||||
dalamudUtil.ClassJobChanged += DalamudUtil_ClassJobChanged;
|
||||
}
|
||||
|
||||
private void DalamudUtil_ClassJobChanged()
|
||||
{
|
||||
if (SemiTransientResources.ContainsKey(ObjectKind.Pet))
|
||||
{
|
||||
SemiTransientResources[ObjectKind.Pet].Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void DalamudUtil_FrameworkUpdate()
|
||||
@@ -57,14 +66,14 @@ namespace MareSynchronos.Managers
|
||||
return new List<string>();
|
||||
}
|
||||
|
||||
public List<string> GetSemiTransientResources(ObjectKind objectKind)
|
||||
public List<FileReplacement> GetSemiTransientResources(ObjectKind objectKind)
|
||||
{
|
||||
if (SemiTransientResources.TryGetValue(objectKind, out var result))
|
||||
{
|
||||
return result.ToList();
|
||||
}
|
||||
|
||||
return new List<string>();
|
||||
return new List<FileReplacement>();
|
||||
}
|
||||
|
||||
private void Manager_PenumbraResourceLoadEvent(IntPtr gameObject, string gamePath, string filePath)
|
||||
@@ -81,7 +90,7 @@ namespace MareSynchronos.Managers
|
||||
|
||||
var newPath = filePath.ToLowerInvariant().Replace("\\", "/");
|
||||
|
||||
if (filePath != gamePath && !TransientResources[gameObject].Contains(newPath) && !SemiTransientResources.Any(r => r.Value.Contains(newPath)))
|
||||
if (filePath != gamePath && !TransientResources[gameObject].Contains(newPath) && !SemiTransientResources.Any(r => r.Value.Any(f => f.ResolvedPath.ToLowerInvariant() == newPath.ToLowerInvariant())))
|
||||
{
|
||||
TransientResources[gameObject].Add(newPath);
|
||||
Logger.Debug($"Adding {filePath.ToLowerInvariant().Replace("\\", "/")} for {gameObject}");
|
||||
@@ -97,11 +106,11 @@ namespace MareSynchronos.Managers
|
||||
}
|
||||
}
|
||||
|
||||
public void PersistTransientResources(IntPtr gameObject, ObjectKind objectKind)
|
||||
public void PersistTransientResources(IntPtr gameObject, ObjectKind objectKind, Func<string, bool, FileReplacement> createFileReplacement)
|
||||
{
|
||||
if (!SemiTransientResources.ContainsKey(objectKind))
|
||||
{
|
||||
SemiTransientResources[objectKind] = new HashSet<string>();
|
||||
SemiTransientResources[objectKind] = new HashSet<FileReplacement>();
|
||||
}
|
||||
|
||||
if (!TransientResources.TryGetValue(gameObject, out var resources))
|
||||
@@ -113,7 +122,10 @@ namespace MareSynchronos.Managers
|
||||
Logger.Debug("Persisting " + transientResources.Count + " transient resources");
|
||||
foreach (var item in transientResources)
|
||||
{
|
||||
SemiTransientResources[objectKind].Add(item);
|
||||
if (!SemiTransientResources[objectKind].Any(f => f.ResolvedPath.ToLowerInvariant() == item.ToLowerInvariant()))
|
||||
{
|
||||
SemiTransientResources[objectKind].Add(createFileReplacement(item.ToLowerInvariant(), false));
|
||||
}
|
||||
}
|
||||
|
||||
TransientResources[gameObject].Clear();
|
||||
@@ -123,7 +135,21 @@ namespace MareSynchronos.Managers
|
||||
{
|
||||
dalamudUtil.FrameworkUpdate -= DalamudUtil_FrameworkUpdate;
|
||||
manager.PenumbraResourceLoadEvent -= Manager_PenumbraResourceLoadEvent;
|
||||
dalamudUtil.ClassJobChanged -= DalamudUtil_ClassJobChanged;
|
||||
TransientResources.Clear();
|
||||
}
|
||||
|
||||
internal void AddSemiTransientResource(ObjectKind objectKind, FileReplacement item)
|
||||
{
|
||||
if (!SemiTransientResources.ContainsKey(objectKind))
|
||||
{
|
||||
SemiTransientResources[objectKind] = new HashSet<FileReplacement>();
|
||||
}
|
||||
|
||||
if (!SemiTransientResources[objectKind].Any(f => f.ResolvedPath.ToLowerInvariant() == item.ResolvedPath.ToLowerInvariant()))
|
||||
{
|
||||
SemiTransientResources[objectKind].Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user