2003-02-16 04:02:21 +00:00
|
|
|
#include "global.h"
|
2003-01-24 23:09:31 +00:00
|
|
|
#include "ArchHooks_Win32.h"
|
2003-07-07 03:53:16 +00:00
|
|
|
#include "RageUtil.h"
|
2004-05-29 23:17:01 +00:00
|
|
|
#include "RageThreads.h"
|
2003-07-07 03:53:16 +00:00
|
|
|
#include "PrefsManager.h"
|
2004-05-29 23:17:01 +00:00
|
|
|
#include "ProductInfo.h"
|
2003-07-07 03:53:16 +00:00
|
|
|
|
|
|
|
|
#include "archutils/win32/AppInstance.h"
|
2003-01-24 23:09:31 +00:00
|
|
|
#include "archutils/win32/crash.h"
|
2003-01-24 23:57:02 +00:00
|
|
|
#include "archutils/win32/DebugInfoHunt.h"
|
2003-09-23 05:06:13 +00:00
|
|
|
#include "archutils/win32/GotoURL.h"
|
2003-10-16 09:07:04 +00:00
|
|
|
#include "archutils/win32/RestartProgram.h"
|
2004-05-29 23:17:01 +00:00
|
|
|
#include "archutils/win32/VideoDriverInfo.h"
|
|
|
|
|
#include "archutils/win32/WindowsResources.h"
|
2003-01-24 23:09:31 +00:00
|
|
|
|
|
|
|
|
ArchHooks_Win32::ArchHooks_Win32()
|
|
|
|
|
{
|
|
|
|
|
SetUnhandledExceptionFilter(CrashHandler);
|
2004-03-21 04:10:43 +00:00
|
|
|
TimeCritMutex = new RageMutex("TimeCritMutex");
|
2004-05-01 01:44:07 +00:00
|
|
|
|
|
|
|
|
/* Disable critical errors, and handle them internally. We never want the
|
|
|
|
|
* "drive not ready", etc. dialogs to pop up. */
|
|
|
|
|
SetErrorMode( SetErrorMode(0) | SEM_FAILCRITICALERRORS );
|
2004-01-18 02:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ArchHooks_Win32::~ArchHooks_Win32()
|
|
|
|
|
{
|
|
|
|
|
delete TimeCritMutex;
|
2003-01-24 23:09:31 +00:00
|
|
|
}
|
|
|
|
|
|
2003-02-17 03:08:53 +00:00
|
|
|
void ArchHooks_Win32::DumpDebugInfo()
|
2003-01-24 23:57:02 +00:00
|
|
|
{
|
|
|
|
|
/* This is a good time to do the debug search: before we actually
|
|
|
|
|
* start OpenGL (in case something goes wrong). */
|
|
|
|
|
SearchForDebugInfo();
|
2004-05-29 23:21:37 +00:00
|
|
|
|
|
|
|
|
CheckVideoDriver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static CString g_sDriverVersion, g_sURL;
|
|
|
|
|
static bool g_Hush;
|
|
|
|
|
static BOOL CALLBACK DriverWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
|
|
|
|
|
{
|
|
|
|
|
switch( msg )
|
|
|
|
|
{
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
{
|
|
|
|
|
g_Hush = false;
|
|
|
|
|
CString sMessage = ssprintf(
|
|
|
|
|
"The graphics drivers you are running, %s, are very old and are known "
|
|
|
|
|
"to cause problems. Upgrading to the latest drivers is recommended.\n",
|
|
|
|
|
g_sDriverVersion.c_str() );
|
|
|
|
|
|
|
|
|
|
sMessage.Replace( "\n", "\r\n" );
|
|
|
|
|
|
|
|
|
|
SendDlgItemMessage( hWnd, IDC_MESSAGE, WM_SETTEXT,
|
|
|
|
|
0, (LPARAM)(LPCTSTR)sMessage );
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
|
|
|
|
case IDOK:
|
|
|
|
|
g_Hush = !!IsDlgButtonChecked(hWnd, IDC_HUSH);
|
|
|
|
|
GotoURL( g_sURL );
|
|
|
|
|
EndDialog( hWnd, 1 );
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case IDCANCEL:
|
|
|
|
|
g_Hush = !!IsDlgButtonChecked(hWnd, IDC_HUSH);
|
|
|
|
|
EndDialog( hWnd, 0 );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This simply does a few manual checks for known bad driver versions. Only nag the
|
|
|
|
|
* user if it's a driver that we receive many complaints about--we don't want to
|
|
|
|
|
* tell users to upgrade if there's no problem, since it's likely to cause new problems.
|
|
|
|
|
*/
|
|
|
|
|
void ArchHooks_Win32::CheckVideoDriver()
|
|
|
|
|
{
|
|
|
|
|
if( MessageIsIgnored( "OLD_DRIVER_WARNING" ) )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CString sPrimaryDeviceName = GetPrimaryVideoName();
|
|
|
|
|
if( sPrimaryDeviceName == "" )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_sDriverVersion = "";
|
|
|
|
|
for( int i=0; true; i++ )
|
|
|
|
|
{
|
|
|
|
|
VideoDriverInfo info;
|
|
|
|
|
if( !GetVideoDriverInfo(i, info) )
|
|
|
|
|
break;
|
|
|
|
|
if( info.sDescription != sPrimaryDeviceName )
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
/* "IntelR 810 Chipset Graphics Driver PV 2.1". I get a lot of crash reports
|
|
|
|
|
* with people using this version. */
|
|
|
|
|
if( Regex( "Intel.* 810 Chipset Graphics Driver PV 2.1").Compare( info.sDescription ) )
|
|
|
|
|
{
|
|
|
|
|
g_sDriverVersion = info.sDescription;
|
|
|
|
|
g_sURL = "http://www.intel.com/design/software/drivers/platform/810.htm";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( g_sDriverVersion == "" )
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bool bExit = !!DialogBox( AppInstance(), MAKEINTRESOURCE(IDD_DRIVER), NULL, DriverWndProc );
|
|
|
|
|
|
|
|
|
|
if( g_Hush )
|
|
|
|
|
IgnoreMessage( "OLD_DRIVER_WARNING" );
|
|
|
|
|
if( bExit )
|
|
|
|
|
ExitProcess(0);
|
2003-01-24 23:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-07 03:53:16 +00:00
|
|
|
static CString g_sMessage;
|
|
|
|
|
static bool g_AllowHush;
|
|
|
|
|
static BOOL CALLBACK OKWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
|
|
|
|
|
{
|
|
|
|
|
switch( msg )
|
|
|
|
|
{
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
{
|
|
|
|
|
g_Hush = false;
|
|
|
|
|
CString sMessage = g_sMessage;
|
|
|
|
|
|
|
|
|
|
sMessage.Replace( "\n", "\r\n" );
|
|
|
|
|
HWND hush = GetDlgItem( hWnd, IDC_HUSH );
|
|
|
|
|
int style = GetWindowLong(hush, GWL_STYLE);
|
|
|
|
|
|
|
|
|
|
if( g_AllowHush )
|
|
|
|
|
style |= WS_VISIBLE;
|
|
|
|
|
else
|
|
|
|
|
style &= ~WS_VISIBLE;
|
|
|
|
|
SetWindowLong( hush, GWL_STYLE, style );
|
|
|
|
|
|
|
|
|
|
SendDlgItemMessage(
|
|
|
|
|
hWnd,
|
|
|
|
|
IDC_MESSAGE,
|
|
|
|
|
WM_SETTEXT,
|
|
|
|
|
0,
|
|
|
|
|
(LPARAM)(LPCTSTR)sMessage
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
|
|
|
|
case IDOK:
|
|
|
|
|
g_Hush = !!IsDlgButtonChecked(hWnd, IDC_HUSH);
|
|
|
|
|
/* fall through */
|
|
|
|
|
case IDCANCEL:
|
|
|
|
|
EndDialog( hWnd, 0 );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-01-13 00:15:10 +00:00
|
|
|
void ArchHooks_Win32::MessageBoxOKPrivate( CString sMessage, CString ID )
|
2003-07-07 03:53:16 +00:00
|
|
|
{
|
|
|
|
|
g_AllowHush = ID != "";
|
|
|
|
|
g_sMessage = sMessage;
|
|
|
|
|
AppInstance handle;
|
|
|
|
|
DialogBox(handle.Get(), MAKEINTRESOURCE(IDD_OK), NULL, OKWndProc);
|
|
|
|
|
if( g_AllowHush && g_Hush )
|
|
|
|
|
IgnoreMessage( ID );
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-23 05:06:13 +00:00
|
|
|
static CString g_sErrorString;
|
|
|
|
|
|
|
|
|
|
static BOOL CALLBACK ErrorWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
|
|
|
|
|
{
|
|
|
|
|
switch( msg )
|
|
|
|
|
{
|
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
|
{
|
|
|
|
|
CString sMessage = g_sErrorString;
|
|
|
|
|
|
|
|
|
|
sMessage.Replace( "\n", "\r\n" );
|
|
|
|
|
|
|
|
|
|
SendDlgItemMessage(
|
|
|
|
|
hWnd,
|
|
|
|
|
IDC_EDIT_ERROR,
|
|
|
|
|
WM_SETTEXT,
|
|
|
|
|
0,
|
|
|
|
|
(LPARAM)(LPCTSTR)sMessage
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
|
switch (LOWORD(wParam))
|
|
|
|
|
{
|
|
|
|
|
case IDC_BUTTON_VIEW_LOG:
|
|
|
|
|
{
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
ZeroMemory( &si, sizeof(si) );
|
|
|
|
|
|
|
|
|
|
CreateProcess(
|
|
|
|
|
NULL, // pointer to name of executable module
|
|
|
|
|
"notepad.exe log.txt", // pointer to command line string
|
|
|
|
|
NULL, // process security attributes
|
|
|
|
|
NULL, // thread security attributes
|
|
|
|
|
false, // handle inheritance flag
|
|
|
|
|
0, // creation flags
|
|
|
|
|
NULL, // pointer to new environment block
|
|
|
|
|
NULL, // pointer to current directory name
|
|
|
|
|
&si, // pointer to STARTUPINFO
|
|
|
|
|
&pi // pointer to PROCESS_INFORMATION
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case IDC_BUTTON_REPORT:
|
|
|
|
|
GotoURL( "http://sourceforge.net/tracker/?func=add&group_id=37892&atid=421366" );
|
|
|
|
|
break;
|
|
|
|
|
case IDC_BUTTON_RESTART:
|
2003-10-16 09:07:04 +00:00
|
|
|
Win32RestartProgram();
|
|
|
|
|
/* not reached */
|
|
|
|
|
ASSERT( 0 );
|
2003-09-23 05:06:13 +00:00
|
|
|
|
|
|
|
|
EndDialog( hWnd, 0 );
|
|
|
|
|
break;
|
2003-09-23 05:14:41 +00:00
|
|
|
|
2003-09-23 05:06:13 +00:00
|
|
|
case IDOK:
|
|
|
|
|
EndDialog( hWnd, 0 );
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-16 22:43:59 +00:00
|
|
|
void ArchHooks_Win32::MessageBoxErrorPrivate( CString error, CString ID )
|
2003-09-23 05:06:13 +00:00
|
|
|
{
|
|
|
|
|
g_sErrorString = error;
|
|
|
|
|
// throw up a pretty error dialog
|
|
|
|
|
AppInstance handle;
|
|
|
|
|
DialogBox(handle.Get(), MAKEINTRESOURCE(IDD_ERROR_DIALOG),
|
|
|
|
|
NULL, ErrorWndProc);
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-13 00:15:10 +00:00
|
|
|
ArchHooks::MessageBoxResult ArchHooks_Win32::MessageBoxAbortRetryIgnorePrivate( CString sMessage, CString ID )
|
2003-07-04 22:45:53 +00:00
|
|
|
{
|
2003-11-15 06:04:24 +00:00
|
|
|
switch( MessageBox(NULL, sMessage, PRODUCT_NAME, MB_ABORTRETRYIGNORE|MB_DEFBUTTON2 ) )
|
2003-07-04 22:45:53 +00:00
|
|
|
{
|
|
|
|
|
case IDABORT: return abort;
|
|
|
|
|
case IDRETRY: return retry;
|
|
|
|
|
default: ASSERT(0);
|
|
|
|
|
case IDIGNORE: return ignore;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-13 00:15:10 +00:00
|
|
|
ArchHooks::MessageBoxResult ArchHooks_Win32::MessageBoxRetryCancelPrivate( CString sMessage, CString ID )
|
2003-11-05 05:29:57 +00:00
|
|
|
{
|
|
|
|
|
switch( MessageBox(NULL, sMessage, PRODUCT_NAME, MB_RETRYCANCEL ) )
|
|
|
|
|
{
|
|
|
|
|
case IDRETRY: return retry;
|
|
|
|
|
default: ASSERT(0);
|
|
|
|
|
case IDCANCEL: return cancel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-10-17 06:32:37 +00:00
|
|
|
void ArchHooks_Win32::RestartProgram()
|
|
|
|
|
{
|
|
|
|
|
Win32RestartProgram();
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-18 02:37:48 +00:00
|
|
|
void ArchHooks_Win32::EnterTimeCriticalSection()
|
|
|
|
|
{
|
|
|
|
|
TimeCritMutex->Lock();
|
|
|
|
|
|
|
|
|
|
OldThreadPriority = GetThreadPriority( GetCurrentThread() );
|
|
|
|
|
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ArchHooks_Win32::ExitTimeCriticalSection()
|
|
|
|
|
{
|
|
|
|
|
SetThreadPriority( GetCurrentThread(), OldThreadPriority );
|
|
|
|
|
OldThreadPriority = 0;
|
|
|
|
|
TimeCritMutex->Unlock();
|
|
|
|
|
}
|
|
|
|
|
|
2004-03-14 06:39:39 +00:00
|
|
|
void ArchHooks_Win32::SetTime( tm newtime )
|
|
|
|
|
{
|
|
|
|
|
SYSTEMTIME st;
|
|
|
|
|
ZERO( st );
|
2004-03-21 17:23:18 +00:00
|
|
|
st.wYear = (WORD)newtime.tm_year+1900;
|
|
|
|
|
st.wMonth = (WORD)newtime.tm_mon+1;
|
|
|
|
|
st.wDay = (WORD)newtime.tm_mday;
|
|
|
|
|
st.wHour = (WORD)newtime.tm_hour;
|
|
|
|
|
st.wMinute = (WORD)newtime.tm_min;
|
|
|
|
|
st.wSecond = (WORD)newtime.tm_sec;
|
2004-03-14 06:39:39 +00:00
|
|
|
st.wMilliseconds = 0;
|
2004-03-21 17:23:18 +00:00
|
|
|
SetLocalTime( &st );
|
2004-03-14 06:39:39 +00:00
|
|
|
}
|
2003-09-23 05:06:13 +00:00
|
|
|
|
2003-01-24 23:09:31 +00:00
|
|
|
/*
|
2004-05-15 21:53:06 +00:00
|
|
|
* (c) 2003-2004 Glenn Maynard, Chris Danford
|
|
|
|
|
* 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.
|
2003-01-24 23:09:31 +00:00
|
|
|
*/
|