summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/configuration.cpp15
-rw-r--r--src/configuration.h2
-rw-r--r--src/log.cpp3
-rw-r--r--src/main.cpp7
4 files changed, 18 insertions, 9 deletions
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 8cacd065..54fe3a1d 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -85,8 +85,17 @@ void Configuration::init(const std::string &filename)
xmlFreeDoc(doc);
}
-bool Configuration::write()
+void Configuration::write()
{
+ // Do not attempt to write to file that cannot be opened for writing
+ FILE *testFile = fopen(configPath.c_str(), "w");
+ if (!testFile) {
+ return;
+ }
+ else {
+ fclose(testFile);
+ }
+
xmlTextWriterPtr writer = xmlNewTextWriterFilename(configPath.c_str(), 0);
if (writer)
@@ -112,11 +121,7 @@ bool Configuration::write()
xmlTextWriterEndDocument(writer);
xmlFreeTextWriter(writer);
-
- return true;
}
-
- return false;
}
void Configuration::setValue(const std::string &key, std::string value)
diff --git a/src/configuration.h b/src/configuration.h
index e6959ee5..719ee711 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -58,7 +58,7 @@ class Configuration {
* \brief Writes the current settings back to an ini-file.
* \param filename Full path to INI file (~/.manaworld/tmw.ini)
*/
- bool write();
+ void write();
/**
* \brief Sets an option using a string value.
diff --git a/src/log.cpp b/src/log.cpp
index df7b4fd5..d71c55d6 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -33,7 +33,8 @@ Logger::Logger(const std::string &logFilename)
if (!logFile.is_open())
{
- std::cout << "Warning: error while opening log file.\n";
+ std::cout << "Warning: error while opening " << logFilename <<
+ " for writing.\n";
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 16a97e61..ce45b460 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -170,10 +170,9 @@ void init_engine()
// If we can't read it, it doesn't exist !
if (tmwFile == NULL) {
// We reopen the file in write mode and we create it
- printf("No file : %s\n, Creating Default Options...\n", configPath);
tmwFile = fopen(configPath, "wt");
if (tmwFile == NULL) {
- printf("Can't create %s file. Using Defaults.\n", configPath);
+ printf("Can't create %s. Using Defaults.\n", configPath);
}
else {
fclose(tmwFile);
@@ -319,6 +318,10 @@ int main(int argc, char *argv[])
xmlInitParser();
LIBXML_TEST_VERSION;
+ // Redirect libxml errors to /dev/null
+ FILE *nullFile = fopen("/dev/null", "w");
+ xmlSetGenericErrorFunc(nullFile, NULL);
+
// Initialize PhysicsFS
PHYSFS_init(argv[0]);