mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-20 06:53:52 +00:00
Merge branch 'FixBsaToolExtract' into 'master'
Update lookup only after sorting files See merge request OpenMW/openmw!893
This commit is contained in:
commit
8774d23830
1 changed files with 19 additions and 5 deletions
|
@ -182,8 +182,6 @@ void BSAFile::readHeader()
|
||||||
if(fs.offset + fs.fileSize > fsize)
|
if(fs.offset + fs.fileSize > fsize)
|
||||||
fail("Archive contains offsets outside itself");
|
fail("Archive contains offsets outside itself");
|
||||||
|
|
||||||
// Add the file name to the lookup
|
|
||||||
mLookup[fs.name()] = i;
|
|
||||||
}
|
}
|
||||||
mStringBuf.resize(endOfNameBuffer);
|
mStringBuf.resize(endOfNameBuffer);
|
||||||
|
|
||||||
|
@ -191,6 +189,13 @@ void BSAFile::readHeader()
|
||||||
return left.offset < right.offset;
|
return left.offset < right.offset;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
for (size_t i = 0; i < filenum; i++)
|
||||||
|
{
|
||||||
|
FileStruct& fs = mFiles[i];
|
||||||
|
// Add the file name to the lookup
|
||||||
|
mLookup[fs.name()] = i;
|
||||||
|
}
|
||||||
|
|
||||||
mIsLoaded = true;
|
mIsLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +252,9 @@ int BSAFile::getIndex(const char *str) const
|
||||||
/// Open an archive file.
|
/// Open an archive file.
|
||||||
void BSAFile::open(const std::string &file)
|
void BSAFile::open(const std::string &file)
|
||||||
{
|
{
|
||||||
|
if (mIsLoaded)
|
||||||
|
close();
|
||||||
|
|
||||||
mFilename = file;
|
mFilename = file;
|
||||||
if(boost::filesystem::exists(file))
|
if(boost::filesystem::exists(file))
|
||||||
readHeader();
|
readHeader();
|
||||||
|
@ -254,16 +262,20 @@ void BSAFile::open(const std::string &file)
|
||||||
{
|
{
|
||||||
{ boost::filesystem::fstream(mFilename, std::ios::binary | std::ios::out); }
|
{ boost::filesystem::fstream(mFilename, std::ios::binary | std::ios::out); }
|
||||||
writeHeader();
|
writeHeader();
|
||||||
|
mIsLoaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close the archive, write the updated headers to the file
|
/// Close the archive, write the updated headers to the file
|
||||||
void Bsa::BSAFile::close()
|
void Bsa::BSAFile::close()
|
||||||
{
|
{
|
||||||
if (!mHasChanged)
|
if (mHasChanged)
|
||||||
return;
|
|
||||||
|
|
||||||
writeHeader();
|
writeHeader();
|
||||||
|
|
||||||
|
mFiles.clear();
|
||||||
|
mStringBuf.clear();
|
||||||
|
mLookup.clear();
|
||||||
|
mIsLoaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Files::IStreamPtr BSAFile::getFile(const char *file)
|
Files::IStreamPtr BSAFile::getFile(const char *file)
|
||||||
|
@ -285,6 +297,8 @@ Files::IStreamPtr BSAFile::getFile(const FileStruct *file)
|
||||||
|
|
||||||
void Bsa::BSAFile::addFile(const std::string& filename, std::istream& 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;
|
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;
|
||||||
|
|
Loading…
Reference in a new issue