refs #621, adjusted reader to load also from local resource directory

This commit is contained in:
Klaus Basan
2016-03-19 18:52:59 +01:00
parent 468182da4c
commit 706f8c7ae1
2 changed files with 44 additions and 37 deletions

View File

@@ -54,56 +54,63 @@ namespace BlackCore
emit this->setupSynchronized(true);
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Using local bootstrap file: " + this->m_localSetupFileValue);
}
else if (this->m_bootstrapMode == CacheOnly)
m_setup.synchronize(); // make sure it is loaded
if (this->m_bootstrapMode == CacheOnly)
{
m_setup.synchronize();
CGlobalSetup currentSetup = m_setup.getCopy();
this->m_updateInfoUrls = currentSetup.updateInfoFileUrls();
this->m_updateInfoUrls = currentSetup.getUpdateInfoFileUrls();
emit this->setupSynchronized(true);
emit this->updateInfoSynchronized(true);
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Cache only setup, using it as it is");
}
else
this->m_bootstrapUrls.clear(); // clean up previous values
// web URL
if (!this->m_bootstrapUrlFileValue.isEmpty())
{
this->m_bootstrapUrls.clear(); // clean up previous values
// start with the one from cmd args
this->m_bootstrapUrls.push_front(CUrl(this->m_bootstrapUrlFileValue));
}
// web URL
if (!this->m_bootstrapUrlFileValue.isEmpty())
{
// start with the one from cmd args
this->m_bootstrapUrls.push_front(CUrl(this->m_bootstrapUrlFileValue));
}
// if ever loaded add those URLs
m_setup.synchronize();
CGlobalSetup currentSetup = m_setup.getCopy();
if (currentSetup.wasLoaded())
{
if (this->m_bootstrapMode != Explicit || this->m_bootstrapUrls.isEmpty())
{
// also use previously cached URLS
this->m_bootstrapUrls.push_back(currentSetup.bootstrapFileUrls());
}
}
// if ever loaded add those URLs
const CGlobalSetup currentSetup = m_setup.getCopy();
if (this->m_bootstrapMode != Explicit)
{
// also use previously cached URLs
this->m_bootstrapUrls.push_back(currentSetup.getBootstrapFileUrls());
// fail over if still empty
//! \todo do we want to keep this or use a cmd line flag to enable the behaviour. Risk here to use an undesired setup
if (this->m_bootstrapUrls.isEmpty())
{
return CStatusMessage(this, CStatusMessage::SeverityError, "No bootstrap URLs, cannot load setup");
}
else
{
this->m_bootstrapUrls.removeDuplicates();
this->ps_readSetup(); // start reading
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Will start loading setup");
CGlobalSetup resourceSetup(CGlobalSetup::fromJsonFile(
CProject::getBootstrapResourceFile()
));
this->m_bootstrapUrls.push_back(resourceSetup.getBootstrapFileUrls());
}
}
this->m_bootstrapUrls.removeDuplicates(); // clean up
if (this->m_bootstrapUrls.isEmpty())
{
// after all still empty
return CStatusMessage(this, CStatusMessage::SeverityError, "No bootstrap URLs, cannot load setup");
}
else
{
this->ps_readSetup(); // start reading
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Will start loading setup");
}
}
bool CSetupReader::parseCmdLineArguments()
{
this->m_bootstrapUrlFileValue = CGlobalSetup::buildBootstrapFileUrl(
sApp->getParserValue(this->m_cmdBootstrapUrl)
);
sApp->getParserValue(this->m_cmdBootstrapUrl)
);
this->m_bootstrapMode = stringToEnum(sApp->getParserValue(this->m_cmdBootstrapMode));
QUrl url(this->m_bootstrapUrlFileValue);
@@ -254,7 +261,7 @@ namespace BlackCore
else
{
const CGlobalSetup currentSetup = m_setup.get();
this->m_updateInfoUrls = currentSetup.updateInfoFileUrls();
this->m_updateInfoUrls = currentSetup.getUpdateInfoFileUrls();
CGlobalSetup loadedSetup;
loadedSetup.convertFromJson(Json::jsonObjectFromString(setupJson));
loadedSetup.markAsLoaded(true);
@@ -287,7 +294,7 @@ namespace BlackCore
}
else
{
this->m_updateInfoUrls = loadedSetup.updateInfoFileUrls();
this->m_updateInfoUrls = loadedSetup.getUpdateInfoFileUrls();
CLogMessage(this).info("Setup: Updated data cache in %1") << this->m_setup.getFilename();
emit setupSynchronized(true);
return; // success

View File

@@ -117,9 +117,9 @@ namespace BlackCore
bool m_shutdown = false;
std::atomic<bool> m_setupSyncronized { false };
std::atomic<bool> m_updateInfoSyncronized { false };
QString m_localSetupFileValue;
QString m_bootstrapUrlFileValue;
BootstrapMode m_bootstrapMode;
QString m_localSetupFileValue; //! Local file for setup, passed by cmd line arguments
QString m_bootstrapUrlFileValue; //! Bootstrap URL if not local
BootstrapMode m_bootstrapMode; //! How to bootstrap
BlackMisc::Network::CFailoverUrlList m_bootstrapUrls; //!< location of setup files
BlackMisc::Network::CFailoverUrlList m_updateInfoUrls; //!< location of info files
BlackMisc::CData<BlackCore::Data::GlobalSetup> m_setup {this, &CSetupReader::ps_setupChanged}; //!< data cache setup