diff --git a/src/fs/FileReaderWUHB.cpp b/src/fs/FileReaderWUHB.cpp index 4e135b6..8f283a6 100644 --- a/src/fs/FileReaderWUHB.cpp +++ b/src/fs/FileReaderWUHB.cpp @@ -28,6 +28,9 @@ FileReaderWUHB::FileReaderWUHB(const std::shared_ptr &info, const std WUHBUtilsStatus status; if ((status = WUHBUtils_FileOpen(filepath.c_str(), &this->fileHandle)) != WUHB_UTILS_RESULT_SUCCESS) { DEBUG_FUNCTION_LINE("Failed to open file in bundle: %s error: %d", filepath.c_str(), status); + + UnmountBundle(); + return; } this->info->fileCount++; @@ -51,13 +54,7 @@ FileReaderWUHB::~FileReaderWUHB() { info->fileCount--; } - if (autoUnmount && info->fileCount <= 0) { - if (!info->UnmountBundle()) { - DEBUG_FUNCTION_LINE_ERR("Failed to unmount"); - } - } else { - DEBUG_FUNCTION_LINE_VERBOSE("Filecount is %d, we don't want to unmount yet", info->fileCount); - } + UnmountBundle(); OSMemoryBarrier(); } @@ -77,3 +74,12 @@ int64_t FileReaderWUHB::read(uint8_t *buffer, uint32_t size) { bool FileReaderWUHB::isReady() { return this->initDone; } +void FileReaderWUHB::UnmountBundle() { + if (autoUnmount && info->fileCount <= 0) { + if (!info->UnmountBundle()) { + DEBUG_FUNCTION_LINE_ERR("Failed to unmount"); + } + } else { + DEBUG_FUNCTION_LINE_VERBOSE("Filecount is %d, we don't want to unmount yet", info->fileCount); + } +} diff --git a/src/fs/FileReaderWUHB.h b/src/fs/FileReaderWUHB.h index 6ba2f67..5ec07bd 100644 --- a/src/fs/FileReaderWUHB.h +++ b/src/fs/FileReaderWUHB.h @@ -15,4 +15,5 @@ public: ~FileReaderWUHB() override; int64_t read(uint8_t *buffer, uint32_t size) override; bool isReady() override; + void UnmountBundle(); };