- use FCompressedBuffer to store level snapshots. FCompressedMemFile has been removed.
This commit is contained in:
parent
da83d9e2bd
commit
075e98c967
11 changed files with 46 additions and 249 deletions
165
src/farchive.cpp
165
src/farchive.cpp
|
|
@ -420,171 +420,6 @@ void FCompressedFile::Explode ()
|
|||
}
|
||||
}
|
||||
|
||||
FCompressedMemFile::FCompressedMemFile ()
|
||||
{
|
||||
m_SourceFromMem = false;
|
||||
m_ImplodedBuffer = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
FCompressedMemFile::FCompressedMemFile (const char *name, EOpenMode mode)
|
||||
: FCompressedFile (name, mode)
|
||||
{
|
||||
m_SourceFromMem = false;
|
||||
m_ImplodedBuffer = NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
FCompressedMemFile::~FCompressedMemFile ()
|
||||
{
|
||||
if (m_ImplodedBuffer != NULL)
|
||||
{
|
||||
M_Free (m_ImplodedBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
bool FCompressedMemFile::Open (const char *name, EOpenMode mode)
|
||||
{
|
||||
if (mode == EWriting)
|
||||
{
|
||||
if (name)
|
||||
{
|
||||
I_Error ("FCompressedMemFile cannot write to disk");
|
||||
}
|
||||
else
|
||||
{
|
||||
return Open ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool res = FCompressedFile::Open (name, EReading);
|
||||
if (res)
|
||||
{
|
||||
fclose (m_File);
|
||||
m_File = NULL;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FCompressedMemFile::Open (void *memblock)
|
||||
{
|
||||
Close ();
|
||||
m_Mode = EReading;
|
||||
m_Buffer = (BYTE *)memblock;
|
||||
m_SourceFromMem = true;
|
||||
Explode ();
|
||||
m_SourceFromMem = false;
|
||||
return !!m_Buffer;
|
||||
}
|
||||
|
||||
bool FCompressedMemFile::Open ()
|
||||
{
|
||||
Close ();
|
||||
m_Mode = EWriting;
|
||||
m_BufferSize = 0;
|
||||
m_MaxBufferSize = 16384;
|
||||
m_Buffer = (unsigned char *)M_Malloc (16384);
|
||||
m_Pos = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FCompressedMemFile::Reopen ()
|
||||
{
|
||||
if (m_Buffer == NULL && m_ImplodedBuffer)
|
||||
{
|
||||
m_Mode = EReading;
|
||||
m_Buffer = m_ImplodedBuffer;
|
||||
m_SourceFromMem = true;
|
||||
try
|
||||
{
|
||||
Explode ();
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
// If we just leave things as they are, m_Buffer and m_ImplodedBuffer
|
||||
// both point to the same memory block and both will try to free it.
|
||||
m_Buffer = NULL;
|
||||
m_SourceFromMem = false;
|
||||
throw;
|
||||
}
|
||||
m_SourceFromMem = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void FCompressedMemFile::Close ()
|
||||
{
|
||||
if (m_Mode == EWriting)
|
||||
{
|
||||
Implode ();
|
||||
m_ImplodedBuffer = m_Buffer;
|
||||
m_Buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void FCompressedMemFile::Serialize(FArchive &arc)
|
||||
{
|
||||
if (arc.IsStoring ())
|
||||
{
|
||||
if (m_ImplodedBuffer == NULL)
|
||||
{
|
||||
I_Error ("FCompressedMemFile must be compressed before storing");
|
||||
}
|
||||
arc.Write (ZSig, 4);
|
||||
|
||||
DWORD sizes[2];
|
||||
sizes[0] = SWAP_DWORD (((DWORD *)m_ImplodedBuffer)[0]);
|
||||
sizes[1] = SWAP_DWORD (((DWORD *)m_ImplodedBuffer)[1]);
|
||||
arc.Write (m_ImplodedBuffer, (sizes[0] ? sizes[0] : sizes[1])+8);
|
||||
}
|
||||
else
|
||||
{
|
||||
Close ();
|
||||
m_Mode = EReading;
|
||||
|
||||
char sig[4];
|
||||
DWORD sizes[2] = { 0, 0 };
|
||||
|
||||
arc.Read (sig, 4);
|
||||
|
||||
if (sig[0] != ZSig[0] || sig[1] != ZSig[1] || sig[2] != ZSig[2] || sig[3] != ZSig[3])
|
||||
I_Error ("Expected to extract a compressed file");
|
||||
|
||||
arc << sizes[0] << sizes[1];
|
||||
DWORD len = sizes[0] == 0 ? sizes[1] : sizes[0];
|
||||
|
||||
m_Buffer = (BYTE *)M_Malloc (len+8);
|
||||
((DWORD *)m_Buffer)[0] = SWAP_DWORD(sizes[0]);
|
||||
((DWORD *)m_Buffer)[1] = SWAP_DWORD(sizes[1]);
|
||||
arc.Read (m_Buffer+8, len);
|
||||
m_ImplodedBuffer = m_Buffer;
|
||||
m_Buffer = NULL;
|
||||
m_Mode = EWriting;
|
||||
}
|
||||
}
|
||||
|
||||
bool FCompressedMemFile::IsOpen () const
|
||||
{
|
||||
return !!m_Buffer;
|
||||
}
|
||||
|
||||
void FCompressedMemFile::GetSizes(unsigned int &compressed, unsigned int &uncompressed) const
|
||||
{
|
||||
if (m_ImplodedBuffer != NULL)
|
||||
{
|
||||
compressed = BigLong(*(unsigned int *)m_ImplodedBuffer);
|
||||
uncompressed = BigLong(*(unsigned int *)(m_ImplodedBuffer + 4));
|
||||
}
|
||||
else
|
||||
{
|
||||
compressed = 0;
|
||||
uncompressed = m_BufferSize;
|
||||
}
|
||||
}
|
||||
|
||||
FPNGChunkFile::FPNGChunkFile (FILE *file, DWORD id)
|
||||
: FCompressedFile (file, EWriting, true, false), m_ChunkID (id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue