Skip to content

Commit

Permalink
More Filesize 0 changes (#803)
Browse files Browse the repository at this point in the history
* Make `OtrArchive` and `O2rArchive` trace on filesize 0 and return nullptr.
Make `LoadResourceProcess` return nullptr from file being nullptr before running `LoadResource`.
Change `fileToLoad == nullptr` log to TRACE in `Archive::LoadFile`.

* formatting
  • Loading branch information
Malkierian authored Feb 11, 2025
1 parent fff4a8e commit 603b6c7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/resource/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ std::shared_ptr<IResource> ResourceManager::LoadResourceProcess(const ResourceId
auto file = LoadFileProcess(identifier.Path, initData);
if (file == nullptr) {
SPDLOG_TRACE("Failed to load resource file at path {}", identifier.Path);
return nullptr;
}

// Transform the raw data into a resource
Expand Down
2 changes: 1 addition & 1 deletion src/resource/archive/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ std::shared_ptr<File> Archive::LoadFile(const std::string& filePath, std::shared
} else {
fileToLoad = LoadFileRaw(filePath);
if (fileToLoad == nullptr) {
SPDLOG_ERROR("Failed to load file at path {}.", filePath);
SPDLOG_TRACE("Failed to load file at path {}.", filePath);
return nullptr;
}
fileToLoad->InitData = ReadResourceInitDataLegacy(filePath, fileToLoad);
Expand Down
6 changes: 6 additions & 0 deletions src/resource/archive/O2rArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ std::shared_ptr<File> O2rArchive::LoadFileRaw(const std::string& filePath) {
return nullptr;
}

// Filesize 0, no logging needed
if (zipEntryStat.size == 0) {
SPDLOG_TRACE("({}) Failed to load file {}; filesize 0", GetLastError(), filePath, GetPath());
return nullptr;
}

struct zip_file* zipEntryFile = zip_fopen_index(mZipArchive, zipEntryIndex, 0);
if (!zipEntryFile) {
SPDLOG_TRACE("Failed to open file {} in zip archive {}.", filePath, GetPath());
Expand Down
4 changes: 4 additions & 0 deletions src/resource/archive/OtrArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ std::shared_ptr<File> OtrArchive::LoadFileRaw(const std::string& filePath) {

auto fileToLoad = std::make_shared<File>();
DWORD fileSize = SFileGetFileSize(fileHandle, 0);
if (fileSize == 0) {
SPDLOG_TRACE("({}) Failed to load file {}; filesize 0", GetLastError(), filePath, GetPath());
return nullptr;
}
DWORD readBytes;
fileToLoad->Buffer = std::make_shared<std::vector<char>>(fileSize);
bool readFileSuccess = SFileReadFile(fileHandle, fileToLoad->Buffer->data(), fileSize, &readBytes, NULL);
Expand Down

0 comments on commit 603b6c7

Please sign in to comment.