I should actually be working
This commit is contained in:
@@ -1,21 +1,29 @@
|
||||
using System;
|
||||
using Dalamud.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using MareSynchronos.FileCacheDB;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
{
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class FileReplacement
|
||||
{
|
||||
private readonly string penumbraDirectory;
|
||||
|
||||
[JsonProperty]
|
||||
public string GamePath { get; private set; }
|
||||
public string ReplacedPath { get; private set; } = string.Empty;
|
||||
|
||||
public string ResolvedPath { get; private set; } = string.Empty;
|
||||
[JsonProperty]
|
||||
public string Hash { get; set; } = string.Empty;
|
||||
public bool IsInUse { get; set; } = false;
|
||||
public List<FileReplacement> Associated { get; set; } = new List<FileReplacement>();
|
||||
|
||||
public bool HasFileReplacement => GamePath != ReplacedPath;
|
||||
[JsonProperty]
|
||||
public string ImcData { get; set; } = string.Empty;
|
||||
public bool HasFileReplacement => GamePath != ResolvedPath;
|
||||
public FileReplacement(string gamePath, string penumbraDirectory)
|
||||
{
|
||||
GamePath = gamePath;
|
||||
@@ -24,6 +32,8 @@ namespace MareSynchronos.Models
|
||||
|
||||
public void AddAssociated(FileReplacement fileReplacement)
|
||||
{
|
||||
fileReplacement.IsInUse = true;
|
||||
|
||||
if (!Associated.Any(a => a.IsReplacedByThis(fileReplacement)))
|
||||
{
|
||||
Associated.Add(fileReplacement);
|
||||
@@ -35,31 +45,40 @@ namespace MareSynchronos.Models
|
||||
GamePath = path;
|
||||
}
|
||||
|
||||
public void SetReplacedPath(string path)
|
||||
public void SetResolvedPath(string path)
|
||||
{
|
||||
ReplacedPath = path.ToLower().Replace('/', '\\').Replace(penumbraDirectory, "").Replace('\\', '/');
|
||||
ResolvedPath = path.ToLower().Replace('/', '\\').Replace(penumbraDirectory, "").Replace('\\', '/');
|
||||
if (!HasFileReplacement) return;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
using FileCacheContext db = new FileCacheContext();
|
||||
var fileCache = db.FileCaches.SingleOrDefault(f => f.Filepath == path.ToLower());
|
||||
if (fileCache != null)
|
||||
Hash = fileCache.Hash;
|
||||
});
|
||||
}
|
||||
|
||||
public bool IsReplacedByThis(string path)
|
||||
{
|
||||
return GamePath.ToLower() == path.ToLower() || ReplacedPath.ToLower() == path.ToLower();
|
||||
return GamePath.ToLower() == path.ToLower() || ResolvedPath.ToLower() == path.ToLower();
|
||||
}
|
||||
|
||||
public bool IsReplacedByThis(FileReplacement replacement)
|
||||
{
|
||||
return IsReplacedByThis(replacement.GamePath) || IsReplacedByThis(replacement.ReplacedPath);
|
||||
return IsReplacedByThis(replacement.GamePath) || IsReplacedByThis(replacement.ResolvedPath);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.AppendLine($"Modded: {HasFileReplacement} - {GamePath} => {ReplacedPath}");
|
||||
builder.AppendLine($"Modded: {HasFileReplacement} - {GamePath} => {ResolvedPath}");
|
||||
foreach (var l1 in Associated)
|
||||
{
|
||||
builder.AppendLine($" + Modded: {l1.HasFileReplacement} - {l1.GamePath} => {l1.ReplacedPath}");
|
||||
builder.AppendLine($" + Modded: {l1.HasFileReplacement} - {l1.GamePath} => {l1.ResolvedPath}");
|
||||
foreach (var l2 in l1.Associated)
|
||||
{
|
||||
builder.AppendLine($" + Modded: {l2.HasFileReplacement} - {l2.GamePath} => {l2.ReplacedPath}");
|
||||
builder.AppendLine($" + Modded: {l2.HasFileReplacement} - {l2.GamePath} => {l2.ResolvedPath}");
|
||||
}
|
||||
}
|
||||
return builder.ToString();
|
||||
|
||||
Reference in New Issue
Block a user