ScummVM API documentation
Common::FSNode Class Reference

#include <fs.h>

Inheritance diagram for Common::FSNode:
Common::ArchiveMember

Public Types

enum  ListMode { kListFilesOnly = 1, kListDirectoriesOnly = 2, kListAll = 3 }
 

Public Member Functions

 FSNode ()
 
 FSNode (const Path &path)
 
bool operator< (const FSNode &node) const
 
bool exists () const
 
FSNode getChild (const String &name) const
 
bool getChildren (FSList &fslist, ListMode mode=kListDirectoriesOnly, bool hidden=true) const
 
U32String getDisplayName () const override
 
String getName () const override
 
String getFileName () const override
 
Path getPathInArchive () const override
 
virtual String getRealName () const
 
Path getPath () const
 
FSNode getParent () const
 
bool isDirectory () const override
 
void listChildren (Common::ArchiveMemberList &childList, const char *pattern=nullptr) const override
 
bool isReadable () const
 
bool isWritable () const
 
SeekableReadStreamcreateReadStream () const override
 
SeekableReadStreamcreateReadStreamForAltStream (AltStreamType altStreamType) const override
 
SeekableWriteStreamcreateWriteStream (bool atomic=true) const
 
bool createDirectory () const
 
- Public Member Functions inherited from Common::ArchiveMember
virtual bool isInMacArchive () const
 

Detailed Description

FSNode, short for "File System Node", provides an abstraction for file paths, allowing for portable file system browsing. This means, for example, that multiple or single roots have to be supported (compare Unix with a single root, Windows with multiple roots C:, D:, ...).

