static bool CreateDemoFileSplit(udtVMLinearAllocator& tempAllocator, udtContext& context, udtStream& file, const char* filePath, const char* outputFolderPath, u32 index, u32 startOffset, u32 endOffset) { if(endOffset <= startOffset) { return false; } if(file.Seek((s32)startOffset, udtSeekOrigin::Start) != 0) { return false; } const udtProtocol::Id protocol = udtGetProtocolByFilePath(filePath); if(protocol == udtProtocol::Invalid) { return false; } udtVMScopedStackAllocator scopedTempAllocator(tempAllocator); const udtString filePathString = udtString::NewConstRef(filePath); udtString fileName; if(!udtPath::GetFileNameWithoutExtension(fileName, tempAllocator, filePathString)) { fileName = udtString::NewConstRef("NEW_UDT_SPLIT_DEMO"); } udtString outputFilePathStart; if(outputFolderPath == NULL) { udtString inputFolderPath; udtPath::GetFolderPath(inputFolderPath, tempAllocator, filePathString); udtPath::Combine(outputFilePathStart, tempAllocator, inputFolderPath, fileName); } else { udtPath::Combine(outputFilePathStart, tempAllocator, udtString::NewConstRef(outputFolderPath), fileName); } char* newFilePath = AllocateSpaceForString(tempAllocator, UDT_MAX_PATH_LENGTH); sprintf(newFilePath, "%s_SPLIT_%u%s", outputFilePathStart.String, index + 1, udtGetFileExtensionByProtocol(protocol)); context.LogInfo("Writing demo %s...", newFilePath); udtFileStream outputFile; if(!outputFile.Open(newFilePath, udtFileOpenMode::Write)) { context.LogError("Could not open file"); return false; } const bool success = CopyFileRange(file, outputFile, tempAllocator, startOffset, endOffset); if(!success) { context.LogError("File copy failed"); } return success; }
bool udtPath::HasValidDemoFileExtension(const udtString& filePath) { for(u32 i = (u32)udtProtocol::FirstProtocol; i < (u32)udtProtocol::AfterLastProtocol; ++i) { const char* const extension = udtGetFileExtensionByProtocol((udtProtocol::Id)i); if(udtString::EndsWithNoCase(filePath, extension)) { return true; } } return false; }