From 0bb63fe6f5a59fd18ad590c2a1df1f478cb93ea2 Mon Sep 17 00:00:00 2001 From: Corey Hickey Date: Wed, 29 Aug 2018 21:58:27 -0700 Subject: [PATCH] save configuration (if desired) right before running game Currently, plugins frequently call ConfigSaveSection(), which results in the configuration being rewritten. I intend to submit patches to remove these calls. In exchange, the front-end should save the configuration at the latest safe opportunity, to capture any changes before most chances of crashes, power outages, kill -9, etc. --- src/core_interface.c | 3 +++ src/core_interface.h | 1 + src/main.c | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/src/core_interface.c b/src/core_interface.c index d8c830c..6aa7d03 100644 --- a/src/core_interface.c +++ b/src/core_interface.c @@ -80,6 +80,7 @@ ptr_ConfigGetParamString ConfigGetParamString = NULL; ptr_ConfigExternalOpen ConfigExternalOpen = NULL; ptr_ConfigExternalClose ConfigExternalClose = NULL; ptr_ConfigExternalGetParameter ConfigExternalGetParameter = NULL; +ptr_ConfigHasUnsavedChanges ConfigHasUnsavedChanges = NULL; ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath = NULL; ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath = NULL; @@ -268,6 +269,7 @@ m64p_error AttachCoreLib(const char *CoreLibFilepath) ConfigExternalOpen = (ptr_ConfigExternalOpen) osal_dynlib_getproc(CoreHandle, "ConfigExternalOpen"); ConfigExternalClose = (ptr_ConfigExternalClose) osal_dynlib_getproc(CoreHandle, "ConfigExternalClose"); ConfigExternalGetParameter = (ptr_ConfigExternalGetParameter) osal_dynlib_getproc(CoreHandle, "ConfigExternalGetParameter"); + ConfigHasUnsavedChanges = (ptr_ConfigHasUnsavedChanges) osal_dynlib_getproc(CoreHandle, "ConfigHasUnsavedChanges"); ConfigGetSharedDataFilepath = (ptr_ConfigGetSharedDataFilepath) osal_dynlib_getproc(CoreHandle, "ConfigGetSharedDataFilepath"); ConfigGetUserConfigPath = (ptr_ConfigGetUserConfigPath) osal_dynlib_getproc(CoreHandle, "ConfigGetUserConfigPath"); @@ -337,6 +339,7 @@ m64p_error DetachCoreLib(void) ConfigExternalOpen = NULL; ConfigExternalClose = NULL; ConfigExternalGetParameter = NULL; + ConfigHasUnsavedChanges = NULL; ConfigGetSharedDataFilepath = NULL; ConfigGetUserDataPath = NULL; diff --git a/src/core_interface.h b/src/core_interface.h index d9d46dd..033d07f 100644 --- a/src/core_interface.h +++ b/src/core_interface.h @@ -73,6 +73,7 @@ extern ptr_ConfigGetParamString ConfigGetParamString; extern ptr_ConfigExternalOpen ConfigExternalOpen; extern ptr_ConfigExternalClose ConfigExternalClose; extern ptr_ConfigExternalGetParameter ConfigExternalGetParameter; +extern ptr_ConfigHasUnsavedChanges ConfigHasUnsavedChanges; extern ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath; extern ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath; diff --git a/src/main.c b/src/main.c index d9b14f1..2b6a0c8 100644 --- a/src/main.c +++ b/src/main.c @@ -1065,6 +1065,12 @@ int main(int argc, char *argv[]) #endif } + /* Save the configuration file again, if necessary, to capture updated + parameters from plugins. This is the last opportunity to save changes + before the relatively long-running game. */ + if (l_SaveOptions && (*ConfigHasUnsavedChanges)(NULL)) + (*ConfigSaveFile)(); + /* run the game */ (*CoreDoCommand)(M64CMD_EXECUTE, 0, NULL);