My Project
Public Types | Public Member Functions | Public Attributes | List of all members
ParaEngine::AssetFileEntry Struct Reference

light-weighted file record header in memory. More...

#include <AssetManifest.h>

Public Types

enum  AssetFileStatus { AssetFileStatus_Unknown = 0, AssetFileStatus_Downloaded = 1, AssetFileStatus_Downloading = 2, AssetFileStatus_Failed = 3 }
 
enum  AssetFileTypeEnum {
  AssetFileType_default = 0, AssetFileType_dds_file, AssetFileType_x_file, AssetFileType_ui_texture,
  AssetFileType_script, AssetFileType_audio, AssetFileType_big_file, AssetFileType_web_file
}
 the asset file type is usually set according to the file extension. More...
 
typedef boost::signals2::signal< void(int, AssetFileEntry *)> SyncFile_Callback_t
 sync file call back function or class. More...
 

Public Member Functions

bool DoesFileExist ()
 whether an up to date file exist locally. More...
 
AssetFileStatus GetStatus ()
 get asset file status
 
void SetStatus (AssetFileStatus status)
 set asset file status
 
AssetFileTypeEnum GetFileType ()
 the asset file type is usually set according to the file extension. More...
 
AssetFileTypeEnum SetFileType (const std::string &file_extension)
 set the asset file type according to file extension. More...
 
ResourceRequestID GetRequestQueueID ()
 get the proper request queue. More...
 
bool IsDownloading ()
 whether this asset is currently being downloaded. More...
 
bool SyncFile ()
 download the file even it is up to date. More...
 
HRESULT SyncFile_Async (URL_LOADER_CALLBACK pFuncCallback=NULL, CUrlProcessorUserData *pUserData=NULL, bool bDeleteUserData=false)
 similar to SyncFile(), except that this function will return immediately and does not redownload or call AddDownloadCount. More...
 
HRESULT SyncFile_Async (const SyncFile_Callback_t::slot_type &slot)
 this function is not thread safe, it must be called from the main render thread. More...
 
bool CheckSyncFile ()
 this is similar to SyncFile, except that it will only sync file if the file is not up to date. More...
 
void SignalComplete (int nResult=0)
 fire the complete signal, causing all callback to be invoked and then delete all callbacks. More...
 
bool HasReachedMaxRetryCount ()
 whether we have downloaded the file so many times, but still can not get it right. More...
 
bool AddDownloadCount ()
 add the download count and return !HasReachedMaxRetryCount() More...
 
const string & GetUrl ()
 get relative url
 
string GetAbsoluteUrl ()
 get the absolute url by prepending the default asset domain. More...
 
bool IsUrlFileCompressed ()
 return true if url file is compressed. More...
 
bool CheckMD5AndSize (const char *buffer, int nSize)
 check whether the MD5 of the input buffer matches. More...
 
bool SaveToDisk (const char *buffer, int nSize, bool bCheckMD5=true)
 save a give buffer to local file. More...
 
int GetFileSize ()
 get the compressed file size of the asset entry. More...
 
const std::string & GetLocalFileName ()
 get local file name. More...
 
std::string GetFullFilePath ()
 get the full disk file path. More...
 

Public Attributes

string m_localFileName
 this is concatenation of hex md5 with file size
 
string m_url
 
bool m_bIsZipFile
 
int m_nDownloadCount
 how many times we have tried to download this file since start. More...
 
int m_nFileSize
 the compressed file size
 
AssetFileTypeEnum m_file_type
 the asset file type
 
SyncFile_Callback_tm_sync_callback
 the sync call back. More...
 
AssetFileStatus m_nStatus
 asset file status. More...
 

Detailed Description

light-weighted file record header in memory.

Member Typedef Documentation

§ SyncFile_Callback_t

typedef boost::signals2::signal<void(int, AssetFileEntry*)> ParaEngine::AssetFileEntry::SyncFile_Callback_t

sync file call back function or class.

Member Enumeration Documentation

§ AssetFileStatus

Enumerator
AssetFileStatus_Unknown 

undetermined.

all assets are undetermined until we query it. One can always safely set asset state to unknown at any time such as during md5 check error.

AssetFileStatus_Downloaded 

In local computer and ready for use.

If file is downloaded and then deleted by another process, this value will still be true, since it will cache last result.

AssetFileStatus_Downloading 

Asset is being downloaded but is not finished yet.

This state is transient and will either be set to AssetFileStatus_Downloaded or AssetFileStatus_Failed after download is complete.

AssetFileStatus_Failed 

Unable to download the file, after trying a number of times.

We will cache last result.

§ AssetFileTypeEnum

the asset file type is usually set according to the file extension.

We will use file type to set download priority and queue type.

Member Function Documentation

§ AddDownloadCount()

bool AssetFileEntry::AddDownloadCount ( )

add the download count and return !HasReachedMaxRetryCount()

Returns
true if we can go on downloading.

§ CheckMD5AndSize()

bool AssetFileEntry::CheckMD5AndSize ( const char *  buffer,
int  nSize 
)

