diff options
author | Jonas Suhr Christensen <jsc@umbraculum.org> | 2014-09-23 17:37:52 +0200 |
---|---|---|
committer | Jonas Suhr Christensen <jsc@umbraculum.org> | 2014-09-23 17:37:52 +0200 |
commit | 173a40e8a55416d759e05739eb9fdfba0ff59bbd (patch) | |
tree | 7339bb2300d12e121448b6edcdae470593e9bbee | |
parent | 7ce9dc89f3d2b072c69d70b1b5b2282b99012380 (diff) |
Testing config file creation on windows XP.
-rw-r--r-- | plugingui/pluginconfig.cc | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/plugingui/pluginconfig.cc b/plugingui/pluginconfig.cc index d129414..690d234 100644 --- a/plugingui/pluginconfig.cc +++ b/plugingui/pluginconfig.cc @@ -63,9 +63,9 @@ Config::~Config() } -static FILE* openFilePtr(std::string mode) { -#ifdef WIN32 - std::string configpath = "."; +static std::string configPath() { + #ifdef WIN32 + std::string configpath; TCHAR szPath[256]; if(SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, @@ -73,13 +73,19 @@ static FILE* openFilePtr(std::string mode) { 0, szPath))); { configpath = szPath; - DEBUG(config, "WINDOWS APP DATA PATH:%s\n", configpath.c_str()); } #else std::string configpath = strdup(getenv("HOME")); #endif configpath += SEP; configpath += CONFIGDIRNAME; + + return configpath; +} + +static bool createConfigPath() { + std::string configpath = configPath(); + if(!Directory::exists(configpath)) { DEBUG(pluginconfig, "No configuration exists, creating directory '%s'\n", configpath.c_str()); #ifdef WIN32 @@ -89,9 +95,16 @@ static FILE* openFilePtr(std::string mode) { #endif DEBUG(pluginconfig, "Could not create config directory\n"); } - return NULL; + return false; } + return true; +} + +static FILE* openConfigFile(std::string mode) { + + std::string configpath = configPath(); + FILE *fp; std::string configfile = configpath; configfile += SEP; @@ -108,7 +121,7 @@ static FILE* openFilePtr(std::string mode) { void Config::load() { DEBUG(pluginconfig, "Loading config file...\n"); - FILE *fp = openFilePtr("r"); + FILE *fp = openConfigFile("r"); if(!fp) return; lastkit.clear(); @@ -137,7 +150,9 @@ void Config::save() { DEBUG(pluginconfig, "Saving configuration...\n"); - FILE *fp = openFilePtr("w"); + createConfigPath(); + + FILE *fp = openConfigFile("w"); if(!fp) return; std::string buf; |