mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 03:30:53 +01:00
30 lines
1.1 KiB
C#
30 lines
1.1 KiB
C#
using System;
|
|
using System.IO;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Shared.ContentPack
|
|
{
|
|
public static class ResourceManagerExt
|
|
{
|
|
/// <summary>
|
|
/// Read a file from the mounted content roots, if it exists.
|
|
/// </summary>
|
|
/// <param name="res">The resource manager.</param>
|
|
/// <param name="path">The path to the file in the VFS. Must be rooted.</param>
|
|
/// <returns>The memory stream of the file, or null if the file does not exist.</returns>
|
|
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
|
|
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
|
|
/// <seealso cref="IResourceManager.ContentFileRead(ResPath)"/>
|
|
/// <seealso cref="IResourceManager.TryContentFileRead(ResPath, out Stream)"/>
|
|
public static Stream? ContentFileReadOrNull(this IResourceManager res, ResPath path)
|
|
{
|
|
if (res.TryContentFileRead(path, out var stream))
|
|
{
|
|
return stream;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|