various arch modifications, mainly for file download support

This commit is contained in:
AJ Kelly
2010-12-15 19:15:53 -06:00
parent 6d70de3199
commit a4fe858757
15 changed files with 258 additions and 116 deletions
+71 -3
View File
@@ -6,15 +6,59 @@
#endif
#include "RageUtil.h"
#include "RageLog.h"
#include "arch/arch.h"
#include "RageThreads.h"
#if !defined(SMPACKAGE)
static Preference<RString> g_sIgnoredDialogs( "IgnoredDialogs", "" );
#endif
#include "Selector_Dialog.h"
DialogDriver *MakeDialogDriver()
{
RString sDrivers = "win32,cocoa,null";
vector<RString> asDriversToTry;
split( sDrivers, ",", asDriversToTry, true );
ASSERT( asDriversToTry.size() != 0 );
RString sDriver;
DialogDriver *pRet = NULL;
for( unsigned i = 0; pRet == NULL && i < asDriversToTry.size(); ++i )
{
sDriver = asDriversToTry[i];
#ifdef USE_DIALOG_DRIVER_COCOA
if( !asDriversToTry[i].CompareNoCase("Cocoa") ) pRet = new DialogDriver_Cocoa;
#endif
#ifdef USE_DIALOG_DRIVER_WIN32
if( !asDriversToTry[i].CompareNoCase("Win32") ) pRet = new DialogDriver_Win32;
#endif
#ifdef USE_DIALOG_DRIVER_NULL
if( !asDriversToTry[i].CompareNoCase("Null") ) pRet = new DialogDriver_Null;
#endif
if( pRet == NULL )
{
continue;
}
RString sError = pRet->Init();
if( sError != "" )
{
if( LOG )
LOG->Info( "Couldn't load driver %s: %s", asDriversToTry[i].c_str(), sError.c_str() );
SAFE_DELETE( pRet );
}
}
return pRet;
}
static DialogDriver *g_pImpl = NULL;
static DialogDriver_Null g_NullDriver;
static bool g_bWindowed = true; // Start out true so that we'll show errors before DISPLAY is init'd.
static bool g_bWindowed = true; // Start out true so that we'll show errors before DISPLAY is init'd.
static bool DialogsEnabled()
{
@@ -28,7 +72,7 @@ void Dialog::Init()
g_pImpl = DialogDriver::Create();
/* DialogDriver_Null should have worked, at least. */
// DialogDriver_Null should have worked, at least.
ASSERT( g_pImpl != NULL );
}
@@ -52,7 +96,7 @@ static bool MessageIsIgnored( RString sID )
void Dialog::IgnoreMessage( RString sID )
{
/* We can't ignore messages before PREFSMAN is around. */
// We can't ignore messages before PREFSMAN is around.
#if !defined(SMPACKAGE)
if( PREFSMAN == NULL )
{
@@ -118,6 +162,30 @@ void Dialog::OK( RString sMessage, RString sID )
RageThread::SetIsShowingDialog( false );
}
Dialog::Result Dialog::OKCancel( RString sMessage, RString sID )
{
Dialog::Init();
if( LOG )
LOG->Trace( "Dialog: \"%s\" [%s]", sMessage.c_str(), sID.c_str() );
if( sID != "" && MessageIsIgnored(sID) )
return g_NullDriver.OKCancel( sMessage, sID );
RageThread::SetIsShowingDialog( true );
// only show Dialog if windowed
Dialog::Result ret;
if( DialogsEnabled() )
ret = g_pImpl->OKCancel( sMessage, sID ); // call derived version
else
ret = g_NullDriver.OKCancel( sMessage, sID );
RageThread::SetIsShowingDialog( false );
return ret;
}
Dialog::Result Dialog::AbortRetryIgnore( RString sMessage, RString sID )
{
Dialog::Init();
+1
View File
@@ -13,6 +13,7 @@ namespace Dialog
enum Result { abort, retry, ignore };
void Error( RString sError, RString sID = "" );
void OK( RString sMessage, RString sID = "" );
Result OKCancel( RString sMessage, RString sID = "" );
Result AbortRetryIgnore( RString sMessage, RString sID = "" );
Result AbortRetry( RString sMessage, RString sID = "" );
+6 -6
View File
@@ -8,7 +8,7 @@ RegisterDialogDriver::RegisterDialogDriver( const istring &sName, CreateDialogDr
{
if( g_pRegistrees == NULL )
g_pRegistrees = new map<istring, CreateDialogDriverFn>;
ASSERT( g_pRegistrees->find(sName) == g_pRegistrees->end() );
(*g_pRegistrees)[sName] = pfn;
}
@@ -20,20 +20,20 @@ DialogDriver *DialogDriver::Create()
RString sDrivers = "win32,macosx,null";
vector<RString> asDriversToTry;
split( sDrivers, ",", asDriversToTry, true );
ASSERT( asDriversToTry.size() != 0 );
FOREACH_CONST( RString, asDriversToTry, Driver )
{
map<istring, CreateDialogDriverFn>::const_iterator iter = RegisterDialogDriver::g_pRegistrees->find( istring(*Driver) );
if( iter == RegisterDialogDriver::g_pRegistrees->end() )
continue;
DialogDriver *pRet = (iter->second)();
DEBUG_ASSERT( pRet );
const RString sError = pRet->Init();
if( sError.empty() )
return pRet;
if( LOG )
+2 -1
View File
@@ -11,6 +11,7 @@ public:
virtual void Error( RString sMessage, RString sID ) { printf("Error: %s\n", sMessage.c_str()); }
virtual void OK( RString sMessage, RString sID ) {}
virtual Dialog::Result OKCancel( RString sMessage, RString sID ) { return Dialog::ok; }
virtual Dialog::Result AbortRetryIgnore( RString sMessage, RString sID ) { return Dialog::ignore; }
virtual Dialog::Result AbortRetry( RString sMessage, RString sID ) { return Dialog::abort; }
@@ -18,6 +19,7 @@ public:
virtual ~DialogDriver() { }
};
class DialogDriver_Null : public DialogDriver { };
#define USE_DIALOG_DRIVER_NULL
typedef DialogDriver *(*CreateDialogDriverFn)();
struct RegisterDialogDriver
@@ -28,7 +30,6 @@ struct RegisterDialogDriver
#define REGISTER_DIALOG_DRIVER_CLASS( name ) \
static RegisterDialogDriver register_##name( #name, CreateClass<DialogDriver_##name, DialogDriver> )
#endif
/*
+1
View File
@@ -11,6 +11,7 @@ public:
Dialog::Result AbortRetryIgnore( RString sMessage, RString sID );
Dialog::Result AbortRetry( RString sMessage, RString sID );
};
#define USE_DIALOG_DRIVER_COCOA
#endif
+27 -3
View File
@@ -57,7 +57,7 @@ static BOOL CALLBACK OKWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
SetWindowText( GetDlgItem(hWnd, IDC_MESSAGE), sMessage );
// Focus is on any of the controls in the dialog by default.
// I'm not sure why. Set focus to the button manually. -Chris
// I'm not sure why. Set focus to the button manually. -Chris
SetFocus( GetDlgItem(hWnd, IDOK) );
}
break;
@@ -72,7 +72,7 @@ static BOOL CALLBACK OKWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPara
{
case IDOK:
g_bHush = !!IsDlgButtonChecked( hWnd, IDC_HUSH );
/* fall through */
// fall through
case IDCANCEL:
EndDialog( hWnd, 0 );
break;
@@ -112,6 +112,30 @@ void DialogDriver_Win32::OK( RString sMessage, RString sID )
Dialog::IgnoreMessage( sID );
}
Dialog::Result DialogDriver_Win32::OKCancel( RString sMessage, RString sID )
{
g_bAllowHush = sID != "";
g_sMessage = sMessage;
AppInstance handle;
#if !defined(SMPACKAGE)
//DialogBox( handle.Get(), MAKEINTRESOURCE(IDD_OK), ::GetHwnd(), OKWndProc );
int result = ::MessageBox( NULL, sMessage, GetWindowTitle(), MB_OKCANCEL );
#else
int result = ::AfxMessageBox( ConvertUTF8ToACP(sMessage).c_str(), MB_OKCANCEL, 0 );
#endif
if( g_bAllowHush && g_bHush )
Dialog::IgnoreMessage( sID );
switch( result )
{
case IDOK:
return Dialog::ok;
default:
return Dialog::cancel;
}
}
#if !defined(SMPACKAGE)
static RString g_sErrorString;
@@ -159,7 +183,7 @@ static BOOL CALLBACK ErrorWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lP
break;
case IDC_BUTTON_RESTART:
Win32RestartProgram();
/* not reached */
// not reached
ASSERT( 0 );
EndDialog( hWnd, 0 );
break;
+1
View File
@@ -8,6 +8,7 @@ class DialogDriver_Win32: public DialogDriver
public:
void Error( RString sMessage, RString sID );
void OK( RString sMessage, RString sID );
Dialog::Result OKCancel( RString sMessage, RString sID );
Dialog::Result AbortRetryIgnore( RString sMessage, RString sID );
Dialog::Result AbortRetry( RString sMessage, RString sID );
};