(d9829ac) v0.9.4.0
This commit is contained in:
@@ -12,14 +12,7 @@ namespace Barotrauma
|
||||
{
|
||||
public static class XMLExtensions
|
||||
{
|
||||
public static string ParseContentPathFromUri(this XObject element)
|
||||
{
|
||||
string[] splitted = element.BaseUri.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar });
|
||||
string currentFolder = Environment.CurrentDirectory.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }).Last();
|
||||
// Filter out the current folder -> result is "Content/blaahblaah" or "Mods/blaahblaah" etc.
|
||||
IEnumerable<string> filtered = splitted.SkipWhile(part => part != currentFolder).Skip(1);
|
||||
return string.Join("/", filtered);
|
||||
}
|
||||
public static string ParseContentPathFromUri(this XObject element) => ToolBox.ConvertAbsoluteToRelativePath(element.BaseUri);
|
||||
|
||||
public static XDocument TryLoadXml(string filePath)
|
||||
{
|
||||
@@ -34,9 +27,11 @@ namespace Barotrauma
|
||||
DebugConsole.ThrowError("Couldn't load xml document \"" + filePath + "\"!", e);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (doc.Root == null) return null;
|
||||
|
||||
if (doc?.Root == null)
|
||||
{
|
||||
DebugConsole.ThrowError("File \"" + filePath + "\" could not be loaded: Document or the root element is invalid!");
|
||||
return null;
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
@@ -559,5 +554,19 @@ namespace Barotrauma
|
||||
|
||||
return floatArray;
|
||||
}
|
||||
|
||||
public static bool IsOverride(this XElement element) => element.Name.ToString().Equals("override", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
public static XElement FirstElement(this XElement element) => element.Elements().FirstOrDefault();
|
||||
|
||||
/// <summary>
|
||||
/// Returns the first child element that matches the name using the provided comparison method.
|
||||
/// </summary>
|
||||
public static XElement GetChildElement(this XContainer container, string name, StringComparison comparisonMethod = StringComparison.OrdinalIgnoreCase) => container.Elements().FirstOrDefault(e => e.Name.ToString().Equals(name, comparisonMethod));
|
||||
|
||||
/// <summary>
|
||||
/// Returns all child elements that match the name using the provided comparison method.
|
||||
/// </summary>
|
||||
public static IEnumerable<XElement> GetChildElements(this XContainer container, string name, StringComparison comparisonMethod = StringComparison.OrdinalIgnoreCase) => container.Elements().Where(e => e.Name.ToString().Equals(name, comparisonMethod));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user