diff options
author | jmarshallnz <jmarshallnz@svn> | 2010-09-15 00:30:37 +0000 |
---|---|---|
committer | jmarshallnz <jmarshallnz@svn> | 2010-09-15 00:30:37 +0000 |
commit | 6d368804f9534e4f3ab93649ca5c2bb4059c7bf0 (patch) | |
tree | a0658c589c9bde98dd5b1546efcb4316fa8254b9 /tools/TexturePacker/XBTFWriter.cpp | |
parent | 14ac82d6063f7246d170a3da8cbe9b333dbb6bfb (diff) |
changed: TexturePacker - don't write to a temporary file, keep it in memory instead.
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@33815 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'tools/TexturePacker/XBTFWriter.cpp')
-rw-r--r-- | tools/TexturePacker/XBTFWriter.cpp | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/tools/TexturePacker/XBTFWriter.cpp b/tools/TexturePacker/XBTFWriter.cpp index d5beb143d7..6435734d91 100644 --- a/tools/TexturePacker/XBTFWriter.cpp +++ b/tools/TexturePacker/XBTFWriter.cpp @@ -34,7 +34,9 @@ CXBTFWriter::CXBTFWriter(CXBTF& xbtf, const std::string& outputFile) : m_xbtf(xbtf) { m_outputFile = outputFile; - m_file = m_tempFile = NULL; + m_file = NULL; + m_data = NULL; + m_size = 0; } bool CXBTFWriter::Create() @@ -45,52 +47,49 @@ bool CXBTFWriter::Create() return false; } - m_tempFile = fopen(TEMP_FILE, "wb"); - if (m_tempFile == NULL) - { - return false; - } - return true; } bool CXBTFWriter::Close() { - if (m_file == NULL || m_tempFile == NULL) + if (m_file == NULL || m_data == NULL) { return false; } - fclose(m_tempFile); - m_tempFile = fopen(TEMP_FILE, "rb"); - if (m_tempFile == NULL) - { - return false; - } - - unsigned char* tmp = new unsigned char[10*1024*1024]; - size_t bytesRead; - while ((bytesRead = fread(tmp, 1, TEMP_SIZE, m_tempFile)) > 0) - { - fwrite(tmp, bytesRead, 1, m_file); - } - delete[] tmp; + fwrite(m_data, 1, m_size, m_file); - fclose(m_file); - fclose(m_tempFile); - unlink(TEMP_FILE); + Cleanup(); return true; } -bool CXBTFWriter::AppendContent(unsigned char const* data, size_t length) +void CXBTFWriter::Cleanup() { - if (m_tempFile == NULL) + free(m_data); + m_data = NULL; + m_size = 0; + if (m_file) { + fclose(m_file); + m_file = NULL; + } +} + +bool CXBTFWriter::AppendContent(unsigned char const* data, size_t length) +{ + unsigned char *new_data = (unsigned char *)realloc(m_data, m_size + length); + + if (new_data == NULL) + { // OOM - cleanup and fail + Cleanup(); return false; } - fwrite(data, length, 1, m_tempFile); + m_data = new_data; + + memcpy(m_data + m_size, data, length); + m_size += length; return true; } |