components/bsa cleanup

pull/593/head
Bret Curtis 4 years ago
parent 43614e2204
commit d826fbdadf

@ -150,7 +150,7 @@ void BSAFile::readHeader()
/// Get the index of a given file name, or -1 if not found
int BSAFile::getIndex(const char *str) const
{
Lookup::const_iterator it = mLookup.find(str);
auto it = mLookup.find(str);
if(it == mLookup.end())
return -1;

@ -24,7 +24,7 @@
#ifndef BSA_BSA_FILE_H
#define BSA_BSA_FILE_H
#include <stdint.h>
#include <cstdint>
#include <string>
#include <vector>
#include <map>
@ -106,8 +106,7 @@ public:
: mIsLoaded(false)
{ }
virtual ~BSAFile()
{ }
virtual ~BSAFile() = default;
/// Open an archive file.
void open(const std::string &file);

@ -36,7 +36,6 @@
#include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/copy.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/device/array.hpp>
#include <components/bsa/memorystream.hpp>
@ -103,8 +102,7 @@ CompressedBSAFile::CompressedBSAFile()
: mCompressedByDefault(false), mEmbeddedFileNames(false)
{ }
CompressedBSAFile::~CompressedBSAFile()
{ }
CompressedBSAFile::~CompressedBSAFile() = default;
/// Read header information from the input source
void CompressedBSAFile::readHeader()
@ -183,7 +181,7 @@ void CompressedBSAFile::readHeader()
else
input.read(reinterpret_cast<char*>(&fr.offset), 4); // not sure purpose of offset
std::map<std::uint64_t, FolderRecord>::const_iterator lb = mFolders.lower_bound(hash);
auto lb = mFolders.lower_bound(hash);
if (lb != mFolders.end() && !(mFolders.key_comp()(hash, lb->first)))
fail("Archive found duplicate folder name hash");
else
@ -194,7 +192,7 @@ void CompressedBSAFile::readHeader()
std::uint64_t fileHash;
FileRecord file;
std::string folder("");
std::string folder;
std::uint64_t folderHash;
if ((archiveFlags & 0x1) == 0)
folderCount = 1; // TODO: not tested - unit test necessary
@ -209,7 +207,7 @@ void CompressedBSAFile::readHeader()
folderHash = generateHash(folder, std::string());
std::map<std::uint64_t, FolderRecord>::iterator iter = mFolders.find(folderHash);
auto iter = mFolders.find(folderHash);
if (iter == mFolders.end())
fail("Archive folder name hash not found");
@ -219,13 +217,13 @@ void CompressedBSAFile::readHeader()
input.read(reinterpret_cast<char*>(&file.size), 4);
input.read(reinterpret_cast<char*>(&file.offset), 4);
std::map<std::uint64_t, FileRecord>::const_iterator lb = iter->second.files.lower_bound(fileHash);
auto lb = iter->second.files.lower_bound(fileHash);
if (lb != iter->second.files.end() && !(iter->second.files.key_comp()(fileHash, lb->first)))
fail("Archive found duplicate file name hash");
iter->second.files.insert(lb, std::pair<std::uint64_t, FileRecord>(fileHash, file));
FileStruct fileStruct;
FileStruct fileStruct{};
fileStruct.fileSize = file.getSizeWithoutCompressionFlag();
fileStruct.offset = file.offset;
fileStruct.name = nullptr;
@ -308,12 +306,12 @@ CompressedBSAFile::FileRecord CompressedBSAFile::getFileRecord(const std::string
std::string folder = p.string();
std::uint64_t folderHash = generateHash(folder, std::string());
std::map<std::uint64_t, FolderRecord>::const_iterator it = mFolders.find(folderHash);
auto it = mFolders.find(folderHash);
if (it == mFolders.end())
return FileRecord(); // folder not found, return default which has offset of sInvalidOffset
std::uint64_t fileHash = generateHash(stem, ext);
std::map<std::uint64_t, FileRecord>::const_iterator iter = it->second.files.find(fileHash);
auto iter = it->second.files.find(fileHash);
if (iter == it->second.files.end())
return FileRecord(); // file not found, return default which has offset of sInvalidOffset
@ -430,12 +428,12 @@ BsaVersion CompressedBSAFile::detectVersion(std::string filePath)
//mFiles used by OpenMW expects uncompressed sizes
void CompressedBSAFile::convertCompressedSizesToUncompressed()
{
for (auto iter = mFiles.begin(); iter != mFiles.end(); ++iter)
for (auto & mFile : mFiles)
{
const FileRecord& fileRecord = getFileRecord(iter->name);
const FileRecord& fileRecord = getFileRecord(mFile.name);
if (!fileRecord.isValid())
{
fail("Could not find file " + std::string(iter->name) + " in BSA");
fail("Could not find file " + std::string(mFile.name) + " in BSA");
}
if (!fileRecord.isCompressed(mCompressedByDefault))
@ -452,11 +450,11 @@ void CompressedBSAFile::convertCompressedSizesToUncompressed()
getBZString(embeddedFileName, *(dataBegin.get()));
}
dataBegin->read(reinterpret_cast<char*>(&(iter->fileSize)), sizeof(iter->fileSize));
dataBegin->read(reinterpret_cast<char*>(&(mFile.fileSize)), sizeof(mFile.fileSize));
}
}
std::uint64_t CompressedBSAFile::generateHash(std::string stem, std::string extension) const
std::uint64_t CompressedBSAFile::generateHash(std::string stem, std::string extension)
{
size_t len = stem.length();
if (len == 0)

@ -80,7 +80,7 @@ namespace Bsa
//mFiles used by OpenMW will contain uncompressed file sizes
void convertCompressedSizesToUncompressed();
/// \brief Normalizes given filename or folder and generates format-compatible hash. See https://en.uesp.net/wiki/Tes4Mod:Hash_Calculation.
std::uint64_t generateHash(std::string stem, std::string extension) const;
static std::uint64_t generateHash(std::string stem, std::string extension) ;
Files::IStreamPtr getFile(const FileRecord& fileRecord);
public:
CompressedBSAFile();

@ -37,8 +37,8 @@ Class used internally by MemoryInputStream.
class MemoryInputStreamBuf : public std::streambuf {
public:
MemoryInputStreamBuf(size_t bufferSize);
char* getRawData();
explicit MemoryInputStreamBuf(size_t bufferSize);
virtual char* getRawData();
private:
//correct call to delete [] on C++ 11
std::vector<char> mBufferPtr;
@ -54,8 +54,8 @@ private:
*/
class MemoryInputStream : virtual MemoryInputStreamBuf, std::istream {
public:
MemoryInputStream(size_t bufferSize);
char* getRawData();
explicit MemoryInputStream(size_t bufferSize);
char* getRawData() override;
};
}

Loading…
Cancel
Save