From 235d36fe69e878e78f81076dec4a21222292d498 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 13 Dec 2023 17:49:20 +0100 Subject: [PATCH] simplification of MemoryArrayReader interface. --- src/common/filesystem/include/fs_files.h | 1 - src/common/filesystem/source/files.cpp | 24 ------------------------ src/common/menu/savegamemanager.cpp | 11 +++-------- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/src/common/filesystem/include/fs_files.h b/src/common/filesystem/include/fs_files.h index 24a252cc75..0fff342725 100644 --- a/src/common/filesystem/include/fs_files.h +++ b/src/common/filesystem/include/fs_files.h @@ -236,7 +236,6 @@ public: bool OpenMemoryArray(const void *mem, Size length); // read from a copy of the buffer. bool OpenMemoryArray(std::vector& data); // take the given array bool OpenMemoryArray(FileData& data); // take the given array - bool OpenMemoryArray(std::function&)> getter); // read contents to a buffer and return a reader to it Size Tell() const { diff --git a/src/common/filesystem/source/files.cpp b/src/common/filesystem/source/files.cpp index e375d0b192..38ac730d71 100644 --- a/src/common/filesystem/source/files.cpp +++ b/src/common/filesystem/source/files.cpp @@ -399,13 +399,6 @@ bool FileReader::OpenMemoryArray(const void *mem, FileReader::Size length) return true; } -bool FileReader::OpenMemoryArray(std::vector& data) -{ - Close(); - if (data.size() > 0) mReader = new MemoryArrayReader>(data); - return true; -} - bool FileReader::OpenMemoryArray(FileData& data) { Close(); @@ -413,23 +406,6 @@ bool FileReader::OpenMemoryArray(FileData& data) return true; } -bool FileReader::OpenMemoryArray(std::function&)> getter) -{ - auto reader = new MemoryArrayReader>(nullptr, 0); - if (getter(reader->GetArray())) - { - Close(); - reader->UpdateBuffer(); - mReader = reader; - return true; - } - else - { - // This will keep the old buffer, if one existed - delete reader; - return false; - } -} //========================================================================== diff --git a/src/common/menu/savegamemanager.cpp b/src/common/menu/savegamemanager.cpp index 2513671d29..069bcf5603 100644 --- a/src/common/menu/savegamemanager.cpp +++ b/src/common/menu/savegamemanager.cpp @@ -317,14 +317,9 @@ unsigned FSavegameManagerBase::ExtractSaveData(int index) if (pic >= 0) { FileReader picreader; - - picreader.OpenMemoryArray([=](std::vector& array) - { - auto rd = resf->GetEntryReader(pic, false); - array.resize(resf->Length(pic)); - rd.Read(array.data(), array.size()); - return true; - }); + // we must create a memory reader copy of the PNG if we want to close the savegame file here. + auto rd = resf->Read(pic); + picreader.OpenMemoryArray(rd); PNGHandle *png = M_VerifyPNG(picreader); if (png != nullptr) {