cocos2d-x  3.5
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
AssetsManagerEx Class Reference

This class is used to auto update resources, such as pictures or scripts. More...

#include <AssetsManagerEx.h>

Inheritance diagram for AssetsManagerEx:
Ref

Public Types

enum  State {
  UNCHECKED, PREDOWNLOAD_VERSION, DOWNLOADING_VERSION, VERSION_LOADED,
  PREDOWNLOAD_MANIFEST, DOWNLOADING_MANIFEST, MANIFEST_LOADED, NEED_UPDATE,
  UPDATING, UP_TO_DATE, FAIL_TO_UPDATE
}
 Update states. More...
 

Public Member Functions

void checkUpdate ()
 Check out if there is a new version of manifest. More...
 
void update ()
 Update with the current local manifest. More...
 
void downloadFailedAssets ()
 Reupdate all failed assets under the current AssetsManagerEx context. More...
 
State getState () const
 Gets the current update state. More...
 
const std::string & getStoragePath () const
 Gets storage path. More...
 
const ManifestgetLocalManifest () const
 Function for retrieve the local manifest object. More...
 
const ManifestgetRemoteManifest () const
 Function for retrieve the remote manifest object. More...
 
virtual ~AssetsManagerEx ()
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 Destructor. More...
 

Static Public Member Functions

