|
| virtual | ~FileUtils () |
| | The destructor of FileUtils.
|
|
virtual void | purgeCachedEntries () |
| | Purges full path caches.
|
|
virtual std::string | getStringFromFile (std::string_view filename) const |
| | Gets string from a file.
|
| virtual Data | getDataFromFile (std::string_view filename) const |
| | Creates binary data from a file.
|
| template<typename T, typename E = std::enable_if_t<tlx::is_resizable_container_v<T>>> |
| Status | getContents (std::string_view filename, T *buffer) const |
| | Gets whole file contents as string from a file.
|
| virtual std::string | fullPathForFilename (std::string_view filename) const |
| | Returns the fullpath for a given filename.
|
| virtual std::string | fullPathFromRelativeFile (std::string_view filename, std::string_view relativeFile) const |
| | Gets full path from a file name and the path of the relative file.
|
| virtual std::string | fullPathForDirectory (std::string_view dirname) const |
| | Returns the fullpath for a given dirname.
|
| template<typename _Range> |
| void | setSearchPaths (_Range &&searchPaths) |
| | Sets the array of search paths.
|
|
const std::string & | getDefaultResourceRootPath () const |
| | Get default resource root path.
|
|
void | setDefaultResourceRootPath (std::string_view path) |
| | Set default resource root path.
|
| void | addSearchPath (std::string_view path, const bool front=false) |
| | Add search path.
|
| virtual const std::vector< std::string > & | getSearchPaths () const |
| | Gets the array of search paths.
|
| virtual const std::vector< std::string > & | getOriginalSearchPaths () const |
| | Gets the original search path array set by 'setSearchPaths' or 'addSearchPath'.
|
| virtual std::string | getWritablePath () const =0 |
| | Gets the writable path that may not be in the format of an absolute path.
|
| virtual std::string | getNativeWritableAbsolutePath () const =0 |
| | Gets the writable path in the native file-system format.
|
|
virtual void | setWritablePath (std::string_view writablePath) |
| | Sets writable path.
|
|
virtual void | setPopupNotify (bool notify) |
| | Sets whether to pop-up a message box when failed to load an image.
|
| virtual bool | isPopupNotify () const |
| | Checks whether to pop up a message box when failed to load an image.
|
| virtual ValueMap | getValueMapFromFile (std::string_view filename) const |
| | Converts the contents of a file to a ValueMap.
|
| virtual ValueMap | getValueMapFromData (const char *filedata, int filesize) const |
| | Converts the contents of a file to a ValueMap.
|
| virtual bool | writeToFile (const ValueMap &dict, std::string_view fullPath) const |
| | write a ValueMap into a plist file
|
| virtual bool | writeStringToFile (std::string_view dataStr, std::string_view fullPath) const |
| | write a string into a file
|
| virtual bool | writeDataToFile (const Data &data, std::string_view fullPath) const |
| | write Data into a file
|
| virtual bool | writeValueMapToFile (const ValueMap &dict, std::string_view fullPath) const |
| | write ValueMap into a plist file
|
| virtual bool | writeValueVectorToFile (const ValueVector &vecData, std::string_view fullPath) const |
| | write ValueVector into a plist file
|
| virtual bool | isFileExist (std::string_view filename) const |
| | Checks whether a file exists.
|
| virtual bool | isAbsolutePath (std::string_view path) const |
| | Checks whether the path is an absolute path.
|
| virtual bool | isDirectoryExist (std::string_view dirPath) const |
| | Checks whether the path is a directory.
|
| virtual bool | createDirectories (std::string_view dirPath) const |
| | Creates a directory.
|
| virtual bool | removeDirectory (std::string_view dirPath) const |
| | Removes a directory.
|
| virtual bool | removeFile (std::string_view filepath) const |
| | Removes a file.
|
| virtual bool | renameFile (std::string_view path, std::string_view oldname, std::string_view name) const |
| | Renames a file under the given directory.
|
| virtual bool | renameFile (std::string_view oldfullpath, std::string_view newfullpath) const |
| | Renames a file under the given directory.
|
| virtual int64_t | getFileSize (std::string_view filepath) const |
| | Retrieve the file size.
|
| virtual std::vector< std::string > | listFiles (std::string_view dirPath) const |
| | List all files in a directory.
|
| virtual void | listFilesRecursively (std::string_view dirPath, std::vector< std::string > *files) const |
| | List all files recursively in a directory.
|
|
const tlx::string_map< std::string > | getFullPathCache () const |
| | Returns the full path cache.
|
|
const tlx::string_map< std::string > | getFullPathCacheDir () const |
| | Returns the full path cache.
|
| virtual bool | isFileExistInternal (std::string_view filename) const =0 |
| | Checks whether a file exists without considering search paths and resolution orders.
|
| virtual bool | isDirectoryExistInternal (std::string_view dirPath) const |
| | Checks whether a directory exists without considering search paths and resolution orders.
|
| virtual std::unique_ptr< IFileStream > | openFileStream (std::string_view filePath, IFileStream::Mode mode) const |
| | Open a FileStream based on the implementation provided in openFileStream or its overrides.
|
| bool | copyFile (std::string_view sourcePath, std::string_view destinationPath, int64_t bufferSize=-1) |
| | Copy a file from source to destination.
|
Helper class to handle file operations.
| virtual std::string fullPathForFilename |
( |
std::string_view | filename | ) |
const |
|
virtual |
Returns the fullpath for a given filename.
First it will try to get a new filename from the "filenameLookup" dictionary. If a new filename can't be found on the dictionary, it will use the original filename. Then it will try to obtain the full path of the filename using the FileUtils search rules: resolutions, and search paths. The file search is based on the array element order of search paths and resolution directories.
For instance:
We set two elements("/mnt/sdcard/", "internal_dir/") to search paths vector by setSearchPaths,
If we have a file named 'sprite.png', the mapping in fileLookup dictionary contains key: sprite.png -> value:
sprite.pvr.gz. Firstly, it will replace 'sprite.png' with 'sprite.pvr.gz', then searching the file sprite.pvr.gz as follows:
/mnt/sdcard/resources-ipadhd/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/resources-ipad/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/resources-iphonehd/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/sprite.pvr.gz (if not found, search next)
internal_dir/resources-ipadhd/sprite.pvr.gz (if not found, search next)
internal_dir/resources-ipad/sprite.pvr.gz (if not found, search next)
internal_dir/resources-iphonehd/sprite.pvr.gz (if not found, search next)
internal_dir/sprite.pvr.gz (if not found, return "sprite.png")
If the filename contains relative path like "gamescene/uilayer/sprite.png", and the mapping in fileLookup dictionary contains key: gamescene/uilayer/sprite.png -> value:
gamescene/uilayer/sprite.pvr.gz. The file search order will be:
/mnt/sdcard/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)
/mnt/sdcard/gamescene/uilayer/sprite.pvr.gz (if not found, search next)
internal_dir/gamescene/uilayer/resources-ipadhd/sprite.pvr.gz (if not found, search next)
internal_dir/gamescene/uilayer/resources-ipad/sprite.pvr.gz (if not found, search next)
internal_dir/gamescene/uilayer/resources-iphonehd/sprite.pvr.gz (if not found, search next)
internal_dir/gamescene/uilayer/sprite.pvr.gz (if not found, return
"gamescene/uilayer/sprite.png")
If the new file can't be found on the file system, it will return the parameter filename directly.
This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable, you might need to load different resources for a given file in the different platforms.
- Since
- v2.1