bool CGameAIRecorder::AddFileToRemoteArchive(const char* szFile) { bool bResult = false; ICryPak *pCryPak = gEnv->pSystem->GetIPak(); assert(pCryPak); if (m_pRemoteArchive && pCryPak) { string sLocalPath = PathUtil::Make("..", szFile); AZ::IO::HandleType fileHandle = pCryPak->FOpen(sLocalPath.c_str(), "rb"); if (fileHandle != AZ::IO::InvalidHandle) { // Add the file to the PAK size_t iFileSize = pCryPak->FGetSize(fileHandle); BYTE* pBuffer = (BYTE*)pCryPak->PoolMalloc(iFileSize); if (!pBuffer) { CryLogAlways("[Warning] Failed when packing file to remote archive: Out of memory. (\'%s\')", szFile); } else { pCryPak->FReadRaw(pBuffer, iFileSize, 1, fileHandle); int iResult = m_pRemoteArchive->UpdateFile(PathUtil::GetFile(szFile), pBuffer, iFileSize, ICryArchive::METHOD_DEFLATE, ICryArchive::LEVEL_BETTER); if (0 != iResult) { CryLogAlways("[Warning] Failed when packing file to remote archive: File update failed. (\'%s\')", szFile); } else { bResult = true; } pCryPak->PoolFree(pBuffer); } pCryPak->FClose(fileHandle); } } return bResult; }
bool CGameAIRecorder::SendRemoteArchive(const char* szRecordingFile) { ICryPak *pCryPak = gEnv->pSystem->GetIPak(); assert(pCryPak); bool bResult = false; string sPAKFileName; sPAKFileName.Format("%s_%s", gEnv->pSystem->GetUserName(), PathUtil::GetFileName(szRecordingFile).c_str()); string sDestFile = PathUtil::Make(CGameAIRecorderCVars::ai_remoteRecorder_serverDir, sPAKFileName.c_str(), "zip"); CryLogAlways("AI Recording packed successfully! Copying to remote directory \'%s\'...", sDestFile.c_str()); // Remote copy the file string sPAKFileLocalPath = PathUtil::Make("..", g_szRemoteTempArchive); AZ::IO::HandleType pakFileHandle = pCryPak->FOpen(sPAKFileLocalPath.c_str(), "rb"); if (pakFileHandle != AZ::IO::InvalidHandle) { AZ::IO::HandleType destFileHandle = pCryPak->FOpen(sDestFile.c_str(), "wb"); if (destFileHandle != AZ::IO::InvalidHandle) { BYTE pBuffer[512]; while (true) { const int iReadAmount = pCryPak->FReadRaw(pBuffer, 1, 512, pakFileHandle); if (iReadAmount <= 0) break; if (pCryPak->FWrite(pBuffer, iReadAmount, 1, destFileHandle) > 0) bResult = true; } pCryPak->FClose(destFileHandle); pCryPak->FClose(pakFileHandle); } } return bResult; }