check whether the MD5 of the input buffer matches.

§ CheckSyncFile()

bool AssetFileEntry::CheckSyncFile ( )

this is similar to SyncFile, except that it will only sync file if the file is not up to date.

§ DoesFileExist()

bool AssetFileEntry::DoesFileExist ( )

whether an up to date file exist locally.

one can use the latest file at GetLocalFileName()

§ GetAbsoluteUrl()

string AssetFileEntry::GetAbsoluteUrl ( )

get the absolute url by prepending the default asset domain.

§ GetFileSize()

int ParaEngine::AssetFileEntry::GetFileSize ( )
inline

get the compressed file size of the asset entry.

§ GetFileType()

AssetFileTypeEnum ParaEngine::AssetFileEntry::GetFileType ( )
inline

the asset file type is usually set according to the file extension.

We will use file type to set download priority and queue type.

§ GetFullFilePath()

std::string AssetFileEntry::GetFullFilePath ( )

get the full disk file path.

on win32 this still return relative file path. On mobile platform, this will return writable file path.

§ GetLocalFileName()

const std::string& ParaEngine::AssetFileEntry::GetLocalFileName ( )
inline

get local file name.

§ GetRequestQueueID()

ParaEngine::ResourceRequestID AssetFileEntry::GetRequestQueueID ( )

get the proper request queue.

Internally it is set according to GetFileType()

§ HasReachedMaxRetryCount()

bool AssetFileEntry::HasReachedMaxRetryCount ( )

whether we have downloaded the file so many times, but still can not get it right.

by default we only try to download once.

§ IsDownloading()

bool AssetFileEntry::IsDownloading ( )

whether this asset is currently being downloaded.

[thread safety]: This function can only be called in the main thread.

§ IsUrlFileCompressed()

bool AssetFileEntry::IsUrlFileCompressed ( )

return true if url file is compressed.

By default, we will assume url file is a compressed file unless the file name ends with .p

§ SaveToDisk()

bool AssetFileEntry::SaveToDisk ( const char *  buffer,
int  nSize,
bool  bCheckMD5 = true 
)

save a give buffer to local file.

§ SetFileType()

AssetFileEntry::AssetFileTypeEnum AssetFileEntry::SetFileType ( const std::string &  file_extension)

set the asset file type according to file extension.

Note
: FileSize must be set before calling this function.
Returns
: the asset file type is returned.

§ SignalComplete()

void AssetFileEntry::SignalComplete ( int  nResult = 0)

fire the complete signal, causing all callback to be invoked and then delete all callbacks.

§ SyncFile()

bool AssetFileEntry::SyncFile ( )

download the file even it is up to date.

this function is synchronous. consider using CheckSyncFile() if one just wants to ensure an up to date copy is available. it may retry download if download failed such as md5 mismatch. If this function is called and failed multiple times, and HasReachedMaxRetryCount() is true, the function will do nothing and return false. Please use DoesFileExist() to check if file exit before calling sync file to avoid redownload the file.

Returns
true if file is downloaded and up to date.

§ SyncFile_Async() [1/2]

HRESULT AssetFileEntry::SyncFile_Async ( URL_LOADER_CALLBACK  pFuncCallback = NULL,
CUrlProcessorUserData pUserData = NULL,
bool  bDeleteUserData = false 
)

similar to SyncFile(), except that this function will return immediately and does not redownload or call AddDownloadCount.

And use callback.

Parameters
pFuncCallbackthe call back function to use. if none is specified, it will pick a default one to use according to pRequestData->m_nAssetType; this function is always called by the main thread.
lpUserDatais expected to be derived class of CUrlProcessorUserData
bDeleteUserDataif true, we will delete lpUserData.
Returns
S_OK if download is initiated.

§ SyncFile_Async() [2/2]

HRESULT AssetFileEntry::SyncFile_Async ( const SyncFile_Callback_t::slot_type &  slot)

this function is not thread safe, it must be called from the main render thread.

This function is same as SyncFile_Async(), except that it allows multiple event listeners for the same entity. if the current file is already being updated, it will not be called multiple times. Example:

AssetFileEntry entry; class SomeCallBack { public: void operator() (int nResult, AssetFileEntry* pEntry) const { if(nResult == 0) { OUTPUT_LOG("asset is successfully downloaded!"); } } }; entry.SyncFile_Async(SomeCallBack());

Returns
: S_OK if file is already downloaded and can be used right away. E_PENDING if file is being downloaded. E_FAIL if some error occurs.

Member Data Documentation

§ m_nDownloadCount

int ParaEngine::AssetFileEntry::m_nDownloadCount

how many times we have tried to download this file since start.

§ m_nStatus

AssetFileStatus ParaEngine::AssetFileEntry::m_nStatus

asset file status.

§ m_sync_callback

SyncFile_Callback_t* ParaEngine::AssetFileEntry::m_sync_callback

the sync call back.

if this is not NULL, it means that we are downloading this entity. Note: this callback is not thread safe.


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