swift
modelcaches.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QtGlobal>
7 
9 #include "misc/logmessage.h"
10 #include "misc/verify.h"
11 
12 using namespace swift::misc;
13 
14 namespace swift::misc::simulation::data
15 {
17  const CSimulatorInfo &simulator)
18  {
19  this->setCachedModels(models, simulator);
20  }
21 
23  const CSimulatorInfo &simulator)
24  {
25  if (models.isEmpty()) { return 0; }
26  CAircraftModelList allModels(this->getSynchronizedCachedModels(simulator));
27  const int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
28  if (c < 1) { return 0; }
29  this->setCachedModels(allModels, simulator);
30  return allModels.size();
31  }
32 
34  {
35  static const QString is("P3D: %1 XP: %2 FG: %3");
36  return is.arg(this->getCachedModelsCount(CSimulatorInfo::P3D))
37  .arg(this->getCachedModelsCount(CSimulatorInfo::XPLANE))
38  .arg(this->getCachedModelsCount(CSimulatorInfo::FG));
39  }
40 
42  {
43  static const QString is("P3D: %1, MSFS: %2, MSFS2024: %3");
44  return is.arg(this->getCachedModelsCount(CSimulatorInfo::P3D))
45  .arg(this->getCachedModelsCount(CSimulatorInfo::MSFS))
46  .arg(this->getCachedModelsCount(CSimulatorInfo::MSFS2024));
47  }
48 
50  {
51  static const QString s("%1 models, ts: %2");
52  return s.arg(this->getCachedModelsCount(simulator))
53  .arg(this->getCacheTimestamp(simulator).toString("yyyy-MM-dd HH:mm:ss"));
54  }
55 
57  {
58  // void
59  }
60 
62  {
63  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
64  switch (simulator.getSimulator())
65  {
66  case CSimulatorInfo::P3D: m_syncP3D = synchronized; break;
67  case CSimulatorInfo::XPLANE: m_syncXPlane = synchronized; break;
68  case CSimulatorInfo::FG: m_syncFG = synchronized; break;
69  case CSimulatorInfo::MSFS: m_syncMsfs = synchronized; break;
70  case CSimulatorInfo::MSFS2024: m_syncMsfs2024 = synchronized; break;
71  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); break;
72  }
73  }
74 
76  {
77  emit this->cacheChanged(simulator);
78  }
79 
81  {
82  return this->getCachedModels(simulator).size();
83  }
84 
86  const CSimulatorInfo &simulator) const
87  {
88  const QString fn = this->getFilename(simulator);
90  }
91 
93  {
94  CSimulatorInfo sim(CSimulatorInfo::None);
100  {
102  }
103  return sim;
104  }
105 
107  {
108  return QStringList({
109  this->getFilename(CSimulatorInfo::P3D),
110  this->getFilename(CSimulatorInfo::XPLANE),
111  this->getFilename(CSimulatorInfo::FG),
112  this->getFilename(CSimulatorInfo::MSFS),
113  this->getFilename(CSimulatorInfo::MSFS2024),
114  });
115  }
116 
118  {
119  if (filename.isEmpty()) { return {}; }
120  CSimulatorInfo sims;
121  const QString compareFileName(QFileInfo(filename).fileName());
122  for (const CSimulatorInfo &singleSim : CSimulatorInfo::allSimulatorsSet())
123  {
124  const QString singleSimFile(getFilename(singleSim));
125  if (singleSimFile.isEmpty()) continue;
126  const QString singleSimFileName(QFileInfo(singleSimFile).fileName());
127  if (singleSimFileName == compareFileName)
128  {
129  sims.add(singleSim);
130  break;
131  }
132  }
133  return sims;
134  }
135 
137  {
138  SWIFT_VERIFY_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
139  this->synchronizeCache(simulator);
140  return this->getCachedModels(simulator);
141  }
142 
144  {
145  SWIFT_VERIFY_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
146  this->synchronizeCache(simulator);
147  return this->getCacheTimestamp(simulator);
148  }
149 
151  {
152  static const QDateTime outdated = QDateTime::currentDateTimeUtc().addDays(-365 * 5);
153  CSimulatorInfo withInitializedCache;
154  for (const CSimulatorInfo &simInfo : CSimulatorInfo::allSimulators().asSingleSimulatorSet())
155  {
156  const QDateTime ts = this->getCacheTimestamp(simInfo);
157  if (ts.isValid() && ts > outdated) { withInitializedCache.add(simInfo); }
158  }
159  return withInitializedCache;
160  }
161 
163  {
164  CSimulatorInfo withModels;
165  for (const CSimulatorInfo &simInfo : CSimulatorInfo::allSimulators().asSingleSimulatorSet())
166  {
167  if (this->getCachedModelsCount(simInfo) > 0) { withModels.add(simInfo); }
168  }
169  return withModels;
170  }
171 
172  CModelCaches::CModelCaches(bool synchronizeCache, QObject *parent) : IMultiSimulatorModelCaches(parent)
173  {
175  const QString simStr(sim.toQString(true));
176  if (synchronizeCache)
177  {
178  this->synchronizeCacheImpl(sim);
179  CLogMessage(this).info(u"Initialized model caches (%1) for %2") << this->getDescription() << simStr;
180  }
181  else
182  {
183  if (this->admitCacheImpl(sim))
184  {
185  CLogMessage(this).info(u"Admit model (%1) caches for %2") << this->getDescription() << simStr;
186  }
187  }
188  }
189 
191  {
192  static const QStringList l({ CLogCategories::modelCache() });
193  return l;
194  }
195 
197  {
198  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
199  switch (simulator.getSimulator())
200  {
201  case CSimulatorInfo::P3D: return m_modelCacheP3D.get();
202  case CSimulatorInfo::XPLANE: return m_modelCacheXP.get();
203  case CSimulatorInfo::FG: return m_modelCacheFG.get();
204  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.get();
205  case CSimulatorInfo::MSFS2024: return m_modelCacheMsfs2024.get();
206  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); return {};
207  }
208  }
209 
211  {
212  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
213  CStatusMessage msg;
214  CAircraftModelList setModels(models);
215  setModels.setModelType(CAircraftModel::TypeOwnSimulatorModel); // unify type
216 
217  switch (simulator.getSimulator())
218  {
219  case CSimulatorInfo::P3D: msg = m_modelCacheP3D.set(setModels); break;
220  case CSimulatorInfo::XPLANE: msg = m_modelCacheXP.set(setModels); break;
221  case CSimulatorInfo::FG: msg = m_modelCacheFG.set(setModels); break;
222  case CSimulatorInfo::MSFS: msg = m_modelCacheMsfs.set(setModels); break;
223  case CSimulatorInfo::MSFS2024: msg = m_modelCacheMsfs2024.set(setModels); break;
224  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); return {};
225  }
226  this->emitCacheChanged(simulator); // set
227  return msg;
228  }
229 
231  {
232  static const CAircraftModelList models;
233  return this->setCachedModels(models, simulator);
234  }
235 
237  {
238  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
239  switch (simulator.getSimulator())
240  {
241  case CSimulatorInfo::P3D: return m_syncP3D;
242  case CSimulatorInfo::XPLANE: return m_syncXPlane;
243  case CSimulatorInfo::FG: return m_syncFG;
244  case CSimulatorInfo::MSFS: return m_syncMsfs;
245  case CSimulatorInfo::MSFS2024: return m_syncMsfs2024;
246  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); break;
247  }
248  return false;
249  }
250 
252  {
253  for (const CSimulatorInfo &singleSimulator : simulator.asSingleSimulatorSet())
254  {
255  this->synchronizeCache(singleSimulator);
256  }
257  }
258 
260  {
261  for (const CSimulatorInfo &singleSimulator : simulator.asSingleSimulatorSet())
262  {
263  this->admitMultiCaches(singleSimulator);
264  }
265  }
266 
268  {
269  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
270  switch (simulator.getSimulator())
271  {
272  case CSimulatorInfo::P3D: return m_modelCacheP3D.getAvailableTimestamp();
273  case CSimulatorInfo::XPLANE: return m_modelCacheXP.getAvailableTimestamp();
274  case CSimulatorInfo::FG: return m_modelCacheFG.getAvailableTimestamp();
275  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.getAvailableTimestamp();
276  case CSimulatorInfo::MSFS2024: return m_modelCacheMsfs2024.getAvailableTimestamp();
277  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); return {};
278  }
279  }
280 
282  {
283  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
284  if (!ts.isValid())
285  {
286  return CStatusMessage(this).error(u"Invalid timestamp for '%1'") << simulator.toQString();
287  }
288  switch (simulator.getSimulator())
289  {
290  case CSimulatorInfo::P3D: return m_modelCacheP3D.set(m_modelCacheP3D.get(), ts.toMSecsSinceEpoch());
291  case CSimulatorInfo::XPLANE: return m_modelCacheXP.set(m_modelCacheXP.get(), ts.toMSecsSinceEpoch());
292  case CSimulatorInfo::FG: return m_modelCacheFG.set(m_modelCacheFG.get(), ts.toMSecsSinceEpoch());
293  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.set(m_modelCacheMsfs.get(), ts.toMSecsSinceEpoch());
294  case CSimulatorInfo::MSFS2024:
295  return m_modelCacheMsfs2024.set(m_modelCacheMsfs2024.get(), ts.toMSecsSinceEpoch());
296  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
297  }
298  return {};
299  }
300 
301  void CModelCaches::synchronizeCache(const CSimulatorInfo &simulator) { this->synchronizeCacheImpl(simulator); }
302 
303  void CModelCaches::admitCache(const CSimulatorInfo &simulator) { this->admitCacheImpl(simulator); }
304 
306  {
307  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
308  switch (simulator.getSimulator())
309  {
310  case CSimulatorInfo::P3D: return m_modelCacheP3D.getFilename();
311  case CSimulatorInfo::XPLANE: return m_modelCacheXP.getFilename();
312  case CSimulatorInfo::FG: return m_modelCacheFG.getFilename();
313  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.getFilename();
314  case CSimulatorInfo::MSFS2024: return m_modelCacheMsfs2024.getFilename();
315  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); break;
316  }
317  return {};
318  }
319 
320  bool CModelCaches::isSaved(const CSimulatorInfo &simulator) const
321  {
322  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
323  switch (simulator.getSimulator())
324  {
325  case CSimulatorInfo::P3D: return m_modelCacheP3D.isSaved();
326  case CSimulatorInfo::XPLANE: return m_modelCacheXP.isSaved();
327  case CSimulatorInfo::FG: return m_modelCacheFG.isSaved();
328  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.isSaved();
329  case CSimulatorInfo::MSFS2024: return m_modelCacheMsfs2024.isSaved();
330  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); break;
331  }
332  return false;
333  }
334 
335  void CModelCaches::synchronizeCacheImpl(const CSimulatorInfo &simulator)
336  {
337  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
338 
339  if (this->isCacheAlreadySynchronized(simulator)) { return; }
340  switch (simulator.getSimulator())
341  {
342  case CSimulatorInfo::P3D: m_modelCacheP3D.synchronize(); break;
343  case CSimulatorInfo::XPLANE: m_modelCacheXP.synchronize(); break;
344  case CSimulatorInfo::FG: m_modelCacheFG.synchronize(); break;
345  case CSimulatorInfo::MSFS: m_modelCacheMsfs.synchronize(); break;
346  case CSimulatorInfo::MSFS2024: m_modelCacheMsfs2024.synchronize(); break;
347  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); break;
348  }
349  this->markCacheAsAlreadySynchronized(simulator, true);
350  this->emitCacheChanged(simulator); // sync
351  }
352 
353  bool CModelCaches::admitCacheImpl(const CSimulatorInfo &simulator)
354  {
355  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
356 
357  if (this->isCacheAlreadySynchronized(simulator)) { return false; }
358  switch (simulator.getSimulator())
359  {
360  case CSimulatorInfo::P3D: m_modelCacheP3D.admit(); break;
361  case CSimulatorInfo::XPLANE: m_modelCacheXP.admit(); break;
362  case CSimulatorInfo::FG: m_modelCacheFG.admit(); break;
363  case CSimulatorInfo::MSFS: m_modelCacheMsfs.admit(); break;
364  case CSimulatorInfo::MSFS2024: m_modelCacheMsfs2024.admit(); break;
365  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); break;
366  }
367  return true;
368  }
369 
370  CModelSetCaches::CModelSetCaches(bool synchronizeCache, QObject *parent) : IMultiSimulatorModelCaches(parent)
371  {
373  const QString simStr(simulator.toQString(true));
374 
375  if (synchronizeCache)
376  {
377  this->synchronizeCacheImpl(simulator);
378  CLogMessage(this).info(u"Initialized model caches (%1) for %2") << this->getDescription() << simStr;
379  }
380  else
381  {
382  if (this->admitCacheImpl(simulator))
383  {
384  CLogMessage(this).info(u"Admit model (%1) caches for %2") << this->getDescription() << simStr;
385  }
386  }
387  }
388 
390  {
391  static const QStringList l({ CLogCategories::modelSetCache() });
392  return l;
393  }
394 
396  {
397  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
398  switch (simulator.getSimulator())
399  {
400  case CSimulatorInfo::P3D: return m_modelCacheP3D.get();
401  case CSimulatorInfo::XPLANE: return m_modelCacheXP.get();
402  case CSimulatorInfo::FG: return m_modelCacheFG.get();
403  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.get();
404  case CSimulatorInfo::MSFS2024: return m_modelCacheMsfs2024.get();
405  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); return {};
406  }
407  }
408 
410  {
411  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
412  CAircraftModelList orderedModels(models);
413  orderedModels.setModelType(CAircraftModel::TypeOwnSimulatorModel); // unify type
414 
415  if (simulator.isXPlane())
416  {
417  // see https://discordapp.com/channels/539048679160676382/539064750055751690/648974956306366499
418  // this solves the issue that ACF models are loaded in CSimulatorXPlane::loadCslPackages
419  const int removed = orderedModels.removeXPlaneFlyablePlanes();
420  if (removed > 0) { CLogMessage(this).info(u"Removed %1 flyable models from XPlane model set!"); }
421  }
422 
423  if (orderedModels.needsOrder()) { orderedModels.resetOrder(); }
424  else { orderedModels.sortAscendingByOrder(); }
425 
426  CStatusMessage msg;
427  switch (simulator.getSimulator())
428  {
429  case CSimulatorInfo::P3D: msg = m_modelCacheP3D.set(orderedModels); break;
430  case CSimulatorInfo::XPLANE: msg = m_modelCacheXP.set(orderedModels); break;
431  case CSimulatorInfo::FG: msg = m_modelCacheFG.set(orderedModels); break;
432  case CSimulatorInfo::MSFS: msg = m_modelCacheMsfs.set(orderedModels); break;
433  case CSimulatorInfo::MSFS2024: msg = m_modelCacheMsfs2024.set(orderedModels); break;
434  default: Q_ASSERT_X(false, Q_FUNC_INFO, "wrong simulator"); return {};
435  }
436  this->emitCacheChanged(simulator); // set
437  return msg;
438  }
439 
441  {
442  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
443  switch (simulator.getSimulator())
444  {
445  case CSimulatorInfo::P3D: return m_modelCacheP3D.getAvailableTimestamp();
446  case CSimulatorInfo::XPLANE: return m_modelCacheXP.getAvailableTimestamp();
447  case CSimulatorInfo::FG: return m_modelCacheFG.getAvailableTimestamp();
448  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.getAvailableTimestamp();
449  case CSimulatorInfo::MSFS2024: return m_modelCacheMsfs2024.getAvailableTimestamp();
450  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); return {};
451  }
452  }
453 
455  {
456  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
457  if (!ts.isValid())
458  {
459  return CStatusMessage(this).error(u"Invalid timestamp for '%1'") << simulator.toQString();
460  }
461  switch (simulator.getSimulator())
462  {
463  case CSimulatorInfo::P3D: return m_modelCacheP3D.set(m_modelCacheP3D.get(), ts.toMSecsSinceEpoch());
464  case CSimulatorInfo::XPLANE: return m_modelCacheXP.set(m_modelCacheXP.get(), ts.toMSecsSinceEpoch());
465  case CSimulatorInfo::FG: return m_modelCacheFG.set(m_modelCacheFG.get(), ts.toMSecsSinceEpoch());
466  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.set(m_modelCacheMsfs.get(), ts.toMSecsSinceEpoch());
467  case CSimulatorInfo::MSFS2024:
468  return m_modelCacheMsfs2024.set(m_modelCacheMsfs2024.get(), ts.toMSecsSinceEpoch());
469  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
470  }
471  return {};
472  }
473 
474  void CModelSetCaches::synchronizeCache(const CSimulatorInfo &simulator) { this->synchronizeCacheImpl(simulator); }
475 
476  void CModelSetCaches::admitCache(const CSimulatorInfo &simulator) { this->admitCacheImpl(simulator); }
477 
479  {
480  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
481  switch (simulator.getSimulator())
482  {
483  case CSimulatorInfo::P3D: return m_modelCacheP3D.getFilename();
484  case CSimulatorInfo::XPLANE: return m_modelCacheXP.getFilename();
485  case CSimulatorInfo::FG: return m_modelCacheFG.getFilename();
486  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.getFilename();
487  case CSimulatorInfo::MSFS2024: return m_modelCacheMsfs2024.getFilename();
488  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
489  }
490  return {};
491  }
492 
493  bool CModelSetCaches::isSaved(const CSimulatorInfo &simulator) const
494  {
495  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
496  switch (simulator.getSimulator())
497  {
498  case CSimulatorInfo::P3D: return m_modelCacheP3D.isSaved();
499  case CSimulatorInfo::XPLANE: return m_modelCacheXP.isSaved();
500  case CSimulatorInfo::FG: return m_modelCacheFG.isSaved();
501  case CSimulatorInfo::MSFS: return m_modelCacheMsfs.isSaved();
502  case CSimulatorInfo::MSFS2024: return m_modelCacheMsfs2024.isSaved();
503  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
504  }
505  return false;
506  }
507 
508  void CModelSetCaches::synchronizeCacheImpl(const CSimulatorInfo &simulator)
509  {
510  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
511 
512  if (this->isCacheAlreadySynchronized(simulator)) { return; }
513  switch (simulator.getSimulator())
514  {
515  case CSimulatorInfo::P3D: m_modelCacheP3D.synchronize(); break;
516  case CSimulatorInfo::XPLANE: m_modelCacheXP.synchronize(); break;
517  case CSimulatorInfo::FG: m_modelCacheFG.synchronize(); break;
518  case CSimulatorInfo::MSFS: m_modelCacheMsfs.synchronize(); break;
519  case CSimulatorInfo::MSFS2024: m_modelCacheMsfs2024.synchronize(); break;
520  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
521  }
522  this->markCacheAsAlreadySynchronized(simulator, true);
523  this->emitCacheChanged(simulator); // sync
524  }
525 
526  bool CModelSetCaches::admitCacheImpl(const CSimulatorInfo &simulator)
527  {
528  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
529 
530  if (this->isCacheAlreadySynchronized(simulator)) { return false; }
531  switch (simulator.getSimulator())
532  {
533  case CSimulatorInfo::P3D: m_modelCacheP3D.admit(); break;
534  case CSimulatorInfo::XPLANE: m_modelCacheXP.admit(); break;
535  case CSimulatorInfo::FG: m_modelCacheFG.admit(); break;
536  case CSimulatorInfo::MSFS: m_modelCacheMsfs.admit(); break;
537  case CSimulatorInfo::MSFS2024: m_modelCacheMsfs2024.admit(); break;
538  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
539  }
540  return true;
541  }
542 } // namespace swift::misc::simulation::data
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 & modelSetCache()
Model set cache.
static const QString & modelCache()
Model cache.
Class for emitting a log message.
Definition: logmessage.h:27
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.
Definition: sequence.h:273
bool isEmpty() const
Synonym for empty.
Definition: sequence.h:285
Streamable status message, e.g.
void sortAscendingByOrder()
Sort ascending.
Definition: orderablelist.h:24
void resetOrder(int offset=0)
Set order member to current order.
Definition: orderablelist.h:34
bool needsOrder() const
All order values set or missing some?
Definition: orderablelist.h:41
QString toQString(bool i18n=false) const
Cast as QString.
Definition: mixinstring.h:74
@ TypeOwnSimulatorModel
represents own simulator model (AI model, model on disk)
Definition: aircraftmodel.h:84
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.
Definition: simulatorinfo.h:41
static const QSet< CSimulatorInfo > & allSimulatorsSet()
All simulators as set.
void addSimulator(Simulator s)
Add simulator flags.
CSimulatorInfo add(const CSimulatorInfo &other)
Add simulator.
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 & guessDefaultSimulator()
Guess a default simulator based on installation.
Simulator getSimulator() const
Simulator.
static const CSimulatorInfo & msfs()
Const simulator info objects.
static const CSimulatorInfo & p3d()
Const simulator info objects.
static const CSimulatorInfo & xplane()
Const simulator info objects.
static const CSimulatorInfo & msfs2024()
Const simulator info objects.
static const CSimulatorInfo & fg()
Const simulator info objects.
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const
Models for simulator.
CModelCaches(bool synchronizeCache, QObject *parent=nullptr)
Construtor.
QString getDescription() const
Descriptive text.
Definition: modelcaches.h:327
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.
Definition: modelcaches.h:368
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.
Cache for multiple simulators specified by CSimulatorInfo.
Definition: modelcaches.h:161
CSimulatorInfo simulatorsWithInitializedCache() const
Initialized caches for which simulator?
CSimulatorInfo otherVersionSimulatorsWithFile(const swift::misc::CApplicationInfo &info) const
Simulators of given other versionwhich have a cache file.
Definition: modelcaches.cpp:92
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.
Definition: modelcaches.cpp:33
virtual void synchronizeCache(const CSimulatorInfo &simulator)=0
Synchronize for given simulator.
int getCachedModelsCount(const CSimulatorInfo &simulator) const
Count of models for simulator.
Definition: modelcaches.cpp:80
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?
Definition: modelcaches.cpp:85
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)
Definition: modelcaches.cpp:75
QString getCacheCountAndTimestamp(const CSimulatorInfo &simulator) const
Cache count and timestamp.
Definition: modelcaches.cpp:49
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.
Definition: modelcaches.cpp:16
void markCacheAsAlreadySynchronized(const CSimulatorInfo &simulator, bool synchronized)
Is the cache already synchronized?
Definition: modelcaches.cpp:61
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)
Definition: modelcaches.cpp:41
virtual QDateTime getCacheTimestamp(const CSimulatorInfo &simulator) const =0
Cache timestamp.
int updateModelsForSimulator(const CAircraftModelList &models, const CSimulatorInfo &simulator)
Set models.
Definition: modelcaches.cpp:22
Free functions in swift::misc.
QDateTime addDays(qint64 ndays) const const
QDateTime currentDateTimeUtc()
bool isValid() const const
qint64 toMSecsSinceEpoch() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
CaseInsensitive
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
Definition: verify.h:26