Ejemplo n.º 1
0
LPSTREAM AFXAPI _AfxGetArchiveStream(CArchive& ar, CArchiveStream& stm)
{
	// Obtain direct access to the archive's LPSTREAM.
	ar.Flush();
	CFile* pFile = ar.GetFile();
	ASSERT(pFile != NULL);
	LPSTREAM pstm;
	if (pFile->IsKindOf(RUNTIME_CLASS(COleStreamFile)))
	{
		pstm = ((COleStreamFile*)pFile)->m_lpStream;
		ASSERT(pstm != NULL);
	}
	else
	{
		ASSERT(stm.m_pArchive == NULL || stm.m_pArchive == &ar);
		stm.m_pArchive = &ar;
		pstm = &stm;
	}
	return pstm;
}
Ejemplo n.º 2
0
int CBoxScript::LoadScriptFile(LPCTSTR pstrFile, CStringA& strScriptText, int nLineNo)
{
	CFile* pFile;
	CString strOldPath;
	CBoxPath path;
	int nIncludeFlagIndex;

	if(!m_strBasePath.IsEmpty() && pstrFile[0] != _T('\\'))
		path.Combine(m_strBasePath.Left(m_strBasePath.ReverseFind(_T('\\')) + 1), pstrFile);
	else path.Combine(pstrFile);

	for(nIncludeFlagIndex = 0; nIncludeFlagIndex < m_pHost->m_arrayFile.GetCount(); nIncludeFlagIndex ++)
	{
		if(!m_pHost->m_arrayFile[nIncludeFlagIndex].CompareNoCase(path.m_strPath))
		{
			if(m_arrayIncludeFlags[nIncludeFlagIndex] != 0)
			{
				SetParserError(nLineNo, m_strBasePath, CString("Cyclic Include \"") + path.m_strPath + _T("\""));
				return 500;
			}

			m_arrayIncludeFlags[nIncludeFlagIndex] = 1;
			break;
		}
	}

	if(nIncludeFlagIndex == m_pHost->m_arrayFile.GetCount())
	{
		m_pHost->m_arrayFile.Add(path.m_strPath);
		m_arrayIncludeFlags.Add(1);
	}

	strOldPath = m_strBasePath;
	m_strBasePath = path.m_strPath;

	if((pFile = g_pFile->Open(m_strBasePath)) && pFile != BOX_FOLDER)
	{
		int nSize;
		char* strBuffer;
		int iResult = 0;

		nSize = (int)pFile->GetLength();

		if(pFile->IsKindOf(RUNTIME_CLASS(CMemFile)))
		{
			m_nCacheFileCount ++;
			if(nSize)
			{
				char *bufptr, *bufptr1;

				pFile->GetBufferPtr(CFile::bufferRead, 0, (void**)&bufptr, (void**)&bufptr1);

				iResult = ParseScriptText(bufptr, nSize, strScriptText, nIncludeFlagIndex);
			}
		}else
		{
			if (::GetFileType(pFile->m_hFile) != FILE_TYPE_DISK)
			{
				delete pFile;
				m_arrayIncludeFlags[nIncludeFlagIndex] = 0;
				m_strBasePath = strOldPath;
				return 404;
			}
			
			m_nDiskFileCount ++;
			if(nSize)
			{
				strBuffer = new char[nSize];
				if(strBuffer == NULL)
				{
					delete pFile;
					m_arrayIncludeFlags[nIncludeFlagIndex] = 0;
					m_strBasePath = strOldPath;
					return 500;
				}

				pFile->Read(strBuffer, nSize);
				iResult = ParseScriptText(strBuffer, nSize, strScriptText, nIncludeFlagIndex);
				delete strBuffer;
			}
		}
		delete pFile;

		if(iResult != 0)
		{
			m_arrayIncludeFlags[nIncludeFlagIndex] = 0;
			m_strBasePath = strOldPath;
			return iResult;
		}

		m_pHost->m_strScriptName = m_strBasePath;

		m_arrayIncludeFlags[nIncludeFlagIndex] = 0;
		m_strBasePath = strOldPath;
		return 0;
	}

	if(!strOldPath.IsEmpty())
		SetParserError(nLineNo, strOldPath, CString("Include File \"") + m_strBasePath + _T("\" not found."));

	m_arrayIncludeFlags[nIncludeFlagIndex] = 0;
	m_strBasePath = strOldPath;
	return 404;
}