Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// Delete temporary files
//-----------------------------------------------------------------------------
void CScriptLib::DeleteTemporaryFiles( const char *pFileMask )
{
#if !defined( _X360 )
	const char *pEnv = getenv( "temp" );
	if ( !pEnv )
	{
		pEnv = getenv( "tmp" );
	}

	if ( pEnv )
	{
		char tempPath[MAX_PATH];
		strcpy( tempPath, pEnv );
		V_AppendSlash( tempPath, sizeof( tempPath ) );
		strcat( tempPath, pFileMask );

		CUtlVector<fileList_t> fileList;
		FindFiles( tempPath, false, fileList );
		for ( int i=0; i<fileList.Count(); i++ )
		{
			_unlink( fileList[i].fileName.String() );
		}
	}
#else
	AssertOnce( !"CScriptLib::DeleteTemporaryFiles:  Not avail on 360\n" );
#endif
}
Exemplo n.º 2
0
//-----------------------------------------------------------------------------
// Purpose: Composes a path and filename together, inserting a path separator
//			if need be
// Input:	path - path to use
//			filename - filename to use
//			dest - buffer to compose result in
//			destSize - size of destination buffer
//-----------------------------------------------------------------------------
void V_ComposeFileName( const char *path, const char *filename, char *dest, int destSize )
{
	V_strncpy( dest, path, destSize );
	V_AppendSlash( dest, destSize );
	V_strncat( dest, filename, destSize, COPY_ALL_CHARACTERS );
	V_FixSlashes( dest );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
boost::python::list PyFS_ListDir( const char *pPath, const char *pPathID, const char *pWildCard, bool appendslashdir )
{
	if( !pPath || !pWildCard )
		return boost::python::list();

	const char *pFileName;
	char wildcard[MAX_PATH];
	FileFindHandle_t fh;
	boost::python::list result;

	// Construct the wildcard
	V_strncpy( wildcard, pPath, sizeof( wildcard ) );
	if( V_strlen( wildcard ) == 0 )
		V_strncpy( wildcard, "./", sizeof( wildcard ) );
	if( appendslashdir && filesystem->IsDirectory( pPath ) )
		V_AppendSlash( wildcard, sizeof( wildcard ) );
	V_strcat( wildcard, pWildCard, sizeof( wildcard ) );

	pFileName = filesystem->FindFirstEx( wildcard, pPathID, &fh );
	while( pFileName )
	{
		result.append( boost::python::object(
			boost::python::handle<>( 
				PyUnicode_DecodeUTF8( pFileName, V_strlen( pFileName ), "ignore" )
			)
		) );
		pFileName = filesystem->FindNext( fh );
	}
	filesystem->FindClose( fh );
	return result;
}
Exemplo n.º 4
0
CefRefPtr<CefResourceHandler> LocalSchemeHandlerFactory::Create(CefRefPtr<CefBrowser> browser,
											CefRefPtr<CefFrame> frame,
											const CefString& scheme_name,
											CefRefPtr<CefRequest> request)
{
	CefRefPtr<CefResourceHandler> pResourceHandler = NULL;

	CefURLParts parts;
	CefParseURL(request->GetURL(), parts);

	if( CefString(&parts.path).size() < 2 )
	{
		return NULL;
	}

	char path[MAX_PATH];
	V_strncpy( path, CefString(&parts.path).ToString().c_str() + 1, sizeof(path) );
	V_FixupPathName( path, sizeof( path ), path );

	if( filesystem->IsDirectory( path ) ) 
	{
		V_AppendSlash( path, sizeof( path ) );
		V_strcat( path, "index.html", sizeof(path) );
	}

	if( filesystem->FileExists( path, NULL ) )
	{
		const char *pExtension = V_GetFileExtension( path );

		if( cef_scheme_debug_local_handler.GetBool() )
		{
			Msg( "Local scheme request => Path: %s, Extension: %s, Mime Type: %s, modified path: %s, exists: %d, resource type: %d\n", 
				CefString(&parts.path).ToString().c_str(), pExtension, CefGetMimeType(pExtension).ToString().c_str(), path, filesystem->FileExists( path ),
				request->GetResourceType() );
		}

		CUtlBuffer buf( 0, filesystem->Size( path, NULL ) );
		if( filesystem->ReadFile( path, NULL, buf ) )
		{
			CefRefPtr<CefStreamReader> stream =
				CefStreamReader::CreateForData( buf.Base(), buf.TellPut() );
			if( stream != NULL ) 
			{
				pResourceHandler = new CefStreamResourceHandler( CefGetMimeType(pExtension), stream );
			}
		}
	}

	return pResourceHandler;
}
Exemplo n.º 5
0
void V_MakeAbsolutePath( char *pOut, int outLen, const char *pPath, const char *pStartingDir )
{
	if ( V_IsAbsolutePath( pPath ) )
	{
		// pPath is not relative.. just copy it.
		V_strncpy( pOut, pPath, outLen );
	}
	else
	{
		// Make sure the starting directory is absolute..
		if ( pStartingDir && V_IsAbsolutePath( pStartingDir ) )
		{
			V_strncpy( pOut, pStartingDir, outLen );
		}
		else
		{
			if ( !_getcwd( pOut, outLen ) )
				Error( "V_MakeAbsolutePath: _getcwd failed." );

			if ( pStartingDir )
			{
				V_AppendSlash( pOut, outLen );
				V_strncat( pOut, pStartingDir, outLen, COPY_ALL_CHARACTERS );
			}
		}

		// Concatenate the paths.
		V_AppendSlash( pOut, outLen );
		V_strncat( pOut, pPath, outLen, COPY_ALL_CHARACTERS );
	}

	if ( !V_RemoveDotSlashes( pOut ) )
		Error( "V_MakeAbsolutePath: tried to \"..\" past the root." );

	V_FixSlashes( pOut );
}
Exemplo n.º 6
0
void Win32_ProcessFilesInDirectory_Internal( const SDirectoryInfo& dir, ADirectoryWalker* callback, bool bRecurseSubfolders )
{
    if( !callback->Enter_Folder( dir ) ) {
        return;
    }

    ANSICHAR	tmp[ MAX_PATH ];
    tMy_sprintfA( tmp, "%s*.*", dir.fullPathName );

    WIN32_FIND_DATAA	findFileData;
    const HANDLE fh = ::FindFirstFileA( tmp, &findFileData );

    if( fh == INVALID_HANDLE_VALUE ) {
        // the folder is empty or it doesn't exist
        return;
    }

    do
    {
        // skip self
        if(!strcmp( findFileData.cFileName, (".") ))
        {
            continue;
        }
        if(!strcmp( findFileData.cFileName, ("..") ))
        {
            continue;
        }

        // skip hidden file
        if( findFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN )
        {
            continue;
        }

        // if this is directory
        if( findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
        {
            if( bRecurseSubfolders )
            {
                ANSICHAR	relativePath[ MAX_PATH ];
                strcpy(relativePath, dir.relativePath);
                strcat(relativePath, findFileData.cFileName);
                V_AppendSlash(relativePath, mxCOUNT_OF(relativePath));

                ANSICHAR	fullChildPath[ MAX_PATH ];
                strcpy(fullChildPath, dir.fullPathName);
                strcat(fullChildPath, findFileData.cFileName);
                V_AppendSlash(fullChildPath, mxCOUNT_OF(fullChildPath));

                SDirectoryInfo	subfolder;
                subfolder.fullPathName = fullChildPath;
                subfolder.relativePath = relativePath;
                Win32_ProcessFilesInDirectory_Internal( subfolder, callback, bRecurseSubfolders );
            }
        }
        else
        {
            SFindFileInfo	fileInfo;

            Str::SetReference(fileInfo.fileNameOnly, findFileData.cFileName);
            Str::SetReference(fileInfo.fullPathName, dir.fullPathName);
            Str::SetReference(fileInfo.relativePath, dir.relativePath);

            ANSICHAR	fullFileName[ MAX_PATH ];
            strcpy(fullFileName, fileInfo.fullPathName.c_str());
            strcat(fullFileName, fileInfo.fileNameOnly.c_str());
            Str::SetReference(fileInfo.fullFileName, fullFileName);

            if( callback->Found_File( fileInfo ) ) {
                return;
            }
        }
    }
    while( ::FindNextFileA( fh , &findFileData ) != 0 );

    callback->Leave_Folder( dir );
}
Exemplo n.º 7
0
//-----------------------------------------------------------------------------
// Models require specialized group handling to generate intermediate lod culled
// versions that are then used as the the source for target conversion.
//-----------------------------------------------------------------------------
bool PreprocessModelFiles( CUtlVector<fileList_t> &fileList )
{
	if ( !InitStudioByteSwap() )
	{
		return false;
	}

	CUtlVector< CUtlString > updateList;
	CUtlRBTree< CUtlString, int > visitedModels( 0, 0, ModelNamesLessFunc );

	char szSourcePath[MAX_PATH];
	strcpy( szSourcePath, g_szSourcePath );
	V_StripFilename( szSourcePath );
	if ( !szSourcePath[0] )
		strcpy( szSourcePath, "." );
	V_AppendSlash( szSourcePath, sizeof( szSourcePath ) );

	char szModelName[MAX_PATH];
	for ( int i=0; i<fileList.Count(); i++ )
	{
		V_strncpy( szModelName, fileList[i].fileName.String(), sizeof( szModelName ) );

		if ( V_stristr( szModelName, ".360." ) )
		{
			// must ignore any target files
			continue;
		}

		// want only model related files
		char *pExtension = V_stristr( szModelName, ".mdl" );
		if ( !pExtension )
		{
			pExtension = V_stristr( szModelName, ".dx90.vtx" );
			if ( !pExtension )
			{
				pExtension = V_stristr( szModelName, ".vvd" );
				if ( !pExtension )
				{
					pExtension = V_stristr( szModelName, ".ani" );
					if ( !pExtension )
					{
						pExtension = V_stristr( szModelName, ".phy" );
						if ( !pExtension )
						{
							pExtension = V_stristr( szModelName, ".vsi" );
							if ( !pExtension )
							{
								continue;
							}
						}
					}
				}
			}
		}

		*pExtension = '\0';
		V_strncat( szModelName, ".mdl", sizeof( szModelName ) );
	
		if ( visitedModels.Find( szModelName ) != visitedModels.InvalidIndex() )
		{
			// already processed
			continue;
		}
		visitedModels.Insert( szModelName );

		// resolve to full source path
		const char *ptr = szModelName;
		if ( !strnicmp( ptr, ".\\", 2 ) )
			ptr += 2;
		else if ( !strnicmp( ptr, szSourcePath, strlen( szSourcePath ) ) )
			ptr += strlen( szSourcePath );
		char szCleanName[MAX_PATH];
		strcpy( szCleanName, szSourcePath );
		strcat( szCleanName, ptr );
		char szFullSourcePath[MAX_PATH];
		_fullpath( szFullSourcePath, szCleanName, sizeof( szFullSourcePath ) );

		// any one dirty component generates the set of all expected files
		if ( ModelNeedsUpdate( szFullSourcePath ) )
		{
			int index = updateList.AddToTail();
			updateList[index].Set( szFullSourcePath );
		}
	}

	Msg( "\n" );
	Msg( "Model Pre Pass: Updating %d Models.\n", updateList.Count() );
	for ( int i = 0; i < updateList.Count(); i++ )
	{
		if ( !GenerateModelFiles( updateList[i].String() ) )
		{
			int error = g_errorList.AddToTail();
			g_errorList[error].result = false;
			g_errorList[error].fileName.Set( updateList[i].String() );
		}
	}

	// iterate error list
	if ( g_errorList.Count() )
	{
		Msg( "\n" );
		for ( int i = 0; i < g_errorList.Count(); i++ )
		{
			Msg( "ERROR: could not pre-process model: %s\n", g_errorList[i].fileName.String() );
		}
	}

	return true;
}
//-----------------------------------------------------------------------------
//	ExcludePathsDlg_Populate
//
//	Generate a path table.
//-----------------------------------------------------------------------------
void ExcludePathsDlg_Populate( HWND hWnd, bool bRefresh )
{
	struct GamePath_t 
	{
		CUtlString	pathName;
		bool		bIsModPath;
	};

	CUtlVector< GamePath_t > gamePaths;		

	// can skip the time consuming directory scan, unless forced
	if ( bRefresh || !g_PathTable.Count() )
	{
		g_PathTable.Purge();

		for ( int i = 0; i < ARRAYSIZE( g_GameNames ); i++ )
		{
			char szTargetPath[MAX_PATH];
			V_strncpy( szTargetPath, g_localPath, sizeof( szTargetPath ) );
			V_AppendSlash( szTargetPath, sizeof( szTargetPath ) );
			V_strncat( szTargetPath, g_GameNames[i].pName, sizeof( szTargetPath ) );

			GamePath_t gamePath;
			gamePath.pathName = szTargetPath;
			gamePath.bIsModPath = g_GameNames[i].bIsModPath;
			gamePaths.AddToTail( gamePath );
		}

		// iterate all game paths
		for ( int i = 0; i < gamePaths.Count(); i++ )
		{
			CUtlVector< CUtlString > dirList;
			RecurseFileTree_r( g_localPath, gamePaths[i].pathName.String(), 0, dirList, gamePaths[i].bIsModPath );
		}
	}

	// reset the tree
	HWND hWndTree = GetDlgItem( hWnd, IDC_PATHS_TREE );
	TreeView_DeleteAllItems( hWndTree );

	// reset and add root
	// only the root is at depth 0
	AddItemToTree( hWndTree, ROOT_NAME, 0, false );

	// build the tree view
	for ( int iIndex = g_PathTable.FirstInorder(); iIndex != g_PathTable.InvalidIndex(); iIndex = g_PathTable.NextInorder( iIndex ) )
	{
		// due to sorting, number of slashes is depth
		const char *pString = g_PathTable[iIndex].pathName.String();
		int depth = 0;
		for ( int j = 0; j < (int)strlen( pString ); j++ )
		{
			if ( pString[j] == '\\' )
			{
				depth++;
			}
		}
		if ( !depth )
		{
			depth = 1;
		}

		char szPath[MAX_PATH];
		V_FileBase( pString, szPath, sizeof( szPath ) );
		AddItemToTree( hWndTree, szPath, depth, g_PathTable[iIndex].bIsModPath );
	}

	HTREEITEM hTreeRoot = TreeView_GetRoot( hWndTree );
	for ( int i = 0; i < g_ExcludePaths.Count(); i++ )
	{
		HTREEITEM hTree = ExcludePathsDlg_Find_r( hWndTree, hTreeRoot, 0, "", g_ExcludePaths[i].String() );
		if ( hTree )
		{
			ExcludePathsDlg_SetCheckState_r( hWndTree, hTree, 0, true );
		}
	}

	// expand the root node to show state
	ExcludePathsDlg_ExpandToShowState_r( hWndTree, hTreeRoot, 0 );
}