mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 15:29:55 +00:00
Check if the archive is opened before adding a file to it and clear state on close
This commit is contained in:
parent
b61249841e
commit
86d137363e
1 changed files with 12 additions and 3 deletions
|
@ -252,6 +252,9 @@ int BSAFile::getIndex(const char *str) const
|
|||
/// Open an archive file.
|
||||
void BSAFile::open(const std::string &file)
|
||||
{
|
||||
if (mIsLoaded)
|
||||
close();
|
||||
|
||||
mFilename = file;
|
||||
if(boost::filesystem::exists(file))
|
||||
readHeader();
|
||||
|
@ -259,16 +262,20 @@ void BSAFile::open(const std::string &file)
|
|||
{
|
||||
{ boost::filesystem::fstream(mFilename, std::ios::binary | std::ios::out); }
|
||||
writeHeader();
|
||||
mIsLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Close the archive, write the updated headers to the file
|
||||
void Bsa::BSAFile::close()
|
||||
{
|
||||
if (!mHasChanged)
|
||||
return;
|
||||
if (mHasChanged)
|
||||
writeHeader();
|
||||
|
||||
writeHeader();
|
||||
mFiles.clear();
|
||||
mStringBuf.clear();
|
||||
mLookup.clear();
|
||||
mIsLoaded = false;
|
||||
}
|
||||
|
||||
Files::IStreamPtr BSAFile::getFile(const char *file)
|
||||
|
@ -290,6 +297,8 @@ Files::IStreamPtr BSAFile::getFile(const FileStruct *file)
|
|||
|
||||
void Bsa::BSAFile::addFile(const std::string& filename, std::istream& file)
|
||||
{
|
||||
if (!mIsLoaded)
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue