|
|
@ -23,11 +23,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "bsa_file.hpp"
|
|
|
|
#include "bsa_file.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
#include <boost/filesystem/path.hpp>
|
|
|
|
#include <filesystem>
|
|
|
|
#include <boost/filesystem/fstream.hpp>
|
|
|
|
#include <fstream>
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Bsa;
|
|
|
|
using namespace Bsa;
|
|
|
|
|
|
|
|
|
|
|
@ -98,8 +98,7 @@ void BSAFile::readHeader()
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
assert(!mIsLoaded);
|
|
|
|
assert(!mIsLoaded);
|
|
|
|
|
|
|
|
|
|
|
|
namespace bfs = boost::filesystem;
|
|
|
|
std::ifstream input(std::filesystem::path(mFilename), std::ios_base::binary);
|
|
|
|
bfs::ifstream input(bfs::path(mFilename), std::ios_base::binary);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Total archive size
|
|
|
|
// Total archive size
|
|
|
|
std::streamoff fsize = 0;
|
|
|
|
std::streamoff fsize = 0;
|
|
|
@ -195,8 +194,7 @@ void BSAFile::readHeader()
|
|
|
|
/// Write header information to the output sink
|
|
|
|
/// Write header information to the output sink
|
|
|
|
void Bsa::BSAFile::writeHeader()
|
|
|
|
void Bsa::BSAFile::writeHeader()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
namespace bfs = boost::filesystem;
|
|
|
|
std::fstream output(mFilename, std::ios::binary | std::ios::in | std::ios::out);
|
|
|
|
bfs::fstream output(mFilename, std::ios::binary | std::ios::in | std::ios::out);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t head[3];
|
|
|
|
uint32_t head[3];
|
|
|
|
head[0] = 0x100;
|
|
|
|
head[0] = 0x100;
|
|
|
@ -237,11 +235,11 @@ void BSAFile::open(const std::string &file)
|
|
|
|
close();
|
|
|
|
close();
|
|
|
|
|
|
|
|
|
|
|
|
mFilename = file;
|
|
|
|
mFilename = file;
|
|
|
|
if(boost::filesystem::exists(file))
|
|
|
|
if(std::filesystem::exists(file))
|
|
|
|
readHeader();
|
|
|
|
readHeader();
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{ boost::filesystem::fstream(mFilename, std::ios::binary | std::ios::out); }
|
|
|
|
{ std::fstream(mFilename, std::ios::binary | std::ios::out); }
|
|
|
|
writeHeader();
|
|
|
|
writeHeader();
|
|
|
|
mIsLoaded = true;
|
|
|
|
mIsLoaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -262,13 +260,12 @@ void Bsa::BSAFile::addFile(const std::string& filename, std::istream& file)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (!mIsLoaded)
|
|
|
|
if (!mIsLoaded)
|
|
|
|
fail("Unable to add file " + filename + " the archive is not opened");
|
|
|
|
fail("Unable to add file " + filename + " the archive is not opened");
|
|
|
|
namespace bfs = boost::filesystem;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto newStartOfDataBuffer = 12 + (12 + 8) * (mFiles.size() + 1) + mStringBuf.size() + filename.size() + 1;
|
|
|
|
auto newStartOfDataBuffer = 12 + (12 + 8) * (mFiles.size() + 1) + mStringBuf.size() + filename.size() + 1;
|
|
|
|
if (mFiles.empty())
|
|
|
|
if (mFiles.empty())
|
|
|
|
bfs::resize_file(mFilename, newStartOfDataBuffer);
|
|
|
|
std::filesystem::resize_file(mFilename, newStartOfDataBuffer);
|
|
|
|
|
|
|
|
|
|
|
|
bfs::fstream stream(mFilename, std::ios::binary | std::ios::in | std::ios::out);
|
|
|
|
std::fstream stream(mFilename, std::ios::binary | std::ios::in | std::ios::out);
|
|
|
|
|
|
|
|
|
|
|
|
FileStruct newFile;
|
|
|
|
FileStruct newFile;
|
|
|
|
file.seekg(0, std::ios::end);
|
|
|
|
file.seekg(0, std::ios::end);
|
|
|
|