Пример #1
0
bool CLevelTheme::SplitThemeAndRoom( const char *pszFullName, char *szThemeOut, int nThemeOutSize, char *szRoomOut, int nRoomOutSize )
{
	const char *pszFirstForwardSlash = Q_strnchr( pszFullName, '/', Q_strlen( pszFullName ) );
	const char *pszFirstBackSlash = Q_strnchr( pszFullName, '\\', Q_strlen( pszFullName ) );

	if ( pszFirstBackSlash && pszFirstForwardSlash )
	{
		pszFirstForwardSlash = pszFirstForwardSlash < pszFirstBackSlash ? pszFirstForwardSlash : pszFirstBackSlash;
	}
	else if ( !pszFirstForwardSlash && pszFirstBackSlash )
	{
		pszFirstForwardSlash = pszFirstBackSlash;
	}
	else if ( !pszFirstForwardSlash && !pszFirstBackSlash )
	{
		return false;
	}

	Q_strncpy( szThemeOut, pszFullName, nThemeOutSize );
	int iSlashPos = pszFirstForwardSlash - pszFullName;
	if ( iSlashPos < nThemeOutSize )
	{
		szThemeOut[ iSlashPos ] = 0;
	}

	Q_strncpy( szRoomOut, pszFirstForwardSlash + 1, nRoomOutSize );
	return true;
}
Пример #2
0
int CTilegenKVEditorPage::RecursiveCreateFolderNodes( int iParentIndex, char *szFilename )
{
	char* szFolder = (char*) Q_strnchr( szFilename, CORRECT_PATH_SEPARATOR, Q_strlen( szFilename ) );
	if ( !szFolder )
	{
		return iParentIndex;
	}

	*szFolder = 0;	
	// check if szFilename node exists already
	for ( int i = 0; i < m_pTree->GetNumChildren( iParentIndex ); i++ )
	{
		int iChild = m_pTree->GetChild( iParentIndex, i );
		KeyValues *pKV = m_pTree->GetItemData( iChild );
		if ( !Q_stricmp( szFilename, pKV->GetString( "Text" ) ) )
		{
			return iChild;
		}
	}
	KeyValues *pFolderEntry = new KeyValues("FolderEntry");
	pFolderEntry->SetString( "Text", szFilename );
	int iItem = m_pTree->AddItem( pFolderEntry, iParentIndex );
	m_pTree->SetItemFgColor( iItem, Color(128, 128, 128, 255) );
	return RecursiveCreateFolderNodes( iItem, szFolder + 1 );
}
Пример #3
0
	void one_pk3(void) {
		char *s;
		//sprintf(clc.downloadList, "@q3ut4/%s.pk3@q3ut4/%s.pk3", clc.mapname);
		
		if( cl_autodownload->integer & DLF_ENABLE ) {
		// check whether there is a <bspname>.pk3; if so, download, else proceed as normal
			if (!(((int)clc.mapname[0] >= (int)('a') && (int)clc.mapname[0] <= (int)('y')) || ((int)clc.mapname[0] >= (int)('A') && (int)clc.mapname[0] <= (int)('Y')))) {
				clc.downloadList[0] = '\0';
			} else {
				s=strstr(clc.downloadList, va("/%s.pk3@", clc.mapname));
				if (s) {
					// remove stuff after current map
					s=Q_strnchr(s, '@', 2);
					if(s)
						s[0] = '\0';
					// remove stuff before current map
					s=Q_strnrchr(clc.downloadList, '@', 2);
					if(s)
						memmove( clc.downloadList, s, strlen(s) + 1);
				} else {
					clc.downloadList[0] = '\0';
				}
			}
		}
	}
//-----------------------------------------------------------------------------
// Converts a buffer from a CRLF buffer to a CR buffer (and back)
// Returns false if no conversion was necessary (and outBuf is left untouched)
// If the conversion occurs, outBuf will be cleared.
//-----------------------------------------------------------------------------
bool CUtlBufferEditor::ConvertCRLF( CUtlBufferEditor &outBuf )
{
	if ( !IsText() || !outBuf.IsText() )
		return false;

	if ( ContainsCRLF() == outBuf.ContainsCRLF() )
		return false;

	int nInCount = TellMaxPut();

	outBuf.Purge();
	outBuf.EnsureCapacity( nInCount );

	bool bFromCRLF = ContainsCRLF();

	// Start reading from the beginning
	int nGet = TellGet();
	int nPut = TellPut();
	int nGetDelta = 0;
	int nPutDelta = 0;

	const char *pBase = (const char*)Base();
	int nCurrGet = 0;
	while ( nCurrGet < nInCount )
	{
		const char *pCurr = &pBase[nCurrGet];
		if ( bFromCRLF )
		{
			const char *pNext = Q_strnistr( pCurr, "\r\n", nInCount - nCurrGet );
			if ( !pNext )
			{
				outBuf.Put( pCurr, nInCount - nCurrGet );
				break;
			}

			int nBytes = (size_t)pNext - (size_t)pCurr;
			outBuf.Put( pCurr, nBytes );
			outBuf.PutChar( '\n' );
			nCurrGet += nBytes + 2;
			if ( nGet >= nCurrGet - 1 )
			{
				--nGetDelta;
			}
			if ( nPut >= nCurrGet - 1 )
			{
				--nPutDelta;
			}
		}
		else
		{
			const char *pNext = Q_strnchr( pCurr, '\n', nInCount - nCurrGet );
			if ( !pNext )
			{
				outBuf.Put( pCurr, nInCount - nCurrGet );
				break;
			}

			int nBytes = (size_t)pNext - (size_t)pCurr;
			outBuf.Put( pCurr, nBytes );
			outBuf.PutChar( '\r' );
			outBuf.PutChar( '\n' );
			nCurrGet += nBytes + 1;
			if ( nGet >= nCurrGet )
			{
				++nGetDelta;
			}
			if ( nPut >= nCurrGet )
			{
				++nPutDelta;
			}
		}
	}

	Assert(	nPut + nPutDelta <= outBuf.TellMaxPut() );

	outBuf.SeekGet( SEEK_HEAD, nGet + nGetDelta ); 
	outBuf.SeekPut( SEEK_HEAD, nPut + nPutDelta ); 

	return true;
}