To this end, we abstract away from paths; implementations can be based on paths (and it is left to them whether '/', '\', or ':' is the path separator) but it is also possible to use inodes or vrefs (MacOS 9) or anything else.

Member Enumeration Documentation

◆ ListMode

Flag to tell listDir() which kind of files to list.

Constructor & Destructor Documentation

◆ FSNode() [1/2]

Common::FSNode::FSNode ( )

Create a new pathless FSNode. Since there is no path associated with this node, path-related operations (i.e. exists(), isDirectory(), getPath()) will always return false or raise an assertion.

◆ FSNode() [2/2]

Common::FSNode::FSNode ( const Path path)
explicit

Create a new FSNode referring to the specified path. This is the counterpart to the path() method.

If the path is empty or equals ".", then a node representing the "current directory" will be created. If that is not possible (since e.g. the operating system does not support the concept), some other directory is used (usually the root directory).

Member Function Documentation

◆ operator<()

bool Common::FSNode::operator< ( const FSNode node) const

Compare the name of this node to the name of another. Directories go before normal files.

◆ exists()

bool Common::FSNode::exists ( ) const

Indicate whether the object referred by this node exists in the file system or not.

Returns
True if the node exists, false otherwise.

◆ getChild()

FSNode Common::FSNode::getChild ( const String name) const

Create a new node referring to a child node of the current node, which must be a directory node (otherwise an invalid node is returned). If a child matching the name exists, a normal node for it is returned. If no child with the name exists, a node for it is still returned, but exists() will return 'false' for it. This node can however be used to create a new file using the createWriteStream() method.

Parameters
nameName of a child of this directory.
Returns
The node referring to the child with the given name.

◆ getChildren()

bool Common::FSNode::getChildren ( FSList fslist,
ListMode  mode = kListDirectoriesOnly,
bool  hidden = true 
) const

Return a list of all child nodes of this directory node. If called on a node that does not represent a directory, false is returned.

Returns
True if successful, false otherwise (e.g. when the directory does not exist).

◆ getDisplayName()

U32String Common::FSNode::getDisplayName ( ) const
overridevirtual

Return a human-readable string for this node, usable for display (e.g. in the GUI code). Do not rely on it being usable for anything else, like constructing paths.

Returns
The display name.

Reimplemented from Common::ArchiveMember.

◆ getName()

String Common::FSNode::getName ( ) const
overridevirtual

Return a string representation of the name of the file. This can be used e.g. by detection code that relies on matching the name of a given file. However, it is not suitable for use with fopen / File::open, nor should it be archived.

Returns
The file name.

Implements Common::ArchiveMember.

◆ getFileName()

String Common::FSNode::getFileName ( ) const
overridevirtual

Return a string representation of the name of the file.

Returns
The file name.

Implements Common::ArchiveMember.

◆ getPathInArchive()

Path Common::FSNode::getPathInArchive ( ) const
overridevirtual

Return a string representation of the name of the file. Since FSNode parents are always the parent FSDirectory, this will not return a full path, only the file name.

Returns
The file name.

Implements Common::ArchiveMember.

◆ getRealName()

virtual String Common::FSNode::getRealName ( ) const
virtual

Return a string representation of the name of the file, without any Punycode transformation. This can be used e.g. by detection code that relies on matching the name of a given file. However, it is not suitable for use with fopen / File::open, nor should it be archived.

Returns
The file name.

◆ getPath()

Path Common::FSNode::getPath ( ) const

Return a path representation of the file that is suitable for archiving (i.e. writing to the config file). What a 'path' is differs greatly from system to system.

Returns
The 'path' represented by this file system node.

◆ getParent()

FSNode Common::FSNode::getParent ( ) const

Get the parent node of this node. If this node has no parent node, then it returns a duplicate of this node.

◆ isDirectory()

bool Common::FSNode::isDirectory ( ) const
overridevirtual

Indicate whether the node refers to a directory or not.

Reimplemented from Common::ArchiveMember.

◆ listChildren()

void Common::FSNode::listChildren ( Common::ArchiveMemberList childList,
const char *  pattern = nullptr 
) const
overridevirtual

Adds the immediate children of this FSNode to a list, optionally matching a pattern. Has no effect if this FSNode is not a directory.

Reimplemented from Common::ArchiveMember.

◆ isReadable()

bool Common::FSNode::isReadable ( ) const

Indicate whether the object referred by this node can be read from or not.

If the node refers to a directory, readability implies being able to read and list the directory entries.

If the node refers to a file, readability implies being able to read the contents of the file.

Returns
True if the object can be read, false otherwise.

◆ isWritable()

bool Common::FSNode::isWritable ( ) const

Indicate whether the object referred by this node can be written to or not.

If the node refers to a directory, writability implies being able to modify the directory entry (i.e. rename the directory, remove it, or write files inside of it).

If the node refers to a file, writability implies being able to write data to the file.

Returns
True if the object can be written to, false otherwise.

◆ createReadStream()

SeekableReadStream* Common::FSNode::createReadStream ( ) const
overridevirtual

Create a SeekableReadStream instance corresponding to the file referred by this node. This assumes that the node actually refers to a readable file. If this is not the case, 0 is returned.

Returns
Pointer to the stream object, nullptr in case of a failure.

Implements Common::ArchiveMember.

◆ createReadStreamForAltStream()

SeekableReadStream* Common::FSNode::createReadStreamForAltStream ( AltStreamType  altStreamType) const
overridevirtual

Create a SeekableReadStream instance corresponding to an alternate stream of the file referred by this node. This assumes that the node actually refers to a readable file and the alternate stream exists. If either is not the case, nullptr is returned.

Returns
Pointer to the stream object, nullptr in case of a failure.

Implements Common::ArchiveMember.

◆ createWriteStream()

SeekableWriteStream* Common::FSNode::createWriteStream ( bool  atomic = true) const

Create a WriteStream instance corresponding to the file referred by this node. This assumes that the node actually refers to a readable file. If this is not the case, 0 is returned.

When an atomic write stream is requested, the backend will write the data in a temporary file before moving it to its final destination.

Parameters
atomicRequest for an atomic file write when closing.
Returns
Pointer to the stream object, 0 in case of a failure.

◆ createDirectory()

bool Common::FSNode::createDirectory ( ) const

Create a directory referred by this node. This assumes that this node refers to a non-existing directory. If this is not the case, false is returned.

Returns
True if the directory was created, false otherwise.

The documentation for this class was generated from the following file: