refs #787, utility functions for shared files

* entity to shared file, shared file for DB Info
* CUrl path function
* removed redundant code in CDbInfo::getEntity() and fixed CEntityFlags::singleEntityByName
This commit is contained in:
Klaus Basan
2016-11-03 01:34:02 +01:00
parent cbcb307748
commit dcaa745e7b
7 changed files with 107 additions and 21 deletions

View File

@@ -101,14 +101,14 @@ namespace BlackCore
QString CGlobalSetup::buildBootstrapFileUrl(const QString &candidate)
{
static const QString version(QString(versionString()).append("/"));
static const QString version(QString(CGlobalSetup::versionString()).append("/"));
if (candidate.endsWith("bootstrap.json")) { return candidate; }
CUrl url(candidate);
if (candidate.contains("/bootstrap"))
{
url.appendPath("bootstrap.json");
}
else if (candidate.endsWith(versionString()) || candidate.endsWith(version))
else if (candidate.endsWith(CGlobalSetup::versionString()) || candidate.endsWith(version))
{
url.appendPath("/bootstrap/bootstrap.json");
}
@@ -123,6 +123,26 @@ namespace BlackCore
return url.getFullUrl();
}
CUrl CGlobalSetup::buildDbDataDirectory(const CUrl &candidate)
{
static const QString version(QString(versionString()).append("/"));
if (candidate.pathEndsWith("dbdata") || candidate.pathEndsWith("dbdata/")) { return candidate; }
CUrl url(candidate);
if (candidate.pathEndsWith(versionString()) || candidate.pathEndsWith(version))
{
url.appendPath("/dbdata");
}
else if (candidate.pathEndsWith("shared") || candidate.pathEndsWith("shared/"))
{
url.appendPath(CGlobalSetup::versionString() + "/dbdata/");
}
else
{
url.appendPath("shared/" + CGlobalSetup::versionString() + "/dbdata/");
}
return url;
}
CGlobalSetup CGlobalSetup::fromJsonFile(const QString &fileNameAndPath)
{
CGlobalSetup setup;
@@ -213,6 +233,10 @@ namespace BlackCore
s.append("FSD test servers: ");
s.append(getFsdTestServers().toQString(i18n));
s.append(separator);
s.append("Crash report server: ");
s.append(getCrashReportServerUrl().toQString(i18n));
return s;
}
@@ -242,12 +266,14 @@ namespace BlackCore
return CVariant::fromValue(this->m_vatsimMetarsUrls);
case IndexUpdateInfo:
return CVariant::fromValue(this->getUpdateInfoFileUrls());
case IndexBootstrap:
case IndexBootstrapFileUrls:
return CVariant::fromValue(this->getBootstrapFileUrls());
case IndexSwiftDbFiles:
return CVariant::fromValue(this->getSwiftDbDataFileLocationUrls());
case IndexShared:
case IndexSharedUrls:
return CVariant::fromValue(this->m_sharedUrls);
case IndexCrashReportServerUrl:
return CVariant::fromValue(this->m_crashReportServerUrl);
case IndexWasLoaded:
return CVariant::fromValue(this->m_wasLoaded);
default:
@@ -287,9 +313,12 @@ namespace BlackCore
case IndexVatsimMetars:
this->m_vatsimMetarsUrls = variant.value<CUrlList>();
break;
case IndexShared:
case IndexSharedUrls:
this->m_sharedUrls = variant.value<CUrlList>();
break;
case IndexCrashReportServerUrl:
this->m_crashReportServerUrl = variant.value<CUrl>();
break;
case IndexWasLoaded:
this->m_wasLoaded = variant.toBool();
break;

View File

@@ -49,10 +49,11 @@ namespace BlackCore
IndexVatsimMetars,
IndexVatsimData,
IndexSwiftDbFiles,
IndexBootstrap,
IndexBootstrapFileUrls,
IndexCrashReportServerUrl,
IndexUpdateInfo,
IndexWasLoaded,
IndexShared
IndexSharedUrls
};
//! Default constructor
@@ -83,7 +84,7 @@ namespace BlackCore
bool hasSameType(const CGlobalSetup &otherSetup) const;
//! Crash report server url
BlackMisc::Network::CUrl getCrashreportServerUrl() const { return m_crashreportServerUrl; }
BlackMisc::Network::CUrl getCrashReportServerUrl() const { return m_crashReportServerUrl; }
//! Home page url
BlackMisc::Network::CUrl getDbHomePageUrl() const;
@@ -166,6 +167,9 @@ namespace BlackCore
//! Build bootstrap file URL
static QString buildBootstrapFileUrl(const QString &candidate);
//! Build the full dbdata directory URL
static BlackMisc::Network::CUrl buildDbDataDirectory(const BlackMisc::Network::CUrl &candidate);
//! Object initialized by JSON file
static CGlobalSetup fromJsonFile(const QString &fileNameAndPath);
@@ -174,7 +178,7 @@ namespace BlackCore
int m_dbHttpPort = 80; //!< port
int m_dbHttpsPort = 443; //!< SSL port
bool m_development = false; //!< dev. version?
BlackMisc::Network::CUrl m_crashreportServerUrl; //!< crash report server
BlackMisc::Network::CUrl m_crashReportServerUrl; //!< crash report server
BlackMisc::Network::CUrl m_dbRootDirectoryUrl; //!< Root directory of DB
BlackMisc::Network::CUrl m_vatsimBookingsUrl; //!< ATC bookings
BlackMisc::Network::CUrlList m_vatsimMetarsUrls; //!< METAR data
@@ -191,7 +195,7 @@ namespace BlackCore
CGlobalSetup,
BLACK_METAMEMBER(wasLoaded),
BLACK_METAMEMBER(timestampMSecsSinceEpoch),
BLACK_METAMEMBER(crashreportServerUrl),
BLACK_METAMEMBER(crashReportServerUrl),
BLACK_METAMEMBER(dbRootDirectoryUrl),
BLACK_METAMEMBER(dbHttpPort),
BLACK_METAMEMBER(dbHttpsPort),