Files
RobustToolbox/SS14.Shared/Interfaces/IResourceManager.cs
Pieter-Jan Briers d7414930ff RSI support (#552)
* RSI WiP

* More work but we're doing bsdiff now

* RSI loading seems to mostly work.

* Vector2u deserialization test.

* Add in packages again.

* This is the part where I realize I need a path manipulation library.

* The start of a path class but it's late so I'm going to bed.

* HIGHLY theoretical ResourcePath code.

Partially tested but not really.

* Allow x86 for unit tests I guess jesus christ.

Thanks Microsoft for still not shipping x64 VS in 2018.

* Resource paths work & are tested.

* I missed a doc spot.

* ResourcePaths implemented on the server.

* Client works with resource paths.

TIME FOR A REFACTOR.

* Some work but this might be a stupid idea so I migh throw it in the trash.

* Resources refactored completely.

They now only get the requested resourcepath.
They're in charge of opening files to load.

* RSI Loader WORKS.

* Update AudioResource for new loading support.

* Fix package references.

* Fix more references.

* Gonna work now?
2018-04-12 21:53:19 +02:00

134 lines
7.5 KiB
C#

using SS14.Shared.Utility;
using System;
using System.Collections.Generic;
using System.IO;
namespace SS14.Shared.Interfaces
{
/// <summary>
/// Virtual file system for all disk resources.
/// </summary>
public interface IResourceManager
{
/// <summary>
/// Sets the manager up so that the base game can run.
/// </summary>
void Initialize();
/// <summary>
/// Loads the default content pack from the configuration file into the VFS.
/// </summary>
void MountDefaultContentPack();
/// <summary>
/// Loads a content pack from disk into the VFS. The path is relative to
/// the executable location on disk.
/// </summary>
/// <param name="pack">The path of the pack to load on disk.</param>
/// <param name="prefix">The resource path to which all files in the pack will be relative to in the VFS.</param>
/// <exception cref="FileNotFoundException">Thrown if <paramref name="pack"/> does not exist on disk.</exception>
/// <exception cref="ArgumentException">Thrown if <paramref name="prefix"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="pack"/> is null.</exception>
void MountContentPack(string pack, ResourcePath prefix = null);
/// <summary>
/// Adds a directory to search inside of to the VFS. The directory is relative to
/// the executable location on disk.
/// </summary>
/// <param name="path">The path of the directory to add to the VFS on disk.</param>
/// <param name="prefix">The resource path to which all files in the directory will be relative to in the VFS.</param>
/// <exception cref="DirectoryNotFoundException">Thrown if <paramref name="path"/> does not exist on disk.</exception>
/// <exception cref="ArgumentException">Thrown if <paramref name="prefix"/> passed is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
void MountContentDirectory(string path, ResourcePath prefix = null);
/// <summary>
/// Read a file from the mounted content roots.
/// </summary>
/// <param name="path">The path to the file in the VFS. Must be rooted.</param>
/// <returns>The memory stream of the file.</returns>
/// <exception cref="FileNotFoundException">Thrown if <paramref name="path"/> does not exist in the VFS.</exception>
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
MemoryStream ContentFileRead(ResourcePath path);
/// <summary>
/// Read a file from the mounted content roots.
/// </summary>
/// <param name="path">The path to the file in the VFS. Must be rooted.</param>
/// <returns>The memory stream of the file.</returns>
/// <exception cref="FileNotFoundException">Thrown if <paramref name="path"/> does not exist in the VFS.</exception>
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
MemoryStream ContentFileRead(string path);
/// <summary>
/// Check if a file exists in any of the mounted content roots.
/// </summary>
/// <param name="path">The path of the file to check.</param>
/// <returns>True if the file exists, false otherwise.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
bool ContentFileExists(ResourcePath path);
/// <summary>
/// Check if a file exists in any of the mounted content roots.
/// </summary>
/// <param name="path">The path of the file to check.</param>
/// <returns>True if the file exists, false otherwise.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
bool ContentFileExists(string path);
/// <summary>
/// Try to read a file from the mounted content roots.
/// </summary>
/// <param name="path">The path of the file to try to read.</param>
/// <param name="fileStream">The memory stream of the file's contents. Null if the file could not be loaded.</param>
/// <returns>True if the file could be loaded, false otherwise.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
bool TryContentFileRead(ResourcePath path, out MemoryStream fileStream);
/// <summary>
/// Try to read a file from the mounted content roots.
/// </summary>
/// <param name="path">The path of the file to try to read.</param>
/// <param name="fileStream">The memory stream of the file's contents. Null if the file could not be loaded.</param>
/// <returns>True if the file could be loaded, false otherwise.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
bool TryContentFileRead(string path, out MemoryStream fileStream);
/// <summary>
/// Recursively finds all files in a directory and all sub directories.
/// </summary>
/// <remarks>
/// If the directory does not exist, an empty enumerable is returned.
/// </remarks>
/// <param name="path">Directory to search inside of.</param>
/// <returns>Enumeration of all relative file paths of the files found, that is they are relative to <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
IEnumerable<ResourcePath> ContentFindFiles(ResourcePath path);
/// <summary>
/// Recursively finds all files in a directory and all sub directories.
/// </summary>
/// <remarks>
/// If the directory does not exist, an empty enumerable is returned.
/// </remarks>
/// <param name="path">Directory to search inside of.</param>
/// <returns>Enumeration of all relative file paths of the files found, that is they are relative to <paramref name="path"/>.</returns>
/// <exception cref="ArgumentException">Thrown if <paramref name="path"/> is not rooted.</exception>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="path"/> is null.</exception>
IEnumerable<ResourcePath> ContentFindFiles(string path);
/// <summary>
/// Absolute disk path to the configuration directory for the game. If you are writing any files,
/// they need to be inside of this directory.
/// </summary>
string ConfigDirectory { get; }
}
}