Mon, 25 Mar 2013 16:05:03 +0200
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
30
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
1 | /* |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
3 | * Copyright (C) 2013 Santeri `arezey` Piippo |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
4 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
8 | * (at your option) any later version. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
9 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
13 | * GNU General Public License for more details. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
14 | * |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
17 | */ |
31ff9aabd506
Licensed LDForge GPL3, added some more icons
Santeri Piippo <crimsondusk64@gmail.com>
parents:
29
diff
changeset
|
18 | |
0 | 19 | #include <stdio.h> |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
20 | #include <stdlib.h> |
0 | 21 | #include <errno.h> |
22 | #include <time.h> | |
23 | #include "str.h" | |
24 | #include "config.h" | |
25 | #include <QDir> | |
26 | ||
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
27 | std::vector<config*> g_pConfigPointers; |
0 | 28 | |
29 | // ============================================================================= | |
30 | const char* g_WeekdayNames[7] = { | |
31 | "Sunday", | |
32 | "Monday", | |
33 | "Tuesday", | |
34 | "Wednesday", | |
35 | "Thursday", | |
36 | "Friday", | |
37 | "Saturday", | |
38 | }; | |
39 | ||
40 | // ============================================================================= | |
41 | static const char* g_MonthNames[12] = { | |
42 | "Januray", | |
43 | "February", | |
44 | "March", | |
45 | "April", | |
46 | "May", | |
47 | "June", | |
48 | "July", | |
49 | "August", | |
50 | "September", | |
51 | "October", | |
52 | "November" | |
53 | "December", | |
54 | }; | |
55 | ||
56 | static const char* g_ConfigTypeNames[] = { | |
57 | "None", | |
58 | "Integer", | |
59 | "String", | |
60 | "Float", | |
61 | "Boolean", | |
62 | }; | |
63 | ||
64 | // ============================================================================= | |
65 | // Load the configuration from file | |
66 | bool config::load () { | |
68
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
67 | // Locale must be disabled for atof |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
68 | setlocale (LC_NUMERIC, "C"); |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
69 | |
0 | 70 | FILE* fp = fopen (filepath().chars(), "r"); |
71 | char linedata[MAX_INI_LINE]; | |
72 | char* line; | |
73 | size_t ln = 0; | |
74 | ||
75 | if (!fp) | |
76 | return false; // can't open for reading | |
77 | ||
78 | // Read the values. | |
79 | while (fgets (linedata, MAX_INI_LINE, fp)) { | |
80 | ln++; | |
81 | line = linedata; | |
82 | ||
83 | while (*line != 0 && (*line <= 32 || *line >= 127)) | |
84 | line++; // Skip junk | |
85 | ||
86 | if (*line == '\0' || line[0] == '#') | |
87 | continue; // Empty line or comment. | |
88 | ||
89 | // Find the equals sign. | |
90 | char* equals = strchr (line, '='); | |
91 | if (!equals) { | |
92 | fprintf (stderr, "couldn't find `=` sign in entry `%s`\n", line); | |
93 | continue; | |
94 | } | |
95 | ||
96 | str entry = str (line).substr (0, equals - line); | |
97 | ||
98 | // Find the config entry for this. | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
99 | config* cfg = nullptr; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
100 | for (config* i : g_pConfigPointers) |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
101 | if (entry == i->name) |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
102 | cfg = i; |
0 | 103 | |
104 | if (!cfg) { | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
105 | fprintf (stderr, "unknown config `%s`\n", entry.chars()); |
0 | 106 | continue; |
107 | } | |
108 | ||
109 | str valstring = str (line).substr (equals - line + 1, -1); | |
110 | ||
111 | // Trim the crap off the end | |
112 | while (~valstring) { | |
113 | char c = valstring[~valstring - 1]; | |
114 | if (c <= 32 || c >= 127) | |
115 | valstring -= 1; | |
116 | else | |
117 | break; | |
118 | } | |
119 | ||
120 | switch (const_cast<config*> (cfg)->getType()) { | |
121 | case CONFIG_int: | |
122 | static_cast<intconfig*> (cfg)->value = atoi (valstring.chars()); | |
123 | break; | |
124 | case CONFIG_str: | |
125 | static_cast<strconfig*> (cfg)->value = valstring; | |
126 | break; | |
127 | case CONFIG_float: | |
128 | static_cast<floatconfig*> (cfg)->value = atof (valstring.chars()); | |
129 | break; | |
130 | case CONFIG_bool: | |
131 | { | |
132 | bool& val = static_cast<boolconfig*> (cfg)->value; | |
133 | ||
134 | if (+valstring == "TRUE" || valstring == "1") | |
135 | val = true; | |
136 | else if (+valstring == "FALSE" || valstring == "0") | |
137 | val = false; | |
138 | break; | |
139 | } | |
140 | default: | |
141 | break; | |
142 | } | |
143 | } | |
144 | ||
145 | fclose (fp); | |
146 | return true; | |
147 | } | |
148 | ||
149 | // ============================================================================= | |
150 | // Write a given formatted string to the given file stream | |
151 | static size_t writef (FILE* fp, const char* fmt, ...) { | |
152 | va_list va; | |
153 | ||
154 | va_start (va, fmt); | |
155 | char* buf = vdynformat (fmt, va, 256); | |
156 | va_end (va); | |
157 | ||
158 | size_t len = fwrite (buf, 1, strlen (buf), fp); | |
159 | delete[] buf; | |
160 | ||
161 | return len; | |
162 | } | |
163 | ||
164 | // ============================================================================= | |
165 | // Save the configuration to disk | |
166 | bool config::save () { | |
68
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
167 | // The function will write floats, disable the locale now so that they |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
168 | // are written properly. |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
169 | setlocale (LC_NUMERIC, "C"); |
c637b172d565
Further fixes to bad color handling. Allow main color be represented with arbitrary transparency.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
30
diff
changeset
|
170 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
171 | // If the directory doesn't exist, create it now. |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
172 | if (!QDir (dirpath().chars()).exists ()) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
173 | fprintf (stderr, "Creating config path %s...\n", dirpath().chars()); |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
174 | if (!QDir ().mkpath (dirpath().chars())) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
175 | fprintf (stderr, "Failed to create the directory. Configuration cannot be saved!\n"); |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
176 | return false; // Couldn't create directory |
0 | 177 | } |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
178 | } |
0 | 179 | |
180 | FILE* fp = fopen (filepath().chars(), "w"); | |
181 | printf ("writing cfg to %s\n", filepath().chars()); | |
182 | ||
183 | if (!fp) { | |
184 | printf ("Couldn't open %s for writing\n", filepath().chars()); | |
185 | return false; | |
186 | } | |
187 | ||
188 | const time_t curtime = time (NULL); | |
189 | const struct tm* timeinfo = localtime (&curtime); | |
190 | const char* daysuffix = | |
191 | (timeinfo->tm_mday % 10 == 1) ? "st" : | |
192 | (timeinfo->tm_mday % 10 == 2) ? "nd" : | |
193 | (timeinfo->tm_mday % 10 == 3) ? "rd" : "th"; | |
194 | ||
195 | writef (fp, "# Configuration file for " APPNAME "\n"); | |
196 | writef (fp, "# Written on %s, %s %d%s %d %.2d:%.2d:%.2d\n", | |
197 | g_WeekdayNames[timeinfo->tm_wday], g_MonthNames[timeinfo->tm_mon], | |
198 | timeinfo->tm_mday, daysuffix, timeinfo->tm_year + 1900, | |
199 | timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | |
200 | ||
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
201 | for (config* cfg : g_pConfigPointers) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
202 | str valstring; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
203 | switch (cfg->getType()) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
204 | case CONFIG_int: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
205 | valstring.format ("%d", static_cast<intconfig*> (cfg)->value); |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
206 | break; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
207 | case CONFIG_str: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
208 | valstring = static_cast<strconfig*> (cfg)->value; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
209 | break; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
210 | case CONFIG_float: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
211 | valstring.format ("%f", static_cast<floatconfig*> (cfg)->value); |
0 | 212 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
213 | // Trim any trailing zeros |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
214 | if (valstring.first (".") != -1) { |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
215 | while (valstring[~valstring - 1] == '0') |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
216 | valstring -= 1; |
0 | 217 | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
218 | // But don't trim the only one out... |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
219 | if (valstring[~valstring - 1] == '.') |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
220 | valstring += '0'; |
0 | 221 | } |
222 | ||
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
223 | break; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
224 | case CONFIG_bool: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
225 | valstring = (static_cast<boolconfig*> (cfg)->value) ? "true" : "false"; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
226 | break; |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
227 | default: |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
228 | break; |
0 | 229 | } |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
230 | |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
231 | // Write the entry now. |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
232 | writef (fp, "\n# [%s] default: %s\n", g_ConfigTypeNames[cfg->getType()], cfg->defaultstring); |
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
233 | writef (fp, "%s=%s\n", cfg->name, valstring.chars()); |
0 | 234 | } |
235 | ||
236 | fclose (fp); | |
237 | return true; | |
238 | } | |
239 | ||
240 | // ============================================================================= | |
241 | void config::reset () { | |
242 | for (size_t i = 0; i < NUM_CONFIG; i++) | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
243 | g_pConfigPointers[i]->resetValue (); |
0 | 244 | } |
245 | ||
246 | // ============================================================================= | |
247 | str config::filepath () { | |
248 | str path; | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
249 | path.format ("%s" CONFIGFILE, dirpath().chars()); |
0 | 250 | return path; |
251 | } | |
252 | ||
253 | // ============================================================================= | |
254 | str config::dirpath () { | |
69
6790dea720a8
Simplified configuration code. Use a std::vector object to contain config pointers and have config objects register themselves upon creation instead of relying on a cfgdefs.h. Removed sections, all configurations are just simply written one after another now.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
255 | str path = (QDir::homePath ().toStdString().c_str()); |
0 | 256 | path += "/." APPNAME "/"; |
257 | ||
258 | return path; | |
259 | } |