summaryrefslogtreecommitdiff
path: root/plugingui/pluginconfig.cc
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2014-08-05 20:15:41 +0200
committerJonas Suhr Christensen <jsc@umbraculum.org>2014-08-05 20:15:41 +0200
commitc35e6f3ae438fb63c571f807037417d9d71b2afd (patch)
treeb66e1665fc7557f49ed4c65827b033041cae5d9f /plugingui/pluginconfig.cc
parente46c013eff23e85d41b04d05663a692143e2977d (diff)
Added global configfile/history file.
Diffstat (limited to 'plugingui/pluginconfig.cc')
-rw-r--r--plugingui/pluginconfig.cc130
1 files changed, 130 insertions, 0 deletions
diff --git a/plugingui/pluginconfig.cc b/plugingui/pluginconfig.cc
new file mode 100644
index 0000000..57a4e08
--- /dev/null
+++ b/plugingui/pluginconfig.cc
@@ -0,0 +1,130 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * config.cc
+ *
+ * Tue Jun 3 13:54:05 CEST 2014
+ * Copyright 2014 Jonas Suhr Christensen
+ * jsc@umbraculum.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with DrumGizmo; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "config.h"
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "directory.h"
+
+#ifdef WIN32
+#include <direct.h>
+#include <windows.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()
+{
+
+}
+
+Config::~Config()
+{
+
+}
+
+FILE* openFilePtr(std::string mode) {
+#ifdef WIN32
+ TCHAR szPath[256];
+ if(SUCCEEDED(SHGetFolderPath(NULL,
+ CSIDL_APPDATA | CSIDL_FLAG_CREATE,
+ NULL,
+ 0,
+ szPath))); {
+ DEBUG(config, "WINDOWS APP DATA PATH:%s\n", szPath);
+// PathAppend(szPath, TEXT(
+// PathAppend(szPath, TEXT(CONFIGFILENAME));
+// HANDLE hFile = CreateFile(szPath, GENERIC_READ | GENERIC_WRITE, 0, NULL);
+ }
+#else
+ std::string configpath = strdup(getenv("HOME"));
+ configpath += SEP;
+ configpath += CONFIGDIRNAME;
+ if(!Directory::exists(configpath)) {
+ if( (mkdir(configpath.c_str(), 0755)) < 0) return NULL;
+ }
+#endif
+
+ FILE *fp;
+ std::string configfile = configpath;
+ configfile += SEP;
+ configfile += CONFIGFILENAME;
+ if(! (fp = fopen(configfile.c_str(), mode.c_str())) ) {
+ return NULL;
+ }
+
+ return fp;
+}
+
+void Config::load()
+{
+ FILE *fp = openFilePtr("r");
+ if(!fp) return;
+
+ lastkit.clear();
+ lastmidimap.clear();
+
+ char buf[4096];
+ while( fgets(buf, 4096, fp) ) {
+ if(!strncmp(buf, "lastkit:", 8)) {
+ // Dont copy newline
+ if(strlen(buf) > 8 + 1) lastkit.append(buf+8, strlen(buf+8) - 1);
+ }
+ if(!strncmp(buf, "lastmidimap:", 12)) {
+ // Dont copy newline
+ if(strlen(buf) > 12+1) lastmidimap.append(buf+12, strlen(buf+12) - 1);
+ }
+ }
+}
+
+void Config::save()
+{
+ FILE *fp = openFilePtr("w");
+ if(!fp) return;
+
+ std::string buf;
+ buf.append("lastkit:" + lastkit + '\n');
+ buf.append("lastmidimap:" + lastmidimap + '\n');
+
+ fputs(buf.c_str(), fp);
+
+ fclose(fp);
+}