Class ResourceFinder#
Defined in File ResourceFinder.h
Class Documentation#
-
class ResourceFinder#
Helper class to resolve filepaths for resources.
Public Functions
-
ResourceFinder()#
ResourceFinder constructor.
-
std::filesystem::path resolve(const std::filesystem::path &path) const#
Find the given file.
If the given path is absolute, it is used verbatim without any searching as long as the path exists.
If the path is relative, this function checks relative to a configured list of search paths, returning the absolute path of the first existing file that is found.
The search paths are a list of filepaths in descending order of priority. First, the current directory is considered, followed by a list determined by the
KARANA_RESOURCE_PATHenvironment variable, which should be a list of filepaths, separated by operating system’s standard delimiter (‘:’ on macos or linux, ‘;’ on windows). The search paths may further be modified at runtime using the methods of this class.If no exiting file can be found, an error will be thrown.
- Parameters:
path – The filepath to search for.
- Returns:
The resolved, existing absolute path.
-
std::filesystem::path shorten(const std::filesystem::path &path) const#
Convert a resolved path back to a relative path.
Given a potentially absolute path within one of the search paths, find the shortest equivalent relative path that can be resolved. If the path cannot be shortened, returns the given path unchanged.
- Parameters:
path – A resolved absolute filepath.
- Returns:
The shortened path relative to a search path or the given path if no matching search path is found.
-
void appendSearchPath(const std::filesystem::path &path)#
Add a low priority search path to the end of the list.
- Parameters:
path – The path to add
-
void prependSearchPath(const std::filesystem::path &path)#
Add a high priority search path to the start of the list.
- Parameters:
path – The path to add
-
std::vector<std::filesystem::path> getSearchPaths() const#
Get the list of search paths in descending priority.
- Returns:
The search paths
-
void setSearchPaths(const std::vector<std::filesystem::path> &paths)#
Overwrite the list of search paths in descending priority.
- Parameters:
paths – The new search paths
Public Static Functions
-
static ResourceFinder &singleton()#
Get the global ResourceFinder instance.
- Returns:
The ResourceFinder
-
ResourceFinder()#