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); emit this->setupSynchronized(true);
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Using local bootstrap file: " + this->m_localSetupFileValue); 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(); CGlobalSetup currentSetup = m_setup.getCopy();
this->m_updateInfoUrls = currentSetup.updateInfoFileUrls(); this->m_updateInfoUrls = currentSetup.getUpdateInfoFileUrls();
emit this->setupSynchronized(true); emit this->setupSynchronized(true);
emit this->updateInfoSynchronized(true); emit this->updateInfoSynchronized(true);
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Cache only setup, using it as it is"); 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 ever loaded add those URLs
if (!this->m_bootstrapUrlFileValue.isEmpty()) const CGlobalSetup currentSetup = m_setup.getCopy();
{ if (this->m_bootstrapMode != Explicit)
// start with the one from cmd args {
this->m_bootstrapUrls.push_front(CUrl(this->m_bootstrapUrlFileValue)); // also use previously cached URLs
} this->m_bootstrapUrls.push_back(currentSetup.getBootstrapFileUrls());
// 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());
}
}
// 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()) if (this->m_bootstrapUrls.isEmpty())
{ {
return CStatusMessage(this, CStatusMessage::SeverityError, "No bootstrap URLs, cannot load setup"); CGlobalSetup resourceSetup(CGlobalSetup::fromJsonFile(
} CProject::getBootstrapResourceFile()
else ));
{ this->m_bootstrapUrls.push_back(resourceSetup.getBootstrapFileUrls());
this->m_bootstrapUrls.removeDuplicates();
this->ps_readSetup(); // start reading
return CStatusMessage(this, CStatusMessage::SeverityInfo, "Will start loading setup");
} }
} }
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() bool CSetupReader::parseCmdLineArguments()
{ {
this->m_bootstrapUrlFileValue = CGlobalSetup::buildBootstrapFileUrl( this->m_bootstrapUrlFileValue = CGlobalSetup::buildBootstrapFileUrl(
sApp->getParserValue(this->m_cmdBootstrapUrl) sApp->getParserValue(this->m_cmdBootstrapUrl)
); );
this->m_bootstrapMode = stringToEnum(sApp->getParserValue(this->m_cmdBootstrapMode)); this->m_bootstrapMode = stringToEnum(sApp->getParserValue(this->m_cmdBootstrapMode));
QUrl url(this->m_bootstrapUrlFileValue); QUrl url(this->m_bootstrapUrlFileValue);
@@ -254,7 +261,7 @@ namespace BlackCore
else else
{ {
const CGlobalSetup currentSetup = m_setup.get(); const CGlobalSetup currentSetup = m_setup.get();
this->m_updateInfoUrls = currentSetup.updateInfoFileUrls(); this->m_updateInfoUrls = currentSetup.getUpdateInfoFileUrls();
CGlobalSetup loadedSetup; CGlobalSetup loadedSetup;
loadedSetup.convertFromJson(Json::jsonObjectFromString(setupJson)); loadedSetup.convertFromJson(Json::jsonObjectFromString(setupJson));
loadedSetup.markAsLoaded(true); loadedSetup.markAsLoaded(true);
@@ -287,7 +294,7 @@ namespace BlackCore
} }
else else
{ {
this->m_updateInfoUrls = loadedSetup.updateInfoFileUrls(); this->m_updateInfoUrls = loadedSetup.getUpdateInfoFileUrls();
CLogMessage(this).info("Setup: Updated data cache in %1") << this->m_setup.getFilename(); CLogMessage(this).info("Setup: Updated data cache in %1") << this->m_setup.getFilename();
emit setupSynchronized(true); emit setupSynchronized(true);
return; // success return; // success

View File

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