The big NULL replacement party part 5.
Right. ' = NULL' would get a lot of these.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include "HIDDevice.h"
|
||||
#include "RageUtil.h"
|
||||
|
||||
HIDDevice::HIDDevice() : m_Interface( NULL ), m_Queue( NULL ), m_bRunning( false )
|
||||
HIDDevice::HIDDevice() : m_Interface(nullptr), m_Queue(nullptr), m_bRunning( false )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ bool HIDDevice::Open( io_object_t device )
|
||||
if( hresult != S_OK )
|
||||
{
|
||||
LOG->Warn( "Couldn't get device interface from plugin interface." );
|
||||
m_Interface = NULL;
|
||||
m_Interface = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ bool HIDDevice::Open( io_object_t device )
|
||||
{
|
||||
PrintIOErr( ret, "Failed to open the interface." );
|
||||
CALL( m_Interface, Release );
|
||||
m_Interface = NULL;
|
||||
m_Interface = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -133,9 +133,9 @@ bool HIDDevice::Open( io_object_t device )
|
||||
{
|
||||
PrintIOErr( ret, "Failed to create the queue." );
|
||||
CALL( m_Queue, Release );
|
||||
m_Queue = NULL;
|
||||
m_Queue = nullptr;
|
||||
CALL( m_Interface, Release );
|
||||
m_Interface = NULL;
|
||||
m_Interface = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -137,8 +137,8 @@ static int get_readable_ranges( const void **starts, const void **ends, int size
|
||||
|
||||
close(fd);
|
||||
|
||||
*starts++ = NULL;
|
||||
*ends++ = NULL;
|
||||
*starts++ = nullptr;
|
||||
*ends++ = nullptr;
|
||||
|
||||
return got;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ static int find_address( const void *p, const void **starts, const void **ends )
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void *SavedStackPointer = NULL;
|
||||
static void *SavedStackPointer = nullptr;
|
||||
|
||||
void InitializeBacktrace()
|
||||
{
|
||||
@@ -364,7 +364,7 @@ static void do_backtrace( const void **buf, size_t size, const BacktraceContext
|
||||
frame = frame->link;
|
||||
}
|
||||
|
||||
buf[i] = NULL;
|
||||
buf[i] = nullptr;
|
||||
}
|
||||
|
||||
#if defined(CPU_X86)
|
||||
@@ -396,7 +396,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
{
|
||||
ctx = &CurrentCtx;
|
||||
|
||||
CurrentCtx.ip = NULL;
|
||||
CurrentCtx.ip = nullptr;
|
||||
CurrentCtx.bp = __builtin_frame_address(0);
|
||||
CurrentCtx.sp = __builtin_frame_address(0);
|
||||
CurrentCtx.pid = GetCurrentThreadId();
|
||||
@@ -523,7 +523,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
if( g_StackPointer == 0 )
|
||||
{
|
||||
buf[0] = BACKTRACE_METHOD_NOT_AVAILABLE;
|
||||
buf[1] = NULL;
|
||||
buf[1] = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
{
|
||||
ctx = &CurrentCtx;
|
||||
|
||||
CurrentCtx.ip = NULL;
|
||||
CurrentCtx.ip = nullptr;
|
||||
CurrentCtx.bp = __builtin_frame_address(0);
|
||||
CurrentCtx.sp = __builtin_frame_address(0);
|
||||
}
|
||||
@@ -562,7 +562,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
{
|
||||
/* There isn't much we can do if this is the case. The stack should be read/write
|
||||
* and since it isn't, give up. */
|
||||
buf[i] = NULL;
|
||||
buf[i] = nullptr;
|
||||
return;
|
||||
}
|
||||
const Frame *frame = (Frame *)ctx->sp;
|
||||
@@ -620,7 +620,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
frame = frame->link;
|
||||
}
|
||||
|
||||
buf[i] = NULL;
|
||||
buf[i] = nullptr;
|
||||
}
|
||||
#undef PROT_RW
|
||||
#undef PROT_EXE
|
||||
@@ -656,7 +656,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
/* __builtin_frame_address is broken on OS X; it sometimes returns bogus results. */
|
||||
register void *r1 __asm__ ("r1");
|
||||
CurrentCtx.FramePtr = (const Frame *) r1;
|
||||
CurrentCtx.PC = NULL;
|
||||
CurrentCtx.PC = nullptr;
|
||||
}
|
||||
|
||||
const Frame *frame = ctx->FramePtr;
|
||||
@@ -673,7 +673,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
frame = frame->stackPointer;
|
||||
}
|
||||
|
||||
buf[i] = NULL;
|
||||
buf[i] = nullptr;
|
||||
}
|
||||
|
||||
#elif defined(BACKTRACE_METHOD_PPC_LINUX)
|
||||
@@ -704,7 +704,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
|
||||
register void *r1 __asm__("1");
|
||||
CurrentCtx.FramePtr = (const Frame *)r1;
|
||||
CurrentCtx.PC = NULL;
|
||||
CurrentCtx.PC = nullptr;
|
||||
}
|
||||
|
||||
const Frame *frame = (const Frame *)ctx->FramePtr;
|
||||
@@ -718,7 +718,7 @@ void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
if( frame->linkReg )
|
||||
buf[i++] = frame->linkReg;
|
||||
}
|
||||
buf[i] = NULL;
|
||||
buf[i] = nullptr;
|
||||
}
|
||||
|
||||
#else
|
||||
@@ -729,7 +729,7 @@ void InitializeBacktrace() { }
|
||||
void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx )
|
||||
{
|
||||
buf[0] = BACKTRACE_METHOD_NOT_AVAILABLE;
|
||||
buf[1] = NULL;
|
||||
buf[1] = nullptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -34,7 +34,7 @@ void InitializeBacktrace();
|
||||
* null-terminated. If ctx is NULL, retrieve the current backtrace; otherwise
|
||||
* retrieve a backtrace for the given context. (Not all backtracers may
|
||||
* support contexts.) */
|
||||
void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx = NULL );
|
||||
void GetBacktrace( const void **buf, size_t size, const BacktraceContext *ctx = nullptr );
|
||||
|
||||
/* Set up a BacktraceContext to get a backtrace for a thread. ThreadID may
|
||||
* not be the current thread. True is returned on success, false on failure. */
|
||||
|
||||
@@ -242,8 +242,8 @@ void BacktraceNames::FromAddr( const void *p )
|
||||
const struct load_command *cmd = (struct load_command *) &header[1];
|
||||
unsigned long diff = 0xffffffff;
|
||||
|
||||
const char *dli_sname = NULL;
|
||||
void *dli_saddr = NULL;
|
||||
const char *dli_sname = nullptr;
|
||||
void *dli_saddr = nullptr;
|
||||
|
||||
for( unsigned long i = 0; i < header->ncmds; i++, cmd = next_load_command(cmd) )
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ extern const char *const version_time;
|
||||
|
||||
bool child_read( int fd, void *p, int size );
|
||||
|
||||
const char *g_pCrashHandlerArgv0 = NULL;
|
||||
const char *g_pCrashHandlerArgv0 = nullptr;
|
||||
|
||||
|
||||
static void output_stack_trace( FILE *out, const void **BacktracePointers )
|
||||
|
||||
@@ -115,7 +115,7 @@ static void *CreateStack( int size )
|
||||
*
|
||||
* mmap entries always show up individually in /proc/#/maps. We could use posix_memalign as
|
||||
* a fallback, but we'd have to put a barrier page on both sides to guarantee that. */
|
||||
char *p = NULL;
|
||||
char *p = nullptr;
|
||||
p = (char *) mmap( NULL, size+PageSize, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0 );
|
||||
|
||||
if( p == (void *) -1 )
|
||||
@@ -156,7 +156,7 @@ void SignalHandler::OnClose( handler h )
|
||||
/* Allocate a separate signal stack. This makes the crash handler work
|
||||
* if we run out of stack space. */
|
||||
const int AltStackSize = 1024*64;
|
||||
void *p = NULL;
|
||||
void *p = nullptr;
|
||||
if( bUseAltSigStack )
|
||||
p = CreateStack( AltStackSize );
|
||||
|
||||
@@ -169,7 +169,7 @@ void SignalHandler::OnClose( handler h )
|
||||
if( sigaltstack( &ss, NULL ) == -1 )
|
||||
{
|
||||
LOG->Info( "sigaltstack failed: %s", strerror(errno) );
|
||||
p = NULL; /* no SA_ONSTACK */
|
||||
p = nullptr; /* no SA_ONSTACK */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "Preference.h"
|
||||
#include "PrefsManager.h" // XXX: only used for m_bShowMouseCursor -aj
|
||||
|
||||
Display *X11Helper::Dpy = NULL;
|
||||
Display *X11Helper::Dpy = nullptr;
|
||||
Window X11Helper::Win = None;
|
||||
|
||||
static int ErrorCallback( Display*, XErrorEvent* );
|
||||
@@ -31,7 +31,7 @@ void X11Helper::CloseXConnection()
|
||||
DEBUG_ASSERT( Dpy != nullptr );
|
||||
DEBUG_ASSERT( Win == None );
|
||||
XCloseDisplay( Dpy );
|
||||
Dpy = NULL;
|
||||
Dpy = nullptr;
|
||||
}
|
||||
|
||||
bool X11Helper::MakeWindow( Window &win, int screenNum, int depth, Visual *visual, int width, int height, bool overrideRedirect )
|
||||
|
||||
@@ -9,7 +9,7 @@ int GetWin32CmdLine( char** &argv )
|
||||
{
|
||||
char *pCmdLine = GetCommandLine();
|
||||
int argc = 0;
|
||||
argv = NULL;
|
||||
argv = nullptr;
|
||||
|
||||
int i = 0;
|
||||
while( pCmdLine[i] )
|
||||
|
||||
@@ -73,7 +73,7 @@ static void GetReason( const EXCEPTION_RECORD *pRecord, CrashInfo *crash )
|
||||
strcpy( crash->m_CrashReason, reason );
|
||||
}
|
||||
|
||||
static HWND g_hForegroundWnd = NULL;
|
||||
static HWND g_hForegroundWnd = nullptr;
|
||||
void CrashHandler::SetForegroundWindow( HWND hWnd )
|
||||
{
|
||||
g_hForegroundWnd = hWnd;
|
||||
@@ -105,7 +105,7 @@ bool StartChild( HANDLE &hProcess, HANDLE &hToStdin, HANDLE &hFromStdout )
|
||||
SECURITY_ATTRIBUTES sa;
|
||||
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
|
||||
sa.bInheritHandle = true;
|
||||
sa.lpSecurityDescriptor = NULL;
|
||||
sa.lpSecurityDescriptor = nullptr;
|
||||
|
||||
CreatePipe( &si.hStdInput, &hToStdin, &sa, 0 );
|
||||
CreatePipe( &hFromStdout, &si.hStdOutput, &sa, 0 );
|
||||
@@ -166,7 +166,7 @@ static const char *CrashGetModuleBaseName(HMODULE hmod, char *pszBaseName)
|
||||
|
||||
pszFile = pszBaseName;
|
||||
|
||||
char *period = NULL;
|
||||
char *period = nullptr;
|
||||
while( *pszFile++ )
|
||||
if( pszFile[-1]=='.' )
|
||||
period = pszFile-1;
|
||||
@@ -299,7 +299,7 @@ static long MainExceptionHandler( EXCEPTION_POINTERS *pExc )
|
||||
/* If we get here, then we've been called recursively, which means we
|
||||
* crashed. If InHere is greater than 1, then we crashed after writing
|
||||
* the crash dump; say so. */
|
||||
SetUnhandledExceptionFilter(NULL);
|
||||
SetUnhandledExceptionFilter(nullptr);
|
||||
MessageBox( NULL,
|
||||
InHere == 1?
|
||||
"The error reporting interface has crashed.\n":
|
||||
@@ -345,7 +345,7 @@ static long MainExceptionHandler( EXCEPTION_POINTERS *pExc )
|
||||
|
||||
InHere = false;
|
||||
|
||||
SetUnhandledExceptionFilter( NULL );
|
||||
SetUnhandledExceptionFilter(nullptr);
|
||||
|
||||
/* Forcibly terminate; if we keep going, we'll try to shut down threads and
|
||||
* do other things that may deadlock, which is confusing for users. */
|
||||
@@ -474,7 +474,7 @@ void CrashHandler::do_backtrace( const void **buf, size_t size,
|
||||
LDT_ENTRY sel;
|
||||
if( !GetThreadSelectorEntry( hThread, pContext->SegFs, &sel ) )
|
||||
{
|
||||
*buf = NULL;
|
||||
*buf = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -523,7 +523,7 @@ void CrashHandler::do_backtrace( const void **buf, size_t size,
|
||||
lpAddr += 4;
|
||||
} while( ReadProcessMemory(hProcess, lpAddr-4, &data, 4, NULL));
|
||||
|
||||
*buf = NULL;
|
||||
*buf = nullptr;
|
||||
}
|
||||
|
||||
// Trigger the crash handler. This works even in the debugger.
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace VDDebugInfo
|
||||
|
||||
const unsigned char *src = (const unsigned char *) pctx->sRawBlock.data();
|
||||
|
||||
pctx->pRVAHeap = NULL;
|
||||
pctx->pRVAHeap = nullptr;
|
||||
|
||||
static const char *header = "symbolic debug information";
|
||||
if( memcmp(src, header, strlen(header)) )
|
||||
@@ -119,7 +119,7 @@ namespace VDDebugInfo
|
||||
return true;
|
||||
|
||||
pctx->sRawBlock = RString();
|
||||
pctx->pRVAHeap = NULL;
|
||||
pctx->pRVAHeap = nullptr;
|
||||
GetVDIPath( pctx->sFilename, ARRAYLEN(pctx->sFilename) );
|
||||
pctx->sError = RString();
|
||||
|
||||
@@ -623,7 +623,7 @@ CrashDialog::CrashDialog( const RString &sCrashReport, const CompleteCrashData &
|
||||
m_CrashData( CrashData )
|
||||
{
|
||||
LoadLocalizedStrings();
|
||||
m_pPost = NULL;
|
||||
m_pPost = nullptr;
|
||||
}
|
||||
|
||||
CrashDialog::~CrashDialog()
|
||||
@@ -656,7 +656,7 @@ BOOL CrashDialog::HandleMessage( UINT msg, WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
HDC hdc = (HDC)wParam;
|
||||
HWND hwndStatic = (HWND)lParam;
|
||||
HBRUSH hbr = NULL;
|
||||
HBRUSH hbr = nullptr;
|
||||
|
||||
// TODO: Change any attributes of the DC here
|
||||
switch( GetDlgCtrlID(hwndStatic) )
|
||||
@@ -839,7 +839,7 @@ void ChildProcess()
|
||||
|
||||
// Now that we've done that, the process is gone. Don't use g_hParent.
|
||||
CloseHandle( SymbolLookup::g_hParent );
|
||||
SymbolLookup::g_hParent = NULL;
|
||||
SymbolLookup::g_hParent = nullptr;
|
||||
|
||||
CrashDialog cd( sCrashReport, Data );
|
||||
#if defined(AUTOMATED_CRASH_REPORTS)
|
||||
|
||||
@@ -18,7 +18,7 @@ struct CrashInfo
|
||||
m_CrashReason[0] = 0;
|
||||
memset( m_AlternateThreadBacktrace, 0, sizeof(m_AlternateThreadBacktrace) );
|
||||
memset( m_AlternateThreadName, 0, sizeof(m_AlternateThreadName) );
|
||||
m_BacktracePointers[0] = NULL;
|
||||
m_BacktracePointers[0] = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -172,8 +172,8 @@ NetworkStream_Win32::NetworkStream_Win32():
|
||||
m_State = STATE_IDLE;
|
||||
m_Socket = NULL;
|
||||
#if defined(WINDOWS)
|
||||
m_hResolve = NULL;
|
||||
m_hResolveHwnd = NULL;
|
||||
m_hResolve = nullptr;
|
||||
m_hResolveHwnd = nullptr;
|
||||
m_hCompletionEvent = CreateEvent( NULL, true, false, NULL );
|
||||
#endif
|
||||
}
|
||||
@@ -355,7 +355,7 @@ void NetworkStream_Win32::Open( const RString &sHost, int iPort, ConnectionType
|
||||
m_iPort = iPort;
|
||||
|
||||
// Look up the hostname.
|
||||
hostent *pHost = NULL;
|
||||
hostent *pHost = nullptr;
|
||||
char pBuf[MAXGETHOSTSTRUCT];
|
||||
{
|
||||
pHost = (hostent *) pBuf;
|
||||
@@ -374,8 +374,8 @@ void NetworkStream_Win32::Open( const RString &sHost, int iPort, ConnectionType
|
||||
mw.Run();
|
||||
|
||||
m_Mutex.Lock();
|
||||
m_hResolve = NULL;
|
||||
m_hResolveHwnd = NULL;
|
||||
m_hResolve = nullptr;
|
||||
m_hResolveHwnd = nullptr;
|
||||
if( m_State == STATE_CANCELLED )
|
||||
{
|
||||
m_Mutex.Unlock();
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// pLogFont->nHeight is interpreted as PointSize * 10
|
||||
static HFONT CreatePointFontIndirect(const LOGFONT* lpLogFont)
|
||||
{
|
||||
HDC hDC = ::GetDC(NULL);
|
||||
HDC hDC = ::GetDC(nullptr);
|
||||
|
||||
// convert nPointSize to logical units based on pDC
|
||||
LOGFONT logFont = *lpLogFont;
|
||||
|
||||
@@ -118,9 +118,9 @@ bool GetProcessFileName( uint32_t iProcessID, RString &sName )
|
||||
|
||||
// This method only works in NT/2K/XP.
|
||||
do {
|
||||
static HINSTANCE hPSApi = NULL;
|
||||
static HINSTANCE hPSApi = nullptr;
|
||||
typedef DWORD (WINAPI* pfnGetProcessImageFileNameA)(HANDLE hProcess, LPSTR lpImageFileName, DWORD nSize);
|
||||
static pfnGetProcessImageFileNameA pGetProcessImageFileName = NULL;
|
||||
static pfnGetProcessImageFileNameA pGetProcessImageFileName = nullptr;
|
||||
static bool bTried = false;
|
||||
|
||||
if( !bTried )
|
||||
|
||||
@@ -22,7 +22,7 @@ static HDC g_HDC;
|
||||
static VideoModeParams g_CurrentParams;
|
||||
static bool g_bResolutionChanged = false;
|
||||
static bool g_bHasFocus = true;
|
||||
static HICON g_hIcon = NULL;
|
||||
static HICON g_hIcon = nullptr;
|
||||
static bool m_bWideWindowClass;
|
||||
static bool g_bD3D = false;
|
||||
|
||||
@@ -36,7 +36,7 @@ static RString GetNewWindow()
|
||||
{
|
||||
HWND h = GetForegroundWindow();
|
||||
if( h == nullptr )
|
||||
return "(NULL)";
|
||||
return "(nullptr)";
|
||||
|
||||
DWORD iProcessID;
|
||||
GetWindowThreadProcessId( h, &iProcessID );
|
||||
@@ -110,7 +110,7 @@ static LRESULT CALLBACK GraphicsWindow_WndProc( HWND hWnd, UINT msg, WPARAM wPar
|
||||
case WM_SETCURSOR:
|
||||
if( !g_CurrentParams.windowed )
|
||||
{
|
||||
SetCursor( NULL );
|
||||
SetCursor(nullptr);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
@@ -322,7 +322,7 @@ void GraphicsWindow::CreateGraphicsWindow( const VideoModeParams &p, bool bForce
|
||||
{
|
||||
SetClassLong( g_hWndMain, GCL_HICON, (LONG) LoadIcon(NULL,IDI_APPLICATION) );
|
||||
DestroyIcon( g_hIcon );
|
||||
g_hIcon = NULL;
|
||||
g_hIcon = nullptr;
|
||||
}
|
||||
g_hIcon = IconFromFile( p.sIconFile );
|
||||
if( g_hIcon != nullptr )
|
||||
@@ -376,7 +376,7 @@ void GraphicsWindow::DestroyGraphicsWindow()
|
||||
if( g_HDC != nullptr )
|
||||
{
|
||||
ReleaseDC( g_hWndMain, g_HDC );
|
||||
g_HDC = NULL;
|
||||
g_HDC = nullptr;
|
||||
}
|
||||
|
||||
CHECKPOINT;
|
||||
@@ -384,7 +384,7 @@ void GraphicsWindow::DestroyGraphicsWindow()
|
||||
if( g_hWndMain != nullptr )
|
||||
{
|
||||
DestroyWindow( g_hWndMain );
|
||||
g_hWndMain = NULL;
|
||||
g_hWndMain = nullptr;
|
||||
CrashHandler::SetForegroundWindow( g_hWndMain );
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ void GraphicsWindow::DestroyGraphicsWindow()
|
||||
if( g_hIcon != nullptr )
|
||||
{
|
||||
DestroyIcon( g_hIcon );
|
||||
g_hIcon = NULL;
|
||||
g_hIcon = nullptr;
|
||||
}
|
||||
|
||||
CHECKPOINT;
|
||||
|
||||
+246
-246
@@ -1,246 +1,246 @@
|
||||
#include "global.h"
|
||||
#include "USB.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageUtil.h"
|
||||
#include "archutils/Win32/ErrorStrings.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma comment(lib, "archutils/Win32/ddk/setupapi.lib")
|
||||
#pragma comment(lib, "archutils/Win32/ddk/hid.lib")
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include "archutils/Win32/ddk/setupapi.h"
|
||||
/* Quiet header warning: */
|
||||
#include "archutils/Win32/ddk/hidsdi.h"
|
||||
}
|
||||
|
||||
static RString GetUSBDevicePath( int iNum )
|
||||
{
|
||||
GUID guid;
|
||||
HidD_GetHidGuid( &guid );
|
||||
|
||||
HDEVINFO DeviceInfo = SetupDiGetClassDevs( &guid, NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE) );
|
||||
|
||||
SP_DEVICE_INTERFACE_DATA DeviceInterface;
|
||||
DeviceInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
||||
|
||||
if( !SetupDiEnumDeviceInterfaces (DeviceInfo,
|
||||
NULL, &guid, iNum, &DeviceInterface) )
|
||||
{
|
||||
SetupDiDestroyDeviceInfoList( DeviceInfo );
|
||||
return RString();
|
||||
}
|
||||
|
||||
unsigned long iSize;
|
||||
SetupDiGetDeviceInterfaceDetail( DeviceInfo, &DeviceInterface, NULL, 0, &iSize, 0 );
|
||||
|
||||
PSP_INTERFACE_DEVICE_DETAIL_DATA DeviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc( iSize );
|
||||
DeviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
|
||||
|
||||
RString sRet;
|
||||
if( SetupDiGetDeviceInterfaceDetail(DeviceInfo, &DeviceInterface,
|
||||
DeviceDetail, iSize, &iSize, NULL) )
|
||||
sRet = DeviceDetail->DevicePath;
|
||||
free( DeviceDetail );
|
||||
|
||||
SetupDiDestroyDeviceInfoList( DeviceInfo );
|
||||
return sRet;
|
||||
}
|
||||
|
||||
bool USBDevice::Open( int iVID, int iPID, int iBlockSize, int iNum, void (*pfnInit)(HANDLE) )
|
||||
{
|
||||
DWORD iIndex = 0;
|
||||
|
||||
RString path;
|
||||
while( (path = GetUSBDevicePath(iIndex++)) != "" )
|
||||
{
|
||||
HANDLE h = CreateFile( path, GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
|
||||
|
||||
if( h == INVALID_HANDLE_VALUE )
|
||||
continue;
|
||||
|
||||
HIDD_ATTRIBUTES attr;
|
||||
if( !HidD_GetAttributes(h, &attr) )
|
||||
{
|
||||
CloseHandle( h );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( (iVID != -1 && attr.VendorID != iVID) ||
|
||||
(iPID != -1 && attr.ProductID != iPID) )
|
||||
{
|
||||
CloseHandle( h );
|
||||
continue; /* This isn't it. */
|
||||
}
|
||||
|
||||
/* The VID and PID match. */
|
||||
if( iNum-- > 0 )
|
||||
{
|
||||
CloseHandle( h );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( pfnInit )
|
||||
pfnInit( h );
|
||||
CloseHandle(h);
|
||||
|
||||
m_IO.Open( path, iBlockSize );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool USBDevice::IsOpen() const
|
||||
{
|
||||
return m_IO.IsOpen();
|
||||
}
|
||||
|
||||
|
||||
int USBDevice::GetPadEvent()
|
||||
{
|
||||
if( !IsOpen() )
|
||||
return -1;
|
||||
|
||||
long iBuf;
|
||||
if( m_IO.read(&iBuf) <= 0 )
|
||||
return -1;
|
||||
|
||||
return iBuf;
|
||||
}
|
||||
|
||||
WindowsFileIO::WindowsFileIO()
|
||||
{
|
||||
ZeroMemory( &m_Overlapped, sizeof(m_Overlapped) );
|
||||
m_Handle = INVALID_HANDLE_VALUE;
|
||||
m_pBuffer = NULL;
|
||||
}
|
||||
|
||||
WindowsFileIO::~WindowsFileIO()
|
||||
{
|
||||
if( m_Handle != INVALID_HANDLE_VALUE )
|
||||
CloseHandle( m_Handle );
|
||||
delete[] m_pBuffer;
|
||||
}
|
||||
|
||||
bool WindowsFileIO::Open( RString path, int iBlockSize )
|
||||
{
|
||||
LOG->Trace( "WindowsFileIO::open(%s)", path.c_str() );
|
||||
m_iBlockSize = iBlockSize;
|
||||
|
||||
if( m_pBuffer )
|
||||
delete[] m_pBuffer;
|
||||
m_pBuffer = new char[m_iBlockSize];
|
||||
|
||||
if( m_Handle != INVALID_HANDLE_VALUE )
|
||||
CloseHandle( m_Handle );
|
||||
|
||||
m_Handle = CreateFile( path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL );
|
||||
|
||||
if( m_Handle == INVALID_HANDLE_VALUE )
|
||||
return false;
|
||||
|
||||
queue_read();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WindowsFileIO::queue_read()
|
||||
{
|
||||
/* Request feedback from the device. */
|
||||
unsigned long iRead;
|
||||
ReadFile( m_Handle, m_pBuffer, m_iBlockSize, &iRead, &m_Overlapped );
|
||||
}
|
||||
|
||||
int WindowsFileIO::finish_read( void *p )
|
||||
{
|
||||
LOG->Trace( "this %p, %p", this, p );
|
||||
/* We do; get the result. It'll go into the original m_pBuffer
|
||||
* we supplied on the original call; that's why m_pBuffer is a
|
||||
* member instead of a local. */
|
||||
unsigned long iCnt;
|
||||
int iRet = GetOverlappedResult( m_Handle, &m_Overlapped, &iCnt, FALSE );
|
||||
|
||||
if( iRet == 0 && (GetLastError() == ERROR_IO_PENDING || GetLastError() == ERROR_IO_INCOMPLETE) )
|
||||
return -1;
|
||||
|
||||
queue_read();
|
||||
|
||||
if( iRet == 0 )
|
||||
{
|
||||
LOG->Warn( werr_ssprintf(GetLastError(), "Error reading USB device") );
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy( p, m_pBuffer, iCnt );
|
||||
return iCnt;
|
||||
}
|
||||
|
||||
int WindowsFileIO::read( void *p )
|
||||
{
|
||||
LOG->Trace( "WindowsFileIO::read()" );
|
||||
|
||||
/* See if we have a response for our request (which we may
|
||||
* have made on a previous call): */
|
||||
if( WaitForSingleObjectEx(m_Handle, 0, TRUE) == WAIT_TIMEOUT )
|
||||
return -1;
|
||||
|
||||
return finish_read(p);
|
||||
}
|
||||
|
||||
int WindowsFileIO::read_several(const vector<WindowsFileIO *> &sources, void *p, int &actual, float timeout)
|
||||
{
|
||||
HANDLE *Handles = new HANDLE[sources.size()];
|
||||
for( unsigned i = 0; i < sources.size(); ++i )
|
||||
Handles[i] = sources[i]->m_Handle;
|
||||
|
||||
int ret = WaitForMultipleObjectsEx( sources.size(), Handles, false, int(timeout * 1000), true);
|
||||
delete[] Handles;
|
||||
|
||||
if( ret == -1 )
|
||||
{
|
||||
LOG->Trace( werr_ssprintf(GetLastError(), "WaitForMultipleObjectsEx failed") );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( ret >= int(WAIT_OBJECT_0) && ret < int(WAIT_OBJECT_0+sources.size()) )
|
||||
{
|
||||
actual = ret - WAIT_OBJECT_0;
|
||||
return sources[actual]->finish_read(p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WindowsFileIO::IsOpen() const
|
||||
{
|
||||
return m_Handle != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2002-2005 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
#include "global.h"
|
||||
#include "USB.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageUtil.h"
|
||||
#include "archutils/Win32/ErrorStrings.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma comment(lib, "archutils/Win32/ddk/setupapi.lib")
|
||||
#pragma comment(lib, "archutils/Win32/ddk/hid.lib")
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
#include "archutils/Win32/ddk/setupapi.h"
|
||||
/* Quiet header warning: */
|
||||
#include "archutils/Win32/ddk/hidsdi.h"
|
||||
}
|
||||
|
||||
static RString GetUSBDevicePath( int iNum )
|
||||
{
|
||||
GUID guid;
|
||||
HidD_GetHidGuid( &guid );
|
||||
|
||||
HDEVINFO DeviceInfo = SetupDiGetClassDevs( &guid, NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE) );
|
||||
|
||||
SP_DEVICE_INTERFACE_DATA DeviceInterface;
|
||||
DeviceInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
||||
|
||||
if( !SetupDiEnumDeviceInterfaces (DeviceInfo,
|
||||
NULL, &guid, iNum, &DeviceInterface) )
|
||||
{
|
||||
SetupDiDestroyDeviceInfoList( DeviceInfo );
|
||||
return RString();
|
||||
}
|
||||
|
||||
unsigned long iSize;
|
||||
SetupDiGetDeviceInterfaceDetail( DeviceInfo, &DeviceInterface, NULL, 0, &iSize, 0 );
|
||||
|
||||
PSP_INTERFACE_DEVICE_DETAIL_DATA DeviceDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA) malloc( iSize );
|
||||
DeviceDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA);
|
||||
|
||||
RString sRet;
|
||||
if( SetupDiGetDeviceInterfaceDetail(DeviceInfo, &DeviceInterface,
|
||||
DeviceDetail, iSize, &iSize, NULL) )
|
||||
sRet = DeviceDetail->DevicePath;
|
||||
free( DeviceDetail );
|
||||
|
||||
SetupDiDestroyDeviceInfoList( DeviceInfo );
|
||||
return sRet;
|
||||
}
|
||||
|
||||
bool USBDevice::Open( int iVID, int iPID, int iBlockSize, int iNum, void (*pfnInit)(HANDLE) )
|
||||
{
|
||||
DWORD iIndex = 0;
|
||||
|
||||
RString path;
|
||||
while( (path = GetUSBDevicePath(iIndex++)) != "" )
|
||||
{
|
||||
HANDLE h = CreateFile( path, GENERIC_READ,
|
||||
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
|
||||
|
||||
if( h == INVALID_HANDLE_VALUE )
|
||||
continue;
|
||||
|
||||
HIDD_ATTRIBUTES attr;
|
||||
if( !HidD_GetAttributes(h, &attr) )
|
||||
{
|
||||
CloseHandle( h );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( (iVID != -1 && attr.VendorID != iVID) ||
|
||||
(iPID != -1 && attr.ProductID != iPID) )
|
||||
{
|
||||
CloseHandle( h );
|
||||
continue; /* This isn't it. */
|
||||
}
|
||||
|
||||
/* The VID and PID match. */
|
||||
if( iNum-- > 0 )
|
||||
{
|
||||
CloseHandle( h );
|
||||
continue;
|
||||
}
|
||||
|
||||
if( pfnInit )
|
||||
pfnInit( h );
|
||||
CloseHandle(h);
|
||||
|
||||
m_IO.Open( path, iBlockSize );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool USBDevice::IsOpen() const
|
||||
{
|
||||
return m_IO.IsOpen();
|
||||
}
|
||||
|
||||
|
||||
int USBDevice::GetPadEvent()
|
||||
{
|
||||
if( !IsOpen() )
|
||||
return -1;
|
||||
|
||||
long iBuf;
|
||||
if( m_IO.read(&iBuf) <= 0 )
|
||||
return -1;
|
||||
|
||||
return iBuf;
|
||||
}
|
||||
|
||||
WindowsFileIO::WindowsFileIO()
|
||||
{
|
||||
ZeroMemory( &m_Overlapped, sizeof(m_Overlapped) );
|
||||
m_Handle = INVALID_HANDLE_VALUE;
|
||||
m_pBuffer = nullptr;
|
||||
}
|
||||
|
||||
WindowsFileIO::~WindowsFileIO()
|
||||
{
|
||||
if( m_Handle != INVALID_HANDLE_VALUE )
|
||||
CloseHandle( m_Handle );
|
||||
delete[] m_pBuffer;
|
||||
}
|
||||
|
||||
bool WindowsFileIO::Open( RString path, int iBlockSize )
|
||||
{
|
||||
LOG->Trace( "WindowsFileIO::open(%s)", path.c_str() );
|
||||
m_iBlockSize = iBlockSize;
|
||||
|
||||
if( m_pBuffer )
|
||||
delete[] m_pBuffer;
|
||||
m_pBuffer = new char[m_iBlockSize];
|
||||
|
||||
if( m_Handle != INVALID_HANDLE_VALUE )
|
||||
CloseHandle( m_Handle );
|
||||
|
||||
m_Handle = CreateFile( path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
|
||||
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL );
|
||||
|
||||
if( m_Handle == INVALID_HANDLE_VALUE )
|
||||
return false;
|
||||
|
||||
queue_read();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WindowsFileIO::queue_read()
|
||||
{
|
||||
/* Request feedback from the device. */
|
||||
unsigned long iRead;
|
||||
ReadFile( m_Handle, m_pBuffer, m_iBlockSize, &iRead, &m_Overlapped );
|
||||
}
|
||||
|
||||
int WindowsFileIO::finish_read( void *p )
|
||||
{
|
||||
LOG->Trace( "this %p, %p", this, p );
|
||||
/* We do; get the result. It'll go into the original m_pBuffer
|
||||
* we supplied on the original call; that's why m_pBuffer is a
|
||||
* member instead of a local. */
|
||||
unsigned long iCnt;
|
||||
int iRet = GetOverlappedResult( m_Handle, &m_Overlapped, &iCnt, FALSE );
|
||||
|
||||
if( iRet == 0 && (GetLastError() == ERROR_IO_PENDING || GetLastError() == ERROR_IO_INCOMPLETE) )
|
||||
return -1;
|
||||
|
||||
queue_read();
|
||||
|
||||
if( iRet == 0 )
|
||||
{
|
||||
LOG->Warn( werr_ssprintf(GetLastError(), "Error reading USB device") );
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy( p, m_pBuffer, iCnt );
|
||||
return iCnt;
|
||||
}
|
||||
|
||||
int WindowsFileIO::read( void *p )
|
||||
{
|
||||
LOG->Trace( "WindowsFileIO::read()" );
|
||||
|
||||
/* See if we have a response for our request (which we may
|
||||
* have made on a previous call): */
|
||||
if( WaitForSingleObjectEx(m_Handle, 0, TRUE) == WAIT_TIMEOUT )
|
||||
return -1;
|
||||
|
||||
return finish_read(p);
|
||||
}
|
||||
|
||||
int WindowsFileIO::read_several(const vector<WindowsFileIO *> &sources, void *p, int &actual, float timeout)
|
||||
{
|
||||
HANDLE *Handles = new HANDLE[sources.size()];
|
||||
for( unsigned i = 0; i < sources.size(); ++i )
|
||||
Handles[i] = sources[i]->m_Handle;
|
||||
|
||||
int ret = WaitForMultipleObjectsEx( sources.size(), Handles, false, int(timeout * 1000), true);
|
||||
delete[] Handles;
|
||||
|
||||
if( ret == -1 )
|
||||
{
|
||||
LOG->Trace( werr_ssprintf(GetLastError(), "WaitForMultipleObjectsEx failed") );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( ret >= int(WAIT_OBJECT_0) && ret < int(WAIT_OBJECT_0+sources.size()) )
|
||||
{
|
||||
actual = ret - WAIT_OBJECT_0;
|
||||
return sources[actual]->finish_read(p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool WindowsFileIO::IsOpen() const
|
||||
{
|
||||
return m_Handle != INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* (c) 2002-2005 Glenn Maynard
|
||||
* All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||
* whom the Software is furnished to do so, provided that the above
|
||||
* copyright notice(s) and this permission notice appear in all copies of
|
||||
* the Software and that both the above copyright notice(s) and this
|
||||
* permission notice appear in supporting documentation.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
* PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
@@ -77,7 +77,7 @@ HICON IconFromSurface( const RageSurface *pSrcImg )
|
||||
HICON icon = CreateIconFromResourceEx( (BYTE *) pBitmap, iSize + iSizeImage, TRUE, 0x00030000, pImg->w, pImg->h, LR_DEFAULTCOLOR );
|
||||
|
||||
delete pImg;
|
||||
pImg = NULL;
|
||||
pImg = nullptr;
|
||||
free( pBitmap );
|
||||
|
||||
if( icon == nullptr )
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
WindowsDialogBox::WindowsDialogBox()
|
||||
{
|
||||
m_hWnd = NULL;
|
||||
m_hWnd = nullptr;
|
||||
}
|
||||
|
||||
void WindowsDialogBox::Run( int iDialog )
|
||||
|
||||
Reference in New Issue
Block a user