add fileswaps first test

This commit is contained in:
Stanley Dimant
2022-09-04 21:17:52 +02:00
parent 2f5159cd4b
commit ddb762c698
10 changed files with 77 additions and 31 deletions

View File

@@ -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()