diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-05-16 08:35:39 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-05-16 08:35:39 +0200 |
commit | 0adc05286d97536637d01ed0a295d45f7bb60c1d (patch) | |
tree | 7f06e82a515d4ab47f5c944eaec98c2b43b8c146 /plugingui/pluginconfig.cc | |
parent | c91ae2624f3d3c003c6b2065f3cc128b1b039801 (diff) | |
parent | ceda77eb38f0b0824f03348f5291e3a42d8f7306 (diff) |
Merge remote-tracking branch 'origin' into diskstreaming
Conflicts:
src/Makefile.am.drumgizmo
src/drumgizmo.h
Diffstat (limited to 'plugingui/pluginconfig.cc')
-rw-r--r-- | plugingui/pluginconfig.cc | 122 |
1 files changed, 8 insertions, 114 deletions
diff --git a/plugingui/pluginconfig.cc b/plugingui/pluginconfig.cc index d57d9df..0beef6e 100644 --- a/plugingui/pluginconfig.cc +++ b/plugingui/pluginconfig.cc @@ -26,140 +26,34 @@ */ #include "pluginconfig.h" -#include <stdio.h> -#include <errno.h> -#include <string.h> -#include <stdlib.h> - -#include "directory.h" - -#ifdef WIN32 -#include <direct.h> -#include <windows.h> -#include <Shlobj.h> -#include <Shlwapi.h> -#else -#endif - #include <hugin.hpp> #define CONFIGFILENAME "plugingui.conf" -#ifdef WIN32 - #define SEP "\\" - #define CONFIGDIRNAME ".drumgizmo" -#else - #define SEP "/" - #define CONFIGDIRNAME ".drumgizmo" -#endif - Config::Config() + : ConfigFile(CONFIGFILENAME) { - } Config::~Config() { - -} - -static std::string configPath() { - #ifdef WIN32 - std::string configpath; - TCHAR szPath[256]; - if(SUCCEEDED(SHGetFolderPath(NULL, - CSIDL_APPDATA | CSIDL_FLAG_CREATE, - NULL, - 0, - szPath))); { - configpath = szPath; - } -#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 - if( (mkdir(configpath.c_str())) < 0) { -#else - if( (mkdir(configpath.c_str(), 0755)) < 0) { -#endif - DEBUG(pluginconfig, "Could not create config directory\n"); - } - return false; - } - - return true; -} - -static FILE* openConfigFile(std::string mode) { - - std::string configpath = configPath(); - - FILE *fp; - std::string configfile = configpath; - configfile += SEP; - configfile += CONFIGFILENAME; - - DEBUG(pluginconfig, "Opening config file '%s'\n", configfile.c_str()); - if(! (fp = fopen(configfile.c_str(), mode.c_str())) ) { - return NULL; - } - - return fp; } void Config::load() { - DEBUG(pluginconfig, "Loading config file...\n"); - FILE *fp = openConfigFile("r"); - if(!fp) return; - lastkit.clear(); lastmidimap.clear(); - char buf[4096]; - while( fgets(buf, 4096, fp) ) { - if(!strncmp(buf, "lastkit:", 8)) { - DEBUG(pluginconfig, "Loading last kit path\n"); - // Dont copy newline - if(strlen(buf) > 8 + 1) { - lastkit.append(buf+8, strlen(buf+8) - 1); - DEBUG(pluginconfig, "\t path is %s\n", lastkit.c_str()); - } - } - if(!strncmp(buf, "lastmidimap:", 12)) { - DEBUG(pluginconfig, "Loading lastmidimap path\n"); - // Dont copy newline - if(strlen(buf) > 12+1) lastmidimap.append(buf+12, strlen(buf+12) - 1); - DEBUG(pluginconfig, "\t path is %s\n", lastmidimap.c_str()); - } - } + ConfigFile::load(); + + lastkit = getValue("lastkit"); + lastmidimap = getValue("lastmidimap"); } void Config::save() { - DEBUG(pluginconfig, "Saving configuration...\n"); - - createConfigPath(); - - FILE *fp = openConfigFile("w"); - if(!fp) return; - - std::string buf; - buf.append("lastkit:" + lastkit + '\n'); - buf.append("lastmidimap:" + lastmidimap + '\n'); - - fputs(buf.c_str(), fp); + setValue("lastkit", lastkit); + setValue("lastmidimap", lastmidimap); - fclose(fp); + ConfigFile::save(); } |