From 92c3de82d6cd26f516df7c20783e522866920d35 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 23 Nov 2005 22:47:47 +0000 Subject: [PATCH] cleanups --- .../archutils/Win32/GetFileInformation.cpp | 16 +-- .../src/archutils/Win32/GetFileInformation.h | 4 +- stepmania/src/archutils/Win32/GotoURL.cpp | 56 ++++----- stepmania/src/archutils/Win32/GotoURL.h | 2 +- .../src/archutils/Win32/RegistryAccess.cpp | 112 +++++++++--------- .../src/archutils/Win32/RegistryAccess.h | 2 +- .../src/archutils/Win32/VideoDriverInfo.cpp | 38 +++--- .../src/archutils/Win32/VideoDriverInfo.h | 2 +- 8 files changed, 116 insertions(+), 116 deletions(-) diff --git a/stepmania/src/archutils/Win32/GetFileInformation.cpp b/stepmania/src/archutils/Win32/GetFileInformation.cpp index 001bbf3da9..27849038b1 100644 --- a/stepmania/src/archutils/Win32/GetFileInformation.cpp +++ b/stepmania/src/archutils/Win32/GetFileInformation.cpp @@ -10,16 +10,16 @@ #pragma comment(lib, "version.lib") #endif -bool GetFileVersion( CString fn, CString &out ) +bool GetFileVersion( CString sFile, CString &sOut ) { do { DWORD ignore; - DWORD iSize = GetFileVersionInfoSize( (char *) fn.c_str(), &ignore ); + DWORD iSize = GetFileVersionInfoSize( sFile, &ignore ); if( !iSize ) break; CString VersionBuffer( iSize, ' ' ); - if( !GetFileVersionInfo( (char *) fn.c_str(), NULL, iSize, (char *) VersionBuffer.c_str() ) ) + if( !GetFileVersionInfo( sFile, NULL, iSize, VersionBuffer.GetBuf() ) ) break; WORD *iTrans; @@ -41,18 +41,18 @@ bool GetFileVersion( CString fn, CString &out ) (void **) &str, &len ) || len < 1) break; - out = CString( str, len-1 ); + sOut = CString( str, len-1 ); } while(0); /* Get the size and date. */ struct stat st; - if( stat( fn, &st ) != -1 ) + if( stat( sFile, &st ) != -1 ) { struct tm t; gmtime_r( &st.st_mtime, &t ); - if( !out.empty() ) - out += " "; - out += ssprintf( "[%ib, %02i-%02i-%04i]", st.st_size, t.tm_mon+1, t.tm_mday, t.tm_year+1900 ); + if( !sOut.empty() ) + sOut += " "; + sOut += ssprintf( "[%ib, %02i-%02i-%04i]", st.st_size, t.tm_mon+1, t.tm_mday, t.tm_year+1900 ); } return true; diff --git a/stepmania/src/archutils/Win32/GetFileInformation.h b/stepmania/src/archutils/Win32/GetFileInformation.h index 84104810d2..55a8f5096c 100644 --- a/stepmania/src/archutils/Win32/GetFileInformation.h +++ b/stepmania/src/archutils/Win32/GetFileInformation.h @@ -3,8 +3,8 @@ #ifndef GET_FILE_INFORMATION_H #define GET_FILE_INFORMATION_H -bool GetFileVersion( CString fn, CString &out ); -CString FindSystemFile( CString fn ); +bool GetFileVersion( CString fsFile, CString &sOut ); +CString FindSystemFile( CString sFile ); bool GetProcessFileName( uint32_t iProcessID, CString &sName ); #endif diff --git a/stepmania/src/archutils/Win32/GotoURL.cpp b/stepmania/src/archutils/Win32/GotoURL.cpp index 02b16cd118..713aa5ad1f 100644 --- a/stepmania/src/archutils/Win32/GotoURL.cpp +++ b/stepmania/src/archutils/Win32/GotoURL.cpp @@ -1,63 +1,63 @@ #include "global.h" #include "GotoURL.h" -#include "windows.h" -#include "shellapi.h" +#include +#include /* This is called from the crash handler; don't use RegistryAccess, since it's * not crash-conditions safe. */ -static LONG GetRegKey(HKEY key, CString subkey, LPTSTR retdata) +static LONG GetRegKey( HKEY key, CString subkey, LPTSTR retdata ) { - HKEY hkey; - LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &hkey); + HKEY hKey; + LONG iRet = RegOpenKeyEx( key, subkey, 0, KEY_QUERY_VALUE, &hKey ); - if (retval != ERROR_SUCCESS) - return retval; + if( iRet != ERROR_SUCCESS ) + return iRet; - long datasize = MAX_PATH; - TCHAR data[MAX_PATH]; - RegQueryValue(hkey, "emulation", data, &datasize); - strcpy(retdata,data); - RegCloseKey(hkey); + long iDataSize = MAX_PATH; + char data[MAX_PATH]; + RegQueryValue( hKey, "emulation", data, &iDataSize ); + strcpy( retdata, data ); + RegCloseKey( hKey ); return ERROR_SUCCESS; } -bool GotoURL(CString url) +bool GotoURL( CString sUrl ) { // First try ShellExecute() - int result = (int) ShellExecute(NULL, "open", url, NULL,NULL, SW_SHOWDEFAULT); + int iRet = (int) ShellExecute( NULL, "open", sUrl, NULL, NULL, SW_SHOWDEFAULT ); // If it failed, get the .htm regkey and lookup the program - if (result > 32) + if( iRet > 32 ) return true; char key[2*MAX_PATH]; - if (GetRegKey(HKEY_CLASSES_ROOT, ".htm", key) != ERROR_SUCCESS) + if( GetRegKey(HKEY_CLASSES_ROOT, ".htm", key) != ERROR_SUCCESS ) return false; - strcpy(key, "\\shell\\open\\command"); + strcpy( key, "\\shell\\open\\command" ); - if (GetRegKey(HKEY_CLASSES_ROOT,key,key) != ERROR_SUCCESS) + if( GetRegKey(HKEY_CLASSES_ROOT, key, key) != ERROR_SUCCESS ) return false; - char *pos = strstr( key, "\"%1\"" ); - if (pos == NULL) + char *szPos = strstr( key, "\"%1\"" ); + if( szPos == NULL ) { // No quotes found. Check for %1 without quotes - pos = strstr( key, "%1" ); - if (pos == NULL) - pos = key+lstrlen(key)-1; // No parameter. + szPos = strstr( key, "%1" ); + if( szPos == NULL ) + szPos = key+lstrlen(key)-1; // No parameter. else - *pos = '\0'; // Remove the parameter + *szPos = '\0'; // Remove the parameter } else - *pos = '\0'; // Remove the parameter + *szPos = '\0'; // Remove the parameter - strcat(pos, " "); - strcat(pos, url); + strcat( szPos, " " ); + strcat( szPos, sUrl ); - return WinExec(key,SW_SHOWDEFAULT) > 32; + return WinExec( key, SW_SHOWDEFAULT ) > 32; } /* diff --git a/stepmania/src/archutils/Win32/GotoURL.h b/stepmania/src/archutils/Win32/GotoURL.h index ab57f020a1..31b963e11e 100644 --- a/stepmania/src/archutils/Win32/GotoURL.h +++ b/stepmania/src/archutils/Win32/GotoURL.h @@ -1,7 +1,7 @@ #ifndef GOTO_URL_H #define GOTO_URL_H -bool GotoURL(CString url); +bool GotoURL( CString sUrl ); #endif diff --git a/stepmania/src/archutils/Win32/RegistryAccess.cpp b/stepmania/src/archutils/Win32/RegistryAccess.cpp index bc0c59d101..710d02339b 100644 --- a/stepmania/src/archutils/Win32/RegistryAccess.cpp +++ b/stepmania/src/archutils/Win32/RegistryAccess.cpp @@ -5,104 +5,104 @@ /* Given "HKEY_LOCAL_MACHINE\hardware\foo", return "hardware\foo", and place * the HKEY_LOCAL_MACHINE constant in key. */ -static bool GetRegKeyType( const CString &in, CString &out, HKEY &key ) +static bool GetRegKeyType( const CString &sIn, CString &sOut, HKEY &key ) { - size_t backslash = in.find( '\\' ); - if( backslash == in.npos ) + size_t iBackslash = sIn.find( '\\' ); + if( iBackslash == sIn.npos ) { - LOG->Warn( "Invalid registry key: \"%s\" ", in.c_str() ); + LOG->Warn( "Invalid registry key: \"%s\" ", sIn.c_str() ); return false; } - CString type = in.substr( 0, backslash ); + CString sType = sIn.substr( 0, iBackslash ); - if( !type.CompareNoCase( "HKEY_CLASSES_ROOT" ) ) key = HKEY_CLASSES_ROOT; - else if( !type.CompareNoCase( "HKEY_CURRENT_CONFIG" ) ) key = HKEY_CURRENT_CONFIG; - else if( !type.CompareNoCase( "HKEY_CURRENT_USER" ) ) key = HKEY_CURRENT_USER; - else if( !type.CompareNoCase( "HKEY_LOCAL_MACHINE" ) ) key = HKEY_LOCAL_MACHINE; - else if( !type.CompareNoCase( "HKEY_USERS" ) ) key = HKEY_USERS; + if( !sType.CompareNoCase( "HKEY_CLASSES_ROOT" ) ) key = HKEY_CLASSES_ROOT; + else if( !sType.CompareNoCase( "HKEY_CURRENT_CONFIG" ) ) key = HKEY_CURRENT_CONFIG; + else if( !sType.CompareNoCase( "HKEY_CURRENT_USER" ) ) key = HKEY_CURRENT_USER; + else if( !sType.CompareNoCase( "HKEY_LOCAL_MACHINE" ) ) key = HKEY_LOCAL_MACHINE; + else if( !sType.CompareNoCase( "HKEY_USERS" ) ) key = HKEY_USERS; else { - LOG->Warn( "Invalid registry key: \"%s\" ", in.c_str() ); + LOG->Warn( "Invalid registry key: \"%s\" ", sIn.c_str() ); return false; } - out = in.substr( backslash+1 ); + sOut = sIn.substr( iBackslash+1 ); return true; } /* Given a full key, eg. "HKEY_LOCAL_MACHINE\hardware\foo", open it and return it. * On error, return NULL. */ -static HKEY OpenRegKey( const CString &key ) +static HKEY OpenRegKey( const CString &sKey ) { - CString subkey; - HKEY type; - if( !GetRegKeyType( key, subkey, type ) ) + CString sSubkey; + HKEY hType; + if( !GetRegKeyType(sKey, sSubkey, hType) ) return NULL; - HKEY retkey; - LONG retval = RegOpenKeyEx( type, subkey, 0, KEY_READ, &retkey ); + HKEY hRetKey; + LONG retval = RegOpenKeyEx( hType, sSubkey, 0, KEY_READ, &hRetKey ); if ( retval != ERROR_SUCCESS ) { - LOG->Warn( werr_ssprintf(retval, "RegOpenKeyEx(%x,%s) error", type, subkey.c_str()) ); + LOG->Warn( werr_ssprintf(retval, "RegOpenKeyEx(%x,%s) error", hType, sSubkey.c_str()) ); return NULL; } - return retkey; + return hRetKey; } -bool GetRegValue( const CString &key, const CString &sName, CString &val ) +bool GetRegValue( const CString &sKey, const CString &sName, CString &sVal ) { - HKEY hkey = OpenRegKey( key ); - if( hkey == NULL ) + HKEY hKey = OpenRegKey( sKey ); + if( hKey == NULL ) return false; char sBuffer[MAX_PATH]; - DWORD nSize = sizeof(sBuffer); - DWORD Type; - LONG ret = RegQueryValueEx( hkey, sName, NULL, &Type, (LPBYTE)sBuffer, &nSize ); - RegCloseKey( hkey ); - if( ret != ERROR_SUCCESS ) + DWORD iSize = sizeof(sBuffer); + DWORD iType; + LONG iRet = RegQueryValueEx( hKey, sName, NULL, &iType, (LPBYTE)sBuffer, &iSize ); + RegCloseKey( hKey ); + if( iRet != ERROR_SUCCESS ) return false; /* Actually, CStrings are 8-bit clean, so we can accept any type of data. Remove * this if that becomes useful. */ - if( Type != REG_SZ && Type != REG_MULTI_SZ && Type != REG_EXPAND_SZ && Type != REG_BINARY ) + if( iType != REG_SZ && iType != REG_MULTI_SZ && iType != REG_EXPAND_SZ && iType != REG_BINARY ) return false; /* type mismatch */ - if( nSize && (Type == REG_SZ || Type == REG_MULTI_SZ || Type == REG_EXPAND_SZ) ) - --nSize; /* remove nul terminator */ + if( iSize && (iType == REG_SZ || iType == REG_MULTI_SZ || iType == REG_EXPAND_SZ) ) + --iSize; /* remove nul terminator */ - val = CString( sBuffer, nSize ); + sVal = CString( sBuffer, iSize ); return true; } -bool GetRegValue( const CString &key, CString sName, int &val ) +bool GetRegValue( const CString &sKey, CString sName, int &iVal ) { - HKEY hkey = OpenRegKey( key ); - if( hkey == NULL ) + HKEY hKey = OpenRegKey( sKey ); + if( hKey == NULL ) return false; - DWORD value; - DWORD nSize = sizeof(value); - DWORD Type; - LONG ret = RegQueryValueEx( hkey, sName, NULL, &Type, (LPBYTE) &value, &nSize ); - RegCloseKey( hkey ); - if( ret != ERROR_SUCCESS ) + DWORD iValue; + DWORD iSize = sizeof(iValue); + DWORD iType; + LONG iRet = RegQueryValueEx( hKey, sName, NULL, &iType, (LPBYTE) &iValue, &iSize ); + RegCloseKey( hKey ); + if( iRet != ERROR_SUCCESS ) return false; - if( Type != REG_DWORD ) + if( iType != REG_DWORD ) return false; /* type mismatch */ - val = value; + iVal = iValue; return true; } -bool GetRegSubKeys( const CString &key, vector &lst, const CString ®ex, bool bReturnPathToo ) +bool GetRegSubKeys( const CString &sKey, vector &lst, const CString ®ex, bool bReturnPathToo ) { - HKEY hkey = OpenRegKey( key ); - if ( hkey == NULL ) + HKEY hKey = OpenRegKey( sKey ); + if( hKey == NULL ) return false; Regex re(regex); @@ -112,29 +112,29 @@ bool GetRegSubKeys( const CString &key, vector &lst, const CString ® { FILETIME ft; char szBuffer[MAX_PATH]; - DWORD nSize = sizeof(szBuffer); - LONG ret = RegEnumKeyEx( hkey, index, szBuffer, &nSize, NULL, NULL, NULL, &ft); - if( ret == ERROR_NO_MORE_ITEMS ) + DWORD iSize = sizeof(szBuffer); + LONG iRet = RegEnumKeyEx( hKey, index, szBuffer, &iSize, NULL, NULL, NULL, &ft); + if( iRet == ERROR_NO_MORE_ITEMS ) break; - if( ret != ERROR_SUCCESS ) + if( iRet != ERROR_SUCCESS ) { - LOG->Warn( werr_ssprintf(ret, "GetRegSubKeys(%p,%i) error", hkey, index) ); + LOG->Warn( werr_ssprintf(iRet, "GetRegSubKeys(%p,%i) error", hKey, index) ); bError = true; break; } - CString str( szBuffer, nSize ); + CString sStr( szBuffer, iSize ); - if( re.Compare(str) ) + if( re.Compare(sStr) ) { if( bReturnPathToo ) - str = key + "\\" + str; - lst.push_back( str ); + sStr = sKey + "\\" + sStr; + lst.push_back( sStr ); } } - RegCloseKey( hkey ); + RegCloseKey( hKey ); return !bError; } diff --git a/stepmania/src/archutils/Win32/RegistryAccess.h b/stepmania/src/archutils/Win32/RegistryAccess.h index 05360b2816..7522bd3af5 100644 --- a/stepmania/src/archutils/Win32/RegistryAccess.h +++ b/stepmania/src/archutils/Win32/RegistryAccess.h @@ -2,7 +2,7 @@ #ifndef REGISTRY_ACCESS_H #define REGISTRY_ACCESS_H -#include "windows.h" +#include bool GetRegValue( const CString &key, const CString &sName, CString &val ); bool GetRegValue( const CString &key, CString sName, int &val ); bool GetRegSubKeys( const CString &key, vector &lst, const CString ®ex = ".*", bool bReturnPathToo = true ); diff --git a/stepmania/src/archutils/Win32/VideoDriverInfo.cpp b/stepmania/src/archutils/Win32/VideoDriverInfo.cpp index 7b3f63a4eb..ca4e7a7386 100644 --- a/stepmania/src/archutils/Win32/VideoDriverInfo.cpp +++ b/stepmania/src/archutils/Win32/VideoDriverInfo.cpp @@ -2,17 +2,17 @@ #include "VideoDriverInfo.h" #include "RageUtil.h" #include "RageLog.h" -#include "windows.h" #include "RegistryAccess.h" +#include -// this will not work on 95 and NT b/c of EnumDisplayDevices +// this will not work on 95 and NT because of EnumDisplayDevices CString GetPrimaryVideoName() { typedef BOOL (WINAPI* pfnEnumDisplayDevices)(PVOID,DWORD,PDISPLAY_DEVICE,DWORD); pfnEnumDisplayDevices EnumDisplayDevices; - HINSTANCE hInstUser32; + HINSTANCE hInstUser32; - hInstUser32 = LoadLibrary("User32.DLL"); + hInstUser32 = LoadLibrary( "User32.DLL" ); if( !hInstUser32 ) return CString(); @@ -25,7 +25,7 @@ CString GetPrimaryVideoName() } CString sPrimaryDeviceName; - for( DWORD i=0; true; i++ ) + for( int i=0; true; ++i ) { DISPLAY_DEVICE dd; ZERO( dd ); @@ -39,7 +39,7 @@ CString GetPrimaryVideoName() } } - FreeLibrary(hInstUser32); + FreeLibrary( hInstUser32 ); return sPrimaryDeviceName; } @@ -59,26 +59,26 @@ CString GetPrimaryVideoDriverName() } /* Get info for the given card number. Return false if that card doesn't exist. */ -bool GetVideoDriverInfo(int cardno, VideoDriverInfo &info) +bool GetVideoDriverInfo( int iCardno, VideoDriverInfo &info ) { OSVERSIONINFO version; - version.dwOSVersionInfoSize=sizeof(version); + version.dwOSVersionInfoSize = sizeof(version); GetVersionEx(&version); const bool bIsWin9x = version.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS; - static bool Initialized=false; + static bool bInitialized=false; static vector lst; - if( !Initialized ) + if( !bInitialized ) { - Initialized = true; + bInitialized = true; - const CString TopKey = bIsWin9x? + const CString sTopKey = bIsWin9x? "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\Class\\Display": "HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E968-E325-11CE-BFC1-08002BE10318}"; - GetRegSubKeys( TopKey, lst, ".*", false ); + GetRegSubKeys( sTopKey, lst, ".*", false ); - for( int i = lst.size()-1; i >= 0; --i ) + for( int i=lst.size()-1; i >= 0; --i ) { /* Remove all keys that aren't four characters long ("Properties"). */ if( lst[i].size() != 4 ) @@ -87,24 +87,24 @@ bool GetVideoDriverInfo(int cardno, VideoDriverInfo &info) continue; } - lst[i] = TopKey + "\\" + lst[i]; + lst[i] = sTopKey + "\\" + lst[i]; } - if ( lst.size() == 0 ) + if( lst.size() == 0 ) { LOG->Warn("GetVideoDriverInfo error: no cards found!"); return false; } } - while( cardno < (int)lst.size() ) + while( iCardno < (int)lst.size() ) { - const CString sKey = lst[cardno]; + const CString sKey = lst[iCardno]; if( !GetRegValue( sKey, "DriverDesc", info.sDescription ) ) { /* Remove this one from the list and ignore it, */ - lst.erase( lst.begin()+cardno ); + lst.erase( lst.begin()+iCardno ); continue; } diff --git a/stepmania/src/archutils/Win32/VideoDriverInfo.h b/stepmania/src/archutils/Win32/VideoDriverInfo.h index 8e9e0efbf9..00c232b08d 100644 --- a/stepmania/src/archutils/Win32/VideoDriverInfo.h +++ b/stepmania/src/archutils/Win32/VideoDriverInfo.h @@ -13,7 +13,7 @@ struct VideoDriverInfo }; CString GetPrimaryVideoName(); -bool GetVideoDriverInfo(int cardno, VideoDriverInfo &info); +bool GetVideoDriverInfo( int iCardno, VideoDriverInfo &info ); CString GetPrimaryVideoDriverName(); #endif