-------------------------------- -- @module FileUtils -- @parent_module cc -------------------------------- -- 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,
-- and set three elements("resources-ipadhd/", "resources-ipad/", "resources-iphonehd")
-- to resolutions vector by setSearchResolutionsOrder. The "internal_dir" is relative to "Resources/".
-- 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 -- @function [parent=#FileUtils] fullPathForFilename -- @param self -- @param #string filename -- @return string#string ret (return value: string) -------------------------------- -- @overload self, string, function -- @overload self, string -- @function [parent=#FileUtils] getStringFromFile -- @param self -- @param #string path -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Sets the filenameLookup dictionary.
-- param filenameLookupDict The dictionary for replacing filename.
-- since v2.1 -- @function [parent=#FileUtils] setFilenameLookupDictionary -- @param self -- @param #map_table filenameLookupDict -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- @overload self, string, function -- @overload self, string -- @function [parent=#FileUtils] removeFile -- @param self -- @param #string filepath -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Checks whether the path is an absolute path.
-- note On Android, if the parameter passed in is relative to "assets/", this method will treat it as an absolute path.
-- Also on Blackberry, path starts with "app/native/Resources/" is treated as an absolute path.
-- param path The path that needs to be checked.
-- return True if it's an absolute path, false if not. -- @function [parent=#FileUtils] isAbsolutePath -- @param self -- @param #string path -- @return bool#bool ret (return value: bool) -------------------------------- -- @overload self, string, string, string, function -- @overload self, string, string, string -- @overload self, string, string -- @overload self, string, string, function -- @function [parent=#FileUtils] renameFile -- @param self -- @param #string path -- @param #string oldname -- @param #string name -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Get default resource root path. -- @function [parent=#FileUtils] getDefaultResourceRootPath -- @param self -- @return string#string ret (return value: string) -------------------------------- -- Loads the filenameLookup dictionary from the contents of a filename.
-- note The plist file name should follow the format below:
-- code
--
--
--
--
-- filenames
--
-- sounds/click.wav
-- sounds/click.caf
-- sounds/endgame.wav
-- sounds/endgame.caf
-- sounds/gem-0.wav
-- sounds/gem-0.caf
--

-- metadata
--
-- version
-- 1
--

--

--

-- endcode
-- param filename The plist file name.
-- since v2.1
-- js loadFilenameLookup
-- lua loadFilenameLookup -- @function [parent=#FileUtils] loadFilenameLookupDictionaryFromFile -- @param self -- @param #string filename -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Checks whether to pop up a message box when failed to load an image.
-- return True if pop up a message box when failed to load an image, false if not. -- @function [parent=#FileUtils] isPopupNotify -- @param self -- @return bool#bool ret (return value: bool) -------------------------------- -- -- @function [parent=#FileUtils] getValueVectorFromFile -- @param self -- @param #string filename -- @return array_table#array_table ret (return value: array_table) -------------------------------- -- Gets the array of search paths.
-- return The array of search paths which may contain the prefix of default resource root path.
-- note In best practise, getter function should return the value of setter function passes in.
-- But since we should not break the compatibility, we keep using the old logic.
-- Therefore, If you want to get the original search paths, please call 'getOriginalSearchPaths()' instead.
-- see fullPathForFilename(const char*).
-- lua NA -- @function [parent=#FileUtils] getSearchPaths -- @param self -- @return array_table#array_table ret (return value: array_table) -------------------------------- -- write a ValueMap into a plist file
-- param dict the ValueMap want to save
-- param fullPath The full path to the file you want to save a string
-- return bool -- @function [parent=#FileUtils] writeToFile -- @param self -- @param #map_table dict -- @param #string fullPath -- @return bool#bool ret (return value: bool) -------------------------------- -- Gets the original search path array set by 'setSearchPaths' or 'addSearchPath'.
-- return The array of the original search paths -- @function [parent=#FileUtils] getOriginalSearchPaths -- @param self -- @return array_table#array_table ret (return value: array_table) -------------------------------- -- Gets the new filename from the filename lookup dictionary.
-- It is possible to have a override names.
-- param filename The original filename.
-- return The new filename after searching in the filename lookup dictionary.
-- If the original filename wasn't in the dictionary, it will return the original filename. -- @function [parent=#FileUtils] getNewFilename -- @param self -- @param #string filename -- @return string#string ret (return value: string) -------------------------------- -- List all files in a directory.
-- param dirPath The path of the directory, it could be a relative or an absolute path.
-- return File paths in a string vector -- @function [parent=#FileUtils] listFiles -- @param self -- @param #string dirPath -- @return array_table#array_table ret (return value: array_table) -------------------------------- -- Converts the contents of a file to a ValueMap.
-- param filename The filename of the file to gets content.
-- return ValueMap of the file contents.
-- note This method is used internally. -- @function [parent=#FileUtils] getValueMapFromFile -- @param self -- @param #string filename -- @return map_table#map_table ret (return value: map_table) -------------------------------- -- @overload self, string, function -- @overload self, string -- @function [parent=#FileUtils] getFileSize -- @param self -- @param #string filepath -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Converts the contents of a file to a ValueMap.
-- This method is used internally. -- @function [parent=#FileUtils] getValueMapFromData -- @param self -- @param #char filedata -- @param #int filesize -- @return map_table#map_table ret (return value: map_table) -------------------------------- -- @overload self, string, function -- @overload self, string -- @function [parent=#FileUtils] removeDirectory -- @param self -- @param #string dirPath -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Sets the array of search paths.
-- You can use this array to modify the search path of the resources.
-- If you want to use "themes" or search resources in the "cache", you can do it easily by adding new entries in this array.
-- note This method could access relative path and absolute path.
-- If the relative path was passed to the vector, FileUtils will add the default resource directory before the relative path.
-- For instance:
-- On Android, the default resource root path is "assets/".
-- If "/mnt/sdcard/" and "resources-large" were set to the search paths vector,
-- "resources-large" will be converted to "assets/resources-large" since it was a relative path.
-- param searchPaths The array contains search paths.
-- see fullPathForFilename(const char*)
-- since v2.1
-- In js:var setSearchPaths(var jsval);
-- lua NA -- @function [parent=#FileUtils] setSearchPaths -- @param self -- @param #array_table searchPaths -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- @overload self, string, string, function -- @overload self, string, string -- @function [parent=#FileUtils] writeStringToFile -- @param self -- @param #string dataStr -- @param #string fullPath -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Sets the array that contains the search order of the resources.
-- param searchResolutionsOrder The source array that contains the search order of the resources.
-- see getSearchResolutionsOrder(), fullPathForFilename(const char*).
-- since v2.1
-- In js:var setSearchResolutionsOrder(var jsval)
-- lua NA -- @function [parent=#FileUtils] setSearchResolutionsOrder -- @param self -- @param #array_table searchResolutionsOrder -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Append search order of the resources.
-- see setSearchResolutionsOrder(), fullPathForFilename().
-- since v2.1 -- @function [parent=#FileUtils] addSearchResolutionsOrder -- @param self -- @param #string order -- @param #bool front -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Add search path.
-- since v2.1 -- @function [parent=#FileUtils] addSearchPath -- @param self -- @param #string path -- @param #bool front -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- @overload self, array_table, string, function -- @overload self, array_table, string -- @function [parent=#FileUtils] writeValueVectorToFile -- @param self -- @param #array_table vecData -- @param #string fullPath -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- @overload self, string, function -- @overload self, string -- @function [parent=#FileUtils] isFileExist -- @param self -- @param #string filename -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Purges full path caches. -- @function [parent=#FileUtils] purgeCachedEntries -- @param self -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Gets full path from a file name and the path of the relative file.
-- param filename The file name.
-- param relativeFile The path of the relative file.
-- return The full path.
-- e.g. filename: hello.png, pszRelativeFile: /User/path1/path2/hello.plist
-- Return: /User/path1/path2/hello.pvr (If there a a key(hello.png)-value(hello.pvr) in FilenameLookup dictionary. ) -- @function [parent=#FileUtils] fullPathFromRelativeFile -- @param self -- @param #string filename -- @param #string relativeFile -- @return string#string ret (return value: string) -------------------------------- -- Windows fopen can't support UTF-8 filename
-- Need convert all parameters fopen and other 3rd-party libs
-- param filenameUtf8 std::string name file for conversion from utf-8
-- return std::string ansi filename in current locale -- @function [parent=#FileUtils] getSuitableFOpen -- @param self -- @param #string filenameUtf8 -- @return string#string ret (return value: string) -------------------------------- -- @overload self, map_table, string, function -- @overload self, map_table, string -- @function [parent=#FileUtils] writeValueMapToFile -- @param self -- @param #map_table dict -- @param #string fullPath -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Gets filename extension is a suffix (separated from the base filename by a dot) in lower case.
-- Examples of filename extensions are .png, .jpeg, .exe, .dmg and .txt.
-- param filePath The path of the file, it could be a relative or absolute path.
-- return suffix for filename in lower case or empty if a dot not found. -- @function [parent=#FileUtils] getFileExtension -- @param self -- @param #string filePath -- @return string#string ret (return value: string) -------------------------------- -- Sets writable path. -- @function [parent=#FileUtils] setWritablePath -- @param self -- @param #string writablePath -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Sets whether to pop-up a message box when failed to load an image. -- @function [parent=#FileUtils] setPopupNotify -- @param self -- @param #bool notify -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- @overload self, string, function -- @overload self, string -- @function [parent=#FileUtils] isDirectoryExist -- @param self -- @param #string fullPath -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Set default resource root path. -- @function [parent=#FileUtils] setDefaultResourceRootPath -- @param self -- @param #string path -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Gets the array that contains the search order of the resources.
-- see setSearchResolutionsOrder(const std::vector&), fullPathForFilename(const char*).
-- since v2.1
-- lua NA -- @function [parent=#FileUtils] getSearchResolutionsOrder -- @param self -- @return array_table#array_table ret (return value: array_table) -------------------------------- -- @overload self, string, function -- @overload self, string -- @function [parent=#FileUtils] createDirectory -- @param self -- @param #string dirPath -- @param #function callback -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Gets the writable path.
-- return The path that can be write/read a file in -- @function [parent=#FileUtils] getWritablePath -- @param self -- @return string#string ret (return value: string) -------------------------------- -- List all files recursively in a directory.
-- param dirPath The path of the directory, it could be a relative or an absolute path.
-- return File paths in a string vector -- @function [parent=#FileUtils] listFilesRecursively -- @param self -- @param #string dirPath -- @param #array_table files -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Destroys the instance of FileUtils. -- @function [parent=#FileUtils] destroyInstance -- @param self -- @return FileUtils#FileUtils self (return value: cc.FileUtils) -------------------------------- -- Gets the instance of FileUtils. -- @function [parent=#FileUtils] getInstance -- @param self -- @return FileUtils#FileUtils ret (return value: cc.FileUtils) return nil