scenemanager_tools.cpp
来自「hl2 source code. Do not use it illegal.」· C++ 代码 · 共 780 行 · 第 1/2 页
CPP
780 行
#include "cbase.h"
#include "StatusWindow.h"
#include "cmdlib.h"
#include <sys/stat.h>
#include "workspace.h"
#include "workspacemanager.h"
#include "workspacebrowser.h"
#include "riff.h"
#include "sentence.h"
#include "utlbuffer.h"
#include "soundemittersystembase.h"
#include <KeyValues.h>
#include "MultipleRequest.h"
bool SceneManager_HasWindowStyle( mxWindow *w, int bits )
{
HWND wnd = (HWND)w->getHandle();
DWORD style = GetWindowLong( wnd, GWL_STYLE );
return ( style & bits ) ? true : false;
}
bool SceneManager_HasWindowExStyle( mxWindow *w, int bits )
{
HWND wnd = (HWND)w->getHandle();
DWORD style = GetWindowLong( wnd, GWL_EXSTYLE );
return ( style & bits ) ? true : false;
}
void SceneManager_AddWindowStyle( mxWindow *w, int addbits )
{
HWND wnd = (HWND)w->getHandle();
DWORD style = GetWindowLong( wnd, GWL_STYLE );
style |= addbits;
SetWindowLong( wnd, GWL_STYLE, style );
}
void SceneManager_AddWindowExStyle( mxWindow *w, int addbits )
{
HWND wnd = (HWND)w->getHandle();
DWORD style = GetWindowLong( wnd, GWL_EXSTYLE );
style |= addbits;
SetWindowLong( wnd, GWL_EXSTYLE, style );
}
void SceneManager_RemoveWindowStyle( mxWindow *w, int removebits )
{
HWND wnd = (HWND)w->getHandle();
DWORD style = GetWindowLong( wnd, GWL_STYLE );
style &= ~removebits;
SetWindowLong( wnd, GWL_STYLE, style );
}
void SceneManager_RemoveWindowExStyle( mxWindow *w, int removebits )
{
HWND wnd = (HWND)w->getHandle();
DWORD style = GetWindowLong( wnd, GWL_EXSTYLE );
style &= ~removebits;
SetWindowLong( wnd, GWL_EXSTYLE, style );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *w -
//-----------------------------------------------------------------------------
void SceneManager_MakeToolWindow( mxWindow *w, bool smallcaption )
{
SceneManager_AddWindowStyle( w, WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS );
if ( smallcaption )
{
SceneManager_AddWindowExStyle( w, WS_EX_OVERLAPPEDWINDOW );
SceneManager_AddWindowExStyle( w, WS_EX_TOOLWINDOW );
}
else
{
SceneManager_RemoveWindowStyle( w, WS_SYSMENU );
}
}
char *va( const char *fmt, ... )
{
va_list args;
static char output[4][1024];
static int outbuffer = 0;
outbuffer++;
va_start( args, fmt );
vprintf( fmt, args );
vsprintf( output[ outbuffer & 3 ], fmt, args );
return output[ outbuffer & 3 ];
}
void Con_Overprintf( const char *fmt, ... )
{
va_list args;
static char output[1024];
va_start( args, fmt );
vprintf( fmt, args );
vsprintf( output, fmt, args );
if ( !g_pStatusWindow )
{
return;
}
g_pStatusWindow->StatusPrint( CONSOLE_R, CONSOLE_G, CONSOLE_B, true, output );
}
void Con_Printf( const char *fmt, ... )
{
va_list args;
static char output[1024];
va_start( args, fmt );
vprintf( fmt, args );
vsprintf( output, fmt, args );
if ( !g_pStatusWindow )
{
return;
}
g_pStatusWindow->StatusPrint( CONSOLE_R, CONSOLE_G, CONSOLE_B, false, output );
}
void Con_ColorPrintf( int r, int g, int b, const char *fmt, ... )
{
va_list args;
static char output[1024];
va_start( args, fmt );
vprintf( fmt, args );
vsprintf( output, fmt, args );
if ( !g_pStatusWindow )
{
return;
}
g_pStatusWindow->StatusPrint( r, g, b, false, output );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pname -
// Output : char
//-----------------------------------------------------------------------------
char *SceneManager_MakeWindowsSlashes( char *pname )
{
static char returnString[ 4096 ];
strcpy( returnString, pname );
pname = returnString;
while ( *pname ) {
if ( *pname == '/' )
*pname = '\\';
pname++;
}
return returnString;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : const char
//-----------------------------------------------------------------------------
const char *SceneManager_GetGameDirectory( void )
{
static char gamedir[ 256 ];
strcpy( gamedir, basegamedir );
int len = strlen( gamedir );
if ( len > 0 )
{
// Strip path separator
if ( gamedir[ len - 1 ] == '/' ||
gamedir[ len - 1 ] == '\\' )
{
gamedir[ len - 1 ] = 0;
}
}
return gamedir;
}
//-----------------------------------------------------------------------------
// Purpose: Takes a full path and determines if the file exists on the disk
// Input : *filename -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool SceneManager_FullpathFileExists( const char *filename )
{
// Should be a full path
Assert( strchr( filename, ':' ) );
struct _stat buf;
int result = _stat( filename, &buf );
if ( result != -1 )
return true;
return false;
}
//-----------------------------------------------------------------------------
// Purpose: converts an english string to unicode
//-----------------------------------------------------------------------------
int ConvertANSIToUnicode(const char *ansi, wchar_t *unicode, int unicodeBufferSize)
{
return ::MultiByteToWideChar(CP_ACP, 0, ansi, -1, unicode, unicodeBufferSize);
}
//-----------------------------------------------------------------------------
// Purpose: converts an unicode string to an english string
//-----------------------------------------------------------------------------
int ConvertUnicodeToANSI(const wchar_t *unicode, char *ansi, int ansiBufferSize)
{
return ::WideCharToMultiByte(CP_ACP, 0, unicode, -1, ansi, ansiBufferSize, NULL, NULL);
}
int Sys_Exec( const char *pProgName, const char *pCmdLine, bool verbose )
{
#if 0
int count = 0;
char cmdLine[1024];
STARTUPINFO si;
memset( &si, 0, sizeof(si) );
si.cb = sizeof(si);
//GetStartupInfo( &si );
sprintf( cmdLine, "%s %s", pProgName, pCmdLine );
PROCESS_INFORMATION pi;
memset( &pi, 0, sizeof( pi ) );
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES;
if ( CreateProcess( NULL, cmdLine, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi ) )
{
WaitForSingleObject( pi.hProcess, INFINITE );
/*
do
{
WaitForInputIdle( pi.hProcess, 100 );
count++;
} while ( count < 100 );
*/
/*
DWORD exitCode = STILL_ACTIVE;
do
{
BOOL ok = GetExitCodeProcess( pi.hProcess, &exitCode );
if ( !ok )
break;
Sleep( 100 );
} while ( exitCode == STILL_ACTIVE );
*/
DWORD exitCode;
GetExitCodeProcess( pi.hProcess, &exitCode );
Con_Printf( "Finished\n" );
CloseHandle( pi.hProcess );
return (int)exitCode;
}
else
{
char *lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
Con_Printf( "error %s\n", lpMsgBuf );
LocalFree( (HLOCAL)lpMsgBuf );
}
return false;
#else
char tmp[1024];
sprintf( tmp, "%s %s\n", pProgName, pCmdLine );
_strlwr( tmp );
int iret = system( tmp );
if ( iret != 0 && verbose )
{
Con_Printf( "Execution failed: %s\n", tmp );
}
return iret;
#endif
}
//-----------------------------------------------------------------------------
// Checks it out/ checks it in baby
//-----------------------------------------------------------------------------
static void SceneManager_VSSCheckout( char const *pUserName, char const *pProjectDir,
char const* pRelativeDir, char const* pDestPath, char const* pFileNameWithExtension )
{
char buf[1024];
// Check for the existence of the file in source safe...
sprintf( buf, "filetype %s/%s%s -O- -y%s\n",
pProjectDir, pRelativeDir, pFileNameWithExtension,
pUserName );
int retVal = Sys_Exec( "ss.exe", buf, false );
if (retVal != 0 )
{
Con_Printf( "File %s missing from VSS\n", pFileNameWithExtension );
return;
}
// It's there, try to check it out
sprintf( buf, "checkout %s/%s%s -GL%s -GWA -O- -y%s\n",
pProjectDir, pRelativeDir, pFileNameWithExtension,
pDestPath, pUserName );
Sys_Exec( "ss.exe", buf, true );
}
//-----------------------------------------------------------------------------
// Checks it out/ checks it in baby
//-----------------------------------------------------------------------------
static void SceneManager_VSSCheckin( char const *pUserName, char const *pProjectDir,
char const* pRelativeDir, char const* pDestPath, char const* pFileNameWithExtension )
{
char buf[1024];
// Check for the existence of the file on disk. If it's not there, don't bother
sprintf( buf, "%s%s", pDestPath, pFileNameWithExtension );
struct _stat statbuf;
int result = _stat( buf, &statbuf );
if (result != 0)
return;
// Check for the existence of the file in source safe...
sprintf( buf, "filetype %s/%s%s -O- -y%s\n",
pProjectDir, pRelativeDir, pFileNameWithExtension,
pUserName );
int retVal = Sys_Exec( "ss.exe", buf, false );
if (retVal != 0)
{
sprintf( buf, "Cp %s -O- -y%s\n",
pProjectDir ,
pUserName );
Sys_Exec( "ss.exe", buf, true );
// Try to add the file to source safe...
sprintf( buf, "add %s%s -GL%s -O- -I- -y%s\n",
pRelativeDir, pFileNameWithExtension,
pDestPath, pUserName );
Sys_Exec( "ss.exe", buf, true );
}
else
{
// It's there, just check it in
sprintf( buf, "checkin %s/%s%s -GL%s -O- -I- -y%s\n",
pProjectDir, pRelativeDir, pFileNameWithExtension,
pDestPath, pUserName );
Sys_Exec( "ss.exe", buf, true );
}
}
void SplitFileName( char const *in, char *path, int maxpath, char *filename, int maxfilename )
{
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath( in, drive, dir, fname, ext );
if ( dir[0] )
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?