mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 16:23:39 +02:00
Move runnings scripts setting storage
So that it doesn't conflict with the "Settings" menu setting storage. Running script would clear those settings while storing its data This adds some backward compatible code to move the scripts settings to the new location.
This commit is contained in:
parent
10c412d8c7
commit
de36cd150e
1 changed files with 38 additions and 1 deletions
|
@ -256,7 +256,7 @@ QVariantList ScriptEngines::getRunning() {
|
|||
}
|
||||
|
||||
|
||||
static const QString SETTINGS_KEY = "Settings";
|
||||
static const QString SETTINGS_KEY = "RunningScripts";
|
||||
|
||||
void ScriptEngines::loadDefaultScripts() {
|
||||
QUrl defaultScriptsLoc = defaultScriptsLocation();
|
||||
|
@ -281,6 +281,43 @@ void ScriptEngines::loadScripts() {
|
|||
|
||||
// loads all saved scripts
|
||||
Settings settings;
|
||||
|
||||
|
||||
// START of backward compatibility code
|
||||
// This following if statement is only meant to update the settings file still using the old setting key.
|
||||
// If you read that comment and it has been more than a couple months since it was merged,
|
||||
// then by all means, feel free to remove it.
|
||||
if (!settings.childGroups().contains(SETTINGS_KEY)) {
|
||||
qWarning() << "Detected old script settings config, loading from previous location";
|
||||
const QString oldKey = "Settings";
|
||||
|
||||
// Load old scripts array from settings
|
||||
int size = settings.beginReadArray(oldKey);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings.setArrayIndex(i);
|
||||
QString string = settings.value("script").toString();
|
||||
if (!string.isEmpty()) {
|
||||
loadScript(string);
|
||||
}
|
||||
}
|
||||
settings.endArray();
|
||||
|
||||
// Cleanup old scripts array from settings
|
||||
settings.beginWriteArray(oldKey);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings.setArrayIndex(i);
|
||||
settings.remove("");
|
||||
}
|
||||
settings.endArray();
|
||||
settings.beginGroup(oldKey);
|
||||
settings.remove("size");
|
||||
settings.endGroup();
|
||||
|
||||
return;
|
||||
}
|
||||
// END of backward compatibility code
|
||||
|
||||
|
||||
int size = settings.beginReadArray(SETTINGS_KEY);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
settings.setArrayIndex(i);
|
||||
|
|
Loading…
Reference in a new issue