]> git.mxchange.org Git - flightgear.git/commitdiff
Fallback URL when official catalog is not found.
authorJames Turner <zakalawe@mac.com>
Wed, 25 May 2016 20:48:06 +0000 (21:48 +0100)
committerRoland Haeder <roland@mxchange.org>
Thu, 22 Sep 2016 21:27:35 +0000 (23:27 +0200)
Tolerate the case where a URL matching the exact FG version is
not found; lookup a generic URL, in the hope it supports our
version (additional changes will make this more likely)

src/GUI/AddCatalogDialog.cxx
src/GUI/PathsDialog.cxx
src/Network/HTTPClient.cxx
src/Network/HTTPClient.hxx

index 95a499bd91eb6f2f299f68ce31faad57f33386c3..b533093edcca9ad1d88c9b58e3b20951ab4ed426 100644 (file)
@@ -24,6 +24,8 @@
 #include <QPushButton>
 #include <QDebug>
 
+#include <Main/globals.hxx>
+#include <Network/HTTPClient.hxx>
 #include <Include/version.h>
 
 using namespace simgear::pkg;
@@ -94,20 +96,24 @@ void AddCatalogDialog::updateUi()
     }
 
     if (m_state == STATE_FINISHED) {
-        QString catDesc = QString::fromStdString(m_result->description());
+        QString catDesc = QString::fromStdString(m_result->name());
         QString s = tr("Successfully retrieved aircraft information from '%1'. "
                        "%2 aircraft are included in this hangar.").arg(catDesc).arg(m_result->packages().size());
         ui->resultsSummaryLabel->setText(s);
     } else if (m_state == STATE_DOWNLOAD_FAILED) {
         Delegate::StatusCode code = m_result->status();
-        qWarning() << Q_FUNC_INFO << "failed with code" << code;
         QString s;
         switch (code) {
         case Delegate::FAIL_DOWNLOAD:
-            s =  tr("Failed to download aircraft descriptions from '%1'. "
+            s = tr("Failed to download aircraft descriptions from '%1'. "
                     "Check the address (URL) and your network connection.").arg(m_catalogUrl.toString());
             break;
 
+        case Delegate::FAIL_NOT_FOUND:
+            s = tr("Failed to download aircraft descriptions at '%1'. "
+                    "Check the URL is correct.").arg(m_catalogUrl.toString());
+            break;
+
         case Delegate::FAIL_VERSION:
             s = tr("The provided hangar is for a different version of FlightGear. "
                    "(This is version %1)").arg(QString::fromUtf8(FLIGHTGEAR_VERSION));
@@ -164,7 +170,6 @@ void AddCatalogDialog::reject()
 void AddCatalogDialog::onCatalogStatusChanged(Catalog* cat)
 {
     Delegate::StatusCode s = cat->status();
-    qDebug() << Q_FUNC_INFO << "cat status:" << s;
     switch (s) {
     case Delegate::STATUS_REFRESHED:
         m_state = STATE_FINISHED;
@@ -174,6 +179,19 @@ void AddCatalogDialog::onCatalogStatusChanged(Catalog* cat)
         // don't jump to STATE_FINISHED
         return;
 
+    case Delegate::FAIL_NOT_FOUND:
+    {
+        FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
+        if (cat->url() == http->getDefaultCatalogUrl()) {
+            cat->setUrl(http->getDefaultCatalogFallbackUrl());
+            cat->refresh(); // and trigger another refresh
+            return;
+        }
+
+        m_state = STATE_DOWNLOAD_FAILED;
+        break;
+    }
+
     // all the actual failure codes
     default:
         m_state = STATE_DOWNLOAD_FAILED;
index 4dcb6a042761f6e3c6eb28ced36d1761e0189a9a..10854f9edc2ed9b59675416fc5fe3cecf60f4fba 100644 (file)
@@ -222,7 +222,7 @@ void AddOnsPage::onRemoveCatalog()
         QString pkgId = mi.data(CatalogIdRole).toString();
 
         if (pkgId.toStdString() == http->getDefaultCatalogId()) {
-            s = QString("Remove default aircraft hangar? "
+            s = QString("Remove the default aircraft hangar? "
                         "This hangar contains all the default aircraft included with FlightGear. "
                         "If you change your mind in the future, click the 'restore' button.");
         } else {
index cf4b490dbf2c676f6b90af233a2d0c6928932df0..f186ca0be6da8338d0bb6346b5b50436145b5e91 100644 (file)
@@ -47,71 +47,34 @@ typedef nasal::Ghost<pkg::PackageRef> NasalPackage;
 typedef nasal::Ghost<pkg::CatalogRef> NasalCatalog;
 typedef nasal::Ghost<pkg::InstallRef> NasalInstall;
 
+const char* OFFICIAL_CATALOG_ID = "org.flightgear.official";
 
-class FGHTTPClient::FGDelegate : public pkg::Delegate
-{
-public:
-  virtual void refreshComplete()
-  {
-    SG_LOG(SG_IO, SG_INFO, "all Catalogs refreshed");
-    
-    // auto-update; make this controlled by a property
-    pkg::Root* r = globals->packageRoot();
-    
-    pkg::PackageList toBeUpdated(r->packagesNeedingUpdate());
-    pkg::PackageList::const_iterator it;
-    for (it = toBeUpdated.begin(); it != toBeUpdated.end(); ++it) {
-      assert((*it)->isInstalled());
-      SG_LOG(SG_IO, SG_INFO, "updating:" << (*it)->id());
-      r->scheduleToUpdate((*it)->install());
+// fallback URL is used when looking up a version-specific catalog fails
+const char* FALLBACK_CATALOG_URL = "http://fgfs.goneabitbursar.com/pkg/catalog.xml";
+
+namespace {
+
+    std::string _getDefaultCatalogId()
+    {
+        return fgGetString("/sim/package-system/default-catalog/id",
+                           OFFICIAL_CATALOG_ID);
     }
-  }
-    
-  virtual void catalogRefreshed(pkg::CatalogRef aCat, StatusCode aReason)
-  {
-      if (aCat.ptr() == NULL) {
-          SG_LOG(SG_IO, SG_INFO, "refresh of all catalogs done");
-          return;
-      }
-      
-    switch (aReason) {
-    case pkg::Delegate::STATUS_SUCCESS:
-    case pkg::Delegate::STATUS_REFRESHED:
-        SG_LOG(SG_IO, SG_INFO, "refresh of Catalog done:" << aCat->url());
-        break;
-            
-    case pkg::Delegate::STATUS_IN_PROGRESS:
-        SG_LOG(SG_IO, SG_INFO, "refresh of Catalog started:" << aCat->url());
-        break;
-            
-    default:
-        SG_LOG(SG_IO, SG_WARN, "refresh of Catalog " << aCat->url() << " failed:" << aReason);
+
+    pkg::CatalogRef getDefaultCatalog()
+    {
+        if (!globals->packageRoot())
+            return pkg::CatalogRef();
+
+        return globals->packageRoot()->getCatalogById(_getDefaultCatalogId());
     }
-  }
-  
-  virtual void startInstall(pkg::InstallRef aInstall)
-  {
-    SG_LOG(SG_IO, SG_INFO, "beginning install of:" << aInstall->package()->id()
-           << " to local path:" << aInstall->path());
 
-  }
-  
-  virtual void installProgress(pkg::InstallRef aInstall, unsigned int aBytes, unsigned int aTotal)
-  {
-  }
-  
-  virtual void finishInstall(pkg::InstallRef aInstall, StatusCode aReason)
-  {
-      if (aReason == STATUS_SUCCESS) {
-    SG_LOG(SG_IO, SG_INFO, "finished install of:" << aInstall->package()->id()
-           << " to local path:" << aInstall->path());
-      } else {
-          SG_LOG(SG_IO, SG_WARN, "install failed of:" << aInstall->package()->id()
-                 << " to local path:" << aInstall->path());
-      }
+    std::string _getDefaultCatalogUrl()
+    {
+        return fgGetString("/sim/package-system/default-catalog/url",
+                    "http://fgfs.goneabitbursar.com/pkg/" FLIGHTGEAR_VERSION "/catalog.xml");
+    }
+} // of anonymous namespace
 
-  }
-}; // of FGHTTPClient::FGDelegate
 
 FGHTTPClient::FGHTTPClient() :
     _inited(false)
@@ -144,10 +107,7 @@ void FGHTTPClient::init()
   if (packageRoot) {
     // package system needs access to the HTTP engine too
     packageRoot->setHTTPClient(_http.get());
-    
-    _packageDelegate.reset(new FGDelegate);
-    packageRoot->addDelegate(_packageDelegate.get());
-    
+
     // start a refresh now
     // setting 'force' true to work around the problem where a slightly stale
     // catalog exists, but aircraft are modified - this causes an MD5 sum
@@ -158,23 +118,6 @@ void FGHTTPClient::init()
     _inited = true;
 }
 
-namespace {
-
-std::string _getDefaultCatalogId()
-{
-    return fgGetString("/sim/package-system/default-catalog/id", "org.flightgear.official" );
-}
-
-pkg::CatalogRef getDefaultCatalog()
-{
-    if (!globals->packageRoot())
-        return pkg::CatalogRef();
-
-    return globals->packageRoot()->getCatalogById(_getDefaultCatalogId());
-}
-
-} // of anonymous namespace
-
 bool FGHTTPClient::isDefaultCatalogInstalled() const
 {
     return getDefaultCatalog().valid();
@@ -195,8 +138,12 @@ std::string FGHTTPClient::getDefaultCatalogId() const
 
 std::string FGHTTPClient::getDefaultCatalogUrl() const
 {
-    return fgGetString("/sim/package-system/default-catalog/url",
-                       "http://fgfs.goneabitbursar.com/pkg/" FLIGHTGEAR_VERSION "/catalog.xml");;
+    return _getDefaultCatalogUrl();
+}
+
+std::string FGHTTPClient::getDefaultCatalogFallbackUrl() const
+{
+    return std::string(FALLBACK_CATALOG_URL);
 }
 
 static naRef f_package_existingInstall( pkg::Package& pkg,
@@ -335,12 +282,6 @@ void FGHTTPClient::postinit()
 
 void FGHTTPClient::shutdown()
 {
-    pkg::Root* packageRoot = globals->packageRoot();
-    if (packageRoot && _packageDelegate.get()) {
-        packageRoot->removeDelegate(_packageDelegate.get());
-    }
-
-    _packageDelegate.reset();
     _http.reset();
 
     _inited = false;
index fe239658578dc5de0983f1d89e141d52387062ec..84e01dca2cd76f394563ff351f45cf21453b699b 100644 (file)
@@ -46,14 +46,12 @@ public:
 
     std::string getDefaultCatalogId() const;
     std::string getDefaultCatalogUrl() const;
-
-    static const char* subsystemName() { return "http"; } 
-private:
-    class FGDelegate;
+    std::string getDefaultCatalogFallbackUrl() const;
     
+    static const char* subsystemName() { return "http"; }
+private:    
     bool _inited;
     std::auto_ptr<simgear::HTTP::Client> _http;
-    std::auto_ptr<FGDelegate> _packageDelegate;
 };
 
 #endif // FG_HTTP_CLIENT_HXX