mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-21 11:09:41 +00:00
Merge remote-tracking branch 'potatoesmaster/ini_fallback_values-draft'
This commit is contained in:
commit
83fe128e87
3 changed files with 40 additions and 9 deletions
|
@ -146,13 +146,6 @@ MwIniImporter::MwIniImporter()
|
||||||
"FontColor:color_negative",
|
"FontColor:color_negative",
|
||||||
"FontColor:color_count",
|
"FontColor:color_count",
|
||||||
|
|
||||||
// cursors
|
|
||||||
"Cursors:Cursor 0",
|
|
||||||
"Cursors:Cursor 1",
|
|
||||||
"Cursors:Cursor 2",
|
|
||||||
"Cursors:Cursor 3",
|
|
||||||
"Cursors:Cursor 4",
|
|
||||||
|
|
||||||
// level up messages
|
// level up messages
|
||||||
"Level Up:Level2",
|
"Level Up:Level2",
|
||||||
"Level Up:Level3",
|
"Level Up:Level3",
|
||||||
|
@ -660,10 +653,21 @@ MwIniImporter::multistrmap MwIniImporter::loadIniFile(std::string filename) {
|
||||||
std::string line;
|
std::string line;
|
||||||
while (std::getline(file, line)) {
|
while (std::getline(file, line)) {
|
||||||
|
|
||||||
|
line = toUTF8(line);
|
||||||
|
|
||||||
|
// unify Unix-style and Windows file ending
|
||||||
|
if (!(line.empty()) && (line[line.length()-1]) == '\r') {
|
||||||
|
line = line.substr(0, line.length()-1);
|
||||||
|
}
|
||||||
|
|
||||||
if(line[0] == '[') {
|
if(line[0] == '[') {
|
||||||
if(line.length() > 2) {
|
int pos = line.find(']');
|
||||||
section = line.substr(1, line.length()-2);
|
if(pos < 2) {
|
||||||
|
std::cout << "Warning: ini file wrongly formatted (" << line << "). Line ignored." << std::endl;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
section = line.substr(1, line.find(']')-1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -824,3 +828,16 @@ void MwIniImporter::writeToFile(boost::iostreams::stream<boost::iostreams::file_
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MwIniImporter::toUTF8(const std::string &str) {
|
||||||
|
char *ptr = ToUTF8::getBuffer(str.length());
|
||||||
|
strncpy(ptr, str.c_str(), str.length());
|
||||||
|
|
||||||
|
// Convert to UTF8 and return
|
||||||
|
return ToUTF8::getUtf8(mEncoding);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MwIniImporter::setInputEncoding(const ToUTF8::FromType &encoding)
|
||||||
|
{
|
||||||
|
mEncoding = encoding;
|
||||||
|
}
|
||||||
|
|
|
@ -8,12 +8,15 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <exception>
|
#include <exception>
|
||||||
|
|
||||||
|
#include "../../components/to_utf8/to_utf8.hpp"
|
||||||
|
|
||||||
class MwIniImporter {
|
class MwIniImporter {
|
||||||
public:
|
public:
|
||||||
typedef std::map<std::string, std::string> strmap;
|
typedef std::map<std::string, std::string> strmap;
|
||||||
typedef std::map<std::string, std::vector<std::string> > multistrmap;
|
typedef std::map<std::string, std::vector<std::string> > multistrmap;
|
||||||
|
|
||||||
MwIniImporter();
|
MwIniImporter();
|
||||||
|
void setInputEncoding(const ToUTF8::FromType& encoding);
|
||||||
void setVerbose(bool verbose);
|
void setVerbose(bool verbose);
|
||||||
multistrmap loadIniFile(std::string filename);
|
multistrmap loadIniFile(std::string filename);
|
||||||
multistrmap loadCfgFile(std::string filename);
|
multistrmap loadCfgFile(std::string filename);
|
||||||
|
@ -25,9 +28,11 @@ class MwIniImporter {
|
||||||
private:
|
private:
|
||||||
void insertMultistrmap(multistrmap &cfg, std::string key, std::string value);
|
void insertMultistrmap(multistrmap &cfg, std::string key, std::string value);
|
||||||
std::string numberToString(int n);
|
std::string numberToString(int n);
|
||||||
|
std::string toUTF8(const std::string &str);
|
||||||
bool mVerbose;
|
bool mVerbose;
|
||||||
strmap mMergeMap;
|
strmap mMergeMap;
|
||||||
std::vector<std::string> mMergeFallback;
|
std::vector<std::string> mMergeFallback;
|
||||||
|
ToUTF8::FromType mEncoding;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,11 @@ int main(int argc, char *argv[]) {
|
||||||
("cfg,c", bpo::value<std::string>(), "openmw.cfg file")
|
("cfg,c", bpo::value<std::string>(), "openmw.cfg file")
|
||||||
("output,o", bpo::value<std::string>()->default_value(""), "openmw.cfg file")
|
("output,o", bpo::value<std::string>()->default_value(""), "openmw.cfg file")
|
||||||
("game-files,g", "import esm and esp files")
|
("game-files,g", "import esm and esp files")
|
||||||
|
("encoding,e", bpo::value<std::string>()-> default_value("win1252"),
|
||||||
|
"Character encoding used in OpenMW game messages:\n"
|
||||||
|
"\n\twin1250 - Central and Eastern European such as Polish, Czech, Slovak, Hungarian, Slovene, Bosnian, Croatian, Serbian (Latin script), Romanian and Albanian languages\n"
|
||||||
|
"\n\twin1251 - Cyrillic alphabet such as Russian, Bulgarian, Serbian Cyrillic and other languages\n"
|
||||||
|
"\n\twin1252 - Western European (Latin) alphabet, used by default")
|
||||||
;
|
;
|
||||||
p_desc.add("ini", 1).add("cfg", 1);
|
p_desc.add("ini", 1).add("cfg", 1);
|
||||||
|
|
||||||
|
@ -57,6 +62,10 @@ int main(int argc, char *argv[]) {
|
||||||
MwIniImporter importer;
|
MwIniImporter importer;
|
||||||
importer.setVerbose(vm.count("verbose"));
|
importer.setVerbose(vm.count("verbose"));
|
||||||
|
|
||||||
|
// Font encoding settings
|
||||||
|
std::string encoding(vm["encoding"].as<std::string>());
|
||||||
|
importer.setInputEncoding(ToUTF8::calculateEncoding(encoding));
|
||||||
|
|
||||||
MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile);
|
MwIniImporter::multistrmap ini = importer.loadIniFile(iniFile);
|
||||||
MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);
|
MwIniImporter::multistrmap cfg = importer.loadCfgFile(cfgFile);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue