mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 17:35:34 +08:00
Ref T28, removed areModelFilesUpdated and info if loading was from cache
* removed CacheUntilNewer * did not really work and had some problems * cache timestamp not really a good value to compare with * too slow with remote file
This commit is contained in:
committed by
Mathew Sutcliffe
parent
6fc48ab160
commit
c3ed0bc394
@@ -69,11 +69,14 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void IAircraftModelLoader::ps_loadFinished(const CStatusMessage &status, const BlackMisc::Simulation::CSimulatorInfo &simulator)
|
||||
void IAircraftModelLoader::ps_loadFinished(const CStatusMessage &status, const BlackMisc::Simulation::CSimulatorInfo &simulator, LoadFinishedInfo info)
|
||||
{
|
||||
Q_UNUSED(info);
|
||||
|
||||
// remark: in the past status used to be bool, now it is CStatusMessage
|
||||
// so there is some redundancy here between status and m_loadingMessages
|
||||
this->m_loadingInProgress = false;
|
||||
|
||||
if (this->m_loadingMessages.hasWarningOrErrorMessages())
|
||||
{
|
||||
CLogMessage::preformatted(this->m_loadingMessages);
|
||||
@@ -87,7 +90,7 @@ namespace BlackMisc
|
||||
void IAircraftModelLoader::ps_cacheChanged(const CSimulatorInfo &simInfo)
|
||||
{
|
||||
static const CStatusMessage status(this, CStatusMessage::SeverityInfo, "Cached changed");
|
||||
emit this->loadingFinished(status, simInfo);
|
||||
emit this->loadingFinished(status, simInfo, CacheLoaded);
|
||||
}
|
||||
|
||||
QStringList IAircraftModelLoader::getModelDirectoriesOrDefault() const
|
||||
@@ -139,20 +142,11 @@ namespace BlackMisc
|
||||
const bool useCachedData = !mode.testFlag(CacheSkipped) && this->hasCachedData();
|
||||
if (useCachedData && (mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly)))
|
||||
{
|
||||
// we just jus cache data
|
||||
static const CStatusMessage status(this, CStatusMessage::SeverityInfo, "Using cached data");
|
||||
emit loadingFinished(status, this->getSimulator());
|
||||
emit loadingFinished(status, this->getSimulator(), CacheLoaded);
|
||||
return;
|
||||
}
|
||||
else if (useCachedData && mode.testFlag(CacheUntilNewer))
|
||||
{
|
||||
//! \todo currently too slow with remote files, does not make sense with that overhead
|
||||
if (!this->areModelFilesUpdated())
|
||||
{
|
||||
static const CStatusMessage status(this, CStatusMessage::SeverityInfo, "No updated model files");
|
||||
emit loadingFinished(status, this->getSimulator());
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mode.testFlag(CacheOnly))
|
||||
{
|
||||
// only cache, but we did not find any data yet (still in progress?)
|
||||
|
||||
@@ -57,15 +57,21 @@ namespace BlackMisc
|
||||
NotSet = 0,
|
||||
LoadDirectly = 1 << 0, //!< load syncronously (blocking), normally for testing
|
||||
LoadInBackground = 1 << 1, //!< load in background, asyncronously
|
||||
CacheUntilNewer = 1 << 2, //!< use cache until newer data re available
|
||||
CacheFirst = 1 << 3, //!< always use cache (if it has data)
|
||||
CacheSkipped = 1 << 4, //!< ignore cache
|
||||
CacheOnly = 1 << 5, //!< only read cache, never load from disk
|
||||
CacheFirst = 1 << 2, //!< always use cache (if it has data)
|
||||
CacheSkipped = 1 << 3, //!< ignore cache
|
||||
CacheOnly = 1 << 4, //!< only read cache, never load from disk
|
||||
InBackgroundWithCache = LoadInBackground | CacheFirst, //!< Background, cached
|
||||
InBackgroundNoCache = LoadInBackground | CacheSkipped //!< Background, not cached
|
||||
};
|
||||
Q_DECLARE_FLAGS(LoadMode, LoadModeFlag)
|
||||
|
||||
//! Load mode
|
||||
enum LoadFinishedInfo
|
||||
{
|
||||
CacheLoaded, //!< cache was loaded
|
||||
ParsedData //!< parsed data
|
||||
};
|
||||
|
||||
//! Destructor
|
||||
virtual ~IAircraftModelLoader();
|
||||
|
||||
@@ -98,9 +104,6 @@ namespace BlackMisc
|
||||
//! Count of loaded models
|
||||
int getAircraftModelsCount() const { return getAircraftModels().size(); }
|
||||
|
||||
//! Model files updated?
|
||||
virtual bool areModelFilesUpdated() const = 0;
|
||||
|
||||
//! Which simulator is supported by that very loader
|
||||
const CSimulatorInfo getSimulator() const;
|
||||
|
||||
@@ -155,7 +158,7 @@ namespace BlackMisc
|
||||
|
||||
signals:
|
||||
//! Parsing is finished or cache has been loaded
|
||||
void loadingFinished(const BlackMisc::CStatusMessage &status, const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
void loadingFinished(const BlackMisc::CStatusMessage &status, const BlackMisc::Simulation::CSimulatorInfo &simulator, LoadFinishedInfo info);
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
@@ -181,7 +184,7 @@ namespace BlackMisc
|
||||
|
||||
protected slots:
|
||||
//! Loading finished, also logs messages
|
||||
void ps_loadFinished(const CStatusMessage &status, const CSimulatorInfo &simulator);
|
||||
void ps_loadFinished(const CStatusMessage &status, const CSimulatorInfo &simulator, LoadFinishedInfo info);
|
||||
|
||||
//! A cache has been changed
|
||||
void ps_cacheChanged(const CSimulatorInfo &simInfo);
|
||||
@@ -191,6 +194,7 @@ namespace BlackMisc
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::IAircraftModelLoader::LoadMode)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::IAircraftModelLoader::LoadModeFlag)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::IAircraftModelLoader::LoadFinishedInfo)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::IAircraftModelLoader::LoadMode)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -105,13 +105,13 @@ namespace BlackMisc
|
||||
this->setCachedModels(models, simulator); // not thread safe
|
||||
}
|
||||
// currently I treat no data as error
|
||||
emit this->loadingFinished(hasData ? statusLoadingOk : statusLoadingError, simulator);
|
||||
emit this->loadingFinished(hasData ? statusLoadingOk : statusLoadingError, simulator, ParsedData);
|
||||
}
|
||||
else
|
||||
{
|
||||
CStatusMessage status = this->m_loadingMessages.toSingleMessage();
|
||||
status.setSeverity(CStatusMessage::SeverityError);
|
||||
emit this->loadingFinished(status, simulator);
|
||||
emit this->loadingFinished(status, simulator, ParsedData);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace BlackMisc
|
||||
this->setCachedModels(models); // not thread safe
|
||||
}
|
||||
// currently I treat no data as error
|
||||
emit this->loadingFinished(hasData ? statusLoadingOk : statusLoadingError, simulator);
|
||||
emit this->loadingFinished(hasData ? statusLoadingOk : statusLoadingError, simulator, ParsedData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,16 +137,6 @@ namespace BlackMisc
|
||||
return !m_parserWorker || m_parserWorker->isFinished();
|
||||
}
|
||||
|
||||
bool CAircraftCfgParser::areModelFilesUpdated() const
|
||||
{
|
||||
const QDateTime cacheTs(getCacheTimestamp());
|
||||
if (!cacheTs.isValid()) { return true; }
|
||||
return CFileUtils::containsFileNewerThan(
|
||||
cacheTs,
|
||||
this->m_settings.getFirstModelDirectoryOrDefault(this->getSimulator()),
|
||||
true, { fileFilter() }, this->getModelExcludeDirectoryPatterns());
|
||||
}
|
||||
|
||||
CAircraftCfgEntriesList CAircraftCfgParser::performParsing(const QString &directory, const QStringList &excludeDirectories, CStatusMessageList &messages, bool *ok)
|
||||
{
|
||||
//
|
||||
|
||||
@@ -52,7 +52,6 @@ namespace BlackMisc
|
||||
//! \name Interface functions
|
||||
//! @{
|
||||
virtual bool isLoadingFinished() const override;
|
||||
virtual bool areModelFilesUpdated() const override;
|
||||
//! @}
|
||||
|
||||
//! Create an parser object for given simulator
|
||||
|
||||
@@ -132,7 +132,7 @@ namespace BlackMisc
|
||||
if (modelDirectory.isEmpty())
|
||||
{
|
||||
this->clearCache();
|
||||
emit loadingFinished(CStatusMessage(this, CStatusMessage::SeverityError, "Model directory '%1' is empty") << modelDirectory, simulator);
|
||||
emit loadingFinished(CStatusMessage(this, CStatusMessage::SeverityError, "Model directory '%1' is empty") << modelDirectory, simulator, ParsedData);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -163,19 +163,10 @@ namespace BlackMisc
|
||||
return !m_parserWorker || m_parserWorker->isFinished();
|
||||
}
|
||||
|
||||
bool CAircraftModelLoaderXPlane::areModelFilesUpdated() const
|
||||
{
|
||||
const QDateTime cacheTs(getCacheTimestamp());
|
||||
if (!cacheTs.isValid()) { return true; }
|
||||
return CFileUtils::containsFileNewerThan(
|
||||
cacheTs, this->getFirstModelDirectoryOrDefault(),
|
||||
true, {fileFilterCsl(), fileFilterFlyable()}, this->getModelExcludeDirectoryPatterns());
|
||||
}
|
||||
|
||||
void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models)
|
||||
{
|
||||
this->setCachedModels(models);
|
||||
emit loadingFinished(CStatusMessage(this, CStatusMessage::SeverityInfo, "Updated '%1' models") << models.size(), this->getSimulator());
|
||||
emit loadingFinished(CStatusMessage(this, CStatusMessage::SeverityInfo, "Updated '%1' models") << models.size(), this->getSimulator(), ParsedData);
|
||||
}
|
||||
|
||||
QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const
|
||||
@@ -386,7 +377,7 @@ namespace BlackMisc
|
||||
return false;
|
||||
}
|
||||
|
||||
auto p = std::find_if(m_cslPackages.cbegin(), m_cslPackages.cend(), [&tokens](const CSLPackage &p) { return p.name == tokens[1]; });
|
||||
auto p = std::find_if(m_cslPackages.cbegin(), m_cslPackages.cend(), [&tokens](const CSLPackage & p) { return p.name == tokens[1]; });
|
||||
if (p == m_cslPackages.cend())
|
||||
{
|
||||
package.path = path;
|
||||
@@ -409,7 +400,7 @@ namespace BlackMisc
|
||||
return false;
|
||||
}
|
||||
|
||||
if (std::count_if(m_cslPackages.cbegin(), m_cslPackages.cend(), [&tokens](const CSLPackage &p) { return p.name == tokens[1]; }) == 0)
|
||||
if (std::count_if(m_cslPackages.cbegin(), m_cslPackages.cend(), [&tokens](const CSLPackage & p) { return p.name == tokens[1]; }) == 0)
|
||||
{
|
||||
CLogMessage(this).warning("WARNING: required package %1 not found. Aborting processing of this package.") << tokens[1];
|
||||
return false;
|
||||
|
||||
@@ -50,7 +50,6 @@ namespace BlackMisc
|
||||
//! \name Interface functions
|
||||
//! @{
|
||||
virtual bool isLoadingFinished() const override;
|
||||
virtual bool areModelFilesUpdated() const override;
|
||||
//! @}
|
||||
|
||||
public slots:
|
||||
|
||||
Reference in New Issue
Block a user