void RunBSP(const char* name) { // http://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=503 // make sure we don't attempt to region compile a map with the camera outside the region if (region_active && !Region_cameraValid()) { globalErrorStream() << "The camera must be in the region to start a region compile.\n"; return; } SaveMap(); if(Map_Unnamed(g_map)) { globalOutputStream() << "build cancelled\n"; return; } if (g_SnapShots_Enabled && !Map_Unnamed(g_map) && Map_Modified(g_map)) { Map_Snapshot(); } if (region_active) { const char* mapname = Map_Name(g_map); StringOutputStream name(256); name << StringRange(mapname, path_get_filename_base_end(mapname)) << ".reg"; Map_SaveRegion(name.c_str()); } Pointfile_Delete(); bsp_init(); if (g_WatchBSP_Enabled) { ArrayCommandListener listener; build_run(name, listener); // grab the file name for engine running const char* fullname = Map_Name(g_map); StringOutputStream bspname(64); bspname << StringRange(path_get_filename_start(fullname), path_get_filename_base_end(fullname)); BuildMonitor_Run( listener.array(), bspname.c_str() ); } else { char junkpath[PATH_MAX]; strcpy(junkpath, SettingsPath_get()); strcat(junkpath, "junk.txt"); char batpath[PATH_MAX]; #if defined(POSIX) strcpy(batpath, SettingsPath_get()); strcat(batpath, "qe3bsp.sh"); #elif defined(WIN32) strcpy(batpath, SettingsPath_get()); strcat(batpath, "qe3bsp.bat"); #else #error "unsupported platform" #endif bool written = false; { TextFileOutputStream batchFile(batpath); if(!batchFile.failed()) { #if defined (POSIX) batchFile << "#!/bin/sh \n\n"; #endif BatchCommandListener listener(batchFile, junkpath); build_run(name, listener); written = true; } } if(written) { #if defined (POSIX) chmod (batpath, 0744); #endif globalOutputStream() << "Writing the compile script to '" << batpath << "'\n"; globalOutputStream() << "The build output will be saved in '" << junkpath << "'\n"; Q_Exec(batpath, NULL, NULL, true); } } bsp_shutdown(); }
void RunBsp( char* command ) { char sys[2048]; char batpath[2048]; char outputpath[2048]; char temppath[1024]; char name[2048]; char cWork[2048]; FILE* hFile; BOOL ret; PROCESS_INFORMATION ProcessInformation; STARTUPINFO startupinfo; HWND hwndPClient = NULL; g_hWnd = g_pParentWnd->GetSafeHwnd(); SetInspectorMode( W_CONSOLE ); g_tBegin = CTime::GetCurrentTime(); DWORD dwExitcode; ret = GetExitCodeProcess( g_hToolThread, &dwExitcode ); if ( dwExitcode != STILL_ACTIVE ) g_hToolThread = NULL; if ( bsp_process || g_hToolThread ) { Sys_Printf( "BSP is still going...\n" ); return; } outputpath[0] = '\0'; GetTempPath( 512, temppath ); CString strOutFile = temppath; AddSlash( strOutFile ); strOutFile += "junk.txt"; sprintf( outputpath, " >>%s\r\n", strOutFile ); strcpy( name, currentmap ); if ( region_active ) { Map_SaveFile( name, false ); StripExtension( name ); strcat( name, ".reg" ); } Map_SaveFile( name, region_active ); // FIXME: this code just gets worse and worse CString strPath, strFile; char* rsh = ValueForKey( g_qeglobals.d_project_entity, "rshcmd" ); if ( rsh == NULL ) { ExtractPath_and_Filename( name, strPath, strFile ); AddSlash( strPath ); BuildShortPathName( strPath, cWork, 1024 ); strcat( cWork, strFile ); } else { strcpy( cWork, name ); } hwndPClient = FindWindow( NULL, "Q3Map Process Client" ); if ( hwndPClient == NULL ) { hwndPClient = FindAnyWindow( "Q3Map Process Client" ); } Sys_Printf( "Window info for Process Client %i\n", reinterpret_cast<int>( hwndPClient ) ); bool processServer = ( rsh && strlen( rsh ) > 0 && hwndPClient ); QE_ExpandBspString( command, sys, cWork, processServer ); // if we can find the q3map process server running // we will submit maps to it instead of via createprocess // if ( processServer ) { CString str; char cBuff[2048]; char* pStart = sys; char* pEnd = strstr( pStart, "&&" ); while ( pEnd ) { int nLen = pEnd - pStart - 1; strncpy( cBuff, pStart, nLen ); cBuff[nLen] = 0; str = cBuff; FindReplace( str, rsh, "" ); str.TrimLeft( ' ' ); str.TrimRight( ' ' ); ATOM a = GlobalAddAtom( str ); PostMessage( hwndPClient, wm_AddCommand, 0, ( LPARAM )a ); pStart = pEnd + 2; pEnd = strstr( pStart, "&&" ); } str = pStart; FindReplace( str, rsh, "" ); str.TrimLeft( ' ' ); str.TrimRight( ' ' ); ATOM a = GlobalAddAtom( str ); PostMessage( hwndPClient, wm_AddCommand, 0, ( LPARAM )a ); Sys_Printf( "Commands sent to Q3Map Process Client\n" ); return; } CString strSys = sys; FindReplace( strSys, "&&", outputpath ); strcpy( sys, strSys ); strcat( sys, outputpath ); Sys_ClearPrintf(); Sys_Printf( "==================\nRunning bsp command...\n" ); Sys_Printf( "\n%s\n", sys ); //++timo removed the old way BSP commands .. dumping to junk.txt doesn't work on my win98 box // FIXME : will most likely break Quake2 BSP commands, is fitted to a one-lined sys command // // write qe3bsp.bat // //const char *basePath = ValueForKey(g_qeglobals.d_project_entity, "basepath"); //if(basePath) { //const char *mapName = //sprintf(batpath,"%s/maps/%s.bat",basePath,mapName); strcpy( batpath, currentmap ); char* dot = strchr( batpath, '.' ); strcpy( dot, ".bat" ); //} else { // sprintf (batpath, "%sqe3bsp.bat", temppath); //} hFile = fopen( batpath, "w" ); if ( !hFile ) Error( "Can't write to %s", batpath ); fprintf( hFile, sys ); fclose( hFile ); Pointfile_Delete(); // delete junk.txt file remove( strOutFile ); GetStartupInfo( &startupinfo ); ret = CreateProcess( batpath, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startupinfo, &ProcessInformation ); if ( !ret ) Error( "CreateProcess failed" ); bsp_process = ProcessInformation.hProcess; Sleep( 100 ); // give the new process a chance to open it's window BringWindowToTop( g_qeglobals.d_hwndMain ); // pop us back on top #if 0 // // write qe3bsp.bat // sprintf( batpath, "%sqe3bsp.bat", temppath ); hFile = fopen( batpath, "w" ); if ( !hFile ) Error( "Can't write to %s", batpath ); fprintf( hFile, sys ); fclose( hFile ); // // write qe3bsp2.bat // sprintf( batpath, "%sqe3bsp2.bat", temppath ); hFile = fopen( batpath, "w" ); if ( !hFile ) Error( "Can't write to %s", batpath ); fprintf( hFile, "%sqe3bsp.bat > %s", temppath, outputpath ); fclose( hFile ); Pointfile_Delete(); GetStartupInfo( &startupinfo ); ret = CreateProcess( batpath, // pointer to name of executable module NULL, // pointer to command line string NULL, // pointer to process security attributes NULL, // pointer to thread security attributes FALSE, // handle inheritance flag 0 /*DETACHED_PROCESS*/, // creation flags NULL, // pointer to new environment block NULL, // pointer to current directory name &startupinfo, // pointer to STARTUPINFO &ProcessInformation // pointer to PROCESS_INFORMATION ); if ( !ret ) Error( "CreateProcess failed" ); bsp_process = ProcessInformation.hProcess; Sleep( 100 ); // give the new process a chance to open it's window //BringWindowToTop( g_qeglobals.d_hwndMain ); // pop us back on top //SetFocus (g_qeglobals.d_hwndCamera); #endif }
void RunBsp (char *command) { char sys[1024]; char batpath[1024]; char outputpath[1024]; char temppath[512]; char name[1024]; FILE *hFile; BOOL ret; PROCESS_INFORMATION ProcessInformation; STARTUPINFO startupinfo; SetInspectorMode (W_CONSOLE); if (bsp_process) { Sys_Printf ("BSP is still going...\n"); return; } GetTempPath(512, temppath); sprintf (outputpath, "%sjunk.txt", temppath); strcpy (name, currentmap); if (region_active) { Map_SaveFile (name, false); StripExtension (name); strcat (name, ".reg"); } Map_SaveFile (name, region_active); QE_ExpandBspString (command, sys, name); Sys_ClearPrintf (); Sys_Printf ("======================================\nRunning bsp command...\n"); Sys_Printf ("\n%s\n", sys); // // write qe3bsp.bat // sprintf (batpath, "%sqe3bsp.bat", temppath); hFile = fopen(batpath, "w"); if (!hFile) Error ("Can't write to %s", batpath); fprintf (hFile, sys); fclose (hFile); // // write qe3bsp2.bat // sprintf (batpath, "%sqe3bsp2.bat", temppath); hFile = fopen(batpath, "w"); if (!hFile) Error ("Can't write to %s", batpath); fprintf (hFile, "%sqe3bsp.bat > %s", temppath, outputpath); fclose (hFile); Pointfile_Delete (); GetStartupInfo (&startupinfo); ret = CreateProcess( batpath, // pointer to name of executable module NULL, // pointer to command line string NULL, // pointer to process security attributes NULL, // pointer to thread security attributes FALSE, // handle inheritance flag 0 /*DETACHED_PROCESS*/, // creation flags NULL, // pointer to new environment block NULL, // pointer to current directory name &startupinfo, // pointer to STARTUPINFO &ProcessInformation // pointer to PROCESS_INFORMATION ); if (!ret) Error ("CreateProcess failed"); bsp_process = ProcessInformation.hProcess; Sleep (100); // give the new process a chance to open it's window BringWindowToTop( g_qeglobals.d_hwndMain ); // pop us back on top SetFocus (g_qeglobals.d_hwndCamera); }