AKRESULT CFileIOHandler_wwise::Open(AkFileID nFileID, AkOpenMode eOpenMode, AkFileSystemFlags* pFlags, bool& rSyncOpen, AkFileDesc& rFileDesc) { AKRESULT eResult = AK_Fail; if (pFlags != nullptr && (rSyncOpen || !m_bAsyncOpen)) { rSyncOpen = true; AkOSChar sFinalFilePath[AK_MAX_PATH] = {'\0'}; AKPLATFORM::SafeStrCat(sFinalFilePath, m_sBankPath, AK_MAX_PATH); if (eOpenMode == AK_OpenModeRead) { // Add language folder if the file is localized. if (pFlags->uCompanyID == AKCOMPANYID_AUDIOKINETIC && pFlags->bIsLanguageSpecific) { AKPLATFORM::SafeStrCat(sFinalFilePath, m_sLanguageFolder, AK_MAX_PATH); } } AkOSChar sFileName[MAX_FILETITLE_SIZE] = {'\0'}; AkOSChar const* const sFilenameFormat = pFlags->uCodecID == AKCODECID_BANK ? ID_TO_STRING_FORMAT_BANK : ID_TO_STRING_FORMAT_WEM; AK_OSPRINTF(sFileName, MAX_FILETITLE_SIZE, sFilenameFormat, static_cast<int unsigned>(nFileID)); AKPLATFORM::SafeStrCat(sFinalFilePath, sFileName, AK_MAX_PATH); char* sTemp = nullptr; CONVERT_OSCHAR_TO_CHAR(sFinalFilePath, sTemp); size_t const nFileSize = gEnv->pCryPak->FGetSize(sTemp); if (nFileSize > 0) { FILE* const pFile = gEnv->pCryPak->FOpen(sTemp, "rbx", ICryPak::FOPEN_HINT_DIRECT_OPERATION); if (pFile != nullptr) { rFileDesc.iFileSize = static_cast<AkInt64>(nFileSize); rFileDesc.hFile = GetFileHandle(pFile); rFileDesc.uSector = 0; rFileDesc.deviceID = m_nDeviceID; rFileDesc.pCustomParam = nullptr; rFileDesc.uCustomParamSize = 0; eResult = AK_Success; } } } return eResult; }
// ID overload. // The name of the file will be formatted as ID.ext. This is meant to be used with options // "Use SoundBank Names" unchecked, and/or "Copy Streamed Files" in the SoundBank Settings. // For more details, refer to the SoundBank Settings in Wwise Help, and to section "Identifying Banks" inside // "Sound Engine Integration Walkthrough > Integrate Wwise Elements into Your Game > Integrating Banks > // Integration Details - Banks > General Information" of the SDK documentation. // Returns AK_Success if input flags are supported and the resulting path is not too long. // Returns AK_Fail otherwise. AKRESULT CAkFileLocationBase::GetFullFilePath( AkFileID in_fileID, // File ID. AkFileSystemFlags * in_pFlags, // Special flags. AkOpenMode /* in_eOpenMode*/, // File open mode (read, write, ...). AkOSChar * out_pszFullFilePath // Full file path. ) { // If the file descriptor could not be found, or if the script-based FS does not exist, // map file ID to file descriptor (string based) for Audiokinetic IDs. if ( !in_pFlags || !(in_pFlags->uCompanyID == AKCOMPANYID_AUDIOKINETIC || in_pFlags->uCompanyID == AKCOMPANYID_AUDIOKINETIC_EXTERNAL)) { AKASSERT( !"Unhandled file type" ); return AK_Fail; } // Compute file name with file system paths. size_t uiPathSize = AKPLATFORM::OsStrLen( m_szBasePath ); // Copy base path. AKPLATFORM::SafeStrCpy( out_pszFullFilePath, m_szBasePath, AK_MAX_PATH ); // Concatenate path for AK banks or streamed audio files (everything except banks). if ( in_pFlags->uCodecID == AKCODECID_BANK ) { uiPathSize += AKPLATFORM::OsStrLen( m_szBankPath ); if ( uiPathSize >= AK_MAX_PATH ) { AKASSERT( !"Path is too large" ); return AK_Fail; } AKPLATFORM::SafeStrCat( out_pszFullFilePath, m_szBankPath, AK_MAX_PATH ); } else { uiPathSize += AKPLATFORM::OsStrLen( m_szAudioSrcPath ); if ( uiPathSize >= AK_MAX_PATH ) { AKASSERT( !"Path is too large" ); return AK_Fail; } AKPLATFORM::SafeStrCat( out_pszFullFilePath, m_szAudioSrcPath, AK_MAX_PATH ); } // Externally supplied source (see External Sources in SDK doc) // In this sample, we will assume that the file to load when receiving an external FileID is // simply the FileID.wem (e.g. "12345.wem"). If you use the External Source feature // you should modify this section to handle your FileIDs properly. /*if (in_pFlags->uCompanyID == AKCOMPANYID_AUDIOKINETIC_EXTERNAL) { }*/ // Add language directory name if needed. if ( in_pFlags->bIsLanguageSpecific ) { size_t uLanguageStrLen = AKPLATFORM::OsStrLen( AK::StreamMgr::GetCurrentLanguage() ); if ( uLanguageStrLen > 0 ) { uiPathSize += ( uLanguageStrLen + 1 ); if ( uiPathSize >= AK_MAX_PATH ) { AKASSERT( !"Path is too large" ); return AK_Fail; } AKPLATFORM::SafeStrCat( out_pszFullFilePath, AK::StreamMgr::GetCurrentLanguage(), AK_MAX_PATH ); AKPLATFORM::SafeStrCat( out_pszFullFilePath, AK_PATH_SEPARATOR, AK_MAX_PATH ); } } // Append file title. if ( ( uiPathSize + MAX_FILETITLE_SIZE ) <= AK_MAX_PATH ) { AkOSChar * pszTitle = out_pszFullFilePath + uiPathSize; if ( in_pFlags->uCodecID == AKCODECID_BANK ) AK_OSPRINTF( pszTitle, MAX_FILETITLE_SIZE, ID_TO_STRING_FORMAT_BANK, (unsigned int)in_fileID ); else AK_OSPRINTF( pszTitle, MAX_FILETITLE_SIZE, ID_TO_STRING_FORMAT_WEM, (unsigned int)in_fileID ); } else { AKASSERT( !"String buffer too small" ); return AK_Fail; } return AK_Success; }