6 using System.Text.RegularExpressions;
16 private static readonly Regex OtherModDirRegex =
new Regex(
23 private string? cachedValue;
24 private string? cachedFullPath;
30 if (
RawValue.IsNullOrEmpty()) {
return ""; }
31 if (!cachedValue.IsNullOrEmpty()) {
return cachedValue!; }
35 var otherMods = OtherModDirRegex.Matches(
RawValue ??
throw new NullReferenceException($
"{nameof(RawValue)} is null."))
36 .Select(m => m.Groups[1].Value.Trim().ToIdentifier())
37 .Distinct().Where(
id => !
id.IsEmpty &&
id != modName).ToHashSet();
42 cachedValue = cachedValue
43 .Replace(
ModDirStr, modPath, StringComparison.OrdinalIgnoreCase)
47 cachedValue = cachedValue
48 .Replace(
string.Format(
OtherModDirFmt, ugcId.StringRepresentation), modPath, StringComparison.OrdinalIgnoreCase);
51 var allPackages = ContentPackageManager.AllPackages;
55 foreach (Identifier otherModName
in otherMods)
59 allPackages.FirstOrDefault(p => ugcId.IsSome() && ugcId == p.UgcId)
60 ?? allPackages.FirstOrDefault(p => p.Name == otherModName)
61 ?? allPackages.FirstOrDefault(p => p.NameMatches(otherModName))
63 cachedValue = cachedValue.Replace(
string.Format(
OtherModDirFmt, otherModName.Value), Path.GetDirectoryName(otherMod.
Path));
65 cachedValue = cachedValue.CleanUpPath();
74 if (cachedFullPath.IsNullOrEmpty())
76 if (
Value.IsNullOrEmpty())
80 cachedFullPath = Path.GetFullPath(
Value).CleanUpPathCrossPlatform(correctFilenameCase:
false);
82 return cachedFullPath!;
91 cachedFullPath =
null;
101 var newRaw =
new ContentPath(contentPackage, rawValue);
102 if (prevCreatedRaw is not
null && prevCreatedRaw.
ContentPackage == contentPackage &&
103 prevCreatedRaw.
RawValue == rawValue)
105 newRaw.cachedValue = prevCreatedRaw.
Value;
107 prevCreatedRaw = newRaw;
111 private static bool StringEquality(
string? a,
string? b)
113 if (a.IsNullOrEmpty() || b.IsNullOrEmpty())
115 return a.IsNullOrEmpty() == b.IsNullOrEmpty();
117 return string.
Equals(Path.GetFullPath(a.CleanUpPathCrossPlatform(correctFilenameCase:
false) ??
""),
118 Path.GetFullPath(b.CleanUpPathCrossPlatform(correctFilenameCase:
false) ??
""), StringComparison.OrdinalIgnoreCase);
127 => StringEquality(a?.
Value, b);
132 => StringEquality(a, b?.
Value);
143 if (ReferenceEquals(
null, obj)) {
return false; }
144 if (ReferenceEquals(
this, obj)) {
return true; }
145 if (obj.GetType() !=
this.GetType()) {
return false; }
157 public bool EndsWith(
string suffix) =>
Value.EndsWith(suffix, StringComparison.OrdinalIgnoreCase);
readonly Option< ContentPackageId > UgcId
static Option< ContentPackageId > Parse(string s)
static bool operator!=(string? a, ContentPath b)
readonly? ContentPackage ContentPackage
override int GetHashCode()
const string OtherModDirFmt
static bool operator==(string? a, ContentPath b)
readonly? string RawValue
override? string ToString()
bool EndsWith(string suffix)
static ContentPath FromRaw(string? rawValue)
static readonly ContentPath Empty
static bool operator==(ContentPath a, ContentPath b)
static bool operator!=(ContentPath a, string? b)
bool IsPathNullOrWhiteSpace()
static bool operator==(ContentPath a, string? b)
override bool Equals(object? obj)
static ContentPath FromRaw(ContentPackage? contentPackage, string? rawValue)
bool Equals(ContentPath other)
static bool operator!=(ContentPath a, ContentPath b)
static ModDownloadScreen ModDownloadScreen
IEnumerable< ContentPackage > DownloadedPackages