Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set parent pointer on file to be the same shared pointer from mFileToArchive #452

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/resource/archive/ArchiveManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ std::shared_ptr<File> ArchiveManager::LoadFile(const std::string& filePath) {
return nullptr;
}

const auto archive = mFileToArchive[CRC64(filePath.c_str())];
if (archive == nullptr) {
return nullptr;
}

return archive->LoadFile(filePath);
return LoadFile(CRC64(filePath.c_str()));
}

std::shared_ptr<File> ArchiveManager::LoadFile(uint64_t hash) {
Expand All @@ -59,20 +54,17 @@ std::shared_ptr<File> ArchiveManager::LoadFile(uint64_t hash) {
return nullptr;
}

return archive->LoadFile(hash);
auto file = archive->LoadFile(hash);
file->Parent = archive;
return file;
}

std::shared_ptr<File> ArchiveManager::LoadFileRaw(const std::string& filePath) {
if (filePath == "") {
return nullptr;
}

const auto archive = mFileToArchive[CRC64(filePath.c_str())];
if (archive == nullptr) {
return nullptr;
}

return archive->LoadFileRaw(filePath);
return LoadFileRaw(CRC64(filePath.c_str()));
}

std::shared_ptr<File> ArchiveManager::LoadFileRaw(uint64_t hash) {
Expand All @@ -81,7 +73,9 @@ std::shared_ptr<File> ArchiveManager::LoadFileRaw(uint64_t hash) {
return nullptr;
}

return archive->LoadFileRaw(hash);
auto file = archive->LoadFileRaw(hash);
file->Parent = archive;
return file;
}

bool ArchiveManager::HasFile(const std::string& filePath) {
Expand Down
1 change: 0 additions & 1 deletion src/resource/archive/O2rArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ std::shared_ptr<File> O2rArchive::LoadFileRaw(const std::string& filePath) {
SPDLOG_TRACE("Error closing file {} in zip archive {}.", filePath, GetPath());
}

fileToLoad->Parent = dynamic_pointer_cast<Archive>(std::make_shared<O2rArchive>(std::move(*this)));
fileToLoad->IsLoaded = true;

return fileToLoad;
Expand Down
1 change: 0 additions & 1 deletion src/resource/archive/OtrArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ std::shared_ptr<File> OtrArchive::LoadFileRaw(const std::string& filePath) {
SPDLOG_ERROR("({}) Failed to close file {} from mpq archive {}", GetLastError(), filePath, GetPath());
}

fileToLoad->Parent = dynamic_pointer_cast<Archive>(std::make_shared<OtrArchive>(std::move(*this)));
fileToLoad->IsLoaded = true;

return fileToLoad;
Expand Down
Loading