Rebel Fork Framework
Urho3D::FileSystem Class Reference

Subsystem for file and directory operations and access control. More...

#include <Urho3D/IO/FileSystem.h>

Inheritance diagram for Urho3D::FileSystem:
Urho3D::Object Urho3D::RefCounted

Public Member Functions

 FileSystem (Context *context)
 Construct.
 
 ~FileSystem () override
 Destruct.
 
bool SetCurrentDir (const ea::string &pathName)
 
bool CreateDir (const ea::string &pathName)
 Create a directory.
 
void SetExecuteConsoleCommands (bool enable)
 
int SystemCommand (const ea::string &commandLine, bool redirectStdOutToLog=false)
 Run a program using the command interpreter, block until it exits and return the exit code. Will fail if any allowed paths are defined.
 
int SystemRun (const ea::string &fileName, const ea::vector< ea::string > &arguments, ea::string &output)
 Run a specific program, block until it exits and return the exit code. Will fail if any allowed paths are defined. Returns STDOUT output of subprocess.
 
int SystemRun (const ea::string &fileName, const ea::vector< ea::string > &arguments)
 Run a specific program, block until it exits and return the exit code. Will fail if any allowed paths are defined.
 
int SystemSpawn (const ea::string &fileName, const ea::vector< ea::string > &arguments)
 Run a specific program, do not block until it exits. Will fail if any allowed paths are defined.
 
unsigned SystemCommandAsync (const ea::string &commandLine)
 Run a program using the command interpreter asynchronously. Return a request ID or M_MAX_UNSIGNED if failed. The exit code will be posted together with the request ID in an AsyncExecFinished event. Will fail if any allowed paths are defined.
 
unsigned SystemRunAsync (const ea::string &fileName, const ea::vector< ea::string > &arguments)
 Run a specific program asynchronously. Return a request ID or M_MAX_UNSIGNED if failed. The exit code will be posted together with the request ID in an AsyncExecFinished event. Will fail if any allowed paths are defined.
 
bool SystemOpen (const ea::string &fileName, const ea::string &mode=EMPTY_STRING)
 Open a file in an external program, with mode such as "edit" optionally specified. Will fail if any allowed paths are defined.
 
bool Copy (const ea::string &srcFileName, const ea::string &destFileName)
 Copy a file. Return true if successful.
 
bool Rename (const ea::string &srcFileName, const ea::string &destFileName)
 Rename a file. Return true if successful.
 
bool Delete (const ea::string &fileName)
 Delete a file. Return true if successful.
 
void RegisterPath (const ea::string &pathName)
 Register a path as allowed to access. If no paths are registered, all are allowed. Registering allowed paths is considered securing the Urho3D execution environment: running programs and opening files externally through the system will fail afterward.
 
bool SetLastModifiedTime (const ea::string &fileName, FileTime newTime)
 Set a file's last modified time as seconds since 1.1.1970. Return true on success.
 
bool Reveal (const ea::string &path)
 Reveal path or file in OS file browser.
 
ea::string GetCurrentDir () const
 
bool GetExecuteConsoleCommands () const
 
bool HasRegisteredPaths () const
 Return whether paths have been registered.
 
bool CheckAccess (const ea::string &pathName) const
 Check if a path is allowed to be accessed. If no paths are registered, all are allowed.
 
FileTime GetLastModifiedTime (const ea::string &fileName, bool creationIsModification=false) const
 Returns the file's last modified time as seconds since 1.1.1970, or 0 if can not be accessed.
 
bool FileExists (const ea::string &fileName) const
 Check if a file exists.
 
bool DirExists (const ea::string &pathName) const
 Check if a directory exists.
 
void ScanDir (ea::vector< ea::string > &result, const ea::string &pathName, const ea::string &filter, ScanFlags flags) const
 Scan a directory for specified files.
 
ea::string GetProgramDir () const
 
ea::string GetProgramFileName () const
 Return the program's executable file path, or empty string if not applicable.
 
ea::string GetUserDocumentsDir () const
 
ea::string GetAppPreferencesDir (const ea::string &org, const ea::string &app) const
 Return the application preferences directory.
 
bool Exists (const ea::string &pathName) const
 Check if a file or directory exists at the specified path.
 
bool CopyDir (const ea::string &directoryIn, const ea::string &directoryOut, StringVector *copiedFiles=nullptr)
 Copy files from one directory to another.
 
bool CreateDirs (const ea::string &root, const ea::string &subdirectory)
 Create subdirectories. New subdirectories will be made only in a subpath specified by subdirectory.
 
bool CreateDirsRecursive (const ea::string &directoryIn)
 Create specified subdirectory and any parent directory if it does not exist.
 
bool RemoveDir (const ea::string &directoryIn, bool recursive)
 Remove files in a directory, or remove entire directory recursively.
 
ea::string GetTemporaryDir () const
 
ea::string FindResourcePrefixPath () const
 Try to find resource prefix path starting from executable and going up.
 
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
 
 ~Object () override
 Destruct. Clean up self from event sender & receiver structures.
 
virtual StringHash GetType () const =0
 
virtual const ea::string & GetTypeName () const =0
 
virtual const TypeInfoGetTypeInfo () const =0
 Return type info.
 
virtual bool IsInstanceOf (StringHash type) const =0
 Check whether current instance implements specified type.
 
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
 
virtual void SerializeInBlock (Archive &archive)
 Serialize content from/to archive. May throw ArchiveException.
 
