MCPcopy Create free account
hub / github.com/awawa-dev/HyperHDR / upgradeDB

Method upgradeDB

sources/base/InstanceConfig.cpp:146–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146bool InstanceConfig::upgradeDB(QJsonObject& dbConfig)
147{
148 auto generalObject = dbConfig["general"].toObject();
149 int version = generalObject["version"].toInt(-1);
150 int orgVersion = version;
151
152 if (version < 0)
153 {
154 Warning(_log, "Could not read DB version");
155 return false;
156 }
157
158 // HyperHDR v20 update
159 if (version < 2)
160 {
161 auto colorObject = dbConfig["color"].toObject();
162 if (colorObject.contains("channelAdjustment"))
163 {
164 QJsonArray adjUpdate = colorObject["channelAdjustment"].toArray(), newArray;
165 for (auto iter = adjUpdate.begin(); iter != adjUpdate.end(); ++iter)
166 {
167 QJsonObject newObject = (iter)->toObject();
168 int threshold = newObject["backlightThreshold"].toInt(0);
169 if (threshold > 1)
170 {
171 newObject["backlightThreshold"] = threshold - 1;
172 }
173 newArray.append(newObject);
174 }
175 colorObject["channelAdjustment"] = newArray;
176 dbConfig["color"] = colorObject;
177 ///////////////////////////////////////////////////////////
178 version = 2;
179 Info(_log, "DB has been upgraded to version: %i", version);
180 }
181 }
182
183 if (version < 3)
184 {
185 if (_sTable->recordExist("boblightServer"))
186 {
187 _sTable->deleteSettingsRecordString("boblightServer");
188 }
189 version = 3;
190 }
191
192 if (version < 4)
193 {
194 auto deviceObject = dbConfig["device"].toObject();
195 if (deviceObject["type"] == "awa_spi")
196 {
197 deviceObject["type"] = "hyperspi";
198 dbConfig["device"] = deviceObject;
199 }
200 version = 4;
201 }
202
203 generalObject["version"] = version;

Callers

nothing calls this directly

Calls 3

beginMethod · 0.80
recordExistMethod · 0.80

Tested by

no test coverage detected