From e6bd008e30bd399ad433b36f3abb69a3fc2140b8 Mon Sep 17 00:00:00 2001 From: Travis Howell Date: Fri, 22 Apr 2005 07:12:29 +0000 Subject: Add support for reading/writing to external config file in HE games. svn-id: r17746 --- scumm/script_v80he.cpp | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'scumm/script_v80he.cpp') diff --git a/scumm/script_v80he.cpp b/scumm/script_v80he.cpp index 482315f47b..e1365581e0 100644 --- a/scumm/script_v80he.cpp +++ b/scumm/script_v80he.cpp @@ -449,35 +449,47 @@ void ScummEngine_v80he::o80_localizeArrayToRoom() { } void ScummEngine_v80he::o80_readConfigFile() { - byte name[128], section[128], filename[256]; - int type; + byte option[128], section[128], filename[256]; + ArrayHeader *ah; + const char *entry; + int len, type; // we pretend that we don't have .ini file + copyScriptString(option, sizeof(option)); copyScriptString(section, sizeof(section)); - copyScriptString(name, sizeof(name)); copyScriptString(filename, sizeof(filename)); + convertFilePath(filename); type = fetchScriptByte(); + ConfMan.loadConfigFile((const char *)filename); + switch (type) { case 43: // HE 100 case 6: // number - push(0); + push(ConfMan.getInt((char *)option, (char *)section)); break; case 77: // HE 100 case 7: // string + entry = (ConfMan.get((char *)option, (char *)section).c_str()); + writeVar(0, 0); - defineArray(0, kStringArray, 0, 0, 0, 0); - writeArray(0, 0, 0, 0); - push(readVar(0)); // var ID string + len = resStrLen((const byte *)entry); + ah = defineArray(0, kStringArray, 0, 0, 0, len); + memcpy(ah->data, entry, len); + + push(readVar(0)); break; default: error("o80_readConfigFile: default type %d", type); } - debug(0, "o80_readConfigFile: Filename %s Section %s Name %s", filename, section, name); + + ConfMan.loadDefaultConfigFile(); + + debug(0, "o80_readConfigFile: Filename %s Section %s Option %s", filename, section, option); } void ScummEngine_v80he::o80_writeConfigFile() { - byte filename[256], section[256], name[256], string[1024]; + byte filename[256], section[256], option[256], string[1024]; int type, value; // we pretend that we don't have .ini file @@ -487,22 +499,33 @@ void ScummEngine_v80he::o80_writeConfigFile() { case 43: // HE 100 case 6: // number value = pop(); + copyScriptString(option, sizeof(option)); copyScriptString(section, sizeof(section)); - copyScriptString(name, sizeof(name)); copyScriptString(filename, sizeof(filename)); - debug(1,"o80_writeConfigFile: Filename %s Section %s Name %s Value %d", filename, section, name, value); + convertFilePath(filename); + + ConfMan.loadConfigFile((const char *)filename); + ConfMan.set((char *)option, value, (char *)section); + debug(0,"o80_writeConfigFile: Filename %s Section %s Option %s Value %d", filename, section, option, value); break; case 77: // HE 100 case 7: // string copyScriptString(string, sizeof(string)); + copyScriptString(option, sizeof(option)); copyScriptString(section, sizeof(section)); - copyScriptString(name, sizeof(name)); copyScriptString(filename, sizeof(filename)); - debug(1,"o80_writeConfigFile: Filename %s Section %s Name %s String %s", filename, section, name, string); + convertFilePath(filename); + + ConfMan.loadConfigFile((const char *)filename); + ConfMan.set((char *)option, (char *)string, (char *)section); + debug(0,"o80_writeConfigFile: Filename %s Section %s Option %s String %s", filename, section, option, string); break; default: error("o80_writeConfigFile: default type %d", type); } + + ConfMan.flushToDisk(); + ConfMan.loadDefaultConfigFile(); } void ScummEngine_v80he::o80_cursorCommand() { -- cgit v1.2.3