mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-01-11 10:31:16 +00:00
Create config with sane defaults if not already present (#71)
* Create config with sane defaults if not present * isleapp: Use binary mode for iniFP Windows treats newlines differently then on *nix systems. Using binary mode makes this consistent. Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com> * isleapp: Remove extern "C" It seems like it's fine including these libraries without extern "C" * isleapp: Use boolean return in LoadConfig This to check if the config loaded correctly or not. Seems to be a good solution to the file loading issue. Maybe there's a better solution SetupWindow failing because of a config erroring seems a bit odd. * isleapp: Remove that dumb use after free. I forgot you don't specify a filename you specify a *file pointer* * isleapp: Fix iniFP to be in proper scope This also fixes the missing parameter in `iniparser_dump_ini` * .gitignore: Exclude the kate .cache folder * isleapp: Match prototype of LoadConfig in header * isleapp: Fix formating to comply with .clang-format * isleapp: Don't create new config if manually set --------- Co-authored-by: Anonymous Maarten <madebr@users.noreply.github.com>
This commit is contained in:
parent
dc8b044b50
commit
c48935a64b
3
.gitignore
vendored
3
.gitignore
vendored
@ -27,3 +27,6 @@ ISLE.EXE
|
||||
LEGO1.DLL
|
||||
|
||||
.DS_Store
|
||||
|
||||
# Kate - Text
|
||||
/.cache
|
||||
|
||||
@ -32,7 +32,9 @@
|
||||
#define SDL_MAIN_USE_CALLBACKS
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <errno.h>
|
||||
#include <iniparser.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
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
|
||||
|
||||
@ -36,7 +36,7 @@ class IsleApp {
|
||||
);
|
||||
MxResult SetupWindow();
|
||||
|
||||
void LoadConfig();
|
||||
bool LoadConfig();
|
||||
void Tick();
|
||||
void SetupCursor(Cursor p_cursor);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user