allow for absolute path handling at entity-server

This commit is contained in:
Stephen Birarda 2016-02-02 14:21:34 -08:00
parent 8e75ce8232
commit cfff765731
3 changed files with 21 additions and 14 deletions

View file

@ -1030,13 +1030,12 @@ void OctreeServer::readConfiguration() {
qDebug() << "wantPersist=" << _wantPersist;
if (_wantPersist) {
QString persistFilename;
if (!readOptionString(QString("persistFilename"), settingsSectionObject, persistFilename)) {
persistFilename = getMyDefaultPersistFilename();
if (!readOptionString("persistFilePath", settingsSectionObject, _persistFilePath)
&& !readOptionString("persistFilename", settingsSectionObject, _persistFilePath)) {
_persistFilePath = getMyDefaultPersistFilename();
}
strcpy(_persistFilename, qPrintable(persistFilename));
qDebug("persistFilename=%s", _persistFilename);
qDebug() << "persistFilePath=" << _persistFilePath;
_persistAsFileType = "json.gz";
@ -1145,8 +1144,16 @@ void OctreeServer::domainSettingsRequestComplete() {
if (_wantPersist) {
// 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
auto persistPath = ServerPathUtils::getDataFilePath("entities/" + QString(_persistFilename));
if (!QFile::exists(persistPath)) {
QDir persistPath { _persistFilePath };
QString absoluteFilePath = persistPath.path();
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);
}
if (!QFile::exists(absoluteFilePath)) {
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";
@ -1154,7 +1161,7 @@ void OctreeServer::domainSettingsRequestComplete() {
// This is the old persist path, based on the current persist filename, which could
// 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.
auto oldDefaultPersistPath = QDir(oldResourcesDirectory).absoluteFilePath(OLD_DEFAULT_PERSIST_FILENAME);
@ -1181,14 +1188,14 @@ void OctreeServer::domainSettingsRequestComplete() {
if (shouldCopy) {
qDebug() << "Old persist file found, copying from " << pathToCopyFrom << " to " << persistPath;
QFile::copy(pathToCopyFrom, persistPath);
QFile::copy(pathToCopyFrom, absoluteFilePath);
} else {
qDebug() << "No existing persist file found";
}
}
// now set up PersistThread
_persistThread = new OctreePersistThread(_tree, persistPath, _persistInterval,
_persistThread = new OctreePersistThread(_tree, absoluteFilePath, _persistInterval,
_wantBackup, _settings, _debugTimestampNow, _persistAsFileType);
_persistThread->initialize(true);
}

View file

@ -169,7 +169,7 @@ protected:
int _statusPort;
QString _statusHost;
char _persistFilename[MAX_FILENAME_LENGTH];
QString _persistFilePath;
QString _persistAsFileType;
int _packetsPerClientPerInterval;
int _packetsTotalPerInterval;

View file

@ -383,9 +383,9 @@
"assignment-types": [6],
"settings": [
{
"name": "persistFilename",
"label": "Entities Filename",
"help": "the path to the file entities are stored in. Make sure the path exists.",
"name": "persistFilePath",
"label": "Entities File Path",
"help": "The path to the file entities are stored in. If path is relative it will be relative to the application data directory.",
"placeholder": "models.json.gz",
"default": "models.json.gz",
"advanced": true