diff --git a/stepmania/src/arch/ErrorDialog/ErrorDialog.h b/stepmania/src/arch/ErrorDialog/ErrorDialog.h new file mode 100644 index 0000000000..c6c9caa418 --- /dev/null +++ b/stepmania/src/arch/ErrorDialog/ErrorDialog.h @@ -0,0 +1,24 @@ +#ifndef ERROR_DIALOG_H +#define ERROR_DIALOG_H + +class ErrorDialog { + CString ErrorText; + +public: + void SetErrorText(const CString &error) { ErrorText = error; } + CString GetErrorText() const { return ErrorText; } + + /* This is used for showing errors from exceptions, so it might be used + * before SDL has been initialized (or SDL may have failed to init); don't + * use SDL. If the window has been opened, it'll be hidden or closed. */ + virtual void ShowError() = 0; + virtual ~ErrorDialog() { } +}; + +#endif + +/* + * Copyright (c) 2002 by the person(s) listed below. All rights reserved. + * + * Glenn Maynard + */ diff --git a/stepmania/src/arch/ErrorDialog/ErrorDialog_Win32.cpp b/stepmania/src/arch/ErrorDialog/ErrorDialog_Win32.cpp new file mode 100644 index 0000000000..2d26c33040 --- /dev/null +++ b/stepmania/src/arch/ErrorDialog/ErrorDialog_Win32.cpp @@ -0,0 +1,104 @@ +#include "../../stdafx.h" +#include "../../RageUtil.h" +#include "../../resource.h" + +#include "ErrorDialog_Win32.h" + +static CString g_sErrorString; + +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: + { + /* Clear the startup mutex, since we're starting a new + * instance before ending ourself. */ + TCHAR szFullAppPath[MAX_PATH]; + GetModuleFileName(NULL, szFullAppPath, MAX_PATH); + + // Launch StepMania + PROCESS_INFORMATION pi; + STARTUPINFO si; + ZeroMemory( &si, sizeof(si) ); + + CreateProcess( + NULL, // pointer to name of executable module + szFullAppPath, // 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 + ); + } + EndDialog( hWnd, 0 ); + break; + // fall through + case IDOK: + EndDialog( hWnd, 0 ); + break; + } + } + return FALSE; +} + + +void ErrorDialog_Win32::ShowError() +{ + g_sErrorString = GetErrorText(); + // throw up a pretty error dialog + DialogBox(handle.Get(), MAKEINTRESOURCE(IDD_ERROR_DIALOG), + NULL, ErrorWndProc); +} + +/* + * Copyright (c) 2002 by the person(s) listed below. All rights reserved. + * + * Chris Danford + * Glenn Maynard + */ diff --git a/stepmania/src/arch/ErrorDialog/ErrorDialog_Win32.h b/stepmania/src/arch/ErrorDialog/ErrorDialog_Win32.h new file mode 100644 index 0000000000..052b54a5e1 --- /dev/null +++ b/stepmania/src/arch/ErrorDialog/ErrorDialog_Win32.h @@ -0,0 +1,24 @@ +#ifndef ERROR_DIALOG_WIN32_H +#define ERROR_DIALOG_WIN32_H + +#include "ErrorDialog.h" +#include "../../archutils/Win32/AppInstance.h" + +class ErrorDialog_Win32: public ErrorDialog +{ + AppInstance handle; + +public: + void ShowError(); +}; + +#undef ARCH_ERROR_DIALOG +#define ARCH_ERROR_DIALOG ErrorDialog_Win32 + +#endif + +/* + * Copyright (c) 2002 by the person(s) listed below. All rights reserved. + * + * Glenn Maynard + */ diff --git a/stepmania/src/arch/ErrorDialog/ErrorDialog_stdout.cpp b/stepmania/src/arch/ErrorDialog/ErrorDialog_stdout.cpp new file mode 100644 index 0000000000..59393ce071 --- /dev/null +++ b/stepmania/src/arch/ErrorDialog/ErrorDialog_stdout.cpp @@ -0,0 +1,14 @@ +#include "../../stdafx.h" +#include "ErrorDialog_stdout.h" + +void ErrorDialog_stdout::ShowError() +{ + /* Simplest "dialog" ever. */ + printf("Error: %s\n", GetErrorText().GetString()); +} + +/* + * Copyright (c) 2002 by the person(s) listed below. All rights reserved. + * + * Glenn Maynard + */ diff --git a/stepmania/src/arch/ErrorDialog/ErrorDialog_stdout.h b/stepmania/src/arch/ErrorDialog/ErrorDialog_stdout.h new file mode 100644 index 0000000000..cd7d719f2f --- /dev/null +++ b/stepmania/src/arch/ErrorDialog/ErrorDialog_stdout.h @@ -0,0 +1,21 @@ +#ifndef ERROR_DIALOG_STDOUT_H +#define ERROR_DIALOG_STDOUT_H + +#include "ErrorDialog.h" + +class ErrorDialog_stdout: public ErrorDialog +{ +public: + void ShowError(); +}; + +#undef ARCH_ERROR_DIALOG +#define ARCH_ERROR_DIALOG ErrorDialog_stdout + +#endif + +/* + * Copyright (c) 2002 by the person(s) listed below. All rights reserved. + * + * Glenn Maynard + */ diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index 670e013083..3162a899a6 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -18,6 +18,7 @@ #endif LoadingWindow *MakeLoadingWindow() { return new ARCH_LOADING_WINDOW; } +ErrorDialog *MakeErrorDialog() { return new ARCH_ERROR_DIALOG; } /* Err, this is ugly--breaks arch encapsulation. Hmm. */ RageSoundDriver *MakeRageSoundDriver(CString drivers) diff --git a/stepmania/src/arch/arch.h b/stepmania/src/arch/arch.h index 5db58b6ac8..793174fdd9 100644 --- a/stepmania/src/arch/arch.h +++ b/stepmania/src/arch/arch.h @@ -2,9 +2,11 @@ #define ARCH_H /* Include this file if you need to create an instance of a driver object. */ +class ErrorDialog; class LoadingWindow; class RageSoundDriver; +ErrorDialog *MakeErrorDialog(); LoadingWindow *MakeLoadingWindow(); RageSoundDriver *MakeRageSoundDriver(CString drivers); diff --git a/stepmania/src/arch/arch_Win32.h b/stepmania/src/arch/arch_Win32.h index 5bf91ff5e1..690802d276 100644 --- a/stepmania/src/arch/arch_Win32.h +++ b/stepmania/src/arch/arch_Win32.h @@ -3,6 +3,7 @@ /* Load drivers for Win32. */ #include "LoadingWindow/LoadingWindow_Win32.h" +#include "ErrorDialog/ErrorDialog_Win32.h" #include "Sound/RageSoundDriver_DSound.h" #include "Sound/RageSoundDriver_DSound_Software.h" diff --git a/stepmania/src/arch/arch_default.h b/stepmania/src/arch/arch_default.h index 6529fddb36..70ac43902f 100644 --- a/stepmania/src/arch/arch_default.h +++ b/stepmania/src/arch/arch_default.h @@ -6,6 +6,7 @@ /* Load default fallback drivers; some of these may be overridden by arch-specific drivers. */ #include "LoadingWindow/LoadingWindow_SDL.h" +#include "ErrorDialog/ErrorDialog_stdout.h" /* no default sound driver */