Beispiel #1
0
int CLogFile::FindNextWriteCommand(int iIndex)
{
	int						i;
	CLogFileCommand*		psCommand;
	int						iNumWrites;
	CLogFileCommandOpen*	psOpen;
	BOOL					bFoundWriteOpen;

	iNumWrites = 0;
	bFoundWriteOpen = FALSE;
	for (i = iIndex; i < macCommands.NumElements(); i++)
	{
		psCommand = (CLogFileCommand*)macCommands.Get(i);
		if (psCommand->IsOpen())
		{
			psOpen = (CLogFileCommandOpen*)psCommand;
			if (IsFileModeWritable(psOpen->eMode))
			{
				bFoundWriteOpen = TRUE;
			}
		}
		else if (psCommand->IsWrite() && bFoundWriteOpen)
		{
			return i;
		}
		else if (bFoundWriteOpen)
		{
			bFoundWriteOpen = FALSE;
		}
	}
	return -1;
}
Beispiel #2
0
//////////////////////////////////////////////////////////////////////////
//																		//
//																		//
//////////////////////////////////////////////////////////////////////////
BOOL CMemoryFile::Open(EFileMode eFileMode)
{
	if (IsFileModeWritable(eFileMode))
	{
		mbFakeArray = FALSE;
		iFlags = MEMORY_FILE_READ_FLAG | MEMORY_FILE_WRITE_FLAG;
		if (miInitialLength != 0)
		{
			cArray.InsertBlockAt((char*)mpvInitialMem, miInitialLength, 0);
		}
		iPos = 0;
	}
	else if (IsFileModeReadOnly(eFileMode))
	{
		mbFakeArray = TRUE;
		iFlags = MEMORY_FILE_READ_FLAG;
		if (miInitialLength != 0)
		{
			cArray.ReInit();
			cArray.Fake((char*)mpvInitialMem, miInitialLength);
		}
		iPos = 0;
	}
	else
	{
		return FALSE;
	}
	mbOpen = TRUE;
	return TRUE;
}
Beispiel #3
0
filePos CLogFile::Write(const void* pvSource, filePos iSize, filePos iCount)
{
	CArrayIntAndPointer			apvOverlapping;
	BOOL					bAny;
	filePos					iByteLength;
	CLogFileCommandWrite*	pcWrite;

	if (IsFileModeWritable(meFileMode))
	{
		mbTouched = TRUE;

		iByteLength = iSize * iCount;

		if (miLastWriteOpenIndex == -1)
		{
			bAny = FALSE;
		}
		else
		{
			bAny = FindTouchingWriteCommands(miLastWriteOpenIndex + 1, &apvOverlapping, miPosition, iByteLength, FALSE);
		}

		if (bAny)
		{
			AmalgamateOverlappingWrites(&apvOverlapping, pvSource, miPosition, iByteLength);
			apvOverlapping.Kill();
			miPosition += iByteLength;
		}
		else
		{
			pcWrite = AddWriteCommand(miPosition, (void*)pvSource, iByteLength);
			if (!pcWrite)
			{
				return 0;
			}

			miPosition += iByteLength;
		}
		UpdateLength();
		return iCount;
	}
	else
	{
		return 0;
	}
}
Beispiel #4
0
BOOL CLogFile::Open(EFileMode eFileMode)
{
	if (!AddOpenCommand(eFileMode))
	{
		meFileMode = EFM_Unknown;
		return FALSE;
	}

	if (IsFileModeWritable(eFileMode))
	{
		miLastWriteOpenIndex = macCommands.NumElements()-1;
	}
	else
	{
		miLastWriteOpenIndex = -1;
	}

	meFileMode = eFileMode;
	
	miPosition = 0;
	return TRUE;
}