My Project
|
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_t * | m_sync_callback |
the sync call back. More... | |
AssetFileStatus | m_nStatus |
asset file status. More... | |
light-weighted file record header in memory.
typedef boost::signals2::signal<void(int, AssetFileEntry*)> ParaEngine::AssetFileEntry::SyncFile_Callback_t |
sync file call back function or class.
the asset file type is usually set according to the file extension.
We will use file type to set download priority and queue type.
bool AssetFileEntry::AddDownloadCount | ( | ) |
add the download count and return !HasReachedMaxRetryCount()
bool AssetFileEntry::CheckMD5AndSize | ( | const char * | buffer, |
int | nSize | ||
) |
check whether the MD5 of the input buffer matches.
bool AssetFileEntry::CheckSyncFile | ( | ) |
this is similar to SyncFile, except that it will only sync file if the file is not up to date.
bool AssetFileEntry::DoesFileExist | ( | ) |
whether an up to date file exist locally.
one can use the latest file at GetLocalFileName()
string AssetFileEntry::GetAbsoluteUrl | ( | ) |
get the absolute url by prepending the default asset domain.
|
inline |
get the compressed file size of the asset entry.
|
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.
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.
|
inline |
get local file name.
ParaEngine::ResourceRequestID AssetFileEntry::GetRequestQueueID | ( | ) |
get the proper request queue.
Internally it is set according to GetFileType()
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.
bool AssetFileEntry::IsDownloading | ( | ) |
whether this asset is currently being downloaded.
[thread safety]: This function can only be called in the main thread.
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
bool AssetFileEntry::SaveToDisk | ( | const char * | buffer, |
int | nSize, | ||
bool | bCheckMD5 = true |
||
) |
save a give buffer to local file.
AssetFileEntry::AssetFileTypeEnum AssetFileEntry::SetFileType | ( | const std::string & | file_extension | ) |
set the asset file type according to file extension.
void AssetFileEntry::SignalComplete | ( | int | nResult = 0 | ) |
fire the complete signal, causing all callback to be invoked and then delete all callbacks.
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.
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.
pFuncCallback | the 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. |
lpUserData | is expected to be derived class of CUrlProcessorUserData |
bDeleteUserData | if true, we will delete lpUserData. |
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());
int ParaEngine::AssetFileEntry::m_nDownloadCount |
how many times we have tried to download this file since start.
AssetFileStatus ParaEngine::AssetFileEntry::m_nStatus |
asset file status.
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.