Loader : Use CxbxMessageBox (a wrapper for Windows' MessageBox API) wherever possible, to avoid repeating the TEXT("Cxbx-Reloaded") caption everywhere, and a different argument-order allowing default argument values and thus more compact code.

This commit is contained in:
PatrickvL 2019-02-12 11:58:25 +01:00 committed by RadWolfie
parent f283dff3b6
commit affc999d70
9 changed files with 62 additions and 40 deletions

View File

@ -26,7 +26,7 @@
// ****************************************************************** // ******************************************************************
#pragma once #pragma once
#ifndef CXBXR_EMU_EXPORTS // Only trim Windows symbols CxbxLoader, not in cxbxr-emu #ifndef CXBXR_EMU_EXPORTS // Only trim Windows symbols in cxbxr-ldr.exe, not in cxbxr-emu.dll (TODO : What about cxbxr.exe and cxbx.exe?)
#include <SDKDDKVer.h> #include <SDKDDKVer.h>
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#endif // CXBXR_EMU_EXPORTS #endif // CXBXR_EMU_EXPORTS

View File

@ -31,8 +31,8 @@
bool VerifyBaseAddr() bool VerifyBaseAddr()
{ {
/*! CXBX_BASE_ADDR is defined as 0x00010000, which is the base address of /*! CXBX_BASE_ADDR is defined as 0x00010000, which is the base address of
the CxbxLoader.exe host executable. the cxbxr-ldr.exe host executable.
Set in CxbxLoader.exe Project options, Linker, Advanced, Base Address */ Set in cxbxr-ldr.exe Project options, Linker, Advanced, Base Address */
return ((UINT_PTR)GetModuleHandle(nullptr) == CXBX_BASE_ADDR); return ((UINT_PTR)GetModuleHandle(nullptr) == CXBX_BASE_ADDR);
} }

View File

@ -1188,7 +1188,7 @@ DWORD WINAPI XTL::EMUPATCH(XLaunchNewImageA)
if (PathFileExists(szDashboardPath)) if (PathFileExists(szDashboardPath))
{ {
MessageBox(CxbxKrnl_hEmuParent, "The title is rebooting to dashboard", "Cxbx-Reloaded", 0); (void)CxbxMessageBox("The title is rebooting to dashboard", MB_OK, CxbxKrnl_hEmuParent);
lpTitlePath = "C:\\xboxdash.xbe"; lpTitlePath = "C:\\xboxdash.xbe";
xboxkrnl::LaunchDataPage->Header.dwLaunchDataType = LDT_FROM_DASHBOARD; xboxkrnl::LaunchDataPage->Header.dwLaunchDataType = LDT_FROM_DASHBOARD;
// Other options include LDT_NONE, LDT_FROM_DEBUGGER_CMDLINE and LDT_FROM_UPDATE // Other options include LDT_NONE, LDT_FROM_DEBUGGER_CMDLINE and LDT_FROM_UPDATE

View File

@ -495,6 +495,18 @@ HANDLE CxbxRestorePageTablesMemory(char* szFilePath_page_tables)
#pragma optimize("", off) #pragma optimize("", off)
int CxbxMessageBox(const char* msg, UINT uType, HWND hWnd)
{
return MessageBox(hWnd, msg, /*lpCaption=*/TEXT("Cxbx-Reloaded"), uType);
}
void CxbxShowError(const char* msg, HWND hWnd)
{
const UINT uType = MB_OK | MB_TOPMOST | MB_SETFOREGROUND | MB_ICONERROR; // Note : MB_ICONERROR == MB_ICONSTOP == MB_ICONHAND
(void)CxbxMessageBox(msg, uType, hWnd);
}
void CxbxPopupMessageEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIcon icon, const char *message, ...) void CxbxPopupMessageEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIcon icon, const char *message, ...)
{ {
char Buffer[1024]; char Buffer[1024];
@ -527,7 +539,7 @@ void CxbxPopupMessageEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIc
EmuLogEx(cxbxr_module, level, "Popup : %s", Buffer); EmuLogEx(cxbxr_module, level, "Popup : %s", Buffer);
MessageBox(NULL, Buffer, TEXT("Cxbx-Reloaded"), uType); (void)CxbxMessageBox(Buffer, uType);
} }
void PrintCurrentConfigurationLog() void PrintCurrentConfigurationLog()
@ -903,7 +915,7 @@ bool CreateSettings()
{ {
g_Settings = new Settings(); g_Settings = new Settings();
if (g_Settings == nullptr) { if (g_Settings == nullptr) {
MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK | MB_ICONERROR); CxbxShowError(szSettings_alloc_error);
return false; return false;
} }
@ -928,9 +940,9 @@ bool HandleFirstLaunch()
bool bElevated = CxbxIsElevated(); bool bElevated = CxbxIsElevated();
if (bElevated && !g_Settings->m_core.allowAdminPrivilege) { if (bElevated && !g_Settings->m_core.allowAdminPrivilege) {
int ret = MessageBox(NULL, "Cxbx-Reloaded has detected that it has been launched with Administrator rights.\n" int ret = CxbxMessageBox("Cxbx-Reloaded has detected that it has been launched with Administrator rights.\n"
"\nThis is dangerous, as a maliciously modified Xbox titles could take control of your system.\n" "\nThis is dangerous, as a maliciously modified Xbox titles could take control of your system.\n"
"\nAre you sure you want to continue?", "Cxbx-Reloaded", MB_YESNO | MB_ICONWARNING); "\nAre you sure you want to continue?", MB_YESNO | MB_ICONWARNING);
if (ret != IDYES) { if (ret != IDYES) {
return false; return false;
} }
@ -1054,7 +1066,7 @@ void CxbxKrnlMain(int argc, char* argv[])
} }
if (!isReady) { if (!isReady) {
EmuLog(LOG_LEVEL::WARNING, "GUI process is not ready!"); EmuLog(LOG_LEVEL::WARNING, "GUI process is not ready!");
int mbRet = MessageBox(NULL, "GUI process is not ready, do you wish to retry?", TEXT("Cxbx-Reloaded"), int mbRet = CxbxMessageBox("GUI process is not ready, do you wish to retry?",
MB_ICONWARNING | MB_RETRYCANCEL | MB_TOPMOST | MB_SETFOREGROUND); MB_ICONWARNING | MB_RETRYCANCEL | MB_TOPMOST | MB_SETFOREGROUND);
if (mbRet == IDRETRY) { if (mbRet == IDRETRY) {
continue; continue;

View File

@ -205,6 +205,10 @@ typedef enum _CxbxMsgDlgIcon {
CxbxMsgDlgIcon_Error, CxbxMsgDlgIcon_Error,
CxbxMsgDlgIcon_Unknown CxbxMsgDlgIcon_Unknown
} CxbxMsgDlgIcon; } CxbxMsgDlgIcon;
int CxbxMessageBox(const char* msg, UINT uType = MB_OK, HWND hWnd = NULL);
void CxbxShowError(const char* msg, HWND hWnd = NULL);
void CxbxPopupMessageEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIcon icon, const char *message, ...); void CxbxPopupMessageEx(CXBXR_MODULE cxbxr_module, LOG_LEVEL level, CxbxMsgDlgIcon icon, const char *message, ...);
@ -223,7 +227,7 @@ extern Xbe::Certificate *g_pCertificate;
bool CxbxKrnlVerifyVersion(const char *szVersion); bool CxbxKrnlVerifyVersion(const char *szVersion);
extern bool g_bIsDebugKernel; extern bool g_bIsDebugKernel;
bool CheckLoadArgument(int argc, char* argv[], DWORD *pguiProcessID); bool CheckLoadArgument(int argc, char* argv[], DWORD *pguiProcessID);
bool CreateSettings(); bool CreateSettings();

View File

@ -170,7 +170,7 @@ bool EmuExceptionBreakpointAsk(LPEXCEPTION_POINTERS e)
" Press Ignore to continue emulation.", " Press Ignore to continue emulation.",
EIPToString(e->ContextRecord->Eip).c_str()); EIPToString(e->ContextRecord->Eip).c_str());
int ret = MessageBox(g_hEmuWindow, buffer, "Cxbx-Reloaded", MB_ICONSTOP | MB_ABORTRETRYIGNORE); int ret = CxbxMessageBox(buffer, MB_ICONSTOP | MB_ABORTRETRYIGNORE, g_hEmuWindow);
if (ret == IDABORT) if (ret == IDABORT)
{ {
EmuExceptionExitProcess(); EmuExceptionExitProcess();
@ -201,7 +201,7 @@ void EmuExceptionNonBreakpointUnhandledShow(LPEXCEPTION_POINTERS e)
" Press \"Cancel\" to debug.", " Press \"Cancel\" to debug.",
e->ExceptionRecord->ExceptionCode, EIPToString(e->ContextRecord->Eip).c_str()); e->ExceptionRecord->ExceptionCode, EIPToString(e->ContextRecord->Eip).c_str());
if (MessageBox(g_hEmuWindow, buffer, "Cxbx-Reloaded", MB_ICONSTOP | MB_OKCANCEL) == IDOK) if (CxbxMessageBox(buffer, MB_ICONSTOP | MB_OKCANCEL, g_hEmuWindow) == IDOK)
{ {
EmuExceptionExitProcess(); EmuExceptionExitProcess();
} }
@ -366,13 +366,13 @@ int ExitException(LPEXCEPTION_POINTERS e)
fflush(stdout); fflush(stdout);
MessageBox(g_hEmuWindow, "Warning: Could not safely terminate process!", "Cxbx-Reloaded", MB_OK); (void)CxbxMessageBox("Warning: Could not safely terminate process!", MB_OK, g_hEmuWindow);
count++; count++;
if(count > 1) if(count > 1)
{ {
MessageBox(g_hEmuWindow, "Warning: Multiple Problems!", "Cxbx-Reloaded", MB_OK); (void)CxbxMessageBox("Warning: Multiple Problems!", MB_OK, g_hEmuWindow);
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
} }

View File

@ -124,43 +124,54 @@ DWORD WINAPI Emulate(int system)
{ {
FUNC_EXPORTS FUNC_EXPORTS
/*! Verify our host executable, CxbxLoader.exe, is loaded to base address 0x00010000 */ /*! Verify our host executable, cxbxr-ldr.exe, is loaded to base address 0x00010000 */
if (!VerifyBaseAddr()) { if (!VerifyBaseAddr()) {
MessageBox(NULL, "CxbxLoader.exe was not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)", "Cxbx-Reloaded", CxbxShowError("cxbx-ldr.exe was not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)");
MB_OK | MB_ICONERROR);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// Before doing anything else that might cause memory fragmentation, // Before doing anything else that might cause memory fragmentation,
// verify that we still got control over all ranges the loader reserved // verify that we still got control over all ranges the loader reserved
if (!VerifyAddressRanges(system)) { if (!VerifyAddressRanges(system)) {
MessageBox(NULL, "Failed to claim required address ranges (which is a requirement for Xbox emulation)", "Cxbx-Reloaded", CxbxShowError("Failed to claim required address ranges (which is a requirement for Xbox emulation)");
MB_OK | MB_ICONERROR);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
LPSTR CommandLine = GetCommandLine(); LPSTR CommandLine = GetCommandLine();
int argc; if (!CommandLine) {
CxbxShowError("Couldn't retrieve command line!");
return EXIT_FAILURE;
}
int argc = 0;
PCHAR *argv = CommandLineToArgvA(CommandLine, &argc); PCHAR *argv = CommandLineToArgvA(CommandLine, &argc);
if (!argv) {
CxbxShowError("Couldn't parse command line!");
return EXIT_FAILURE;
}
DWORD guiProcessID = 0; DWORD guiProcessID = 0;
bool bHasLoadArgument = CheckLoadArgument(argc, argv, &guiProcessID); bool bHasLoadArgument = CheckLoadArgument(argc, argv, &guiProcessID);
if (!bHasLoadArgument) {
CxbxShowError("No /load argument on command line!");
return EXIT_FAILURE;
}
/*! initialize shared memory */ /*! initialize shared memory */
if (!EmuShared::Init(guiProcessID)) { if (!EmuShared::Init(guiProcessID)) {
MessageBox(NULL, "Could not map shared memory!", "Cxbx-Reloaded", MB_OK | MB_ICONERROR); CxbxShowError("Could not map shared memory!");
LocalFree(argv); LocalFree(argv);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
HandleFirstLaunch(); if (!HandleFirstLaunch()) {
CxbxShowError("First launch failed!");
if (bHasLoadArgument) { EmuShared::Cleanup();
CxbxKrnlMain(argc, argv); return EXIT_FAILURE;
} else {
// TODO : Enter "2nd GUI" mode here, as done in Cxbx's WinMain() - but how?
} }
CxbxKrnlMain(argc, argv);
LocalFree(argv); LocalFree(argv);
/*! cleanup shared memory */ /*! cleanup shared memory */
@ -175,4 +186,3 @@ DWORD WINAPI Emulate(int system)
// This line will never be reached: // This line will never be reached:
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -48,15 +48,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// First detect if we are running on WoW64, if not, prevent Cxbx-Reloaded from starting // First detect if we are running on WoW64, if not, prevent Cxbx-Reloaded from starting
// Cxbx-Relaoded needs access to high memory, only exposed to WoW64. // Cxbx-Relaoded needs access to high memory, only exposed to WoW64.
if (!VerifyWow64()) { if (!VerifyWow64()) {
MessageBox(NULL, "Cxbx-Reloaded can only run under WoW64\nThis means either a 64-bit version of Windows or Wine with a 64-bit prefix", "Cxbx-Reloaded", CxbxShowError("Cxbx-Reloaded can only run under WoW64\nThis means either a 64-bit version of Windows or Wine with a 64-bit prefix");
MB_OK | MB_ICONERROR);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
/*! verify Cxbx.exe is loaded to base address 0x00010000 */ /*! verify Cxbx.exe is loaded to base address 0x00010000 */
if (!VerifyBaseAddr()) { if (!VerifyBaseAddr()) {
MessageBox(NULL, "Cxbx.exe is not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)", "Cxbx-Reloaded", CxbxShowError("Cxbx.exe is not loaded to base address 0x00010000 (which is a requirement for Xbox emulation)");
MB_OK | MB_ICONERROR);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -65,7 +63,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
bool bHasLoadArgument = CheckLoadArgument(__argc, __argv, &guiProcessID); bool bHasLoadArgument = CheckLoadArgument(__argc, __argv, &guiProcessID);
/*! initialize shared memory */ /*! initialize shared memory */
EmuShared::Init(guiProcessID); if (!EmuShared::Init(guiProcessID)) {
CxbxShowError("Could not map shared memory!");
return EXIT_FAILURE;
}
if (!HandleFirstLaunch()) { if (!HandleFirstLaunch()) {
EmuShared::Cleanup(); EmuShared::Cleanup();
@ -121,9 +122,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
} }
/*! if an error occurred, notify user */ /*! if an error occurred, notify user */
if(MainWindow->HasError()) if(MainWindow->HasError()) {
{ CxbxShowError(MainWindow->GetError().c_str());
MessageBox(NULL, MainWindow->GetError().c_str(), "Cxbx-Reloaded", MB_ICONSTOP | MB_OK);
} }
delete MainWindow; delete MainWindow;

View File

@ -81,10 +81,6 @@ unsigned char virtual_memory_placeholder[VM_PLACEHOLDER_SIZE] = { 0 }; // = { OP
void OutputMessage(const char *msg) void OutputMessage(const char *msg)
{ {
if (!msg) {
return;
}
OutputDebugStringA(msg); // Send message to debugger output too OutputDebugStringA(msg); // Send message to debugger output too
HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);