add fileswaps first test
This commit is contained in:
@@ -3,6 +3,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
@@ -39,16 +41,31 @@ namespace MareSynchronos.Models
|
||||
|
||||
public CharacterCacheDto ToCharacterCacheDto()
|
||||
{
|
||||
var fileReplacements = FileReplacements.ToDictionary(k => k.Key, k => k.Value.Where(f => f.HasFileReplacement && !f.IsFileSwap).GroupBy(f => f.Hash).Select(g =>
|
||||
{
|
||||
return new FileReplacementDto()
|
||||
{
|
||||
GamePaths = g.SelectMany(g => g.GamePaths).Distinct().ToArray(),
|
||||
Hash = g.First().Hash,
|
||||
};
|
||||
}).ToList());
|
||||
|
||||
Logger.Debug("Adding fileSwaps");
|
||||
foreach (var item in FileReplacements)
|
||||
{
|
||||
Logger.Debug("Checking fileSwaps for " + item.Key);
|
||||
var fileSwapsToAdd = item.Value.Where(f => f.IsFileSwap).Select(f => f.ToFileReplacementDto());
|
||||
Logger.Debug("Adding " + fileSwapsToAdd.Count() + " file swaps");
|
||||
foreach (var swap in fileSwapsToAdd)
|
||||
{
|
||||
Logger.Debug("Adding: " + swap.GamePaths.First() + ":" + swap.FileSwapPath);
|
||||
}
|
||||
fileReplacements[item.Key].AddRange(fileSwapsToAdd);
|
||||
}
|
||||
|
||||
return new CharacterCacheDto()
|
||||
{
|
||||
FileReplacements = FileReplacements.ToDictionary(k => k.Key, k => k.Value.Where(f => f.HasFileReplacement).GroupBy(f => f.Hash).Select(g =>
|
||||
{
|
||||
return new FileReplacementDto()
|
||||
{
|
||||
GamePaths = g.SelectMany(g => g.GamePaths).Distinct().ToArray(),
|
||||
Hash = g.First().Hash
|
||||
};
|
||||
}).ToList()),
|
||||
FileReplacements = fileReplacements,
|
||||
GlamourerData = GlamourerString.ToDictionary(d => d.Key, d => d.Value),
|
||||
ManipulationData = ManipulationString
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ using MareSynchronos.FileCacheDB;
|
||||
using System.IO;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
@@ -20,12 +21,14 @@ namespace MareSynchronos.Models
|
||||
_penumbraDirectory = penumbraDirectory;
|
||||
}
|
||||
|
||||
public bool Computed => !HasFileReplacement || !string.IsNullOrEmpty(Hash);
|
||||
public bool Computed => IsFileSwap || !HasFileReplacement || !string.IsNullOrEmpty(Hash);
|
||||
|
||||
public List<string> GamePaths { get; set; } = new();
|
||||
|
||||
public bool HasFileReplacement => GamePaths.Count >= 1 && GamePaths.Any(p => p != ResolvedPath);
|
||||
|
||||
public bool IsFileSwap => !Regex.IsMatch(ResolvedPath, @"^[a-zA-Z]:(/|\\)", RegexOptions.ECMAScript) && GamePaths.First() != ResolvedPath;
|
||||
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
|
||||
public string ResolvedPath { get; set; } = string.Empty;
|
||||
@@ -33,7 +36,7 @@ namespace MareSynchronos.Models
|
||||
public void SetResolvedPath(string path)
|
||||
{
|
||||
ResolvedPath = path.ToLowerInvariant().Replace('/', '\\').Replace(_penumbraDirectory, "").Replace('\\', '/');
|
||||
if (!HasFileReplacement) return;
|
||||
if (!HasFileReplacement || IsFileSwap) return;
|
||||
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
@@ -73,6 +76,7 @@ namespace MareSynchronos.Models
|
||||
{
|
||||
GamePaths = GamePaths.ToArray(),
|
||||
Hash = Hash,
|
||||
FileSwapPath = IsFileSwap ? ResolvedPath : string.Empty
|
||||
};
|
||||
}
|
||||
public override string ToString()
|
||||
|
||||
Reference in New Issue
Block a user