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