Loader : Deduplicate code via new CreateSettings()

This commit is contained in:
patrickvl 2019-02-10 16:57:59 +01:00 committed by RadWolfie
parent 890a5ffd2f
commit 170b971a8e
3 changed files with 20 additions and 19 deletions

View File

@ -872,6 +872,22 @@ void ImportLibraries(XbeImportEntry *pImportDirectory)
} }
} }
bool CreateSettings()
{
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();
return true;
}
bool HandleFirstLaunch() bool HandleFirstLaunch()
{ {
bool bFirstLaunch; bool bFirstLaunch;
@ -879,18 +895,10 @@ bool HandleFirstLaunch()
/* check if process is launch with elevated access then prompt for continue on or not. */ /* check if process is launch with elevated access then prompt for continue on or not. */
if (!bFirstLaunch) { if (!bFirstLaunch) {
g_Settings = new Settings(); if (!CreateSettings()) {
if (g_Settings == nullptr) {
MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK);
return false; return false;
} }
if (!g_Settings->Init()) {
return false;
}
log_get_settings();
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 = MessageBox(NULL, "Cxbx-Reloaded has detected that it has been launched with Administrator rights.\n"

View File

@ -224,6 +224,8 @@ bool CxbxKrnlVerifyVersion(const char *szVersion);
extern bool g_bIsDebugKernel; extern bool g_bIsDebugKernel;
bool CreateSettings();
bool HandleFirstLaunch(); bool HandleFirstLaunch();
/*! Cxbx Kernel Entry Point */ /*! Cxbx Kernel Entry Point */

View File

@ -99,19 +99,10 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
// If 2nd GUI executable is launched, load settings file for GUI for editable support. // If 2nd GUI executable is launched, load settings file for GUI for editable support.
if (g_Settings == nullptr) { if (g_Settings == nullptr) {
g_Settings = new Settings(); if (!CreateSettings()) {
if (g_Settings == nullptr) {
MessageBox(nullptr, szSettings_alloc_error, "Cxbx-Reloaded", MB_OK);
EmuShared::Cleanup(); EmuShared::Cleanup();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!g_Settings->Init()) {
EmuShared::Cleanup();
return EXIT_FAILURE;
}
log_get_settings();
} }
// Possible optional output for GUI // Possible optional output for GUI