The last byte of stv demos is cut off, so do that here too

This commit is contained in:
Jordan Cristiano 2015-06-30 01:34:55 -04:00
parent 7bdbce9aef
commit 8e13067339
3 changed files with 33 additions and 0 deletions

View File

@ -108,6 +108,11 @@ DemoFileWriter::DemoFileWriter(FILE* fp) :
{
}
FILE* DemoFileWriter::GetFp() const
{
return m_demoFp;
}
bool DemoFileWriter::IsOk() const
{
return ferror(m_demoFp) == 0;

View File

@ -32,6 +32,7 @@ class DemoFileWriter
public:
DemoFileWriter(FILE* fp);
FILE* GetFp() const;
bool IsOk() const;
void WriteDemoHeader(const demoheader_t& header);
void WriteRawData(const uint8_t* buffer, int32_t length);

View File

@ -9,6 +9,30 @@
#include <cstdio>
#include <memory>
#ifdef _WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include <sys/stat.h>
int truncate(FILE* fp, int relative_offset)
{
fflush(fp);
#ifdef _WIN32
const int fd = _fileno(fp);
#else
const int fd = fileno(fp);
#endif
struct stat statbuf;
fstat(fd, &statbuf);
#ifdef _WIN32
return _chsize_s(fd, statbuf.st_size + relative_offset);
#else
return ftruncate(fd, statbuf.st_size + relative_offset);
#endif
}
class DemoWriter: public IDemoWriter
{
public:
@ -47,6 +71,9 @@ void DemoWriter::StartWriting(demoheader_t& header)
void DemoWriter::EndWriting()
{
// stv demos have a byte chopped off of the end
// i dunno why, just doit
truncate(m_writer.GetFp(), -1);
}
void DemoWriter::StartCommandPacket(const CommandPacket& packet)