mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 07:53:08 +02:00
Merge pull request #7019 from birarda/absolute-paths
allow absolute path to entity-server persist file
This commit is contained in:
commit
3c9043987f
4 changed files with 75 additions and 21 deletions
|
@ -289,6 +289,8 @@ void OctreeServer::initHTTPManager(int port) {
|
||||||
_httpManager = new HTTPManager(QHostAddress::AnyIPv4, port, documentRoot, this, this);
|
_httpManager = new HTTPManager(QHostAddress::AnyIPv4, port, documentRoot, this, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString PERSIST_FILE_DOWNLOAD_PATH = "/models.json.gz";
|
||||||
|
|
||||||
bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) {
|
bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url, bool skipSubHandler) {
|
||||||
|
|
||||||
#ifdef FORCE_CRASH
|
#ifdef FORCE_CRASH
|
||||||
|
@ -310,7 +312,6 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool showStats = false;
|
bool showStats = false;
|
||||||
QString persistFile = "/" + getPersistFilename();
|
|
||||||
|
|
||||||
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
if (connection->requestOperation() == QNetworkAccessManager::GetOperation) {
|
||||||
if (url.path() == "/") {
|
if (url.path() == "/") {
|
||||||
|
@ -320,7 +321,7 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
_tree->resetEditStats();
|
_tree->resetEditStats();
|
||||||
resetSendingStats();
|
resetSendingStats();
|
||||||
showStats = true;
|
showStats = true;
|
||||||
} else if ((url.path() == persistFile) || (url.path() == persistFile + "/")) {
|
} else if ((url.path() == PERSIST_FILE_DOWNLOAD_PATH) || (url.path() == PERSIST_FILE_DOWNLOAD_PATH + "/")) {
|
||||||
if (_persistFileDownload) {
|
if (_persistFileDownload) {
|
||||||
QByteArray persistFileContents = getPersistFileContents();
|
QByteArray persistFileContents = getPersistFileContents();
|
||||||
if (persistFileContents.length() > 0) {
|
if (persistFileContents.length() > 0) {
|
||||||
|
@ -374,9 +375,9 @@ bool OctreeServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
|
||||||
statsString += "\r\n";
|
statsString += "\r\n";
|
||||||
|
|
||||||
if (_persistFileDownload) {
|
if (_persistFileDownload) {
|
||||||
statsString += QString("Persist file: <a href='%1'>%1</a>\r\n").arg(persistFile);
|
statsString += QString("Persist file: <a href='%1'>Click to Download</a>\r\n").arg(PERSIST_FILE_DOWNLOAD_PATH);
|
||||||
} else {
|
} else {
|
||||||
statsString += QString("Persist file: %1\r\n").arg(persistFile);
|
statsString += QString("Persist file: %1\r\n").arg(_persistFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1030,13 +1031,12 @@ void OctreeServer::readConfiguration() {
|
||||||
qDebug() << "wantPersist=" << _wantPersist;
|
qDebug() << "wantPersist=" << _wantPersist;
|
||||||
|
|
||||||
if (_wantPersist) {
|
if (_wantPersist) {
|
||||||
QString persistFilename;
|
if (!readOptionString("persistFilePath", settingsSectionObject, _persistFilePath)
|
||||||
if (!readOptionString(QString("persistFilename"), settingsSectionObject, persistFilename)) {
|
&& !readOptionString("persistFilename", settingsSectionObject, _persistFilePath)) {
|
||||||
persistFilename = getMyDefaultPersistFilename();
|
_persistFilePath = getMyDefaultPersistFilename();
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(_persistFilename, qPrintable(persistFilename));
|
qDebug() << "persistFilePath=" << _persistFilePath;
|
||||||
qDebug("persistFilename=%s", _persistFilename);
|
|
||||||
|
|
||||||
_persistAsFileType = "json.gz";
|
_persistAsFileType = "json.gz";
|
||||||
|
|
||||||
|
@ -1145,8 +1145,26 @@ void OctreeServer::domainSettingsRequestComplete() {
|
||||||
if (_wantPersist) {
|
if (_wantPersist) {
|
||||||
// If persist filename does not exist, let's see if there is one beside the application binary
|
// If persist filename does not exist, let's see if there is one beside the application binary
|
||||||
// If there is, let's copy it over to our target persist directory
|
// If there is, let's copy it over to our target persist directory
|
||||||
auto persistPath = ServerPathUtils::getDataFilePath("entities/" + QString(_persistFilename));
|
QDir persistPath { _persistFilePath };
|
||||||
if (!QFile::exists(persistPath)) {
|
QString absoluteFilePath = persistPath.absolutePath();
|
||||||
|
|
||||||
|
if (persistPath.isRelative()) {
|
||||||
|
// if the domain settings passed us a relative path, make an absolute path that is relative to the
|
||||||
|
// default data directory
|
||||||
|
absoluteFilePath = QDir(ServerPathUtils::getDataFilePath("entities/")).absoluteFilePath(_persistFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const QString ENTITY_PERSIST_EXTENSION = ".json.gz";
|
||||||
|
|
||||||
|
// force the persist file to end with .json.gz
|
||||||
|
if (!absoluteFilePath.endsWith(ENTITY_PERSIST_EXTENSION, Qt::CaseInsensitive)) {
|
||||||
|
absoluteFilePath += ENTITY_PERSIST_EXTENSION;
|
||||||
|
} else {
|
||||||
|
// make sure the casing of .json.gz is correct
|
||||||
|
absoluteFilePath.replace(ENTITY_PERSIST_EXTENSION, ENTITY_PERSIST_EXTENSION, Qt::CaseInsensitive);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!QFile::exists(absoluteFilePath)) {
|
||||||
qDebug() << "Persist file does not exist, checking for existence of persist file next to application";
|
qDebug() << "Persist file does not exist, checking for existence of persist file next to application";
|
||||||
|
|
||||||
static const QString OLD_DEFAULT_PERSIST_FILENAME = "resources/models.json.gz";
|
static const QString OLD_DEFAULT_PERSIST_FILENAME = "resources/models.json.gz";
|
||||||
|
@ -1154,7 +1172,7 @@ void OctreeServer::domainSettingsRequestComplete() {
|
||||||
|
|
||||||
// This is the old persist path, based on the current persist filename, which could
|
// This is the old persist path, based on the current persist filename, which could
|
||||||
// be a custom filename set by the user.
|
// be a custom filename set by the user.
|
||||||
auto oldPersistPath = QDir(oldResourcesDirectory).absoluteFilePath(_persistFilename);
|
auto oldPersistPath = QDir(oldResourcesDirectory).absoluteFilePath(_persistFilePath);
|
||||||
|
|
||||||
// This is the old default persist path.
|
// This is the old default persist path.
|
||||||
auto oldDefaultPersistPath = QDir(oldResourcesDirectory).absoluteFilePath(OLD_DEFAULT_PERSIST_FILENAME);
|
auto oldDefaultPersistPath = QDir(oldResourcesDirectory).absoluteFilePath(OLD_DEFAULT_PERSIST_FILENAME);
|
||||||
|
@ -1172,23 +1190,24 @@ void OctreeServer::domainSettingsRequestComplete() {
|
||||||
pathToCopyFrom = oldDefaultPersistPath;
|
pathToCopyFrom = oldDefaultPersistPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir persistFileDirectory = QDir(persistPath).filePath("..");
|
QDir persistFileDirectory { QDir::cleanPath(absoluteFilePath + "/..") };
|
||||||
|
|
||||||
if (!persistFileDirectory.exists()) {
|
if (!persistFileDirectory.exists()) {
|
||||||
qDebug() << "Creating data directory " << persistFileDirectory.absolutePath();
|
qDebug() << "Creating data directory " << persistFileDirectory.absolutePath();
|
||||||
persistFileDirectory.mkpath(".");
|
persistFileDirectory.mkpath(".");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldCopy) {
|
if (shouldCopy) {
|
||||||
qDebug() << "Old persist file found, copying from " << pathToCopyFrom << " to " << persistPath;
|
qDebug() << "Old persist file found, copying from " << pathToCopyFrom << " to " << absoluteFilePath;
|
||||||
|
|
||||||
QFile::copy(pathToCopyFrom, persistPath);
|
QFile::copy(pathToCopyFrom, absoluteFilePath);
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "No existing persist file found";
|
qDebug() << "No existing persist file found";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now set up PersistThread
|
// now set up PersistThread
|
||||||
_persistThread = new OctreePersistThread(_tree, persistPath, _persistInterval,
|
_persistThread = new OctreePersistThread(_tree, absoluteFilePath, _persistInterval,
|
||||||
_wantBackup, _settings, _debugTimestampNow, _persistAsFileType);
|
_wantBackup, _settings, _debugTimestampNow, _persistAsFileType);
|
||||||
_persistThread->initialize(true);
|
_persistThread->initialize(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ protected:
|
||||||
int _statusPort;
|
int _statusPort;
|
||||||
QString _statusHost;
|
QString _statusHost;
|
||||||
|
|
||||||
char _persistFilename[MAX_FILENAME_LENGTH];
|
QString _persistFilePath;
|
||||||
QString _persistAsFileType;
|
QString _persistAsFileType;
|
||||||
int _packetsPerClientPerInterval;
|
int _packetsPerClientPerInterval;
|
||||||
int _packetsTotalPerInterval;
|
int _packetsTotalPerInterval;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"version": 1.0,
|
"version": 1.1,
|
||||||
"settings": [
|
"settings": [
|
||||||
{
|
{
|
||||||
"name": "metaverse",
|
"name": "metaverse",
|
||||||
|
@ -383,9 +383,9 @@
|
||||||
"assignment-types": [6],
|
"assignment-types": [6],
|
||||||
"settings": [
|
"settings": [
|
||||||
{
|
{
|
||||||
"name": "persistFilename",
|
"name": "persistFilePath",
|
||||||
"label": "Entities Filename",
|
"label": "Entities File Path",
|
||||||
"help": "the path to the file entities are stored in. Make sure the path exists.",
|
"help": "The path to the file entities are stored in. If this path is relative it will be relative to the application data directory. The filename must end in .json.gz.",
|
||||||
"placeholder": "models.json.gz",
|
"placeholder": "models.json.gz",
|
||||||
"default": "models.json.gz",
|
"default": "models.json.gz",
|
||||||
"advanced": true
|
"advanced": true
|
||||||
|
|
|
@ -124,6 +124,41 @@ void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList
|
||||||
// reload the master and user config so that the merged config is right
|
// reload the master and user config so that the merged config is right
|
||||||
_configMap.loadMasterAndUserConfig(argumentList);
|
_configMap.loadMasterAndUserConfig(argumentList);
|
||||||
}
|
}
|
||||||
|
} else if (oldVersion < 1.1) {
|
||||||
|
static const QString ENTITY_SERVER_SETTINGS_KEY = "entity_server_settings";
|
||||||
|
static const QString ENTITY_FILE_NAME_KEY = "persistFilename";
|
||||||
|
static const QString ENTITY_FILE_PATH_KEYPATH = ENTITY_SERVER_SETTINGS_KEY + ".persistFilePath";
|
||||||
|
|
||||||
|
// this was prior to change of poorly named entitiesFileName to entitiesFilePath
|
||||||
|
QVariant* persistFileNameVariant = valueForKeyPath(_configMap.getMergedConfig(),
|
||||||
|
ENTITY_SERVER_SETTINGS_KEY + "." + ENTITY_FILE_NAME_KEY);
|
||||||
|
if (persistFileNameVariant && persistFileNameVariant->canConvert(QMetaType::QString)) {
|
||||||
|
QString persistFileName = persistFileNameVariant->toString();
|
||||||
|
|
||||||
|
qDebug() << "Migrating persistFilename to persistFilePath for entity-server settings";
|
||||||
|
|
||||||
|
// grab the persistFilePath option, create it if it doesn't exist
|
||||||
|
QVariant* persistFilePath = valueForKeyPath(_configMap.getUserConfig(), ENTITY_FILE_PATH_KEYPATH, true);
|
||||||
|
|
||||||
|
// write the migrated value
|
||||||
|
*persistFilePath = persistFileName;
|
||||||
|
|
||||||
|
// remove the old setting
|
||||||
|
QVariant* entityServerVariant = valueForKeyPath(_configMap.getUserConfig(), ENTITY_SERVER_SETTINGS_KEY);
|
||||||
|
if (entityServerVariant && entityServerVariant->canConvert(QMetaType::QVariantMap)) {
|
||||||
|
QVariantMap entityServerMap = entityServerVariant->toMap();
|
||||||
|
entityServerMap.remove(ENTITY_FILE_NAME_KEY);
|
||||||
|
|
||||||
|
*entityServerVariant = entityServerMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write the new settings to the json file
|
||||||
|
persistToFile();
|
||||||
|
|
||||||
|
// reload the master and user config so that the merged config is right
|
||||||
|
_configMap.loadMasterAndUserConfig(argumentList);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue