summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/configuration.cpp55
-rw-r--r--src/configuration.h6
-rw-r--r--src/main.cpp31
3 files changed, 74 insertions, 18 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 07e6005f..0b1f24a7 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -54,17 +54,64 @@ void Configuration::Init(std::string filename) {
#ifdef __DEBUG
for (iter = iniOptions.begin(); iter != iniOptions.end(); iter++) {
optionTmp = *iter;
- std::cout << "key=(" << optionTmp.key << ") stringValue=(" << optionTmp.stringValue << ") numericValue=(" << optionTmp.numericValue << ")\n";
+ std::cout << "Configuration::Init(" << optionTmp.key << ", \"" << optionTmp.stringValue << "\" / " << optionTmp.numericValue << ")\n";
}
#endif
}
-bool Configuration::Write() {
+bool Configuration::Write(std::string filename) {
+ std::ofstream out(filename.c_str(), std::ofstream::out | std::ofstream::trunc);
+ char tmp[20];
+
+ INI_OPTION optionTmp;
+ for (iter = iniOptions.begin(); iter != iniOptions.end(); iter++) {
+ optionTmp = *iter;
+ out.write(optionTmp.key.c_str(), optionTmp.key.length());
+ out.write("=", 1);
+
+ if(optionTmp.numericValue == 0) {
+ out.write(optionTmp.stringValue.c_str(), optionTmp.stringValue.length());
+ }else{
+ sprintf(tmp, "%19f", optionTmp.numericValue);
+ out.write(tmp, strlen(tmp));
+ strcpy(tmp, "");
+ }
+
+ out.write("\n", 1);
+ }
+
+ out.close();
return true;
}
-bool Configuration::setValue(std::string, std::string) {
- return true;
+void Configuration::setValue(std::string key, std::string value) {
+ if(getValue(key, value) == value) {
+ #ifdef __DEBUG
+ std::cout << "Configuration::setValue(" << key << ", \"" << value << "\")\n";
+ #endif
+ INI_OPTION optionTmp;
+
+ optionTmp.key = key;
+ optionTmp.stringValue = value;
+ optionTmp.numericValue = 0;
+
+ iniOptions.push_back(optionTmp);
+ }
+}
+
+void Configuration::setValue(std::string key, float value) {
+ if(getValue(key, value) == value) {
+ #ifdef __DEBUG
+ std::cout << "Configuration::setValue(" << key << ", " << value << ")\n";
+ #endif
+
+ INI_OPTION optionTmp;
+
+ optionTmp.key = key;
+ optionTmp.numericValue = value;
+
+ iniOptions.push_back(optionTmp);
+ }
}
/**
diff --git a/src/configuration.h b/src/configuration.h
index e3e5b9aa..2bd8f83b 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -39,9 +39,11 @@ class Configuration {
public:
void Init(std::string);
- bool Write();
+ bool Write(std::string);
+
+ void setValue(std::string, std::string);
+ void setValue(std::string, float);
- bool setValue(std::string, std::string);
std::string getValue(std::string, std::string);
float getValue(std::string, float);
private:
diff --git a/src/main.cpp b/src/main.cpp
index 120fb881..68f5cb2a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -173,25 +173,32 @@ void init_engine() {
if ( tmwFile == NULL ) {
printf("Can't create %s file. Using Defaults.\n", dir);
} else {
+ fclose(tmwFile);
// tmw.ini creation
- fprintf(tmwFile, "system=\nkeyboard=en\nlanguage=\ncore_version=" CORE_VERSION "\n\n");
- fprintf(tmwFile, "host=animesites.de\nport=6901\n\n");
- fprintf(tmwFile, "#=Screen mode:\n# = 1 Fullscreen\n# = 2 Windowed\nscreen=2\n");
- fprintf(tmwFile, "# = Sound:\n#=1 enabled\n# = 0 disabled\nsound=0\n");
+ config.setValue("system", "");
+ config.setValue("keyboard", "en");
+ config.setValue("language", "");
+ config.setValue("core_version", CORE_VERSION);
+
+
+ config.setValue("host", "animesites.de");
+ config.setValue("port", 6901);
+ config.setValue("screen", 1);
+ config.setValue("sound", 1);
+
- char * chatlogFilename = new char [400];
#ifdef __USE_UNIX98
+ char * chatlogFilename = new char [400];
sprintf(chatlogFilename, "%s/.manaworld/chatlog.txt", userHome);
+ config.setValue("chatlog", chatlogFilename);
+ delete chatlogFilename;
#else
- strcpy(chatlogFilename, "chatlog.txt");
+ config.setValue("chatlog", "chatlog.txt");
#endif
- fprintf(tmwFile, "# = Chat logfile location:\nchatlog=%s\n", chatlogFilename);
- delete chatlogFilename; chatlogFilename = 0;
- fprintf(tmwFile, "#= Display strecth mode:\n# = 0 Disabled (Test only)\n# = 1 Normal\n# = 2 SuperEagle\n");
- fprintf(tmwFile, "stretch=1\n\n");
- fprintf(tmwFile, "[login]\nremember=1\nusername=Player\n");
- fclose(tmwFile);
+ config.setValue("stretch", 1);
+ config.setValue("remember", 1);
+ config.setValue("username", "Player");
}
}