Skip to content

Commit

Permalink
Export speed-up
Browse files Browse the repository at this point in the history
  • Loading branch information
ousnius committed Aug 16, 2015
1 parent 85a1161 commit 45730a1
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 28 deletions.
2 changes: 1 addition & 1 deletion BSAManager.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BSAManager", "BSAManager\BSAManager.vcxproj", "{2763829F-75E0-4275-A047-0035842B9EB7}"
EndProject
Expand Down
20 changes: 2 additions & 18 deletions BSAManager/BSAManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,9 @@ int BSAManagerApp::ExportFile(const wxString& bsaName, const wxString& fileName,
{
if (archive && archive->name() == bsaName)
{
wxMemoryBuffer data;
archive->fileContents(fileName, data);
if (!data.IsEmpty())
{
wxFile file(targetPath, wxFile::OpenMode::write);
if (file.IsOpened())
{
file.Write(data.GetData(), data.GetBufSize());
file.Close();
}
else
{
return 2;
}
}
else
{
if (!archive->exportFile(fileName, targetPath))
return 1;
}

break;
}
}
Expand Down
4 changes: 0 additions & 4 deletions BSAManager/BSAManager.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Ressourcendateien">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BSAManager.h">
Expand Down
52 changes: 47 additions & 5 deletions BSAManager/FSBSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <vector>
#include <wx/zstream.h>
#include <wx/mstream.h>
#include <wx/wfstream.h>


/* Default header data */
Expand Down Expand Up @@ -414,7 +415,6 @@ void BSA::fileTree(std::vector<std::string> &tree) const

bool BSA::fileContents(const wxString &fn, wxMemoryBuffer &content)
{
//qDebug() << "entering fileContents for" << fn;
if (const BSAFile *file = getFile(fn))
{
wxMutexLocker lock(bsaMutex);
Expand All @@ -440,15 +440,14 @@ bool BSA::fileContents(const wxString &fn, wxMemoryBuffer &content)
{
wxMemoryInputStream memInStream(dataPtr + 4, filesz);
wxMemoryOutputStream memOutStream;
wxZlibInputStream* zOutput = new wxZlibInputStream(memInStream);
zOutput->Read(memOutStream);
delete zOutput;
wxZlibInputStream zOutput(memInStream);
zOutput.Read(memOutStream);

size_t streamSize = memOutStream.GetSize();
content.SetBufSize(streamSize);
content.SetDataLen(streamSize);
size_t numCopied = memOutStream.CopyTo(content.GetData(), streamSize);

size_t numCopied = memOutStream.CopyTo(content.GetData(), streamSize);
if (numCopied != streamSize)
return false;
}
Expand All @@ -462,6 +461,49 @@ bool BSA::fileContents(const wxString &fn, wxMemoryBuffer &content)
return false;
}

bool BSA::exportFile(const wxString &fn, const wxString &target)
{
if (const BSAFile *file = getFile(fn))
{
wxMutexLocker lock(bsaMutex);
if (bsa.Seek(file->offset))
{
wxInt64 filesz = file->size();
ssize_t ok = 1;
if (namePrefix) {
char len;
ok = bsa.Read(&len, 1);
filesz -= len;
if (ok != wxInvalidOffset)
ok = bsa.Seek(file->offset + 1 + len);
}

wxMemoryBuffer content(filesz);

if (ok != wxInvalidOffset && bsa.Read(content.GetData(), filesz) == filesz)
{
char *dataPtr = static_cast<char*>(content.GetData());
wxFileOutputStream fileOutStream(target);

if (file->compressed() ^ compressToggle)
{
wxMemoryInputStream memInStream(dataPtr + 4, filesz);
wxZlibInputStream zOutput(memInStream);
zOutput.Read(fileOutStream);
}
else
{
wxMemoryInputStream memInStream(dataPtr, filesz);
memInStream.Read(fileOutStream);
}

return true;
}
}
}
return false;
}

wxString BSA::absoluteFilePath(const wxString &fn) const
{
if (hasFile(fn))
Expand Down
1 change: 1 addition & 0 deletions BSAManager/FSBSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class BSA final : public FSArchiveFile
* \return True if successful
*/
bool fileContents(const wxString&, wxMemoryBuffer&) override final;
bool exportFile(const wxString&, const wxString&) override final;

//! See QFileInfo::created().
wxDateTime fileTime(const wxString&) const override final;
Expand Down
1 change: 1 addition & 0 deletions BSAManager/FSEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class FSArchiveFile
virtual void addFilesOfFolders(const wxString&, std::vector<std::string>&) const = 0;
virtual void fileTree(std::vector<std::string>&) const = 0;
virtual bool fileContents(const wxString&, wxMemoryBuffer&) = 0;
virtual bool exportFile(const wxString&, const wxString&) = 0;
virtual wxString absoluteFilePath(const wxString&) const = 0;
virtual wxDateTime fileTime(const wxString&) const = 0;

Expand Down

0 comments on commit 45730a1

Please sign in to comment.