diff --git a/.gitignore b/.gitignore index e66fe925..662466db 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ ISLE.EXE LEGO1.DLL .DS_Store + +# Kate - Text +/.cache diff --git a/ISLE/isleapp.cpp b/ISLE/isleapp.cpp index f96be68a..8350cab6 100644 --- a/ISLE/isleapp.cpp +++ b/ISLE/isleapp.cpp @@ -32,7 +32,9 @@ #define SDL_MAIN_USE_CALLBACKS #include #include +#include #include +#include #include DECOMP_SIZE_ASSERT(IsleApp, 0x8c) @@ -444,7 +446,10 @@ MxU8 IsleApp::MapMouseButtonFlagsToModifier(SDL_MouseButtonFlags p_flags) // FUNCTION: ISLE 0x4023e0 MxResult IsleApp::SetupWindow() { - LoadConfig(); + if (!LoadConfig()) { + return FAILURE; + } + SetupVideoFlags( m_fullScreen, m_flipSurfaces, @@ -519,7 +524,7 @@ MxResult IsleApp::SetupWindow() } // FUNCTION: ISLE 0x4028d0 -void IsleApp::LoadConfig() +bool IsleApp::LoadConfig() { char* prefPath = SDL_GetPrefPath("isledecomp", "isle"); char* iniConfig; @@ -540,6 +545,56 @@ void IsleApp::LoadConfig() dictionary* dict = iniparser_load(iniConfig); + // [library:config] + // Load sane defaults if dictionary failed to load + if (!dict) { + if (m_iniPath) { + SDL_Log("Invalid config path '%s'", m_iniPath); + return false; + } + + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Loading sane defaults"); + FILE* iniFP = fopen(iniConfig, "wb"); + + if (!iniFP) { + SDL_LogError( + SDL_LOG_CATEGORY_APPLICATION, + "Failed to write config at '%s': %s", + iniConfig, + strerror(errno) + ); + return false; + } + + dict = iniparser_load(iniConfig); + iniparser_set(dict, "isle", NULL); + + iniparser_set(dict, "isle:diskpath", SDL_GetBasePath()); + iniparser_set(dict, "isle:cdpath", MxOmni::GetCD()); + iniparser_set(dict, "isle:mediapath", SDL_GetBasePath()); + iniparser_set(dict, "isle:savepath", prefPath); + + iniparser_set(dict, "isle:Flip Surfaces", m_flipSurfaces ? "true" : "false"); + iniparser_set(dict, "isle:Full Screen", m_fullScreen ? "true" : "false"); + iniparser_set(dict, "isle:Wide View Angle", m_wideViewAngle ? "true" : "false"); + + iniparser_set(dict, "isle:3DSound", m_use3dSound ? "true" : "false"); + iniparser_set(dict, "isle:Music", m_useMusic ? "true" : "false"); + + iniparser_set(dict, "isle:UseJoystick", m_useJoystick ? "true" : "false"); + iniparser_set(dict, "isle:JoystickIndex", m_joystickIndex ? "true" : "false"); + iniparser_set(dict, "isle:Draw Cursor", m_drawCursor ? "true" : "false"); + + iniparser_set(dict, "isle:Back Buffers in Video RAM", "-1"); + + iniparser_set(dict, "isle:Island Quality", "1"); + iniparser_set(dict, "isle:Island Texture", "1"); + + iniparser_dump_ini(dict, iniFP); + SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "New config written at '%s'", iniConfig); + fclose(iniFP); + } + const char* hdPath = iniparser_getstring(dict, "isle:diskpath", SDL_GetBasePath()); m_hdPath = new char[strlen(hdPath) + 1]; strcpy(m_hdPath, hdPath); @@ -597,6 +652,8 @@ void IsleApp::LoadConfig() iniparser_freedict(dict); delete[] iniConfig; SDL_free(prefPath); + + return true; } // FUNCTION: ISLE 0x402c20 diff --git a/ISLE/isleapp.h b/ISLE/isleapp.h index 42a0df3a..68110e58 100644 --- a/ISLE/isleapp.h +++ b/ISLE/isleapp.h @@ -36,7 +36,7 @@ class IsleApp { ); MxResult SetupWindow(); - void LoadConfig(); + bool LoadConfig(); void Tick(); void SetupCursor(Cursor p_cursor);