diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /utils/runme | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'utils/runme')
| -rw-r--r-- | utils/runme/runme.cpp | 53 | ||||
| -rw-r--r-- | utils/runme/runme.vpc | 18 |
2 files changed, 71 insertions, 0 deletions
diff --git a/utils/runme/runme.cpp b/utils/runme/runme.cpp new file mode 100644 index 0000000..5f61430 --- /dev/null +++ b/utils/runme/runme.cpp @@ -0,0 +1,53 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: a very simple wrapper to spawn another process based upon the contents of runme.dat +// +//============================================================================= +#include <stdio.h> +#define WIN32_LEAN_AND_MEAN +#include <windows.h> + +int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) +{ + // runme.dat contains the command line to run (passed directly to createprocess() ) + FILE *f = fopen( "runme.dat", "rb" ); + if ( !f ) + return -1; + + char szCommand[MAX_PATH]; + memset( szCommand, 0x0, sizeof(szCommand) ); + fread( szCommand, sizeof(szCommand), 1, f ); + fclose( f ); + int iCh = 0; + while ( iCh < sizeof(szCommand) && szCommand[ iCh ] && szCommand[ iCh ] != '\r' && szCommand[ iCh ] != '\n' ) + { + iCh++; + } + szCommand[ iCh ] = ' '; + szCommand[ iCh + 1 ] = 0; + strncpy( &szCommand[ iCh + 1 ], lpCmdLine, sizeof(szCommand) - iCh - 1 ); + szCommand[ sizeof(szCommand) - 1 ] = 0; + + STARTUPINFO si; + PROCESS_INFORMATION pi; + memset(&si, 0x0, sizeof(si)); + si.cb = sizeof(si); + memset(&pi, 0x0, sizeof(pi)); + + // run the command + if(!CreateProcess(NULL, szCommand, 0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0, 0,&si, &pi)) + { + return -1; + } + + // Wait until child process exits. + WaitForSingleObject( pi.hProcess, INFINITE ); + + // Close process and thread handles. + CloseHandle( pi.hProcess ); + CloseHandle( pi.hThread ); + + return 0; +} + + diff --git a/utils/runme/runme.vpc b/utils/runme/runme.vpc new file mode 100644 index 0000000..4b696a6 --- /dev/null +++ b/utils/runme/runme.vpc @@ -0,0 +1,18 @@ +//----------------------------------------------------------------------------- +// RUNME.VPC +// +// Project Script +//----------------------------------------------------------------------------- + +$Macro SRCDIR "..\.." +$Macro OUTBINDIR "$SRCDIR\devtools\bin" + +$Include "$SRCDIR\vpc_scripts\source_exe_win_win32_base.vpc" + +$Project "Runme" +{ + $Folder "Source Files" + { + $File "runme.cpp" + } +} |