diff --git a/src/blackgui/components/installxswiftbuscomponent.cpp b/src/blackgui/components/installxswiftbuscomponent.cpp index 8162fab8b..a6a8c3ac4 100644 --- a/src/blackgui/components/installxswiftbuscomponent.cpp +++ b/src/blackgui/components/installxswiftbuscomponent.cpp @@ -15,6 +15,7 @@ #include "blackmisc/logmessage.h" #include "blackmisc/directoryutils.h" #include "blackmisc/fileutils.h" +#include "blackconfig/buildconfig.h" #include #include @@ -25,6 +26,7 @@ #include #include +using namespace BlackConfig; using namespace BlackMisc; using namespace BlackMisc::Db; using namespace BlackMisc::Network; @@ -102,8 +104,8 @@ namespace BlackGui const CRemoteFile rf = this->getRemoteFileSelected(); const QString downloadFileName = CFileUtils::appendFilePathsAndFixUnc(this->downloadDir(), rf.getName()); QPointer myself(this); - QFile downloadFile(downloadFileName); + if (!downloadFile.exists()) { const CStatusMessage msg = CStatusMessage(this, CLogCategory::validation()).error(u"Cannot read downloaded file '%1'") << downloadFileName; @@ -183,7 +185,7 @@ namespace BlackGui //! fixme Ref T253, once we have a zip library we will directly unzip const QMessageBox::StandardButton reply = QMessageBox::question(this, - "Install swiftXDBus", + "Install XSwiftXBus", "You need to manually unzip XSwiftBus into the plugins directory.\nIt needs to look like 'plugin/xswiftbus'.\n\nOpen the archive?", QMessageBox::Yes | QMessageBox::No); @@ -196,6 +198,20 @@ namespace BlackGui void CInstallXSwiftBusComponent::triggerDownloadingOfXSwiftBusFile() { if (!sGui || !sGui->hasWebDataServices() || sGui->isShuttingDown()) { return; } + const CRemoteFile rf = this->getRemoteFileSelected(); + if (!rf.getName().contains(CBuildConfig::getVersionString())) + { + const QMessageBox::StandardButton reply = QMessageBox::question(this, + "Download XSwiftBus", + QStringLiteral( + u"The XSwiftBus versions seems to be for a different version\n" + u"Your version is '%1'. Use this version.\n\n" + u"If not available, you can try the version next to your version number.\n\n" + u"Continue with this version?").arg(CBuildConfig::getVersionString()), + QMessageBox::Yes | QMessageBox::No); + if (reply != QMessageBox::Yes) { return; } + } + if (!this->existsDownloadDir()) { const CStatusMessage msg = CStatusMessage(this, CLogCategory::validation()).error(u"Invalid download directory"); @@ -203,7 +219,6 @@ namespace BlackGui return; } - const CRemoteFile rf = this->getRemoteFileSelected(); const CUrl download = rf.getSmartUrl(); if (download.isEmpty()) { @@ -317,15 +332,22 @@ namespace BlackGui if (!remoteFiles.isEmpty()) { const QStringList xSwiftBusFiles(remoteFiles.getNamesPlusSize(false)); + m_xSwiftBusArtifacts = artifacts; ui->cb_DownloadFile->addItems(xSwiftBusFiles); // current text - QString current; - if (!m_defaultDownloadName.isEmpty()) + QString current = xSwiftBusFiles.front(); // default latest first + if (m_defaultDownloadName.isEmpty()) + { + const CRemoteFile rf = remoteFiles.findFirstContainingNameOrDefault(CBuildConfig::getVersionString(), Qt::CaseInsensitive); + if (rf.hasName()) { current = rf.getNameAndSize(); } + } + else { const CRemoteFile rf = remoteFiles.findFirstByMatchingNameOrDefault(m_defaultDownloadName); - current = rf.getNameAndSize(); + if (rf.hasName()) { current = rf.getNameAndSize(); } } + ui->cb_DownloadFile->setCurrentText( current.isEmpty() ? remoteFiles.frontOrDefault().getNameAndSize() : diff --git a/src/blackgui/components/installxswiftbuscomponent.h b/src/blackgui/components/installxswiftbuscomponent.h index bea913070..1c28f3fe2 100644 --- a/src/blackgui/components/installxswiftbuscomponent.h +++ b/src/blackgui/components/installxswiftbuscomponent.h @@ -55,7 +55,10 @@ namespace BlackGui BlackMisc::CDataReadOnly m_updates { this, &CInstallXSwiftBusComponent::updatesChanged }; BlackMisc::CSettingReadOnly m_updateSettings { this }; //!< channel/platform selected const QFileDialog::Options m_fileDialogOptions { QFileDialog::ShowDirsOnly | QFileDialog::ReadOnly | QFileDialog::DontResolveSymlinks }; + + // the xSwiftBus artifacts QString m_defaultDownloadName; //!< default name for download + BlackMisc::Db::CArtifactList m_xSwiftBusArtifacts; //!< selectable artifacts //! Select X-Plane plugin directory void selectPluginDirectory(); diff --git a/src/blackmisc/network/remotefilelist.cpp b/src/blackmisc/network/remotefilelist.cpp index b195a4dd2..2c3ddde41 100644 --- a/src/blackmisc/network/remotefilelist.cpp +++ b/src/blackmisc/network/remotefilelist.cpp @@ -57,6 +57,16 @@ namespace BlackMisc return this->findFirstByOrDefault(&CRemoteFile::getName, name); } + CRemoteFile CRemoteFileList::findFirstContainingNameOrDefault(const QString &name, Qt::CaseSensitivity cs) const + { + if (name.isEmpty()) { return CRemoteFile(); } + for (const CRemoteFile &rf : *this) + { + if (rf.getName().contains(name, cs)) { return rf; } + } + return CRemoteFile(); + } + CRemoteFile CRemoteFileList::findFirstByMatchingNameOrDefault(const QString &name) const { if (name.isEmpty()) { return CRemoteFile(); } diff --git a/src/blackmisc/network/remotefilelist.h b/src/blackmisc/network/remotefilelist.h index 4dd07a06d..f941a4092 100644 --- a/src/blackmisc/network/remotefilelist.h +++ b/src/blackmisc/network/remotefilelist.h @@ -52,6 +52,9 @@ namespace BlackMisc //! First by name of default CRemoteFile findFirstByNameOrDefault(const QString &name) const; + //! First by name contained of default + CRemoteFile findFirstContainingNameOrDefault(const QString &name, Qt::CaseSensitivity cs) const; + //! Find first matching name of default CRemoteFile findFirstByMatchingNameOrDefault(const QString &name) const;