mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01:00
add a content settings backup handler
This commit is contained in:
parent
e0e04b8bb2
commit
f624e1b464
5 changed files with 116 additions and 11 deletions
66
domain-server/src/ContentSettingsBackupHandler.cpp
Normal file
66
domain-server/src/ContentSettingsBackupHandler.cpp
Normal file
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// ContentSettingsBackupHandler.cpp
|
||||
// domain-server/src
|
||||
//
|
||||
// Created by Stephen Birarda on 2/15/18.
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include "ContentSettingsBackupHandler.h"
|
||||
|
||||
#include <quazip5/quazip.h>
|
||||
#include <quazip5/quazipfile.h>
|
||||
|
||||
ContentSettingsBackupHandler::ContentSettingsBackupHandler(DomainServerSettingsManager& domainServerSettingsManager) :
|
||||
_settingsManager(domainServerSettingsManager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static const QString CONTENT_SETTINGS_BACKUP_FILENAME = "content-settings.json";
|
||||
|
||||
void ContentSettingsBackupHandler::createBackup(QuaZip& zip) {
|
||||
|
||||
// grab the content settings as JSON,excluding default values and values hidden from backup
|
||||
QJsonObject contentSettingsJSON = _settingsManager.settingsResponseObjectForType("", true, false, true, false, true);
|
||||
|
||||
// make a QJSonDocument using the object
|
||||
QJsonDocument contentSettingsDocument { contentSettingsJSON };
|
||||
|
||||
QuaZipFile zipFile { &zip };
|
||||
|
||||
zipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(CONTENT_SETTINGS_BACKUP_FILENAME));
|
||||
zipFile.write(contentSettingsDocument.toJson());
|
||||
zipFile.close();
|
||||
|
||||
if (zipFile.getZipError() != UNZ_OK) {
|
||||
qCritical().nospace() << "Failed to zip " << CONTENT_SETTINGS_BACKUP_FILENAME << ": " << zipFile.getZipError();
|
||||
}
|
||||
}
|
||||
|
||||
void ContentSettingsBackupHandler::recoverBackup(QuaZip& zip) {
|
||||
if (!zip.setCurrentFile(CONTENT_SETTINGS_BACKUP_FILENAME)) {
|
||||
qWarning() << "Failed to find" << CONTENT_SETTINGS_BACKUP_FILENAME << "while recovering backup";
|
||||
return;
|
||||
}
|
||||
|
||||
QuaZipFile zipFile { &zip };
|
||||
if (!zipFile.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open" << CONTENT_SETTINGS_BACKUP_FILENAME << "in backup";
|
||||
return;
|
||||
}
|
||||
|
||||
auto rawData = zipFile.readAll();
|
||||
zipFile.close();
|
||||
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(rawData);
|
||||
|
||||
if (!_settingsManager.restoreSettingsFromObject(jsonDocument.object(), ContentSettings)) {
|
||||
qCritical() << "Failed to restore settings from" << CONTENT_SETTINGS_BACKUP_FILENAME << "in content archive";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
35
domain-server/src/ContentSettingsBackupHandler.h
Normal file
35
domain-server/src/ContentSettingsBackupHandler.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
//
|
||||
// ContentSettingsBackupHandler.h
|
||||
// domain-server/src
|
||||
//
|
||||
// Created by Stephen Birarda on 2/15/18.
|
||||
// Copyright 2018 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_ContentSettingsBackupHandler_h
|
||||
#define hifi_ContentSettingsBackupHandler_h
|
||||
|
||||
#include "BackupHandler.h"
|
||||
#include "DomainServerSettingsManager.h"
|
||||
|
||||
class ContentSettingsBackupHandler : public BackupHandlerInterface {
|
||||
public:
|
||||
ContentSettingsBackupHandler(DomainServerSettingsManager& domainServerSettingsManager);
|
||||
|
||||
void loadBackup(QuaZip& zip) {};
|
||||
|
||||
void createBackup(QuaZip& zip);
|
||||
|
||||
void recoverBackup(QuaZip& zip);
|
||||
|
||||
void deleteBackup(QuaZip& zip) {};
|
||||
|
||||
void consolidateBackup(QuaZip& zip) {};
|
||||
private:
|
||||
DomainServerSettingsManager& _settingsManager;
|
||||
};
|
||||
|
||||
#endif // hifi_ContentSettingsBackupHandler_h
|
|
@ -46,6 +46,7 @@
|
|||
#include <StatTracker.h>
|
||||
|
||||
#include "AssetsBackupHandler.h"
|
||||
#include "ContentSettingsBackupHandler.h"
|
||||
#include "DomainServerNodeData.h"
|
||||
#include "EntitiesBackupHandler.h"
|
||||
#include "NodeConnectionData.h"
|
||||
|
@ -299,6 +300,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
_contentManager.reset(new DomainContentBackupManager(getContentBackupDir(), _settingsManager.settingsResponseObjectForType("6")["entity_server_settings"].toObject()));
|
||||
_contentManager->addBackupHandler(BackupHandlerPointer(new EntitiesBackupHandler(getEntitiesFilePath(), getEntitiesReplacementFilePath())));
|
||||
_contentManager->addBackupHandler(BackupHandlerPointer(new AssetsBackupHandler(getContentBackupDir())));
|
||||
_contentManager->addBackupHandler(BackupHandlerPointer(new ContentSettingsBackupHandler(_settingsManager)));
|
||||
_contentManager->initialize(true);
|
||||
|
||||
qDebug() << "Existing backups:";
|
||||
|
|
|
@ -111,6 +111,11 @@ public:
|
|||
|
||||
void debugDumpGroupsState();
|
||||
|
||||
QJsonObject settingsResponseObjectForType(const QString& typeValue, bool isAuthenticated = false,
|
||||
bool includeDomainSettings = true, bool includeContentSettings = true,
|
||||
bool includeDefaults = true, bool isForBackup = false);
|
||||
bool restoreSettingsFromObject(QJsonObject settingsToRestore, SettingsType settingsType);
|
||||
|
||||
signals:
|
||||
void updateNodePermissions();
|
||||
void settingsUpdated();
|
||||
|
@ -130,9 +135,6 @@ private:
|
|||
QStringList _argumentList;
|
||||
|
||||
QJsonArray filteredDescriptionArray(bool isContentSettings);
|
||||
QJsonObject settingsResponseObjectForType(const QString& typeValue, bool isAuthenticated = false,
|
||||
bool includeDomainSettings = true, bool includeContentSettings = true,
|
||||
bool includeDefaults = true, bool isForBackup = false);
|
||||
bool recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject, SettingsType settingsType);
|
||||
|
||||
void updateSetting(const QString& key, const QJsonValue& newValue, QVariantMap& settingMap,
|
||||
|
@ -143,8 +145,6 @@ private:
|
|||
|
||||
void splitSettingsDescription();
|
||||
|
||||
bool restoreSettingsFromObject(QJsonObject settingsToRestore, SettingsType settingsType);
|
||||
|
||||
double _descriptionVersion;
|
||||
|
||||
QJsonArray _descriptionArray;
|
||||
|
|
|
@ -24,28 +24,30 @@ EntitiesBackupHandler::EntitiesBackupHandler(QString entitiesFilePath, QString e
|
|||
{
|
||||
}
|
||||
|
||||
static const QString ENTITIES_BACKUP_FILENAME = "models.json.gz";
|
||||
|
||||
void EntitiesBackupHandler::createBackup(QuaZip& zip) {
|
||||
QFile entitiesFile { _entitiesFilePath };
|
||||
|
||||
if (entitiesFile.open(QIODevice::ReadOnly)) {
|
||||
QuaZipFile zipFile { &zip };
|
||||
zipFile.open(QIODevice::WriteOnly, QuaZipNewInfo("models.json.gz", _entitiesFilePath));
|
||||
zipFile.open(QIODevice::WriteOnly, QuaZipNewInfo(ENTITIES_BACKUP_FILENAME, _entitiesFilePath));
|
||||
zipFile.write(entitiesFile.readAll());
|
||||
zipFile.close();
|
||||
if (zipFile.getZipError() != UNZ_OK) {
|
||||
qCritical() << "Failed to zip models.json.gz: " << zipFile.getZipError();
|
||||
qCritical().nospace() << "Failed to zip " << ENTITIES_BACKUP_FILENAME << ": " << zipFile.getZipError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EntitiesBackupHandler::recoverBackup(QuaZip& zip) {
|
||||
if (!zip.setCurrentFile("models.json.gz")) {
|
||||
qWarning() << "Failed to find models.json.gz while recovering backup";
|
||||
if (!zip.setCurrentFile(ENTITIES_BACKUP_FILENAME)) {
|
||||
qWarning() << "Failed to find" << ENTITIES_BACKUP_FILENAME << "while recovering backup";
|
||||
return;
|
||||
}
|
||||
QuaZipFile zipFile { &zip };
|
||||
if (!zipFile.open(QIODevice::ReadOnly)) {
|
||||
qCritical() << "Failed to open models.json.gz in backup";
|
||||
qCritical() << "Failed to open" << ENTITIES_BACKUP_FILENAME << "in backup";
|
||||
return;
|
||||
}
|
||||
auto rawData = zipFile.readAll();
|
||||
|
@ -61,7 +63,7 @@ void EntitiesBackupHandler::recoverBackup(QuaZip& zip) {
|
|||
data.resetIdAndVersion();
|
||||
|
||||
if (zipFile.getZipError() != UNZ_OK) {
|
||||
qCritical() << "Failed to unzip models.json.gz: " << zipFile.getZipError();
|
||||
qCritical().nospace() << "Failed to unzip " << ENTITIES_BACKUP_FILENAME << ": " << zipFile.getZipError();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue