IsChildOf function for AbsolutePath

Iterates up the parent directories to find if this path is a child of the given path.
This commit is contained in:
Unnoen 2021-05-20 18:05:08 +10:00
parent 8231d5252c
commit 8e39f9f4eb
No known key found for this signature in database
GPG Key ID: 8F8E42252BA20553

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@ -209,6 +209,21 @@ namespace Wabbajack.Common
return new RelativePath(relPath);
}
public bool IsChildOf(AbsolutePath? parent)
{
if (parent is null) return false;
var child = this;
if (child == parent) return true;
while (child.Parent.Exists)
{
if (child.Parent == parent)
{
return true;
}
child = child.Parent;
}
return false;
}
public async Task<string> ReadAllTextAsync()
{