2019-01-18 20:14:44 +00:00
|
|
|
/*
|
|
|
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
|
|
|
Copyright (C) 2008-2010 Nicolay Korslund
|
|
|
|
Email: < korslund@gmail.com >
|
|
|
|
WWW: http://openmw.sourceforge.net/
|
|
|
|
|
|
|
|
This file (compressedbsafile.hpp) is part of the OpenMW package.
|
|
|
|
|
|
|
|
OpenMW is distributed as free software: you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License
|
|
|
|
version 3, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
version 3 along with this program. If not, see
|
|
|
|
http://www.gnu.org/licenses/ .
|
|
|
|
|
|
|
|
Compressed BSA stuff added by cc9cii 2018
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BSA_COMPRESSED_BSA_FILE_H
|
|
|
|
#define BSA_COMPRESSED_BSA_FILE_H
|
|
|
|
|
|
|
|
#include <components/bsa/bsa_file.hpp>
|
|
|
|
|
|
|
|
namespace Bsa
|
|
|
|
{
|
|
|
|
enum BsaVersion
|
|
|
|
{
|
|
|
|
BSAVER_UNKNOWN = 0x0,
|
|
|
|
BSAVER_UNCOMPRESSED = 0x100,
|
|
|
|
BSAVER_COMPRESSED = 0x415342 //B, S, A
|
|
|
|
};
|
|
|
|
|
|
|
|
class CompressedBSAFile : public BSAFile
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
//special marker for invalid records,
|
|
|
|
//equal to max uint32_t value
|
|
|
|
static const uint32_t sInvalidOffset;
|
|
|
|
|
|
|
|
//bit marking compression on file size
|
|
|
|
static const uint32_t sCompressedFlag;
|
|
|
|
|
|
|
|
struct FileRecord
|
|
|
|
{
|
|
|
|
std::uint32_t size;
|
|
|
|
std::uint32_t offset;
|
|
|
|
|
|
|
|
FileRecord();
|
|
|
|
bool isCompressed(bool bsaCompressedByDefault) const;
|
|
|
|
bool isValid() const;
|
|
|
|
std::uint32_t getSizeWithoutCompressionFlag() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
//if files in BSA without 30th bit enabled are compressed
|
|
|
|
bool mCompressedByDefault;
|
|
|
|
|
|
|
|
//if each file record begins with BZ string with file name
|
|
|
|
bool mEmbeddedFileNames;
|
|
|
|
|
2020-10-10 11:00:03 +00:00
|
|
|
std::uint32_t mVersion{0u};
|
|
|
|
|
2019-01-18 20:14:44 +00:00
|
|
|
struct FolderRecord
|
|
|
|
{
|
|
|
|
std::uint32_t count;
|
2020-10-10 11:00:03 +00:00
|
|
|
std::uint64_t offset;
|
2019-01-18 20:14:44 +00:00
|
|
|
std::map<std::uint64_t, FileRecord> files;
|
|
|
|
};
|
|
|
|
std::map<std::uint64_t, FolderRecord> mFolders;
|
|
|
|
|
|
|
|
FileRecord getFileRecord(const std::string& str) const;
|
|
|
|
|
|
|
|
void getBZString(std::string& str, std::istream& filestream);
|
|
|
|
//mFiles used by OpenMW will contain uncompressed file sizes
|
|
|
|
void convertCompressedSizesToUncompressed();
|
2019-01-20 19:59:25 +00:00
|
|
|
/// \brief Normalizes given filename or folder and generates format-compatible hash. See https://en.uesp.net/wiki/Tes4Mod:Hash_Calculation.
|
2020-10-22 20:39:59 +00:00
|
|
|
static std::uint64_t generateHash(std::string stem, std::string extension) ;
|
2019-01-18 20:14:44 +00:00
|
|
|
Files::IStreamPtr getFile(const FileRecord& fileRecord);
|
|
|
|
public:
|
|
|
|
CompressedBSAFile();
|
|
|
|
virtual ~CompressedBSAFile();
|
|
|
|
|
|
|
|
//checks version of BSA from file header
|
2021-06-23 21:13:59 +00:00
|
|
|
static BsaVersion detectVersion(const std::string& filePath);
|
2019-01-18 20:14:44 +00:00
|
|
|
|
|
|
|
/// Read header information from the input source
|
2020-10-16 18:18:54 +00:00
|
|
|
void readHeader() override;
|
2019-01-18 20:14:44 +00:00
|
|
|
|
2020-10-16 18:18:54 +00:00
|
|
|
Files::IStreamPtr getFile(const char* filePath) override;
|
2021-10-11 08:09:48 +00:00
|
|
|
Files::IStreamPtr getFile(const FileStruct* fileStruct);
|
2021-04-07 16:58:46 +00:00
|
|
|
void addFile(const std::string& filename, std::istream& file) override;
|
2019-01-18 20:14:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|