MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / OpenContentFile

Method OpenContentFile

Sources/Jazz2/ContentResolver.cpp:344–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

342#endif
343
344 std::unique_ptr<Stream> ContentResolver::OpenContentFile(StringView path, std::int32_t bufferSize)
345 {
346 // Search .paks first, then Content directory and Cache directory
347#if !defined(DEATH_TARGET_EMSCRIPTEN)
348 for (std::size_t i = 0; i < _mountedPaks.size(); i++) {
349 auto mountPoint = _mountedPaks[i]->GetMountPoint();
350 if (path.hasPrefix(mountPoint)) {
351 auto packedFile = _mountedPaks[i]->OpenFile(path.exceptPrefix(mountPoint.size()), bufferSize);
352 if (packedFile != nullptr && packedFile->IsValid()) {
353 return packedFile;
354 }
355 }
356 }
357#endif
358
359 String fullPath = fs::CombinePath(GetContentPath(), path);
360 if (fs::IsReadableFile(fullPath)) {
361 auto realFile = fs::Open(fullPath, FileAccess::Read, bufferSize);
362 if (realFile->IsValid()) {
363 return realFile;
364 }
365 }
366
367 fullPath = fs::CombinePath(GetCachePath(), path);
368 return fs::Open(fullPath, FileAccess::Read, bufferSize);
369 }
370
371 void ContentResolver::BeginLoading()
372 {

Callers 2

LoadSfxListMethod · 0.80

Calls 6

GetMountPointMethod · 0.80
OpenFileMethod · 0.80
sizeMethod · 0.45
hasPrefixMethod · 0.45
exceptPrefixMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected