mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
isle: parse cli argument (--ini for custom ini path)
This commit is contained in:
parent
049f00df85
commit
fdb9c4e552
@ -113,6 +113,8 @@ IsleApp::IsleApp()
|
|||||||
m_cursorCurrent = NULL;
|
m_cursorCurrent = NULL;
|
||||||
|
|
||||||
LegoOmni::CreateInstance();
|
LegoOmni::CreateInstance();
|
||||||
|
|
||||||
|
m_iniPath = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION: ISLE 0x4011a0
|
// FUNCTION: ISLE 0x4011a0
|
||||||
@ -251,6 +253,16 @@ int SDL_AppInit(void** appstate, int argc, char** argv)
|
|||||||
// Create global app instance
|
// Create global app instance
|
||||||
g_isle = new IsleApp();
|
g_isle = new IsleApp();
|
||||||
|
|
||||||
|
if (g_isle->ParseArguments(argc, argv) != SUCCESS) {
|
||||||
|
SDL_ShowSimpleMessageBox(
|
||||||
|
SDL_MESSAGEBOX_ERROR,
|
||||||
|
"LEGO® Island Error",
|
||||||
|
"\"LEGO® Island\" failed to start. Invalid CLI arguments.",
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
return SDL_APP_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
// Create window
|
// Create window
|
||||||
if (g_isle->SetupWindow() != SUCCESS) {
|
if (g_isle->SetupWindow() != SUCCESS) {
|
||||||
SDL_ShowSimpleMessageBox(
|
SDL_ShowSimpleMessageBox(
|
||||||
@ -499,9 +511,18 @@ void IsleApp::LoadConfig()
|
|||||||
{
|
{
|
||||||
char* basePath = SDL_GetBasePath();
|
char* basePath = SDL_GetBasePath();
|
||||||
char* prefPath = SDL_GetPrefPath("isledecomp", "isle");
|
char* prefPath = SDL_GetPrefPath("isledecomp", "isle");
|
||||||
char* iniConfig = new char[strlen(prefPath) + strlen("isle.ini") + 1]();
|
char* iniConfig;
|
||||||
|
if (m_iniPath) {
|
||||||
|
iniConfig = new char[strlen(m_iniPath) + 1];
|
||||||
|
strcpy(iniConfig, m_iniPath);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
iniConfig = new char[strlen(prefPath) + strlen("isle.ini") + 1]();
|
||||||
strcat(iniConfig, prefPath);
|
strcat(iniConfig, prefPath);
|
||||||
strcat(iniConfig, "isle.ini");
|
strcat(iniConfig, "isle.ini");
|
||||||
|
}
|
||||||
|
SDL_Log("Reading configuration from \"%s\"", iniConfig);
|
||||||
|
|
||||||
dictionary* dict = iniparser_load(iniConfig);
|
dictionary* dict = iniparser_load(iniConfig);
|
||||||
|
|
||||||
const char* hdPath = iniparser_getstring(dict, "isle:diskpath", basePath);
|
const char* hdPath = iniparser_getstring(dict, "isle:diskpath", basePath);
|
||||||
@ -674,3 +695,21 @@ void IsleApp::SetupCursor(Cursor p_cursor)
|
|||||||
SDL_HideCursor();
|
SDL_HideCursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MxResult IsleApp::ParseArguments(int argc, char** argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
for (int i = 1, consumed; i < argc; i += consumed) {
|
||||||
|
consumed = -1;
|
||||||
|
|
||||||
|
if (strcmp(argv[i], "--ini") == 0 && i + 1 < argc) {
|
||||||
|
m_iniPath = argv[i + 1];
|
||||||
|
consumed = 2;
|
||||||
|
}
|
||||||
|
if (consumed <= 0) {
|
||||||
|
SDL_Log("Invalid argument(s): %s", argv[i]);
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SUCCESS;
|
||||||
|
}
|
||||||
|
|||||||
@ -47,6 +47,8 @@ class IsleApp {
|
|||||||
|
|
||||||
inline void SetWindowActive(MxS32 p_windowActive) { m_windowActive = p_windowActive; }
|
inline void SetWindowActive(MxS32 p_windowActive) { m_windowActive = p_windowActive; }
|
||||||
|
|
||||||
|
MxResult ParseArguments(int argc, char** argv);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char* m_hdPath; // 0x00
|
char* m_hdPath; // 0x00
|
||||||
char* m_cdPath; // 0x04
|
char* m_cdPath; // 0x04
|
||||||
@ -75,6 +77,8 @@ class IsleApp {
|
|||||||
SDL_Cursor* m_cursorBusy; // 0x80
|
SDL_Cursor* m_cursorBusy; // 0x80
|
||||||
SDL_Cursor* m_cursorNo; // 0x84
|
SDL_Cursor* m_cursorNo; // 0x84
|
||||||
SDL_Cursor* m_cursorCurrent; // 0x88
|
SDL_Cursor* m_cursorCurrent; // 0x88
|
||||||
|
|
||||||
|
char* m_iniPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ISLEAPP_H
|
#endif // ISLEAPP_H
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user