static AssetsManagerExcreate (const std::string &manifestUrl, const std::string &storagePath)
 Create function for creating a new AssetsManagerEx. More...
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: AssetsManagerEx(const std::string& manifestUrl
CC_CONSTRUCTOR_ACCESS const
std::string & 
storagePath

Static Public Attributes

static const std::string VERSION_ID
static const std::string MANIFEST_ID
static const std::string BATCH_UPDATE_ID

Protected Member Functions

std::string basename (const std::string &path) const
std::string get (const std::string &key) const
void initManifests (const std::string &manifestUrl)
void loadLocalManifest (const std::string &manifestUrl)
void prepareLocalManifest ()
void setStoragePath (const std::string &storagePath)
void adjustPath (std::string &path)
void dispatchUpdateEvent (EventAssetsManagerEx::EventCode code, const std::string &message="", const std::string &assetId="", int curle_code=0, int curlm_code=0)
void downloadVersion ()
void parseVersion ()
void downloadManifest ()
void parseManifest ()
void startUpdate ()
void updateSucceed ()
bool decompress (const std::string &filename)
void decompressDownloadedZip ()
void updateAssets (const Downloader::DownloadUnits &assets)
 Update a list of assets under the current AssetsManagerEx context. More...
 
const Downloader::DownloadUnitsgetFailedAssets () const
 Retrieve all failed assets during the last update. More...
 
void destroyDownloadedVersion ()
 Function for destorying the downloaded version file and manifest file. More...
 
virtual void onError (const Downloader::Error &error)
 Call back function for error handling, the error will then be reported to user's listener registed in addUpdateEventListener. More...
 
virtual void onProgress (double total, double downloaded, const std::string &url, const std::string &customId)
 Call back function for recording downloading percent of the current asset, the progression will then be reported to user's listener registed in addUpdateProgressEventListener. More...
 
virtual void onSuccess (const std::string &srcUrl, const std::string &storagePath, const std::string &customId)
 Call back function for success of the current asset the success event will then be send to user's listener registed in addUpdateEventListener. More...
 
- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 

Friends

class Downloader
int downloadProgressFunc (Downloader::ProgressData *ptr, double totalToDownload, double nowDownloaded, double totalToUpLoad, double nowUpLoaded)

Additional Inherited Members

- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 

Detailed Description

This class is used to auto update resources, such as pictures or scripts.

Member Enumeration Documentation

enum State
strong

Update states.

Enumerator
UNCHECKED 
PREDOWNLOAD_VERSION 
DOWNLOADING_VERSION 
VERSION_LOADED 
PREDOWNLOAD_MANIFEST 
DOWNLOADING_MANIFEST 
MANIFEST_LOADED 
NEED_UPDATE 
UPDATING 
UP_TO_DATE 
FAIL_TO_UPDATE 

Constructor & Destructor Documentation

virtual ~AssetsManagerEx ( )
virtual

Member Function Documentation

void adjustPath ( std::string &  path)
protected
std::string basename ( const std::string &  path) const
protected
void checkUpdate ( )

Check out if there is a new version of manifest.

You may use this method before updating, then let user determine whether he wants to update resources.

static AssetsManagerEx* create ( const std::string &  manifestUrl,
const std::string &  storagePath 
)
static

Create function for creating a new AssetsManagerEx.

Parameters
manifestUrlThe url for the local manifest file
storagePathThe storage path for downloaded assetes
Warning
The cached manifest in your storage path have higher priority and will be searched first, only if it doesn't exist, AssetsManagerEx will use the given manifestUrl.
bool decompress ( const std::string &  filename)
protected
void decompressDownloadedZip ( )
protected
void destroyDownloadedVersion ( )
protected

Function for destorying the downloaded version file and manifest file.

void dispatchUpdateEvent ( EventAssetsManagerEx::EventCode  code,
const std::string &  message = "",
const std::string &  assetId = "",
int  curle_code = 0,
int  curlm_code = 0 
)
protected
void downloadFailedAssets ( )

Reupdate all failed assets under the current AssetsManagerEx context.

void downloadManifest ( )
protected
void downloadVersion ( )
protected
std::string get ( const std::string &  key) const
protected
const
Downloader::DownloadUnits&
getFailedAssets
( ) const
protected

Retrieve all failed assets during the last update.

const Manifest* getLocalManifest ( ) const

Function for retrieve the local manifest object.

const Manifest* getRemoteManifest ( ) const

Function for retrieve the remote manifest object.

State getState ( ) const

Gets the current update state.

const std::string& getStoragePath ( ) const

Gets storage path.

void initManifests ( const std::string &  manifestUrl)
protected
void loadLocalManifest ( const std::string &  manifestUrl)
protected
virtual void onError ( const Downloader::Error error)
protectedvirtual

Call back function for error handling, the error will then be reported to user's listener registed in addUpdateEventListener.

Parameters
errorThe error object contains ErrorCode, message, asset url, asset key
Warning
AssetsManagerEx internal use only
virtual void onProgress ( double  total,
double  downloaded,
const std::string &  url,
const std::string &  customId 
)
protectedvirtual

Call back function for recording downloading percent of the current asset, the progression will then be reported to user's listener registed in addUpdateProgressEventListener.

Parameters
totalTotal size to download for this asset
downloadedTotal size already downloaded for this asset
urlThe url of this asset
customIdThe key of this asset
Warning
AssetsManagerEx internal use only
virtual void onSuccess ( const std::string &  srcUrl,
const std::string &  storagePath,
const std::string &  customId 
)
protectedvirtual

Call back function for success of the current asset the success event will then be send to user's listener registed in addUpdateEventListener.

Parameters
srcUrlThe url of this asset
customIdThe key of this asset
Warning
AssetsManagerEx internal use only
void parseManifest ( )
protected
void parseVersion ( )
protected
void prepareLocalManifest ( )
protected
void setStoragePath ( const std::string &  storagePath)
protected
void startUpdate ( )
protected
void update ( )

Update with the current local manifest.

void updateAssets ( const Downloader::DownloadUnits assets)
protected

Update a list of assets under the current AssetsManagerEx context.

void updateSucceed ( )
protected

Friends And Related Function Documentation

friend class Downloader
friend
int downloadProgressFunc ( Downloader::ProgressData ptr,
double  totalToDownload,
double  nowDownloaded,
double  totalToUpLoad,
double  nowUpLoaded 
)
friend

Member Data Documentation

const std::string BATCH_UPDATE_ID
static
const std::string MANIFEST_ID
static
CC_CONSTRUCTOR_ACCESS const
std::string& storagePath
const std::string VERSION_ID
static

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