FileReaderWUHB: Fix unmounting when opening the file fails

This commit is contained in:
Maschell 2022-04-28 20:23:18 +02:00
parent 11e89b04ce
commit 622dff63c6
2 changed files with 14 additions and 7 deletions

View File

@ -28,6 +28,9 @@ FileReaderWUHB::FileReaderWUHB(const std::shared_ptr<FileInfos> &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);
}
}

View File

@ -15,4 +15,5 @@ public:
~FileReaderWUHB() override;
int64_t read(uint8_t *buffer, uint32_t size) override;
bool isReady() override;
void UnmountBundle();
};