Files
ClubPenguinClient/MareSynchronos/PlayerData/Data/FileReplacement.cs
rootdarkarchon 14575a4a6b Mare 0.9 (#65)
* add jwt expiry

* start of 0.9 api impl

* some stuff idk

* some more impl

* some cleanup

* remove grouppair, add configuration, rework some pair drawing stuff

* do some stuff

* rework some ui

* I don't even know anymore

* add cancellationtoken

* token bla

* ui fixes etc

* probably individual adding/removing now working fully as expected

* add working report popup

* I guess it's more syncshell shit or so

* popup shit idk

* work out most of the syncshell bullshit I guess

* delete some old crap

* are we actually getting closer to the end

* update pair info stuff

* more fixes/adjustments, idk

* refactor some things

* some rework

* some more cleanup

* cleanup

* make menu buttons w i d e

* better icon text buttons

* add all syncshell folder and ordering fixes

---------

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
2023-10-17 21:36:44 +02:00

40 lines
1.3 KiB
C#

using MareSynchronos.API.Data;
using System.Text.RegularExpressions;
namespace MareSynchronos.PlayerData.Data;
public partial class FileReplacement
{
public FileReplacement(string[] gamePaths, string filePath)
{
GamePaths = gamePaths.Select(g => g.Replace('\\', '/').ToLowerInvariant()).ToHashSet(StringComparer.Ordinal);
ResolvedPath = filePath.Replace('\\', '/');
}
public HashSet<string> GamePaths { get; init; }
public bool HasFileReplacement => GamePaths.Count >= 1 && GamePaths.Any(p => !string.Equals(p, ResolvedPath, StringComparison.Ordinal));
public string Hash { get; set; } = string.Empty;
public bool IsFileSwap => !LocalPathRegex().IsMatch(ResolvedPath) && GamePaths.All(p => !LocalPathRegex().IsMatch(p));
public string ResolvedPath { get; init; }
public FileReplacementData ToFileReplacementDto()
{
return new FileReplacementData
{
GamePaths = [.. GamePaths],
Hash = Hash,
FileSwapPath = IsFileSwap ? ResolvedPath : string.Empty,
};
}
public override string ToString()
{
return $"HasReplacement:{HasFileReplacement},IsFileSwap:{IsFileSwap} - {string.Join(",", GamePaths)} => {ResolvedPath}";
}
[GeneratedRegex(@"^[a-zA-Z]:(/|\\)", RegexOptions.ECMAScript)]
private static partial Regex LocalPathRegex();
}