Sun, 08 Sep 2013 17:44:58 +0300
the demo auth checksums need to be read in with readString and not operator>>
20
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * ZanDemo: Zandronum demo launcher |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include <cassert> |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include <QDir> |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | #include <QTextStream> |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include <QSettings> |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "main.h" |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | #include "config.h" |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | #define MAX_CONFIG 512 |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | // ============================================================================= |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | // ----------------------------------------------------------------------------- |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | namespace cfg { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | static struct { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | void* ptr; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | Type type; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | const char* name; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | QVariant def; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | } g_configData[MAX_CONFIG]; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | static int g_cfgDataCursor = 0; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | #define CASE(T) case T##Type: return QVariant (*(reinterpret_cast<T*> (ptr))); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | static QVariant getConfigValue (void* ptr, Type type) { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | switch (type) { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | CASE (Int) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | CASE (String) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | CASE (Float) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | CASE (Bool) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | CASE (List) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | CASE (Map) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | case KeySeqType: |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | return QVariant (reinterpret_cast<KeySeq*> (ptr)->toString()); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | assert (false); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | return QVariant(); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | #undef CASE |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | #define CASE(T, METHOD) case T##Type: (*(reinterpret_cast<T*> (ptr))) = val.METHOD(); return; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | static void setConfigValue (void* ptr, Type type, const QVariant& val) { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | switch (type) { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | CASE (Int, toInt) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | CASE (String, toString) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | CASE (Float, toFloat) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | CASE (Bool, toBool) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | CASE (List, toList) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | CASE (Map, toMap) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | case KeySeqType: |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | reinterpret_cast<KeySeq*> (ptr)->fromString (val.toString()); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | break; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | // ============================================================================= |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | // Get the QSettings object. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | // ----------------------------------------------------------------------------- |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | static QSettings* getSettingsObject() { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | return new QSettings; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | // ============================================================================= |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | // Load the configuration from file |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
84 | // ----------------------------------------------------------------------------- |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | bool load() { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | QSettings* settings = getSettingsObject(); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | print ("config::load: Loading configuration file from %1\n", settings->fileName()); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | for (alias i : g_configData) { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | if (i.name == null) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | break; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
92 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
93 | setConfigValue (i.ptr, i.type, settings->value (i.name, i.def)); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | settings->deleteLater(); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | return true; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | // ============================================================================= |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | // Save the configuration to disk |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | // ----------------------------------------------------------------------------- |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
103 | bool save() { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
104 | QSettings* settings = getSettingsObject(); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | settings->clear(); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | print ("Saving configuration to %1...\n", settings->fileName()); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | for (alias i : g_configData) { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | if (i.name == null) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | break; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | QVariant val = getConfigValue (i.ptr, i.type); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | if (val == i.def) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | continue; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | settings->setValue (i.name, val); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | settings->sync(); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | settings->deleteLater(); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | return true; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | // ============================================================================= |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | // Reset configuration defaults. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | // ----------------------------------------------------------------------------- |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | void reset() { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | for (alias i : g_configData) { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | if (i.name == null) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | break; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
133 | setConfigValue (i.ptr, i.type, i.def); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
134 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | // ============================================================================= |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | // We cannot just add config objects to a list or vector because that would rely |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | // on the vector's c-tor being called before the configs' c-tors. With global |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | // variables we cannot assume that!! Therefore we need to use a C-style array here. |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | // ----------------------------------------------------------------------------- |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | ConfigAdder::ConfigAdder (void* ptr, Type type, const char* name, QVariant def) { |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | if (g_cfgDataCursor == 0) |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | memset (g_configData, 0, sizeof g_configData); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
146 | assert (g_cfgDataCursor < MAX_CONFIG); |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
147 | alias i = g_configData[g_cfgDataCursor++]; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | i.ptr = ptr; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | i.type = type; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | i.name = name; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | i.def = def; |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | } |
a5457405cc9b
Use the cfg:: namespace system I made up a while ago instead of using QSettings directly, it's unsafe
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | } |