2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2013-02-01 11:20:46 +08:00
|
|
|
Copyright (c) 2010-2013 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2013-02-01 11:20:46 +08:00
|
|
|
#ifndef __CC_FILEUTILS_H__
|
|
|
|
#define __CC_FILEUTILS_H__
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
#include <string>
|
2013-01-26 22:31:57 +08:00
|
|
|
#include <vector>
|
2013-02-01 16:46:15 +08:00
|
|
|
#include <map>
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "CCPlatformMacros.h"
|
|
|
|
#include "ccTypes.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class Dictionary;
|
|
|
|
class Array;
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup platform
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-02-01 15:41:41 +08:00
|
|
|
//! @brief Helper class to handle file operations
|
2013-08-22 18:16:50 +08:00
|
|
|
class CC_DLL FileUtils
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
friend class Array;
|
|
|
|
friend class Dictionary;
|
2012-04-19 14:35:52 +08:00
|
|
|
public:
|
2013-01-18 18:05:32 +08:00
|
|
|
|
2013-01-26 22:31:57 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* Gets the instance of FileUtils.
|
2013-01-26 22:31:57 +08:00
|
|
|
*/
|
2013-07-12 06:24:23 +08:00
|
|
|
static FileUtils* getInstance();
|
|
|
|
|
2013-01-26 22:31:57 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* Destroys the instance of FileUtils.
|
2013-01-26 22:31:57 +08:00
|
|
|
*/
|
2013-07-12 06:24:23 +08:00
|
|
|
static void destroyInstance();
|
|
|
|
|
|
|
|
/** @deprecated Use getInstance() instead */
|
2013-09-07 06:33:28 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static FileUtils* sharedFileUtils() { return getInstance(); }
|
2013-07-12 06:24:23 +08:00
|
|
|
|
|
|
|
/** @deprecated Use destroyInstance() instead */
|
2013-09-07 06:33:28 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE static void purgeFileUtils() { destroyInstance(); }
|
2013-07-12 06:24:23 +08:00
|
|
|
|
2013-02-01 11:20:46 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* The destructor of FileUtils.
|
2013-02-01 11:20:46 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~FileUtils();
|
2013-02-01 11:20:46 +08:00
|
|
|
|
2013-01-26 22:31:57 +08:00
|
|
|
/**
|
|
|
|
* Purges the file searching cache.
|
|
|
|
*
|
|
|
|
* @note It should be invoked after the resources were updated.
|
|
|
|
* For instance, in the CocosPlayer sample, every time you run application from CocosBuilder,
|
|
|
|
* All the resources will be downloaded to the writable folder, before new js app launchs,
|
2013-01-29 15:50:57 +08:00
|
|
|
* this method should be invoked to clean the file search cache.
|
2013-01-26 22:31:57 +08:00
|
|
|
*/
|
2013-02-01 11:20:46 +08:00
|
|
|
virtual void purgeCachedEntries();
|
2013-01-26 22:31:57 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/**
|
2013-02-01 15:41:41 +08:00
|
|
|
* Gets resource file data
|
|
|
|
*
|
2013-07-26 06:53:24 +08:00
|
|
|
* @param[in] filename The resource file name which contains the path.
|
2013-02-01 15:41:41 +08:00
|
|
|
* @param[in] pszMode The read mode of the file.
|
|
|
|
* @param[out] pSize If the file read operation succeeds, it will be the data size, otherwise 0.
|
|
|
|
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
|
|
|
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
|
|
|
*/
|
2013-09-07 09:46:33 +08:00
|
|
|
virtual unsigned char* getFileData(const char* filename, const char* mode, unsigned long * size);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/**
|
2013-02-01 15:41:41 +08:00
|
|
|
* Gets resource file data from a zip file.
|
|
|
|
*
|
2013-07-26 06:53:24 +08:00
|
|
|
* @param[in] filename The resource file name which contains the relative path of the zip file.
|
2013-08-01 21:40:13 +08:00
|
|
|
* @param[out] size If the file read operation succeeds, it will be the data size, otherwise 0.
|
2013-02-01 15:41:41 +08:00
|
|
|
* @return Upon success, a pointer to the data is returned, otherwise NULL.
|
|
|
|
* @warning Recall: you are responsible for calling delete[] on any Non-NULL pointer returned.
|
|
|
|
*/
|
2013-09-07 09:46:33 +08:00
|
|
|
virtual unsigned char* getFileDataFromZip(const char* zipFilePath, const char* filename, unsigned long *size);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-01-18 18:05:32 +08:00
|
|
|
|
|
|
|
/** Returns the fullpath for a given filename.
|
|
|
|
|
2013-01-29 16:28:59 +08:00
|
|
|
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.
|
2013-06-20 14:13:12 +08:00
|
|
|
Then it will try to obtain the full path of the filename using the FileUtils search rules: resolutions, and search paths.
|
2013-01-29 15:50:57 +08:00
|
|
|
The file search is based on the array element order of search paths and resolution directories.
|
2013-01-18 18:05:32 +08:00
|
|
|
|
2013-01-29 15:50:57 +08:00
|
|
|
For instance:
|
2013-01-29 16:28:59 +08:00
|
|
|
|
2013-01-29 16:07:50 +08:00
|
|
|
We set two elements("/mnt/sdcard/", "internal_dir/") to search paths vector by setSearchPaths,
|
2013-01-29 15:56:08 +08:00
|
|
|
and set three elements("resources-ipadhd/", "resources-ipad/", "resources-iphonehd")
|
2013-01-29 16:10:18 +08:00
|
|
|
to resolutions vector by setSearchResolutionsOrder. The "internal_dir" is relative to "Resources/".
|
2013-01-29 15:50:57 +08:00
|
|
|
|
2013-01-29 16:28:59 +08:00
|
|
|
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")
|
|
|
|
|
2013-07-26 06:53:24 +08:00
|
|
|
If the new file can't be found on the file system, it will return the parameter filename directly.
|
2013-01-18 18:05:32 +08:00
|
|
|
|
|
|
|
This method was added to simplify multiplatform support. Whether you are using cocos2d-js or any cross-compilation toolchain like StellaSDK or Apportable,
|
2013-01-29 16:28:59 +08:00
|
|
|
you might need to load different resources for a given file in the different platforms.
|
2013-01-29 15:50:57 +08:00
|
|
|
|
2013-01-18 18:05:32 +08:00
|
|
|
@since v2.1
|
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual std::string fullPathForFilename(const std::string &filename);
|
2013-01-18 18:05:32 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the filenameLookup dictionary from the contents of a filename.
|
|
|
|
*
|
|
|
|
* @note The plist file name should follow the format below:
|
2013-02-01 15:41:41 +08:00
|
|
|
*
|
|
|
|
* @code
|
2013-01-18 18:05:32 +08:00
|
|
|
* <?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
* <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
* <plist version="1.0">
|
|
|
|
* <dict>
|
2013-01-25 20:51:52 +08:00
|
|
|
* <key>filenames</key>
|
2013-01-18 18:05:32 +08:00
|
|
|
* <dict>
|
|
|
|
* <key>sounds/click.wav</key>
|
|
|
|
* <string>sounds/click.caf</string>
|
|
|
|
* <key>sounds/endgame.wav</key>
|
|
|
|
* <string>sounds/endgame.caf</string>
|
|
|
|
* <key>sounds/gem-0.wav</key>
|
|
|
|
* <string>sounds/gem-0.caf</string>
|
|
|
|
* </dict>
|
|
|
|
* <key>metadata</key>
|
|
|
|
* <dict>
|
|
|
|
* <key>version</key>
|
|
|
|
* <integer>1</integer>
|
|
|
|
* </dict>
|
|
|
|
* </dict>
|
|
|
|
* </plist>
|
2013-02-01 15:41:41 +08:00
|
|
|
* @endcode
|
2013-01-18 18:05:32 +08:00
|
|
|
* @param filename The plist file name.
|
|
|
|
*
|
|
|
|
@since v2.1
|
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual void loadFilenameLookupDictionaryFromFile(const std::string &filename);
|
2013-01-18 18:05:32 +08:00
|
|
|
|
2013-01-28 23:28:14 +08:00
|
|
|
/**
|
|
|
|
* Sets the filenameLookup dictionary.
|
|
|
|
*
|
|
|
|
* @param pFilenameLookupDict The dictionary for replacing filename.
|
|
|
|
* @since v2.1
|
2013-01-18 18:05:32 +08:00
|
|
|
*/
|
2013-09-07 09:46:33 +08:00
|
|
|
virtual void setFilenameLookupDictionary(Dictionary* filenameLookupDict);
|
2013-01-18 18:05:32 +08:00
|
|
|
|
2013-01-28 23:28:14 +08:00
|
|
|
/**
|
|
|
|
* Gets full path from a file name and the path of the reletive file.
|
2013-07-26 06:53:24 +08:00
|
|
|
* @param filename The file name.
|
2013-01-28 23:28:14 +08:00
|
|
|
* @param pszRelativeFile The path of the relative file.
|
|
|
|
* @return The full path.
|
2013-07-26 06:53:24 +08:00
|
|
|
* e.g. filename: hello.png, pszRelativeFile: /User/path1/path2/hello.plist
|
2013-01-28 23:40:56 +08:00
|
|
|
* Return: /User/path1/path2/hello.pvr (If there a a key(hello.png)-value(hello.pvr) in FilenameLookup dictionary. )
|
2013-01-28 23:28:14 +08:00
|
|
|
*
|
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual std::string fullPathFromRelativeFile(const std::string &filename, const std::string &relativeFile);
|
2013-01-23 22:29:00 +08:00
|
|
|
|
2013-01-26 22:31:57 +08:00
|
|
|
/**
|
2013-01-28 23:28:14 +08:00
|
|
|
* Sets the array that contains the search order of the resources.
|
2013-01-26 22:31:57 +08:00
|
|
|
*
|
2013-01-28 23:28:14 +08:00
|
|
|
* @param searchResolutionsOrder The source array that contains the search order of the resources.
|
2013-02-01 15:41:41 +08:00
|
|
|
* @see getSearchResolutionsOrder(void), fullPathForFilename(const char*).
|
2013-01-26 22:31:57 +08:00
|
|
|
* @since v2.1
|
2013-01-23 22:29:00 +08:00
|
|
|
*/
|
2013-02-01 11:20:46 +08:00
|
|
|
virtual void setSearchResolutionsOrder(const std::vector<std::string>& searchResolutionsOrder);
|
2013-02-04 12:41:24 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append search order of the resources.
|
|
|
|
*
|
|
|
|
* @see setSearchResolutionsOrder(), fullPathForFilename().
|
|
|
|
* @since v2.1
|
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual void addSearchResolutionsOrder(const std::string &order);
|
2013-01-28 23:28:14 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the array that contains the search order of the resources.
|
|
|
|
*
|
2013-02-01 15:41:41 +08:00
|
|
|
* @see setSearchResolutionsOrder(const std::vector<std::string>&), fullPathForFilename(const char*).
|
2013-01-28 23:28:14 +08:00
|
|
|
* @since v2.1
|
|
|
|
*/
|
2013-02-01 11:20:46 +08:00
|
|
|
virtual const std::vector<std::string>& getSearchResolutionsOrder();
|
2013-01-23 22:29:00 +08:00
|
|
|
|
2013-01-26 22:31:57 +08:00
|
|
|
/**
|
|
|
|
* Sets the array of search paths.
|
2013-02-01 15:41:41 +08:00
|
|
|
*
|
2013-01-26 22:31:57 +08:00
|
|
|
* 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.
|
2013-01-29 15:50:57 +08:00
|
|
|
*
|
2013-01-29 16:45:11 +08:00
|
|
|
* @note This method could access relative path and absolute path.
|
2013-06-20 14:13:12 +08:00
|
|
|
* If the relative path was passed to the vector, FileUtils will add the default resource directory before the relative path.
|
2013-01-29 16:45:11 +08:00
|
|
|
* 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.
|
|
|
|
*
|
2013-01-29 15:50:57 +08:00
|
|
|
* @param searchPaths The array contains search paths.
|
2013-02-01 15:41:41 +08:00
|
|
|
* @see fullPathForFilename(const char*)
|
2013-01-26 22:31:57 +08:00
|
|
|
* @since v2.1
|
2013-01-23 22:29:00 +08:00
|
|
|
*/
|
2013-02-01 11:20:46 +08:00
|
|
|
virtual void setSearchPaths(const std::vector<std::string>& searchPaths);
|
2013-01-28 23:28:14 +08:00
|
|
|
|
2013-02-04 12:41:24 +08:00
|
|
|
/**
|
|
|
|
* Add search path.
|
|
|
|
*
|
|
|
|
* @since v2.1
|
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
void addSearchPath(const std::string & path);
|
2013-02-04 12:41:24 +08:00
|
|
|
|
2013-01-28 23:28:14 +08:00
|
|
|
/**
|
|
|
|
* Gets the array of search paths.
|
|
|
|
*
|
2013-01-29 15:50:57 +08:00
|
|
|
* @return The array of search paths.
|
2013-02-01 15:41:41 +08:00
|
|
|
* @see fullPathForFilename(const char*).
|
2013-01-28 23:28:14 +08:00
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual const std::vector<std::string>& getSearchPaths() const;
|
2012-08-09 12:49:33 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/**
|
2013-02-06 18:04:40 +08:00
|
|
|
* Gets the writable path.
|
2013-02-01 18:48:44 +08:00
|
|
|
* @return The path that can be write/read a file in
|
2013-02-01 15:41:41 +08:00
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual std::string getWritablePath() const = 0;
|
2013-02-01 11:20:46 +08:00
|
|
|
|
|
|
|
/**
|
2013-02-01 18:48:44 +08:00
|
|
|
* Checks whether a file exists.
|
2013-02-01 11:20:46 +08:00
|
|
|
*
|
2013-02-01 22:19:58 +08:00
|
|
|
* @note If a relative path was passed in, it will be inserted a default root path at the beginning.
|
|
|
|
* @param strFilePath The path of the file, it could be a relative or absolute path.
|
|
|
|
* @return true if the file exists, otherwise it will return false.
|
2013-02-01 11:20:46 +08:00
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual bool isFileExist(const std::string& filePath) const = 0;
|
2013-02-01 11:20:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether the path is an absolute path.
|
2013-02-01 22:19:58 +08:00
|
|
|
*
|
2013-02-01 16:46:15 +08:00
|
|
|
* @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.
|
2013-02-01 11:20:46 +08:00
|
|
|
*
|
|
|
|
* @param strPath The path that needs to be checked.
|
2013-02-01 22:19:58 +08:00
|
|
|
* @return true if it's an absolute path, otherwise it will return false.
|
2013-02-01 11:20:46 +08:00
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual bool isAbsolutePath(const std::string& path) const;
|
2013-02-01 11:20:46 +08:00
|
|
|
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/**
|
2013-02-01 18:48:44 +08:00
|
|
|
* Sets/Gets whether to pop-up a message box when failed to load an image.
|
2013-02-01 15:41:41 +08:00
|
|
|
*/
|
2013-09-07 09:46:33 +08:00
|
|
|
virtual void setPopupNotify(bool notify);
|
2013-02-01 11:20:46 +08:00
|
|
|
virtual bool isPopupNotify();
|
2013-01-24 17:23:53 +08:00
|
|
|
|
2012-08-08 17:42:04 +08:00
|
|
|
protected:
|
2013-02-01 15:41:41 +08:00
|
|
|
/**
|
|
|
|
* The default constructor.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
FileUtils();
|
2012-09-03 18:05:59 +08:00
|
|
|
|
2013-02-01 15:41:41 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* Initializes the instance of FileUtils. It will set _searchPathArray and _searchResolutionsOrderArray to default values.
|
2013-02-01 15:41:41 +08:00
|
|
|
*
|
|
|
|
* @note When you are porting Cocos2d-x to a new platform, you may need to take care of this method.
|
2013-06-20 14:13:12 +08:00
|
|
|
* You could assign a default value to _defaultResRootPath in the subclass of FileUtils(e.g. FileUtilsAndroid). Then invoke the FileUtils::init().
|
2013-02-01 18:48:44 +08:00
|
|
|
* @return true if successed, otherwise it returns false.
|
2013-02-01 15:41:41 +08:00
|
|
|
*
|
|
|
|
*/
|
2013-02-01 11:20:46 +08:00
|
|
|
virtual bool init();
|
2013-01-23 22:29:00 +08:00
|
|
|
|
2013-02-01 15:41:41 +08:00
|
|
|
/**
|
|
|
|
* Gets the new filename from the filename lookup dictionary.
|
2013-09-07 06:33:28 +08:00
|
|
|
* It is possible to have a override names.
|
2013-07-26 06:53:24 +08:00
|
|
|
* @param filename The original filename.
|
2013-02-01 15:41:41 +08:00
|
|
|
* @return The new filename after searching in the filename lookup dictionary.
|
2013-02-01 18:48:44 +08:00
|
|
|
* If the original filename wasn't in the dictionary, it will return the original filename.
|
2013-02-01 15:41:41 +08:00
|
|
|
*/
|
2013-09-07 13:54:08 +08:00
|
|
|
virtual std::string getNewFilename(const std::string &filename);
|
2013-01-23 22:29:00 +08:00
|
|
|
|
2013-02-01 11:20:46 +08:00
|
|
|
/**
|
2013-02-01 15:41:41 +08:00
|
|
|
* Gets full path for filename, resolution directory and search path.
|
2013-02-01 11:20:46 +08:00
|
|
|
*
|
|
|
|
* @param filename The file name.
|
|
|
|
* @param resolutionDirectory The resolution directory.
|
|
|
|
* @param searchPath The search path.
|
2013-02-01 22:19:58 +08:00
|
|
|
* @return The full path of the file. It will return an empty string if the full path of the file doesn't exist.
|
2013-02-01 11:20:46 +08:00
|
|
|
*/
|
|
|
|
virtual std::string getPathForFilename(const std::string& filename, const std::string& resolutionDirectory, const std::string& searchPath);
|
|
|
|
|
2013-02-01 15:41:41 +08:00
|
|
|
/**
|
|
|
|
* Gets full path for the directory and the filename.
|
|
|
|
*
|
|
|
|
* @note Only iOS and Mac need to override this method since they are using
|
|
|
|
* `[[NSBundle mainBundle] pathForResource: ofType: inDirectory:]` to make a full path.
|
|
|
|
* Other platforms will use the default implementation of this method.
|
|
|
|
* @param strDirectory The directory contains the file we are looking for.
|
|
|
|
* @param strFilename The name of the file.
|
|
|
|
* @return The full path of the file, if the file can't be found, it will return an empty string.
|
|
|
|
*/
|
2013-09-07 09:46:33 +08:00
|
|
|
virtual std::string getFullPathForDirectoryAndFilename(const std::string& directory, const std::string& filename);
|
2013-01-18 18:05:32 +08:00
|
|
|
|
2013-02-01 18:48:44 +08:00
|
|
|
/**
|
|
|
|
* Creates a dictionary by the contents of a file.
|
|
|
|
* @note This method is used internally.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual Dictionary* createDictionaryWithContentsOfFile(const std::string& filename);
|
2013-02-01 18:48:44 +08:00
|
|
|
|
2013-04-13 16:55:24 +08:00
|
|
|
/**
|
|
|
|
* Write a dictionary to a plist file.
|
|
|
|
* @note This method is used internally.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual bool writeToFile(Dictionary *dict, const std::string& fullPath);
|
2013-04-13 16:55:24 +08:00
|
|
|
|
2013-02-01 18:48:44 +08:00
|
|
|
/**
|
|
|
|
* Creates an array by the contents of a file.
|
|
|
|
* @note This method is used internally.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual Array* createArrayWithContentsOfFile(const std::string& filename);
|
2013-02-01 18:48:44 +08:00
|
|
|
|
2013-01-18 18:05:32 +08:00
|
|
|
/** Dictionary used to lookup filenames based on a key.
|
2013-02-01 22:19:58 +08:00
|
|
|
* It is used internally by the following methods:
|
|
|
|
*
|
|
|
|
* std::string fullPathForFilename(const char*);
|
|
|
|
*
|
|
|
|
* @since v2.1
|
2013-01-18 18:05:32 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
Dictionary* _filenameLookupDict;
|
2013-01-23 22:29:00 +08:00
|
|
|
|
2013-02-01 15:41:41 +08:00
|
|
|
/**
|
|
|
|
* The vector contains resolution folders.
|
2013-02-01 17:16:33 +08:00
|
|
|
* The lower index of the element in this vector, the higher priority for this resolution directory.
|
2013-02-01 15:41:41 +08:00
|
|
|
*/
|
2013-06-15 14:03:30 +08:00
|
|
|
std::vector<std::string> _searchResolutionsOrderArray;
|
2013-02-01 15:41:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The vector contains search paths.
|
2013-02-01 17:16:33 +08:00
|
|
|
* The lower index of the element in this vector, the higher priority for this search path.
|
2013-02-01 15:41:41 +08:00
|
|
|
*/
|
2013-06-15 14:03:30 +08:00
|
|
|
std::vector<std::string> _searchPathArray;
|
2013-02-01 15:41:41 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The default root path of resources.
|
2013-06-20 14:13:12 +08:00
|
|
|
* If the default root path of resources needs to be changed, do it in the `init` method of FileUtils's subclass.
|
2013-02-01 17:16:33 +08:00
|
|
|
* For instance:
|
2013-06-20 14:13:12 +08:00
|
|
|
* On Android, the default root path of resources will be assigned with "assets/" in FileUtilsAndroid::init().
|
|
|
|
* Similarly on Blackberry, we assign "app/native/Resources/" to this variable in FileUtilsBlackberry::init().
|
2013-02-01 15:41:41 +08:00
|
|
|
*/
|
2013-06-15 14:03:30 +08:00
|
|
|
std::string _defaultResRootPath;
|
2013-02-01 11:20:46 +08:00
|
|
|
|
2013-02-01 16:46:15 +08:00
|
|
|
/**
|
2013-02-01 18:48:44 +08:00
|
|
|
* The full path cache. When a file is found, it will be added into this cache.
|
|
|
|
* This variable is used for improving the performance of file search.
|
2013-02-01 16:46:15 +08:00
|
|
|
*/
|
2013-06-15 14:03:30 +08:00
|
|
|
std::map<std::string, std::string> _fullPathCache;
|
2013-02-01 16:46:15 +08:00
|
|
|
|
2013-02-01 15:41:41 +08:00
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
* The singleton pointer of FileUtils.
|
2013-02-01 15:41:41 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
static FileUtils* s_sharedFileUtils;
|
2013-02-01 16:46:15 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of platform group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|
|
|
|
|
2013-02-01 11:20:46 +08:00
|
|
|
#endif // __CC_FILEUTILS_H__
|