Refactorings preparing actual emulation start for DLL (just need to move two functions to a shared file)

This commit is contained in:
PatrickvL 2019-02-08 18:29:01 +01:00 committed by RadWolfie
parent cd62ac9cc1
commit daffa99825
2 changed files with 81 additions and 75 deletions

View File

@ -143,20 +143,19 @@ DWORD WINAPI Emulate(int system)
return EXIT_FAILURE;
}
/* Initialize Cxbx File Paths */
// CxbxInitFilePaths();
/*! initialize shared memory */
if (!EmuShared::Init(0)) {
MessageBox(NULL, "Could not map shared memory!", "Cxbx-Reloaded", MB_OK);
return EXIT_FAILURE;
}
// TODO : Call HandleFirstLaunch();
LPSTR CommandLine = GetCommandLine();
int argc;
PCHAR *argv = CommandLineToArgvA(CommandLine, &argc);
// CxbxKrnlMain(argc, argv);
// TODO : Call LaunchEmulation(argc, argv);
LocalFree(argv);

View File

@ -40,6 +40,72 @@
name = 'Microsoft.Windows.Common-Controls' version = '6.0.0.0' \
processorArchitecture = '*' publicKeyToken = '6595b64144ccf1df' language = '*'\"")
// TODO : Move HandleFirstLaunch() to a file shared with the CxbxEmulator project
bool HandleFirstLaunch()
{
bool bFirstLaunch;
g_EmuShared->GetIsFirstLaunch(&bFirstLaunch);
/* check if process is launch with elevated access then prompt for continue on or not. */
if (!bFirstLaunch) {
g_Settings = new Settings();
if (g_Settings == nullptr) {
MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK);
return false;
}
if (!g_Settings->Init()) {
return false;
}
log_get_settings();
bool bElevated = CxbxIsElevated();
if (bElevated && !g_Settings->m_core.allowAdminPrivilege) {
int ret = MessageBox(NULL, "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"
"\nAre you sure you want to continue?", "Cxbx-Reloaded", MB_YESNO | MB_ICONWARNING);
if (ret != IDYES) {
return false;
}
}
g_EmuShared->SetIsFirstLaunch(true);
}
return true;
}
// TODO : Move LaunchEmulation() to a file shared with the CxbxEmulator project
void LaunchEmulation(int argc, char* argv[])
{
// NOTE: This is designated for standalone kernel mode launch without GUI
if (g_Settings != nullptr) {
// Reset to default
g_EmuShared->Reset();
g_Settings->Verify();
g_Settings->SyncToEmulator();
// We don't need to keep Settings open plus allow emulator to use unused memory.
delete g_Settings;
g_Settings = nullptr;
// Perform identical to what GUI will do to certain EmuShared's variable before launch.
g_EmuShared->SetIsEmulating(true);
// NOTE: This setting the ready status is optional. Internal kernel process is checking if GUI is running.
// Except if enforce check, then we need to re-set ready status every time for non-GUI.
//g_EmuShared->SetIsReady(true);
}
/* Initialize Cxbx File Paths */
CxbxInitFilePaths();
CxbxKrnlMain(argc, argv);
}
/*! program entry point */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
@ -60,112 +126,53 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
return EXIT_FAILURE;
}
bool bRet, bKernel;
bool bHasLoadArgument;
HWND hWnd = nullptr;
DWORD guiProcessID = 0;
// TODO: Convert ALL __argc & __argv to use main(int argc, char** argv) method.
if (__argc >= 2 && std::strcmp(__argv[1], "/load") == 0 && std::strlen(__argv[2]) > 0) {
bKernel = true;
bHasLoadArgument = true;
// Perform check if command line contain gui's hWnd value.
if (__argc > 3) {
hWnd = (HWND)std::stoi(__argv[3], nullptr, 10);
hWnd = IsWindow(hWnd) ? hWnd : nullptr;
if (hWnd != nullptr) {
// We don't need thread ID from window handle.
GetWindowThreadProcessId(hWnd, &guiProcessID);
}
}
}
else {
bKernel = false;
} else {
bHasLoadArgument = false;
guiProcessID = GetCurrentProcessId();
}
g_exec_filepath = __argv[0]; // NOTE: Workaround solution until simulated "main" function is made.
/*! initialize shared memory */
EmuShared::Init(guiProcessID);
bool bFirstLaunch;
g_EmuShared->GetIsFirstLaunch(&bFirstLaunch);
/* check if process is launch with elevated access then prompt for continue on or not. */
if (!bFirstLaunch) {
g_Settings = new Settings();
if (g_Settings == nullptr) {
MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK);
EmuShared::Cleanup();
return EXIT_FAILURE;
}
bRet = g_Settings->Init();
if (!bRet) {
EmuShared::Cleanup();
return EXIT_FAILURE;
}
log_get_settings();
bool bElevated = CxbxIsElevated();
if (bElevated && !g_Settings->m_core.allowAdminPrivilege) {
int ret = MessageBox(NULL, "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"
"\nAre you sure you want to continue?", "Cxbx-Reloaded", MB_YESNO | MB_ICONWARNING);
if (ret != IDYES) {
EmuShared::Cleanup();
return EXIT_FAILURE;
}
}
g_EmuShared->SetIsFirstLaunch(true);
if (!HandleFirstLaunch()) {
EmuShared::Cleanup();
return EXIT_FAILURE;
}
if (bKernel) {
// NOTE: This is designated for standalone kernel mode launch without GUI
if (g_Settings != nullptr) {
// Reset to default
g_EmuShared->Reset();
g_Settings->Verify();
g_Settings->SyncToEmulator();
// We don't need to keep Settings open plus allow emulator to use unused memory.
delete g_Settings;
g_Settings = nullptr;
// Perform identical to what GUI will do to certain EmuShared's variable before launch.
g_EmuShared->SetIsEmulating(true);
// NOTE: This setting the ready status is optional. Internal kernel process is checking if GUI is running.
// Except if enforce check, then we need to re-set ready status every time for non-GUI.
//g_EmuShared->SetIsReady(true);
}
/* Initialize Cxbx File Paths */
CxbxInitFilePaths();
CxbxKrnlMain(__argc, __argv);
if (bHasLoadArgument) {
LaunchEmulation(__argc, __argv);
EmuShared::Cleanup();
return EXIT_SUCCESS;
}
// If 2nd GUI executable is launched, load settings file for GUI for editable support.
if (g_Settings == nullptr) {
g_Settings = new Settings();
if (g_Settings == nullptr) {
MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK);
EmuShared::Cleanup();
return EXIT_FAILURE;
}
bRet = g_Settings->Init();
if (!bRet) {
if (!g_Settings->Init()) {
EmuShared::Cleanup();
return EXIT_FAILURE;
}