1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
#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);
}
#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)) {
if(strlen(buf) > 8 + 1) lastkit.append(buf+8, strlen(buf+8) - 1);
}
if(!strncmp(buf, "lastmidimap:", 12)) {
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);
}
|