14namespace swift::misc::simulation::data
36 return allModels.
size();
41 static const QString is(
"P3D: %1 XP: %2 FG: %3");
49 static const QString is(
"P3D: %1, MSFS: %2, MSFS2024: %3");
57 static const QString s(
"%1 models, ts: %2");
72 case CSimulatorInfo::P3D: m_syncP3D =
synchronized;
break;
73 case CSimulatorInfo::XPLANE: m_syncXPlane =
synchronized;
break;
74 case CSimulatorInfo::FG: m_syncFG =
synchronized;
break;
75 case CSimulatorInfo::MSFS: m_syncMsfs =
synchronized;
break;
76 case CSimulatorInfo::MSFS2024: m_syncMsfs2024 =
synchronized;
break;
77 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
break;
146 if (singleSimFile.
isEmpty())
continue;
148 if (singleSimFileName == compareFileName)
178 if (ts.
isValid() && ts > outdated)
180 withInitializedCache.
add(simInfo);
183 return withInitializedCache;
193 withModels.
add(simInfo);
205 this->synchronizeCacheImpl(sim);
210 if (this->admitCacheImpl(sim))
228 case CSimulatorInfo::P3D:
return m_modelCacheP3D.get();
229 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.get();
230 case CSimulatorInfo::FG:
return m_modelCacheFG.get();
231 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.get();
232 case CSimulatorInfo::MSFS2024:
return m_modelCacheMsfs2024.get();
233 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
return {};
246 case CSimulatorInfo::P3D: msg = m_modelCacheP3D.set(setModels);
break;
247 case CSimulatorInfo::XPLANE: msg = m_modelCacheXP.set(setModels);
break;
248 case CSimulatorInfo::FG: msg = m_modelCacheFG.set(setModels);
break;
249 case CSimulatorInfo::MSFS: msg = m_modelCacheMsfs.set(setModels);
break;
250 case CSimulatorInfo::MSFS2024: msg = m_modelCacheMsfs2024.set(setModels);
break;
251 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
return {};
268 case CSimulatorInfo::P3D:
return m_syncP3D;
269 case CSimulatorInfo::XPLANE:
return m_syncXPlane;
270 case CSimulatorInfo::FG:
return m_syncFG;
271 case CSimulatorInfo::MSFS:
return m_syncMsfs;
272 case CSimulatorInfo::MSFS2024:
return m_syncMsfs2024;
273 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
break;
299 case CSimulatorInfo::P3D:
return m_modelCacheP3D.getAvailableTimestamp();
300 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.getAvailableTimestamp();
301 case CSimulatorInfo::FG:
return m_modelCacheFG.getAvailableTimestamp();
302 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.getAvailableTimestamp();
303 case CSimulatorInfo::MSFS2024:
return m_modelCacheMsfs2024.getAvailableTimestamp();
304 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
return {};
317 case CSimulatorInfo::P3D:
return m_modelCacheP3D.set(m_modelCacheP3D.get(), ts.
toMSecsSinceEpoch());
318 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.set(m_modelCacheXP.get(), ts.
toMSecsSinceEpoch());
319 case CSimulatorInfo::FG:
return m_modelCacheFG.set(m_modelCacheFG.get(), ts.
toMSecsSinceEpoch());
320 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.set(m_modelCacheMsfs.get(), ts.
toMSecsSinceEpoch());
321 case CSimulatorInfo::MSFS2024:
322 return m_modelCacheMsfs2024.set(m_modelCacheMsfs2024.get(), ts.
toMSecsSinceEpoch());
323 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong simulator");
break;
337 case CSimulatorInfo::P3D:
return m_modelCacheP3D.getFilename();
338 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.getFilename();
339 case CSimulatorInfo::FG:
return m_modelCacheFG.getFilename();
340 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.getFilename();
341 case CSimulatorInfo::MSFS2024:
return m_modelCacheMsfs2024.getFilename();
342 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
break;
352 case CSimulatorInfo::P3D:
return m_modelCacheP3D.isSaved();
353 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.isSaved();
354 case CSimulatorInfo::FG:
return m_modelCacheFG.isSaved();
355 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.isSaved();
356 case CSimulatorInfo::MSFS2024:
return m_modelCacheMsfs2024.isSaved();
357 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
break;
362 void CModelCaches::synchronizeCacheImpl(
const CSimulatorInfo &simulator)
372 case CSimulatorInfo::P3D: m_modelCacheP3D.synchronize();
break;
373 case CSimulatorInfo::XPLANE: m_modelCacheXP.synchronize();
break;
374 case CSimulatorInfo::FG: m_modelCacheFG.synchronize();
break;
375 case CSimulatorInfo::MSFS: m_modelCacheMsfs.synchronize();
break;
376 case CSimulatorInfo::MSFS2024: m_modelCacheMsfs2024.synchronize();
break;
377 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
break;
383 bool CModelCaches::admitCacheImpl(
const CSimulatorInfo &simulator)
385 Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO,
"No single simulator");
391 switch (simulator.getSimulator())
393 case CSimulatorInfo::P3D: m_modelCacheP3D.admit();
break;
394 case CSimulatorInfo::XPLANE: m_modelCacheXP.admit();
break;
395 case CSimulatorInfo::FG: m_modelCacheFG.admit();
break;
396 case CSimulatorInfo::MSFS: m_modelCacheMsfs.admit();
break;
397 case CSimulatorInfo::MSFS2024: m_modelCacheMsfs2024.admit();
break;
398 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
break;
410 this->synchronizeCacheImpl(simulator);
415 if (this->admitCacheImpl(simulator))
433 case CSimulatorInfo::P3D:
return m_modelCacheP3D.get();
434 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.get();
435 case CSimulatorInfo::FG:
return m_modelCacheFG.get();
436 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.get();
437 case CSimulatorInfo::MSFS2024:
return m_modelCacheMsfs2024.get();
438 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
return {};
455 CLogMessage(
this).
info(u
"Removed %1 flyable models from XPlane model set!");
471 case CSimulatorInfo::P3D: msg = m_modelCacheP3D.set(orderedModels);
break;
472 case CSimulatorInfo::XPLANE: msg = m_modelCacheXP.set(orderedModels);
break;
473 case CSimulatorInfo::FG: msg = m_modelCacheFG.set(orderedModels);
break;
474 case CSimulatorInfo::MSFS: msg = m_modelCacheMsfs.set(orderedModels);
break;
475 case CSimulatorInfo::MSFS2024: msg = m_modelCacheMsfs2024.set(orderedModels);
break;
476 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"wrong simulator");
return {};
487 case CSimulatorInfo::P3D:
return m_modelCacheP3D.getAvailableTimestamp();
488 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.getAvailableTimestamp();
489 case CSimulatorInfo::FG:
return m_modelCacheFG.getAvailableTimestamp();
490 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.getAvailableTimestamp();
491 case CSimulatorInfo::MSFS2024:
return m_modelCacheMsfs2024.getAvailableTimestamp();
492 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong simulator");
return {};
505 case CSimulatorInfo::P3D:
return m_modelCacheP3D.set(m_modelCacheP3D.get(), ts.
toMSecsSinceEpoch());
506 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.set(m_modelCacheXP.get(), ts.
toMSecsSinceEpoch());
507 case CSimulatorInfo::FG:
return m_modelCacheFG.set(m_modelCacheFG.get(), ts.
toMSecsSinceEpoch());
508 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.set(m_modelCacheMsfs.get(), ts.
toMSecsSinceEpoch());
509 case CSimulatorInfo::MSFS2024:
510 return m_modelCacheMsfs2024.set(m_modelCacheMsfs2024.get(), ts.
toMSecsSinceEpoch());
511 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong simulator");
break;
525 case CSimulatorInfo::P3D:
return m_modelCacheP3D.getFilename();
526 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.getFilename();
527 case CSimulatorInfo::FG:
return m_modelCacheFG.getFilename();
528 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.getFilename();
529 case CSimulatorInfo::MSFS2024:
return m_modelCacheMsfs2024.getFilename();
530 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong simulator");
break;
540 case CSimulatorInfo::P3D:
return m_modelCacheP3D.isSaved();
541 case CSimulatorInfo::XPLANE:
return m_modelCacheXP.isSaved();
542 case CSimulatorInfo::FG:
return m_modelCacheFG.isSaved();
543 case CSimulatorInfo::MSFS:
return m_modelCacheMsfs.isSaved();
544 case CSimulatorInfo::MSFS2024:
return m_modelCacheMsfs2024.isSaved();
545 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong simulator");
break;
550 void CModelSetCaches::synchronizeCacheImpl(
const CSimulatorInfo &simulator)
560 case CSimulatorInfo::P3D: m_modelCacheP3D.synchronize();
break;
561 case CSimulatorInfo::XPLANE: m_modelCacheXP.synchronize();
break;
562 case CSimulatorInfo::FG: m_modelCacheFG.synchronize();
break;
563 case CSimulatorInfo::MSFS: m_modelCacheMsfs.synchronize();
break;
564 case CSimulatorInfo::MSFS2024: m_modelCacheMsfs2024.synchronize();
break;
565 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong simulator");
break;
571 bool CModelSetCaches::admitCacheImpl(
const CSimulatorInfo &simulator)
573 Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO,
"No single simulator");
579 switch (simulator.getSimulator())
581 case CSimulatorInfo::P3D: m_modelCacheP3D.admit();
break;
582 case CSimulatorInfo::XPLANE: m_modelCacheXP.admit();
break;
583 case CSimulatorInfo::FG: m_modelCacheFG.admit();
break;
584 case CSimulatorInfo::MSFS: m_modelCacheMsfs.admit();
break;
585 case CSimulatorInfo::MSFS2024: m_modelCacheMsfs2024.admit();
break;
586 default: Q_ASSERT_X(
false, Q_FUNC_INFO,
"Wrong simulator");
break;
Description of a swift application.
static bool hasOtherVersionCacheFile(const swift::misc::CApplicationInfo &info, const QString &myCacheFile)
Has the cache file for the given other version?
static const QString & modelCache()
Model cache.
static const QString & modelSetCache()
Model set cache.
Class for emitting a log message.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
size_type size() const
Returns number of elements in the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
void sortAscendingByOrder()
Sort ascending.
void resetOrder(int offset=0)
Set order member to current order.
bool needsOrder() const
All order values set or missing some?
QString toQString(bool i18n=false) const
Cast as QString.
@ TypeOwnSimulatorModel
represents own simulator model (AI model, model on disk)
Value object encapsulating a list of aircraft models.
int replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)
Replace or add based on model string.
int removeXPlaneFlyablePlanes()
Remove the XPlane flyable planes.
int setModelType(CAircraftModel::ModelType type)
Set type for all elements.
Simple hardcoded info about the corresponding simulator.
static const QSet< CSimulatorInfo > & allSimulatorsSet()
All simulators as set.
void addSimulator(Simulator s)
Add simulator flags.
static const CSimulatorInfo & msfs()
Const simulator info objects.
static const CSimulatorInfo & xplane()
Const simulator info objects.
CSimulatorInfo add(const CSimulatorInfo &other)
Add simulator.
static const CSimulatorInfo & p3d()
Const simulator info objects.
static const CSimulatorInfo & fg()
Const simulator info objects.
QSet< CSimulatorInfo > asSingleSimulatorSet() const
As a set of single simulator info objects.
static const CSimulatorInfo & allSimulators()
All simulators.
bool isSingleSimulator() const
Single simulator selected.
static const CSimulatorInfo & msfs2024()
Const simulator info objects.
static const CSimulatorInfo & guessDefaultSimulator()
Guess a default simulator based on installation.
Simulator getSimulator() const
Simulator.
bool isXPlane() const
XPlane.
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const
Models for simulator.
CModelCaches(bool synchronizeCache, QObject *parent=nullptr)
Construtor.
QString getDescription() const
Descriptive text.
CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
Set cached models.
bool isSaved(const CSimulatorInfo &simulator) const
Cache saved?
void synchronizeCache(const CSimulatorInfo &simulator)
Synchronize for given simulator.
QDateTime getCacheTimestamp(const CSimulatorInfo &simulator) const
Cache timestamp.
void admitCache(const CSimulatorInfo &simulator)
Admit the cache for given simulator.
CStatusMessage setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator)
Set cache timestamp.
static const QStringList & getLogCategories()
Log categories.
QString getFilename(const CSimulatorInfo &simulator) const
Get filename for simulator cache file.
void admitCache(const CSimulatorInfo &simulator)
Admit the cache for given simulator.
QString getDescription() const
Descriptive text.
QString getFilename(const CSimulatorInfo &simulator) const
Get filename for simulator cache file.
CModelSetCaches(bool synchronizeCache, QObject *parent=nullptr)
Construtor.
CStatusMessage setCacheTimestamp(const QDateTime &ts, const CSimulatorInfo &simulator)
Set cache timestamp.
CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
Set cached models.
bool isSaved(const CSimulatorInfo &simulator) const
Cache saved?
void synchronizeCache(const CSimulatorInfo &simulator)
Synchronize for given simulator.
static const QStringList & getLogCategories()
Log categories.
QDateTime getCacheTimestamp(const CSimulatorInfo &simulator) const
Cache timestamp.
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const
Models for simulator.
CSimulatorInfo simulatorsWithInitializedCache() const
Initialized caches for which simulator?
IMultiSimulatorModelCaches(QObject *parent=nullptr)
Construtor.
virtual void gracefulShutdown()
Graceful shutdown.
CSimulatorInfo otherVersionSimulatorsWithFile(const swift::misc::CApplicationInfo &info) const
Simulators of given other versionwhich have a cache file.
CSimulatorInfo getSimulatorForFilename(const QString &filename) const
Simulator which uses cache with filename.
bool isCacheAlreadySynchronized(const CSimulatorInfo &simulator) const
Is the cache already synchronized?
QString getInfoString() const
Info string about models in cache.
virtual void synchronizeCache(const CSimulatorInfo &simulator)=0
Synchronize for given simulator.
int getCachedModelsCount(const CSimulatorInfo &simulator) const
Count of models for simulator.
virtual CStatusMessage clearCachedModels(const CSimulatorInfo &simulator)
Clear cached models.
bool hasOtherVersionFile(const swift::misc::CApplicationInfo &info, const CSimulatorInfo &simulator) const
Has the other version the file?
virtual CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const =0
Models for simulator.
CAircraftModelList getSynchronizedCachedModels(const CSimulatorInfo &simulator)
Models.
CSimulatorInfo simulatorsWithModels() const
Simulators which have models.
virtual CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)=0
Set cached models.
virtual QString getFilename(const CSimulatorInfo &simulator) const =0
Get filename for simulator cache file.
virtual void synchronizeMultiCaches(const CSimulatorInfo &simulator)
Synchronize multiple simulators.
void emitCacheChanged(const CSimulatorInfo &simulator)
Emit cacheChanged() utility function (allows breakpoint).
QString getCacheCountAndTimestamp(const CSimulatorInfo &simulator) const
Cache count and timestamp.
virtual QStringList getAllFilenames() const
All file names.
void cacheChanged(const swift::misc::simulation::CSimulatorInfo &simulator)
Cache has been changed.
void setModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator)
Set models.
void markCacheAsAlreadySynchronized(const CSimulatorInfo &simulator, bool synchronized)
Is the cache already synchronized?
QDateTime getSynchronizedTimestamp(const CSimulatorInfo &simulator)
Timestamp.
virtual void admitMultiCaches(const CSimulatorInfo &simulator)
Synchronize multiple simulators.
QString getInfoStringFsFamily() const
Info string without XPlane (FSX,P3D, FS9).
virtual QDateTime getCacheTimestamp(const CSimulatorInfo &simulator) const =0
Cache timestamp.
int updateModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator)
Set models.
Free functions in swift::misc.
QDateTime addDays(qint64 ndays) const const
QDateTime currentDateTimeUtc()
bool isValid() const const
qint64 toMSecsSinceEpoch() const const
QObject * parent() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.