template<typename T >
bool IsInstanceOf () const
 Check current instance is type of specified class.
 
template<typename T >
T * Cast ()
 Cast the object to specified most derived class.
 
template<typename T >
const T * Cast () const
 Cast the object to specified most derived class.
 
void SubscribeToEventManual (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
 
void SubscribeToEventManual (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
 
template<class T >
void SubscribeToEvent (StringHash eventType, T handler)
 Subscribe to an event that can be sent by any sender.
 
template<class T >
void SubscribeToEvent (Object *sender, StringHash eventType, T handler)
 Subscribe to a specific sender's event.
 
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
 
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
 
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
 
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
 
void UnsubscribeFromAllEventsExcept (const ea::vector< StringHash > &exceptions)
 Unsubscribe from all events except those listed.
 
void UnsubscribeFromAllEventsExcept (const ea::vector< Object * > &exceptions)
 Unsubscribe from all events except those with listed senders.
 
void SendEvent (StringHash eventType)
 Send event to all subscribers.
 
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
 
VariantMapGetEventDataMap () const
 Return a preallocated map for event data. Used for optimization to avoid constant re-allocation of event data maps.
 
template<typename... Args>
void SendEvent (StringHash eventType, const Args &... args)
 Send event with variadic parameter pairs to all subscribers. The parameters are (paramID, paramValue) pairs.
 
ContextGetContext () const
 Return execution context.
 
const VariantGetGlobalVar (StringHash key) const
 
const VariantMapGetGlobalVars () const
 
void SetGlobalVar (StringHash key, const Variant &value)
 
ObjectGetSubsystem (StringHash type) const
 Return subsystem by type.
 
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
 
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
 
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
 
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
 
bool HasEventHandlers () const
 Return whether has subscribed to any event.
 
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
 
const ea::string & GetCategory () const
 
void SendEvent (StringHash eventType, const VariantMap &eventData)
 Send event with parameters to all subscribers.
 
void SetBlockEvents (bool block)
 Block object from sending and receiving events.
 
bool GetBlockEvents () const
 Return sending and receiving events blocking status.
 
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
 
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
 
 RefCounted (const RefCounted &rhs)=delete
 Prevent copy construction.
 
RefCountedoperator= (const RefCounted &rhs)=delete
 Prevent assignment.
 
int AddRef ()
 
int ReleaseRef ()
 
int Refs () const
 
int WeakRefs () const
 
RefCountRefCountPtr () const
 Return pointer to the reference count structure.
 
bool HasScriptObject () const
 Return true if script runtime object wrapping this native object exists.
 
bool IsScriptStrongRef () const
 Return true if script reference is strong.
 

Private Member Functions

 URHO3D_OBJECT (FileSystem, Object)
 
void ScanDirInternal (ea::vector< ea::string > &result, ea::string path, const ea::string &startPath, const ea::string &filter, ScanFlags flags) const
 Scan directory, called internally. More...
 
void HandleBeginFrame (StringHash eventType, VariantMap &eventData)
 Handle begin frame event to check for completed async executions.
 
void HandleConsoleCommand (StringHash eventType, VariantMap &eventData)
 Handle a console command event.
 

Private Attributes

ea::hash_set< ea::string > allowedPaths_
 Allowed directories.
 
ea::list< AsyncExecRequest * > asyncExecQueue_
 Async execution queue.
 
unsigned nextAsyncExecID_ {1}
 Next async execution ID.
 
bool executeConsoleCommands_ {}
 Flag for executing engine console commands as OS-specific system command. Default to true.
 

Additional Inherited Members

- Static Public Member Functions inherited from Urho3D::Object
static const TypeInfoGetTypeInfoStatic ()
 Return type info static.
 
- Static Public Attributes inherited from Urho3D::Object
static constexpr ea::array< StringHash, 0 > TypeHierarchy {}
 
- Protected Attributes inherited from Urho3D::Object
WeakPtr< Contextcontext_
 Execution context.
 

Detailed Description

Subsystem for file and directory operations and access control.

Member Function Documentation

◆ GetCurrentDir()

ea::string Urho3D::FileSystem::GetCurrentDir ( ) const

Return the absolute current working directory.

◆ GetExecuteConsoleCommands()

bool Urho3D::FileSystem::GetExecuteConsoleCommands ( ) const
inline

Return whether is executing engine console commands as OS-specific system command.

◆ GetProgramDir()

ea::string Urho3D::FileSystem::GetProgramDir ( ) const

Return the program's directory.

◆ GetTemporaryDir()

ea::string Urho3D::FileSystem::GetTemporaryDir ( ) const

Return path of temporary directory. Path always ends with a forward slash.

◆ GetUserDocumentsDir()

ea::string Urho3D::FileSystem::GetUserDocumentsDir ( ) const

Return the user documents directory.

◆ ScanDirInternal()

void Urho3D::FileSystem::ScanDirInternal ( ea::vector< ea::string > &  result,
ea::string  path,
const ea::string &  startPath,
const ea::string &  filter,
ScanFlags  flags 
) const
private

Scan directory, called internally.

◆ SetCurrentDir()

bool Urho3D::FileSystem::SetCurrentDir ( const ea::string &  pathName)

Set the current working directory.

◆ SetExecuteConsoleCommands()

void Urho3D::FileSystem::SetExecuteConsoleCommands ( bool  enable)

Set whether to execute engine console commands as OS-specific system command.


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