本文整理汇总了C++中FileList::AddCallback方法的典型用法代码示例。如果您正苦于以下问题:C++ FileList::AddCallback方法的具体用法?C++ FileList::AddCallback怎么用?C++ FileList::AddCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileList
的用法示例。
在下文中一共展示了FileList::AddCallback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DownloadFromSubdirectory
unsigned short DirectoryDeltaTransfer::DownloadFromSubdirectory(const char *subdir, const char *outputSubdir, bool prependAppDirToOutputSubdir, SystemAddress host, FileListTransferCBInterface *onFileCallback, PacketPriority _priority, char _orderingChannel, FileListProgress *cb)
{
RakAssert(host!=UNASSIGNED_SYSTEM_ADDRESS);
DDTCallback *transferCallback;
FileList localFiles;
localFiles.AddCallback(cb);
// Get a hash of all the files that we already have (if any)
localFiles.AddFilesFromDirectory(prependAppDirToOutputSubdir ? applicationDirectory : 0, outputSubdir, true, false, true, FileListNodeContext(0,0));
// Prepare the callback data
transferCallback = RakNet::OP_NEW<DDTCallback>( _FILE_AND_LINE_ );
if (subdir && subdir[0])
{
transferCallback->subdirLen=(unsigned int)strlen(subdir);
if (subdir[transferCallback->subdirLen-1]!='/' && subdir[transferCallback->subdirLen-1]!='\\')
transferCallback->subdirLen++;
}
else
transferCallback->subdirLen=0;
if (prependAppDirToOutputSubdir)
strcpy(transferCallback->outputSubdir, applicationDirectory);
else
transferCallback->outputSubdir[0]=0;
if (outputSubdir)
strcat(transferCallback->outputSubdir, outputSubdir);
if (transferCallback->outputSubdir[strlen(transferCallback->outputSubdir)-1]!='/' && transferCallback->outputSubdir[strlen(transferCallback->outputSubdir)-1]!='\\')
strcat(transferCallback->outputSubdir, "/");
transferCallback->onFileCallback=onFileCallback;
// Setup the transfer plugin to get the response to this download request
unsigned short setId = fileListTransfer->SetupReceive(transferCallback, true, host);
// Send to the host, telling it to process this request
RakNet::BitStream outBitstream;
outBitstream.Write((MessageID)ID_DDT_DOWNLOAD_REQUEST);
outBitstream.Write(setId);
StringCompressor::Instance()->EncodeString(subdir, 256, &outBitstream);
StringCompressor::Instance()->EncodeString(outputSubdir, 256, &outBitstream);
localFiles.Serialize(&outBitstream);
SendUnified(&outBitstream, _priority, RELIABLE_ORDERED, _orderingChannel, host, false);
return setId;
}
示例2: UpdateApplicationFiles
bool AutopatcherMySQLRepository::UpdateApplicationFiles(const char *applicationName, const char *applicationDirectory, const char *userName, FileListProgress *cb)
{
MYSQL_STMT *stmt;
MYSQL_BIND bind[3];
char query[512];
FileList filesOnHarddrive;
filesOnHarddrive.AddCallback(cb);
int prepareResult;
my_bool falseVar=false;
RakNet::RakString escapedApplicationName = GetEscapedString(applicationName);
filesOnHarddrive.AddFilesFromDirectory(applicationDirectory,"", true, true, true, FileListNodeContext(0,0));
if (filesOnHarddrive.fileList.Size()==0)
{
sprintf(lastError,"ERROR: Can't find files at %s in UpdateApplicationFiles\n",applicationDirectory);
return false;
}
sprintf(query, "SELECT applicationID FROM Applications WHERE applicationName='%s';", escapedApplicationName.C_String());
int applicationID;
//sqlCommandMutex.Lock();
if (!ExecuteQueryReadInt(query, &applicationID))
{
//sqlCommandMutex.Unlock();
sprintf(lastError,"ERROR: %s not found in UpdateApplicationFiles\n",escapedApplicationName.C_String());
return false;
}
if (!ExecuteBlockingCommand("BEGIN;"))
{
//sqlCommandMutex.Unlock();
return false;
}
//sqlCommandMutex.Unlock();
sprintf(query, "UPDATE Applications SET changeSetId = changeSetId + 1 where applicationID=%i;", applicationID);
//sqlCommandMutex.Lock();
if (!ExecuteBlockingCommand(query))
{
Rollback ();
//sqlCommandMutex.Unlock();
return false;
}
//sqlCommandMutex.Unlock();
int changeSetId = 0;
sprintf(query, "SELECT changeSetId FROM Applications WHERE applicationID=%i;", applicationID);
//sqlCommandMutex.Lock();
if (!ExecuteQueryReadInt(query, &changeSetId))
{
Rollback ();
//sqlCommandMutex.Unlock();
return false;
}
//sqlCommandMutex.Unlock();
// +1 was added in the update
changeSetId--;
// Gets all newest files
sprintf(query, "SELECT filename, contentHash, createFile FROM FileVersionHistory "
"JOIN (SELECT max(fileId) maxId FROM FileVersionHistory WHERE applicationId=%i GROUP BY fileName) MaxId "
"ON FileVersionHistory.fileId = MaxId.maxId "
"ORDER BY filename DESC;", applicationID);
MYSQL_RES *result = 0;
//sqlCommandMutex.Lock();
if (!ExecuteBlockingCommand(query, &result))
{
Rollback();
//sqlCommandMutex.Unlock();
return false;
}
//sqlCommandMutex.Unlock();
DataStructures::List <FileInfo> newestFiles;
MYSQL_ROW row;
while ((row = mysql_fetch_row (result)) != 0)
{
FileInfo fi;
fi.filename = row [0];
fi.createFile = (atoi (row [2]) != 0);
if (fi.createFile)
{
RakAssert(mysql_fetch_lengths (result) [1] == HASH_LENGTH); // check the data is sensible
memcpy (fi.contentHash, row [1], HASH_LENGTH);
}
newestFiles.Insert (fi, _FILE_AND_LINE_ );
}
mysql_free_result(result);
FileList newFiles;
// Loop through files on filesOnHarddrive
// If the file in filesOnHarddrive does not exist in the query result, or if it does but the hash is different or non-existent, add this file to the create list
for (unsigned fileListIndex=0; fileListIndex < filesOnHarddrive.fileList.Size(); fileListIndex++)
{
bool addFile=true;
if (fileListIndex%10==0)
printf("Hashing files %i/%i\n", fileListIndex+1, filesOnHarddrive.fileList.Size());
const char * hardDriveFilename=filesOnHarddrive.fileList[fileListIndex].filename;
//.........这里部分代码省略.........