Add support for reading/writing config files through saveGameManager and use for config files in HE games
svn-id: r22273
This commit is contained in:
parent
84b2a4f76f
commit
01c92cf6f5
5 changed files with 45 additions and 24 deletions
|
@ -24,6 +24,8 @@
|
||||||
|
|
||||||
#include "common/config-file.h"
|
#include "common/config-file.h"
|
||||||
#include "common/file.h"
|
#include "common/file.h"
|
||||||
|
#include "common/savefile.h"
|
||||||
|
#include "common/system.h"
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
|
|
||||||
#define MAXLINELEN 256
|
#define MAXLINELEN 256
|
||||||
|
@ -74,6 +76,18 @@ bool ConfigFile::loadFromFile(const String &filename) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ConfigFile::loadFromSaveFile(const char *filename) {
|
||||||
|
SaveFileManager *saveFileMan = g_system->getSavefileManager();
|
||||||
|
SeekableReadStream *loadFile;
|
||||||
|
|
||||||
|
if (!(loadFile = saveFileMan->openForLoading(filename)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool status = loadFromStream(*loadFile);
|
||||||
|
delete loadFile;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
|
bool ConfigFile::loadFromStream(SeekableReadStream &stream) {
|
||||||
char buf[MAXLINELEN];
|
char buf[MAXLINELEN];
|
||||||
Section section;
|
Section section;
|
||||||
|
@ -176,6 +190,18 @@ bool ConfigFile::saveToFile(const String &filename) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ConfigFile::saveToSaveFile(const char *filename) {
|
||||||
|
SaveFileManager *saveFileMan = g_system->getSavefileManager();
|
||||||
|
WriteStream *saveFile;
|
||||||
|
|
||||||
|
if (!(saveFile = saveFileMan->openForSaving(filename)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
bool status = saveToStream(*saveFile);
|
||||||
|
delete saveFile;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
bool ConfigFile::saveToStream(WriteStream &stream) {
|
bool ConfigFile::saveToStream(WriteStream &stream) {
|
||||||
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
|
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
|
||||||
// Write out the section comment, if any
|
// Write out the section comment, if any
|
||||||
|
@ -203,6 +229,7 @@ bool ConfigFile::saveToStream(WriteStream &stream) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stream.flush();
|
||||||
return !stream.ioFailed();
|
return !stream.ioFailed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,10 @@ public:
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
bool loadFromFile(const String &filename);
|
bool loadFromFile(const String &filename);
|
||||||
|
bool loadFromSaveFile(const char *filename);
|
||||||
bool loadFromStream(SeekableReadStream &stream);
|
bool loadFromStream(SeekableReadStream &stream);
|
||||||
bool saveToFile(const String &filename);
|
bool saveToFile(const String &filename);
|
||||||
|
bool saveToSaveFile(const char *filename);
|
||||||
bool saveToStream(WriteStream &stream);
|
bool saveToStream(WriteStream &stream);
|
||||||
|
|
||||||
bool hasSection(const String §ion) const;
|
bool hasSection(const String §ion) const;
|
||||||
|
|
|
@ -83,7 +83,7 @@ protected:
|
||||||
int virtScreenSave(byte *dst, int x1, int y1, int x2, int y2);
|
int virtScreenSave(byte *dst, int x1, int y1, int x2, int y2);
|
||||||
void virtScreenLoad(int resIdx, int x1, int y1, int x2, int y2);
|
void virtScreenLoad(int resIdx, int x1, int y1, int x2, int y2);
|
||||||
|
|
||||||
int convertFilePath(byte *dst, bool setFilePath = false);
|
int convertFilePath(byte *dst);
|
||||||
virtual void decodeParseString(int a, int b);
|
virtual void decodeParseString(int a, int b);
|
||||||
void swapObjects(int object1, int object2);
|
void swapObjects(int object1, int object2);
|
||||||
|
|
||||||
|
|
|
@ -399,10 +399,10 @@ const char *ScummEngine_v60he::getOpcodeDesc(byte i) {
|
||||||
return _opcodesv60he[i].desc;
|
return _opcodesv60he[i].desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScummEngine_v60he::convertFilePath(byte *dst, bool setFilePath) {
|
int ScummEngine_v60he::convertFilePath(byte *dst) {
|
||||||
debug(1, "convertFilePath: original filePath is %s", dst);
|
debug(1, "convertFilePath: original filePath is %s", dst);
|
||||||
|
|
||||||
int len = resStrLen(dst) + 1;
|
int len = resStrLen(dst);
|
||||||
if (dst[0] == ':') {
|
if (dst[0] == ':') {
|
||||||
// Switch all : to / for portablity
|
// Switch all : to / for portablity
|
||||||
int j = 0;
|
int j = 0;
|
||||||
|
@ -431,19 +431,7 @@ int ScummEngine_v60he::convertFilePath(byte *dst, bool setFilePath) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setFilePath) {
|
debug(1, "convertFilePath: converted filePath is %s", dst + r);
|
||||||
char filePath[256];
|
|
||||||
strncpy(filePath, (char *)dst + r, sizeof(filePath));
|
|
||||||
if (!Common::File::exists(filePath)) {
|
|
||||||
// FIXME: Using getSavePath() to generate filepaths used with
|
|
||||||
// File::open is not portable!
|
|
||||||
strncpy(filePath, _saveFileMan->getSavePath(), sizeof(filePath));
|
|
||||||
strncat(filePath, (char *)dst + r, sizeof(filePath));
|
|
||||||
}
|
|
||||||
strcpy((char *)dst, filePath);
|
|
||||||
debug(1, "convertFilePath: filePath is %s", dst);
|
|
||||||
}
|
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -449,15 +449,18 @@ void ScummEngine_v80he::o80_readConfigFile() {
|
||||||
byte option[128], section[128], filename[256];
|
byte option[128], section[128], filename[256];
|
||||||
ArrayHeader *ah;
|
ArrayHeader *ah;
|
||||||
Common::String entry;
|
Common::String entry;
|
||||||
int len;
|
int len, r;
|
||||||
|
|
||||||
copyScriptString(option, sizeof(option));
|
copyScriptString(option, sizeof(option));
|
||||||
copyScriptString(section, sizeof(section));
|
copyScriptString(section, sizeof(section));
|
||||||
copyScriptString(filename, sizeof(filename));
|
copyScriptString(filename, sizeof(filename));
|
||||||
convertFilePath(filename, true);
|
r = convertFilePath(filename);
|
||||||
|
|
||||||
Common::ConfigFile ConfFile;
|
Common::ConfigFile ConfFile;
|
||||||
ConfFile.loadFromFile((const char *)filename);
|
if (!strcmp((char *)filename + r, "map.ini"))
|
||||||
|
ConfFile.loadFromFile((const char *)filename + r);
|
||||||
|
else
|
||||||
|
ConfFile.loadFromSaveFile((const char *)filename + r);
|
||||||
|
|
||||||
byte subOp = fetchScriptByte();
|
byte subOp = fetchScriptByte();
|
||||||
|
|
||||||
|
@ -487,7 +490,7 @@ void ScummEngine_v80he::o80_readConfigFile() {
|
||||||
|
|
||||||
void ScummEngine_v80he::o80_writeConfigFile() {
|
void ScummEngine_v80he::o80_writeConfigFile() {
|
||||||
byte filename[256], section[256], option[256], string[1024];
|
byte filename[256], section[256], option[256], string[1024];
|
||||||
int value;
|
int r, value;
|
||||||
|
|
||||||
byte subOp = fetchScriptByte();
|
byte subOp = fetchScriptByte();
|
||||||
|
|
||||||
|
@ -499,7 +502,6 @@ void ScummEngine_v80he::o80_writeConfigFile() {
|
||||||
copyScriptString(option, sizeof(option));
|
copyScriptString(option, sizeof(option));
|
||||||
copyScriptString(section, sizeof(section));
|
copyScriptString(section, sizeof(section));
|
||||||
copyScriptString(filename, sizeof(filename));
|
copyScriptString(filename, sizeof(filename));
|
||||||
convertFilePath(filename, true);
|
|
||||||
break;
|
break;
|
||||||
case 77: // HE 100
|
case 77: // HE 100
|
||||||
case 7: // string
|
case 7: // string
|
||||||
|
@ -507,16 +509,18 @@ void ScummEngine_v80he::o80_writeConfigFile() {
|
||||||
copyScriptString(option, sizeof(option));
|
copyScriptString(option, sizeof(option));
|
||||||
copyScriptString(section, sizeof(section));
|
copyScriptString(section, sizeof(section));
|
||||||
copyScriptString(filename, sizeof(filename));
|
copyScriptString(filename, sizeof(filename));
|
||||||
convertFilePath(filename, true);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("o80_writeConfigFile: default type %d", subOp);
|
error("o80_writeConfigFile: default type %d", subOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r = convertFilePath(filename);
|
||||||
|
|
||||||
Common::ConfigFile ConfFile;
|
Common::ConfigFile ConfFile;
|
||||||
ConfFile.loadFromFile((const char *)filename);
|
ConfFile.loadFromSaveFile((const char *)filename + r);
|
||||||
ConfFile.setKey((char *)option, (char *)section, (char *)string);
|
ConfFile.setKey((char *)option, (char *)section, (char *)string);
|
||||||
ConfFile.saveToFile((const char *)filename);
|
ConfFile.saveToSaveFile((const char *)filename + r);
|
||||||
|
|
||||||
debug(1,"o80_writeConfigFile: Filename %s Section %s Option %s String %s", filename, section, option, string);
|
debug(1,"o80_writeConfigFile: Filename %s Section %s Option %s String %s", filename, section, option, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue