Exemple #1
0
/////////////////////////////////////////////////////////////////
// SaveModHdrsToStream ()
//    save module headers to stream w/o compressing the array
//	  first. Compression should be done outside this function
/////////////////////////////////////////////////////////////////
BOOL Ncb::SaveModHdrsToStream(PDB * pdb)
{
	Stream * pstmMod;
	Buffer buffer;
	PB pBuffer;
	
	// open stream for module hdrs
	if (!pdb->OpenStream (SZ_NCB_MODULE_INFO, &pstmMod))
		return FALSE;

	if (!pstmMod->Truncate (0))
		goto fail;
	// save the array to the buffer
	if (!m_rgModHdr.save (&buffer))
		goto fail;
	// find where the buffer starts
	pBuffer = buffer.Start();
	// start writing the buffer to the stream
	if (!pstmMod->Append (pBuffer, buffer.Size()))
		goto fail;

	m_rgModHdr.setSize(0); // clean up arrays
	m_rgStat.setSize(0);
	m_rgNotifyBuild.setSize (0);
	pstmMod->Release();
	return TRUE;
fail:
	pstmMod->Release();
	return FALSE;
};
Exemple #2
0
/////////////////////////////////////////////////////////////////
// SaveReadModToStream()
//	given the module index (iBuf), we want to save it back to stream
//  This is typically called after we LoadFrWriteToRead(), so we need
//  to save its content to the stream.
/////////////////////////////////////////////////////////////////
BOOL Ncb::SaveReadModToStream (PDB * pdb, USHORT iBuf)
{
	_ASSERT (iBuf < NCB_MOD_BUF_SIZE);

	Stream * pstmMod;
	char buf[512];
	SZ szMod;
	unsigned iHdr;

	iHdr = m_rgContBuf[iBuf].m_iModHdr;
	szMod = szFrNi (m_rgModHdr[iHdr].m_ni);
	strcpy (buf, SZ_NCB_MODULE_PREFIX);
	strcat (buf, szMod);
	if (!pdb->OpenStream (buf, & pstmMod))
		return FALSE;

	if (!pstmMod->Truncate(0))
		goto fail;

	if (!pstmMod->Append (m_rgContBuf[iBuf].m_rgProp,
		m_rgModHdr[iHdr].m_cProp * sizeof (NCB_PROP)))
		goto fail;

	if (!pstmMod->Append (m_rgContBuf[iBuf].m_rgUse,
		m_rgModHdr[iHdr].m_cUse * sizeof (NCB_USE)))
		goto fail;
	
	if (!pstmMod->Append (m_rgContBuf[iBuf].m_rgParam,
		m_rgModHdr[iHdr].m_cParam * sizeof (NI)))
		goto fail;

	// set buffer to be the oldest one:
	pstmMod->Release();
	m_rgContBuf[iBuf].m_prio = NCB_MOD_BUF_SIZE;
	return TRUE;
fail:
	pstmMod->Release();
	return FALSE;
};
Exemple #3
0
////////////////////////////////////////////////////////////////
//
// SaveTargetsToStream(pdb)
//    save target information to stream
/////////////////////////////////////////////////////////////////
BOOL Ncb::SaveTargetsToStream (PDB * pdb)
{
	NCB_TARGET * rgTargets; // temporary array to store target info
	Stream * pstmTarget;
	char buf[512];
	int i;
	Array<NCB_MODINFO>	rgModInfo;
	USHORT cSize;

	rgTargets = new NCB_TARGET[m_cTargets];

	if (!rgTargets)
		goto fail;
	
	// for each target, save two arrays
	// array of modules (m_rgModInfo)
	for (i = 0 ; i < m_cTargets; i++)
	{	
		Buffer buffer;
		PB pBuffer;
		SZ szTarget;
		if (m_rgTargetInfo[i].m_ni == (NI)-1)
			return FALSE;
		szTarget = szFrNi (m_rgTargetInfo[i].m_ni);
		strcpy (buf, SZ_NCB_TARGET_PREFIX);
		strcat (buf, szTarget);

		// REVIEW: should we compress it here or
		// do this before compressing the modules
		if (!CompressTarget (&m_rgTargetInfo[i], rgModInfo))
			goto fail;
		rgTargets[i].m_ni = m_rgTargetInfo[i].m_ni;
		// store each target in a separate stream:
		if (!pdb->OpenStream (buf, &pstmTarget))
			goto fail;
		if (!pstmTarget->Truncate(0))
			goto fail;
		cSize = 0;
		// save the arrays in the buffer and write the content
		// of the buffer to the stream
		if (!rgModInfo.save (&buffer))
			goto fail;
		pBuffer = buffer.Start();
		if (!pstmTarget->Append (pBuffer, buffer.Size()))
			goto fail; 
		pstmTarget->Release();
		pstmTarget = NULL;
	}
	
	if (!pdb->OpenStream (SZ_NCB_TARGET_INFO, &pstmTarget))
		goto fail;

	// store rgTargets
	if (!pstmTarget->Truncate(0)) // delete previous information
		goto fail;
	if (!pstmTarget->Append (rgTargets, m_cTargets * sizeof (NCB_TARGET)))
		goto fail;

	pstmTarget->Release();
	delete [] rgTargets;
	return TRUE;

fail:
	delete [] rgTargets;
	pstmTarget->Release();
	pstmTarget = NULL;
	return FALSE;
};