mirror of
https://github.com/Caraxi/mare.client.git
synced 2025-12-12 20:17:22 +01:00
add api to mare, change all to file scoped namespace
This commit is contained in:
parent
b10a02f228
commit
ac6c46390c
27 changed files with 4436 additions and 4373 deletions
|
|
@ -6,55 +6,54 @@ using MareSynchronos.API;
|
|||
using System.Text.RegularExpressions;
|
||||
using MareSynchronos.FileCache;
|
||||
|
||||
namespace MareSynchronos.Models
|
||||
namespace MareSynchronos.Models;
|
||||
|
||||
public class FileReplacement
|
||||
{
|
||||
public class FileReplacement
|
||||
private readonly FileCacheManager fileDbManager;
|
||||
|
||||
public FileReplacement(FileCacheManager fileDbManager)
|
||||
{
|
||||
private readonly FileCacheManager fileDbManager;
|
||||
this.fileDbManager = fileDbManager;
|
||||
}
|
||||
|
||||
public FileReplacement(FileCacheManager fileDbManager)
|
||||
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;
|
||||
|
||||
public void SetResolvedPath(string path)
|
||||
{
|
||||
ResolvedPath = path.ToLowerInvariant().Replace('\\', '/');
|
||||
if (!HasFileReplacement || IsFileSwap) return;
|
||||
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
this.fileDbManager = fileDbManager;
|
||||
}
|
||||
var cache = fileDbManager.GetFileCacheByPath(ResolvedPath);
|
||||
Hash = cache.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;
|
||||
|
||||
public void SetResolvedPath(string path)
|
||||
public FileReplacementDto ToFileReplacementDto()
|
||||
{
|
||||
return new FileReplacementDto
|
||||
{
|
||||
ResolvedPath = path.ToLowerInvariant().Replace('\\', '/');
|
||||
if (!HasFileReplacement || IsFileSwap) return;
|
||||
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
var cache = fileDbManager.GetFileCacheByPath(ResolvedPath);
|
||||
Hash = cache.Hash;
|
||||
});
|
||||
}
|
||||
|
||||
public FileReplacementDto ToFileReplacementDto()
|
||||
{
|
||||
return new FileReplacementDto
|
||||
{
|
||||
GamePaths = GamePaths.ToArray(),
|
||||
Hash = Hash,
|
||||
FileSwapPath = IsFileSwap ? ResolvedPath : string.Empty
|
||||
};
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
builder.AppendLine($"Modded: {HasFileReplacement} - {string.Join(",", GamePaths)} => {ResolvedPath}");
|
||||
return builder.ToString();
|
||||
}
|
||||
GamePaths = GamePaths.ToArray(),
|
||||
Hash = Hash,
|
||||
FileSwapPath = IsFileSwap ? ResolvedPath : string.Empty
|
||||
};
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
builder.AppendLine($"Modded: {HasFileReplacement} - {string.Join(",", GamePaths)} => {ResolvedPath}");
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue