Add support for reading/writing to external config file in HE games.
svn-id: r17746
This commit is contained in:
parent
45bc8afad0
commit
e6bd008e30
3 changed files with 79 additions and 35 deletions
|
@ -823,6 +823,7 @@ protected:
|
||||||
virtual void decodeParseString(int a, int b);
|
virtual void decodeParseString(int a, int b);
|
||||||
void decodeScriptString(byte *dst, bool scriptString = false);
|
void decodeScriptString(byte *dst, bool scriptString = false);
|
||||||
void copyScriptString(byte *dst, int dstSize);
|
void copyScriptString(byte *dst, int dstSize);
|
||||||
|
void convertFilePath(byte *dst);
|
||||||
|
|
||||||
byte *heFindResourceData(uint32 tag, byte *ptr);
|
byte *heFindResourceData(uint32 tag, byte *ptr);
|
||||||
byte *heFindResource(uint32 tag, byte *ptr);
|
byte *heFindResource(uint32 tag, byte *ptr);
|
||||||
|
|
|
@ -518,6 +518,42 @@ void ScummEngine_v72he::readArrayFromIndexFile() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScummEngine_v72he::convertFilePath(byte *dst) {
|
||||||
|
// Switch all \ to / for portablity
|
||||||
|
int len = resStrLen(dst) + 1;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (dst[i] == '\\')
|
||||||
|
dst[i] = '/';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Strip path
|
||||||
|
int r = 0;
|
||||||
|
if (dst[0] == '.' && dst[1] == '/') {
|
||||||
|
r = 2;
|
||||||
|
} else if (dst[0] == 'c' && dst[1] == ':') {
|
||||||
|
for (r = len; r != 0; r--) {
|
||||||
|
if (dst[r - 1] == '/')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File f;
|
||||||
|
char filePath[256], newFilePath[256];
|
||||||
|
|
||||||
|
sprintf(filePath, "%s%s", _gameDataPath.c_str(), dst + r);
|
||||||
|
if (f.exists(filePath)) {
|
||||||
|
sprintf(newFilePath, "%s%s", _gameDataPath.c_str(), dst + r);
|
||||||
|
} else {
|
||||||
|
sprintf(newFilePath, "%s%s", _saveFileMan->getSavePath(), dst + r);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = resStrLen((const byte *)newFilePath);
|
||||||
|
memcpy(dst, newFilePath, len);
|
||||||
|
dst[len] = 0;
|
||||||
|
|
||||||
|
debug(0, "convertFilePath: newFilePath is %s", newFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
void ScummEngine_v72he::copyScriptString(byte *dst, int dstSize) {
|
void ScummEngine_v72he::copyScriptString(byte *dst, int dstSize) {
|
||||||
byte string[1024];
|
byte string[1024];
|
||||||
byte chr;
|
byte chr;
|
||||||
|
@ -1506,7 +1542,7 @@ void ScummEngine_v72he::o72_arrayOps() {
|
||||||
c = pop();
|
c = pop();
|
||||||
id = readVar(array);
|
id = readVar(array);
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
defineArray(array, kDwordArray, 0, 0, 0, b + c);
|
defineArray(array, kDwordArray, 0, 0, 0, b + c - 1);
|
||||||
}
|
}
|
||||||
while (c--) {
|
while (c--) {
|
||||||
writeArray(array, 0, b + c, pop());
|
writeArray(array, 0, b + c, pop());
|
||||||
|
@ -1670,7 +1706,7 @@ void ScummEngine_v72he::o72_jumpToScript() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine_v72he::o72_openFile() {
|
void ScummEngine_v72he::o72_openFile() {
|
||||||
int mode, slot, len, i;
|
int mode, slot, i;
|
||||||
byte filename[256];
|
byte filename[256];
|
||||||
|
|
||||||
mode = pop();
|
mode = pop();
|
||||||
|
@ -1686,22 +1722,8 @@ void ScummEngine_v72he::o72_openFile() {
|
||||||
strcpy((char *)filename, buf1);
|
strcpy((char *)filename, buf1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int r = 0;
|
convertFilePath(filename);
|
||||||
if (filename[0] == 'c' && filename[1] == ':') {
|
debug(0,"Final filename to %s", filename);
|
||||||
// Strip path
|
|
||||||
for (r = strlen((char*)filename); r != 0; r--) {
|
|
||||||
if (filename[r - 1] == '\\')
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Switch all \ to / for portablity
|
|
||||||
len = resStrLen(filename) + 1;
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
if (filename[i] == '\\')
|
|
||||||
filename[i] = '/';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
debug(0,"Final filename to %s", filename + r);
|
|
||||||
|
|
||||||
slot = -1;
|
slot = -1;
|
||||||
for (i = 0; i < 17; i++) {
|
for (i = 0; i < 17; i++) {
|
||||||
|
@ -1714,12 +1736,10 @@ void ScummEngine_v72he::o72_openFile() {
|
||||||
if (slot != -1) {
|
if (slot != -1) {
|
||||||
switch(mode) {
|
switch(mode) {
|
||||||
case 1:
|
case 1:
|
||||||
_hFileTable[slot].open((char*)filename + r, File::kFileReadMode, _saveFileMan->getSavePath());
|
_hFileTable[slot].open((char*)filename, File::kFileReadMode);
|
||||||
if (_hFileTable[slot].isOpen() == false)
|
|
||||||
_hFileTable[slot].open((char*)filename + r, File::kFileReadMode);
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
_hFileTable[slot].open((char*)filename + r, File::kFileWriteMode, _saveFileMan->getSavePath());
|
_hFileTable[slot].open((char*)filename, File::kFileWriteMode);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("o72_openFile(): wrong open file mode %d", mode);
|
error("o72_openFile(): wrong open file mode %d", mode);
|
||||||
|
|
|
@ -449,35 +449,47 @@ void ScummEngine_v80he::o80_localizeArrayToRoom() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine_v80he::o80_readConfigFile() {
|
void ScummEngine_v80he::o80_readConfigFile() {
|
||||||
byte name[128], section[128], filename[256];
|
byte option[128], section[128], filename[256];
|
||||||
int type;
|
ArrayHeader *ah;
|
||||||
|
const char *entry;
|
||||||
|
int len, type;
|
||||||
|
|
||||||
// we pretend that we don't have .ini file
|
// we pretend that we don't have .ini file
|
||||||
|
copyScriptString(option, sizeof(option));
|
||||||
copyScriptString(section, sizeof(section));
|
copyScriptString(section, sizeof(section));
|
||||||
copyScriptString(name, sizeof(name));
|
|
||||||
copyScriptString(filename, sizeof(filename));
|
copyScriptString(filename, sizeof(filename));
|
||||||
|
convertFilePath(filename);
|
||||||
type = fetchScriptByte();
|
type = fetchScriptByte();
|
||||||
|
|
||||||
|
ConfMan.loadConfigFile((const char *)filename);
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 43: // HE 100
|
case 43: // HE 100
|
||||||
case 6: // number
|
case 6: // number
|
||||||
push(0);
|
push(ConfMan.getInt((char *)option, (char *)section));
|
||||||
break;
|
break;
|
||||||
case 77: // HE 100
|
case 77: // HE 100
|
||||||
case 7: // string
|
case 7: // string
|
||||||
|
entry = (ConfMan.get((char *)option, (char *)section).c_str());
|
||||||
|
|
||||||
writeVar(0, 0);
|
writeVar(0, 0);
|
||||||
defineArray(0, kStringArray, 0, 0, 0, 0);
|
len = resStrLen((const byte *)entry);
|
||||||
writeArray(0, 0, 0, 0);
|
ah = defineArray(0, kStringArray, 0, 0, 0, len);
|
||||||
push(readVar(0)); // var ID string
|
memcpy(ah->data, entry, len);
|
||||||
|
|
||||||
|
push(readVar(0));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
error("o80_readConfigFile: default type %d", type);
|
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() {
|
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;
|
int type, value;
|
||||||
|
|
||||||
// we pretend that we don't have .ini file
|
// we pretend that we don't have .ini file
|
||||||
|
@ -487,22 +499,33 @@ void ScummEngine_v80he::o80_writeConfigFile() {
|
||||||
case 43: // HE 100
|
case 43: // HE 100
|
||||||
case 6: // number
|
case 6: // number
|
||||||
value = pop();
|
value = pop();
|
||||||
|
copyScriptString(option, sizeof(option));
|
||||||
copyScriptString(section, sizeof(section));
|
copyScriptString(section, sizeof(section));
|
||||||
copyScriptString(name, sizeof(name));
|
|
||||||
copyScriptString(filename, sizeof(filename));
|
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;
|
break;
|
||||||
case 77: // HE 100
|
case 77: // HE 100
|
||||||
case 7: // string
|
case 7: // string
|
||||||
copyScriptString(string, sizeof(string));
|
copyScriptString(string, sizeof(string));
|
||||||
|
copyScriptString(option, sizeof(option));
|
||||||
copyScriptString(section, sizeof(section));
|
copyScriptString(section, sizeof(section));
|
||||||
copyScriptString(name, sizeof(name));
|
|
||||||
copyScriptString(filename, sizeof(filename));
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
error("o80_writeConfigFile: default type %d", type);
|
error("o80_writeConfigFile: default type %d", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfMan.flushToDisk();
|
||||||
|
ConfMan.loadDefaultConfigFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScummEngine_v80he::o80_cursorCommand() {
|
void ScummEngine_v80he::o80_cursorCommand() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue