class ProjectLibraryDatabase

Inherits: IReflectable

Maintains a database for all entries in the project library.

This allows for quick access to the project library structure, as well as meta-data for resources. Note this class does not deal with actual resources, folders or packages - instead it is just a reflection of the actual data present in the packages, and as such this database can always be rebuilt from the package data.

Public

Constructors

ProjectLibraryDatabase

ProjectLibraryDatabase()

Methods

BuildFromFiles

void BuildFromFiles(const Path &rootFolderPath)

Rebuilds the database from files found in the provided folder.

Note packages must already be loaded by the package manager or they will be ignored.

rootFolderPath
Absolute path to the folder containing packages which to visit to create the database from. All entries in the database will be stored relative to this folder. Package file-names are not included in database paths. For example: A package 'C:/Resources/Imported/Textures/MyPackage.b3d' containing 'MyTexture' resource will have the resulting entry relative path be '/Textures/MyTexture/', provided is 'C:/Resources/Imported/'.

BuildEntriesForPackage

Result BuildEntriesForPackage(const Path &rootFolderPath, const Path &packagePath)

Attempts to create project library entries from an existing package.

rootFolderPath
Absolute path to the folder containing packages. See BuildFromFiles().
packagePath
Absolute path to the package. Must be a child of .

MoveEntry

TResult<MoveOperationOutput> MoveEntry(const Path &sourceRelativePath, const Path &destinationRelativePath)

Moves an entry from one location to another.

If the entry is a folder, all the children will be moved as well. If destination already contains an entry with the same name, the move operation will be skipped for that source entry - except if both source and destination is a folder, in which case their contents will be merged.

sourceRelativePath
Path to the file or folder to move. Relative to the package folder path the database was built from.
destinationRelativePath
Path to which to move the file or folder. Relative to the package folder path the database was built from.

Returns: Operation result and optional error message if failed. If successful returns a list of all entries that were affected by the operation.

CopyEntry

TResult<CopyOperationOutput> CopyEntry(const Path &sourceRelativePath, const Path &destinationRelativePath)

Copies an entry from one location to another.

If the entry is a folder, all the children will be copied as well. If destination already contains an entry with the same name, the copy operation will be skipped for that source entry - except if both source and destination is a folder, in which case their contents will be merged.

sourceRelativePath
Path to the file or folder to move. Relative to the package folder path the database was built from.
destinationRelativePath
Path to which to move the file or folder. Relative to the package folder path the database was built from.

Returns: Operation result and optional error message if failed. If successful returns a list of all entries that were affected by the operation.

FindEntry

SPtr<ProjectLibraryEntry> FindEntry(const Path &relativePath) const

Attempts to a find a library entry at the specified path.

relativePath
Path to the entry to search. Relative to the package folder path the database was built from.

Returns: Found entry, or null if not found.

FindEntry

SPtr<ProjectLibraryResourceEntry> FindEntry(const UUID &resourceId) const

Attempts to find a library resource entry from the resource ID.

resourceId
ID of the resource to find.

Returns: Found entry, or null if not found.

FindFirstValidEntry

SPtr<ProjectLibraryEntry> FindFirstValidEntry(const Path &relativePath) const

Attempts to find an entry at the provided path.

If one doesn't exist, it searches for the parent of that path. And so on until the path root is reached.

relativePath
Path to the entry to search for. Relative to the package folder path the database was built from.

Returns: First existing parent folder. Returns null if invalid path is provided (e.g. absolute path).

Search

Vector<SPtr<ProjectLibraryEntry>> Search(const String &pattern, const Vector<u32> &typeIds) const

Searches the library for a pattern, but only among specific resource types.

pattern
Pattern to search for. Use wildcard * to match any character(s).
typeIds
RTTI type IDs of the resource types to limit the search for.

Returns: A list of entries matching the pattern.

Search

Vector<SPtr<ProjectLibraryEntry>> Search(const Path &relativePath, const String &pattern, const Vector<u32> &typeIds, bool recurse) const

Searches a particular folder or package for a pattern, but only among specific resource types.

relativePath
Path to the folder or package to search.
pattern
Pattern to search for. Use wildcard * to match any character(s).
typeIds
RTTI type IDs of the resource types to limit the search for.
recurse
If true, child folders or packages of the current folder will also be searched.

Returns: A list of entries matching the pattern.

Iterate

void Iterate(const Path &relativePath, std::function<bool (const SPtr<ProjectLibraryEntry> &)> callback, bool recursive) const

Iterates over all entries at the provided path, and triggers the callback for each entry.

Iteration is depth first.

relativePath
Path to iterate. Callback will be triggered for this path (if valid), and any children if is true. Relative to the package folder path the database was built from.
callback
Callback to trigger for each found entry. Return false to stop iterating.
recursive
If true, children of child container entries will be iterated.

FindOrCreateParentFolderHierarchy

TResult<SPtr<ProjectLibraryContainerEntry>> FindOrCreateParentFolderHierarchy(const Path &relativePath) const

Creates a full hierarchy of folder entries up to the provided path, if any are needed.

Or returns existing container entry if it is already present.

relativePath
Path to the entry we're creating the parent hierarchy for. Relative to the package folder path the database was built from.

Returns: Operation result and optional error message if failed.

TryCreateResourceEntry

TResult<SPtr<ProjectLibraryResourceEntry>> TryCreateResourceEntry(const Path &relativePath, const SPtr<PackageResourceMetaData> &resourceMetaData, bool allowCreateInReadOnly = false)

Creates a new resource entry at the provided path.

Operation will fail if the entry already exists.

relativePath
Path at which to create the entry. Relative to the package folder path the database was built from.
allowCreateInReadOnly
Allows creation of entries with read-only parents.
resourceMetaData
Meta-data of the resource.

Returns: Operation result and optional error message if failed.

TryCreateFolderEntry

TResult<SPtr<ProjectLibraryFolderEntry>> TryCreateFolderEntry(const Path &relativePath, bool allowCreateInReadOnly = false)

Creates a new folder entry at the provided path.

Operation will fail if the entry already exists.

relativePath
Path at which to create the entry. Relative to the package folder path the database was built from.
allowCreateInReadOnly
Allows creation of entries with read-only parents.

Returns: Operation result and optional error message if failed.

TryCreateSynchronizedPackageEntry

TResult<SPtr<ProjectLibrarySynchronizedPackageEntry>> TryCreateSynchronizedPackageEntry(const Path &relativePath, const SPtr<ProjectLibrarySynchronizedPackageMetaData> &synchronizedPackageMetaData)

Creates a new synchronized package entry at the provided path.

Operation will fail if the entry already exists.

relativePath
Path at which to create the entry. Relative to the package folder path the database was built from.
synchronizedPackageMetaData
Meta-data about the source resource the synchronized package was created from.

Returns: Operation result and optional error message if failed.

DeleteEntry

TResult<DeleteOperationOutput> DeleteEntry(const Path &relativePath)

Deletes an new entry at the provided path.

relativePath
Path at which to delete the entry. Relative to the package folder path the database was built from.

ReloadPackageMetaDataForEntry

void ReloadPackageMetaDataForEntry(const Path &rootFolderPath, const Path &relativePath)

Reloads the resource meta-data for the resource entry at the provided path.

Does nothing if the path is not found, or is not a resource.

rootFolderPath
Absolute path to which is relative to.
relativePath
Path to the entry whose meta-data to reload. Relative to the package folder path the database was built from.

ReloadPackageMetaDataForEntry

void ReloadPackageMetaDataForEntry(const Path &rootFolderPath, const SPtr<ProjectLibraryResourceEntry> &entry)

Reloads the resource meta-data for the provided resource entry.

rootFolderPath
Absolute path to which relative path of the provided entry is relative to.

ReloadMetaDataForSynchronizedPackageEntry

void ReloadMetaDataForSynchronizedPackageEntry(const Path &rootFolderPath, const SPtr<ProjectLibrarySynchronizedPackageEntry> &entry)

Reloads the package meta-data for the provided synchronized package entry.

rootFolderPath
Absolute path to which relative path of the provided entry is relative to.
entry
Entry for which to reload the meta-data for.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const

Returns an interface you can use to access class' Run Time Type Information.

Private

Methods

FindOrCreateParentFolderHierarchy

TResult<SPtr<ProjectLibraryContainerEntry>> FindOrCreateParentFolderHierarchy(const Path &relativePath, bool allowCreateInReadOnly) const

Creates a full hierarchy of folder entries up to the provided path, if any are needed.

Or returns existing container entry if it is already present.

relativePath
Path to the entry we're creating the parent hierarchy for. Relative to the package folder path the database was built from.
allowCreateInReadOnly
Allows creation of entries with read-only parents.

Returns: Operation result and optional error message if failed.

CreatePackageHierarchyRecursive

void CreatePackageHierarchyRecursive(const Path &relativeFolderPath, PackageHierarchy::Entry *entry, bool allowCreateInReadOnly)

Iterates the provided package hierarchy and creates entries for each file or folder in the package.

relativeFolderPath
Path to the folder in which to create the package hierarchy in. Relative to the package folder path the database was built from.
entry
Entry containing the root of the package hierarchy.
allowCreateInReadOnly
Allows creation of entries with read-only parents.

Fields

mRoot

mResourceIdToRelativePath

UnorderedMap<UUID, Path> mResourceIdToRelativePath