2017-05-26 05:24:38 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-06-05 19:10:47 +02:00
|
|
|
#include "sludge/allfiles.h"
|
|
|
|
#include "sludge/newfatal.h"
|
|
|
|
#include "sludge/moreio.h"
|
|
|
|
#include "sludge/language.h"
|
|
|
|
#include "sludge/sludge.h"
|
|
|
|
#include "sludge/CommonCode/version.h"
|
2017-05-27 20:16:54 +02:00
|
|
|
|
|
|
|
#include "common/debug.h"
|
|
|
|
|
2017-05-26 21:25:11 +02:00
|
|
|
namespace Sludge {
|
|
|
|
|
2017-05-26 05:24:38 +02:00
|
|
|
int *languageTable;
|
2017-07-11 14:57:31 +02:00
|
|
|
Common::String *languageName;
|
2017-05-26 05:24:38 +02:00
|
|
|
settingsStruct gameSettings;
|
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
Common::String getPrefsFilename(Common::String filename) {
|
2017-05-26 05:24:38 +02:00
|
|
|
// Yes, this trashes the original string, but
|
|
|
|
// we also free it at the end (warning!)...
|
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
int n = filename.size();
|
2017-05-26 05:24:38 +02:00
|
|
|
|
|
|
|
if (n > 4 && filename[n - 4] == '.') {
|
2017-07-11 14:57:31 +02:00
|
|
|
filename.setChar(0, n - 4);
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
// get file name from dir
|
|
|
|
int pos = 0;
|
|
|
|
for (int i = 0; i < n; i++) {
|
2017-05-26 05:24:38 +02:00
|
|
|
if (filename[i] == '/')
|
2017-07-11 14:57:31 +02:00
|
|
|
pos = i + 1;
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
Common::String f = filename.c_str() + pos;
|
|
|
|
Common::String joined = f + ".ini";
|
2017-05-26 05:24:38 +02:00
|
|
|
|
|
|
|
return joined;
|
|
|
|
}
|
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
void readIniFile(const Common::String &filename) {
|
2017-05-27 20:16:54 +02:00
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
Common::String langName = getPrefsFilename(filename);
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-05-27 20:16:54 +02:00
|
|
|
Common::File fd;
|
|
|
|
if (!fd.open(langName)) {
|
2017-07-11 14:57:31 +02:00
|
|
|
debug(kSludgeDebugDataLoad, "Fail to open language file : %s", langName.c_str());
|
2017-05-27 20:16:54 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-05-26 05:24:38 +02:00
|
|
|
|
|
|
|
gameSettings.languageID = 0;
|
2017-05-27 20:16:54 +02:00
|
|
|
gameSettings.userFullScreen = false; //defaultUserFullScreen(); TODO: false value
|
2017-05-26 05:24:38 +02:00
|
|
|
gameSettings.refreshRate = 0;
|
|
|
|
gameSettings.antiAlias = 1;
|
|
|
|
gameSettings.fixedPixels = false;
|
|
|
|
gameSettings.noStartWindow = false;
|
|
|
|
gameSettings.debugMode = false;
|
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
Common::String lineSoFar = "";
|
|
|
|
Common::String secondSoFar = "";
|
2017-05-27 20:16:54 +02:00
|
|
|
char readChar = ' ';
|
|
|
|
bool keepGoing = true;
|
|
|
|
bool doingSecond = false;
|
|
|
|
|
|
|
|
do {
|
2017-05-30 09:59:56 +02:00
|
|
|
readChar = fd.readByte();
|
2017-05-27 20:16:54 +02:00
|
|
|
if (fd.eos()) {
|
|
|
|
readChar = '\n';
|
|
|
|
keepGoing = false;
|
|
|
|
}
|
|
|
|
switch (readChar) {
|
2017-06-05 11:49:19 +02:00
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
if (doingSecond) {
|
2017-07-11 14:57:31 +02:00
|
|
|
if (lineSoFar == "LANGUAGE") {
|
|
|
|
gameSettings.languageID = (uint)secondSoFar.asUint64();
|
|
|
|
} else if (lineSoFar == "WINDOW") {
|
|
|
|
gameSettings.userFullScreen = !secondSoFar.asUint64();
|
|
|
|
} else if (lineSoFar == "REFRESH") {
|
|
|
|
gameSettings.refreshRate = (uint)secondSoFar.asUint64();
|
|
|
|
} else if (lineSoFar == "ANTIALIAS") {
|
|
|
|
gameSettings.antiAlias = (int)secondSoFar.asUint64();
|
|
|
|
} else if (lineSoFar == "FIXEDPIXELS") {
|
|
|
|
gameSettings.fixedPixels = secondSoFar.asUint64();
|
|
|
|
} else if (lineSoFar == "NOSTARTWINDOW") {
|
|
|
|
gameSettings.noStartWindow = secondSoFar.asUint64();
|
|
|
|
} else if (lineSoFar == "DEBUGMODE") {
|
|
|
|
gameSettings.debugMode = secondSoFar.asUint64();
|
2017-06-05 11:49:19 +02:00
|
|
|
}
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
2017-06-05 11:49:19 +02:00
|
|
|
doingSecond = false;
|
2017-07-11 14:57:31 +02:00
|
|
|
lineSoFar.clear();
|
|
|
|
secondSoFar.clear();
|
2017-06-05 11:49:19 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '=':
|
|
|
|
doingSecond = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (doingSecond) {
|
2017-07-11 14:57:31 +02:00
|
|
|
secondSoFar += readChar;
|
2017-06-05 11:49:19 +02:00
|
|
|
} else {
|
2017-07-11 14:57:31 +02:00
|
|
|
lineSoFar += readChar;
|
2017-06-05 11:49:19 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-05-27 20:16:54 +02:00
|
|
|
}
|
|
|
|
} while (keepGoing);
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-05-27 20:16:54 +02:00
|
|
|
fd.close();
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
void saveIniFile(const Common::String &filename) {
|
2017-05-27 20:16:54 +02:00
|
|
|
#if 0
|
2017-05-26 05:24:38 +02:00
|
|
|
char *langName = getPrefsFilename(copyString(filename));
|
|
|
|
FILE *fp = fopen(langName, "wt");
|
|
|
|
delete langName;
|
|
|
|
|
|
|
|
fprintf(fp, "LANGUAGE=%d\n", gameSettings.languageID);
|
|
|
|
fprintf(fp, "WINDOW=%d\n", ! gameSettings.userFullScreen);
|
|
|
|
fprintf(fp, "ANTIALIAS=%d\n", gameSettings.antiAlias);
|
|
|
|
fprintf(fp, "FIXEDPIXELS=%d\n", gameSettings.fixedPixels);
|
|
|
|
fprintf(fp, "NOSTARTWINDOW=%d\n", gameSettings.noStartWindow);
|
|
|
|
fprintf(fp, "DEBUGMODE=%d\n", gameSettings.debugMode);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-05-27 20:16:54 +02:00
|
|
|
void makeLanguageTable(Common::File *table) {
|
2017-05-26 05:24:38 +02:00
|
|
|
languageTable = new int[gameSettings.numLanguages + 1];
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!checkNew(languageTable))
|
|
|
|
return;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-11 14:57:31 +02:00
|
|
|
languageName = new Common::String[gameSettings.numLanguages + 1];
|
2017-05-29 08:02:59 +02:00
|
|
|
if (!checkNew(languageName))
|
|
|
|
return;
|
2017-05-26 05:24:38 +02:00
|
|
|
|
2017-07-10 21:44:14 +02:00
|
|
|
for (uint i = 0; i <= gameSettings.numLanguages; i++) {
|
2017-05-30 09:59:56 +02:00
|
|
|
languageTable[i] = i ? table->readUint16BE() : 0;
|
2017-06-05 11:49:19 +02:00
|
|
|
debug(kSludgeDebugDataLoad, "languageTable %i: %i", i, languageTable[i]);
|
2017-07-11 14:57:31 +02:00
|
|
|
languageName[i].clear();
|
2017-05-26 05:24:38 +02:00
|
|
|
if (gameVersion >= VERSION(2, 0)) {
|
|
|
|
if (gameSettings.numLanguages) {
|
|
|
|
languageName[i] = readString(table);
|
2017-07-11 14:57:31 +02:00
|
|
|
debug(kSludgeDebugDataLoad, "languageName %i: %s\n", i, languageName[i].c_str());
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int getLanguageForFileB() {
|
|
|
|
int indexNum = -1;
|
|
|
|
|
2017-07-10 21:44:14 +02:00
|
|
|
for (uint i = 0; i <= gameSettings.numLanguages; i++) {
|
2017-05-29 08:02:59 +02:00
|
|
|
if (languageTable[i] == gameSettings.languageID)
|
|
|
|
indexNum = i;
|
2017-05-26 05:24:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return indexNum;
|
|
|
|
}
|
2017-05-26 21:25:11 +02:00
|
|
|
|
|
|
|
} // End of namespace Sludge
|