bool CWriter::WriteAllIntoMemory( uint8* &rpData, uint32& outSize )
{
	if (!m_rootAddr.IsValid())
		Done();

	SFileHeader fileHeader;
	CreateFileHeader(fileHeader);

	outSize = sizeof(fileHeader);
	outSize += m_tableTags.GetDataSize();
	outSize += m_tableAttrNames.GetDataSize();
	outSize += m_tableStrData.GetDataSize();
	outSize += m_tableAttrSets.GetDataSize();
	outSize += m_mainBuffer.GetDataSize();

	if (outSize > 0)
	{
		rpData = (uint8*)realloc((void*)rpData, outSize*sizeof(uint8));

		uint32 uWriteLoc = 0;
		WriteDataIntoMemory( rpData, &fileHeader, sizeof(fileHeader), uWriteLoc);
		m_mainBuffer.WriteToMemory( rpData, uWriteLoc );
		m_tableTags.WriteToMemory( rpData, uWriteLoc );
		m_tableAttrNames.WriteToMemory( rpData, uWriteLoc );
		m_tableStrData.WriteToMemory( rpData, uWriteLoc );
		m_tableAttrSets.WriteToMemory( rpData, uWriteLoc );
	}

	if (m_hasInternalError)
		CryWarning( VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "XMLCPB: ERROR in binary save-into-memory generation. (probably something wrong in a pooled entity). The data will be corrupted" );

	return (outSize > 0);
}
bool CWriter::FinishWritingFile()
{
	// if this happens, most likely is an overflow of some of the hard coded limits ( which usually is caused by an error in game side ).
	if (m_hasInternalError)
		CryWarning( VALIDATOR_MODULE_SYSTEM, VALIDATOR_ERROR, "XMLCPB: ERROR in binary save generation. The savegame is corrupted." );

	if (!m_compressor->m_errorWritingIntoFile)	
	{
		if (!m_rootAddr.IsValid())
			Done();

		assert( m_rootAddr.IsValid() );


		m_mainBuffer.WriteToFile(); // this actually writes only the last data remains, because it has been writing all along the process.
		m_tableTags.WriteToFile();
		m_tableAttrNames.WriteToFile();
		m_tableStrData.WriteToFile();
		m_tableAttrSets.WriteToFile();

		CreateFileHeader(m_compressor->GetFileHeader());

		m_compressor->FlushZLibBuffer();
	}	
	
		
	return !m_compressor->m_errorWritingIntoFile;
}
Ejemplo n.º 3
0
int Folder2Img (char *InputFolderPath, char *OutputFilePath) 
{
  int Res = 0;
  FILE *fo = NULL;
  RootFolder = malloc (strlen (InputFolderPath) + 1) ;
  strcpy (RootFolder, InputFolderPath) ;
  /*
    1. Travel directories and files
    2. After fount a entry type is file, add path to file list
  */
  
  strcat (CurrentPath, InputFolderPath) ;
  printf ("Root folder : %s\n", CurrentPath) ;
  Res = FolderTraveler (InputFolderPath) ;  /*Start from the root folder */
  printf ("-- Folder travel done. --\n") ;
  printf ("File counts : %d\n", FileCounter) ;
  printf ("File Size   : %d\n", FileTotalSize) ;



  /*
    1. Travel ihfs file list
    2. Create file image in memory
  */
  ListTraveler (OutputFileList) ;

  //fo = fopen ("table", "wb") ;
  //fwrite (OutputSectorHeader, 1, FileCounter * 64, fo) ;
  //fclose (fo) ;

  /*
    Create file header info
  */
  CreateFileHeader () ;


  /*
    1. Merge 3 parts
    2. Write fw file
  */
  CreateFile () ;


  free (RootFolder) ;
  
  return 0;
}