]> git.mxchange.org Git - simgear.git/blobdiff - simgear/package/pkgutil.cxx
Package support hacking
[simgear.git] / simgear / package / pkgutil.cxx
index 837f0d71d9b1a7a5e4fbb9472a8ddd40449e1506..bcbe8318226060ebd76d0965191cac454537cb36 100644 (file)
@@ -26,7 +26,7 @@
 #include <iostream>
 #include <cstring>
 
-using namespace simgear; 
+using namespace simgear;
 using namespace std;
 
 bool keepRunning = true;
@@ -34,44 +34,50 @@ bool keepRunning = true;
 class MyDelegate : public pkg::Delegate
 {
 public:
-    virtual void refreshComplete()
+    virtual void catalogRefreshed(pkg::CatalogRef aCatalog, StatusCode aReason)
     {
+        if (aReason == STATUS_REFRESHED) {
+            if (aCatalog.ptr() == NULL) {
+                cout << "refreshed all catalogs" << endl;
+            } else {
+                cout << "refreshed catalog " << aCatalog->url() << endl;
+            }
+        } else if (aReason == STATUS_IN_PROGRESS) {
+            cout << "started refresh of " << aCatalog->url() << endl;
+        } else {
+            cerr << "failed refresh of " << aCatalog->url() << ":" << aReason << endl;
+        }
     }
-    
-    virtual void failedRefresh(pkg::Catalog* aCatalog, FailureCode aReason)
-    {
-        cerr << "failed refresh of " << aCatalog->description() << ":" << aReason << endl;
-    }
-    
-    virtual void startInstall(pkg::Install* aInstall)
+
+    virtual void startInstall(pkg::InstallRef aInstall)
     {
         _lastPercent = 999;
         cout << "starting install of " << aInstall->package()->name() << endl;
     }
-    
-    virtual void installProgress(pkg::Install* aInstall, unsigned int bytes, unsigned int total)
+
+    virtual void installProgress(pkg::InstallRef aInstall, unsigned int bytes, unsigned int total)
     {
         unsigned int percent = (bytes * 100) / total;
         if (percent == _lastPercent) {
             return;
         }
-        
+
         _lastPercent = percent;
         cout << percent << "%" << endl;
     }
-    
-    virtual void finishInstall(pkg::Install* aInstall)
-    {
-        cout << "done install of " << aInstall->package()->name() << endl;
-    }
 
-    virtual void failedInstall(pkg::Install* aInstall, FailureCode aReason)
+    virtual void finishInstall(pkg::InstallRef aInstall, StatusCode aReason)
     {
-        cerr << "failed install of " << aInstall->package()->name() << endl;
+        if (aReason == STATUS_SUCCESS) {
+            cout << "done install of " << aInstall->package()->name() << endl;
+        } else {
+            cerr << "failed install of " << aInstall->package()->name() << endl;
+        }
     }
+
 private:
     unsigned int _lastPercent;
-    
+
 };
 
 void printRating(pkg::Package* pkg, const std::string& aRating, const std::string& aLabel)
@@ -87,24 +93,24 @@ void printPackageInfo(pkg::Package* pkg)
     cout << "Name:" << pkg->name() << endl;
     cout << "Description:" << pkg->description() << endl;
     cout << "Long description:\n" << pkg->getLocalisedProp("long-description") << endl << endl;
-    
+
     if (pkg->properties()->hasChild("author")) {
         cout << "Authors:" << endl;
         BOOST_FOREACH(SGPropertyNode* author, pkg->properties()->getChildren("author")) {
             if (author->hasChild("name")) {
                 cout << "\t" << author->getStringValue("name") << endl;
-                
+
             } else {
                 // simple author structure
                 cout << "\t" << author->getStringValue() << endl;
             }
-        
-            
+
+
         }
-        
+
         cout << endl;
     }
-    
+
     cout << "Ratings:" << endl;
     printRating(pkg, "fdm",     "Flight-model    ");
     printRating(pkg, "cockpit", "Cockpit         ");
@@ -117,48 +123,48 @@ int main(int argc, char** argv)
 
     HTTP::Client* http = new HTTP::Client();
     pkg::Root* root = new pkg::Root(Dir::current().path(), "");
-    
+
     MyDelegate dlg;
-    root->setDelegate(&dlg);
-    
+    root->addDelegate(&dlg);
+
     cout << "Package root is:" << Dir::current().path() << endl;
-    cout << "have " << pkg::Catalog::allCatalogs().size() << " catalog(s)" << endl;
-        
+    cout << "have " << root->catalogs().size() << " catalog(s)" << endl;
+
     root->setHTTPClient(http);
-    
+
     if (!strcmp(argv[1], "add")) {
         std::string url(argv[2]);
         pkg::Catalog::createFromUrl(root, url);
     } else if (!strcmp(argv[1], "refresh")) {
         root->refresh(true);
     } else if (!strcmp(argv[1], "install")) {
-        pkg::Package* pkg = root->getPackageById(argv[2]);
+        pkg::PackageRef pkg = root->getPackageById(argv[2]);
         if (!pkg) {
             cerr << "unknown package:" << argv[2] << endl;
             return EXIT_FAILURE;
         }
-        
+
         if (pkg->isInstalled()) {
             cout << "package " << pkg->id() << " is already installed at " << pkg->install()->path() << endl;
             return EXIT_SUCCESS;
         }
-        
-        pkg::Catalog* catalog = pkg->catalog();
+
+        pkg::CatalogRef catalog = pkg->catalog();
         cout << "Will install:" << pkg->id() << " from " << catalog->id() <<
                 "(" << catalog->description() << ")" << endl;
         pkg->install();
     } else if (!strcmp(argv[1], "uninstall") || !strcmp(argv[1], "remove")) {
-        pkg::Package* pkg = root->getPackageById(argv[2]);
+        pkg::PackageRef pkg = root->getPackageById(argv[2]);
         if (!pkg) {
             cerr << "unknown package:" << argv[2] << endl;
             return EXIT_FAILURE;
         }
-        
+
         if (!pkg->isInstalled()) {
             cerr << "package " << argv[2] << " not installed" << endl;
             return EXIT_FAILURE;
         }
-        
+
         cout << "Will uninstall:" << pkg->id() << endl;
         pkg->install()->uninstall();
     } else if (!strcmp(argv[1], "update-all")) {
@@ -172,24 +178,24 @@ int main(int argc, char** argv)
             cout << "no packages with updates" << endl;
             return EXIT_SUCCESS;
         }
-        
+
         cout << updates.size() << " packages have updates" << endl;
         BOOST_FOREACH(pkg::Package* p, updates) {
             cout << "\t" << p->id() << " " << p->getLocalisedProp("name") << endl;
         }
     } else if (!strcmp(argv[1], "info")) {
-        pkg::Package* pkg = root->getPackageById(argv[2]);
+        pkg::PackageRef pkg = root->getPackageById(argv[2]);
         if (!pkg) {
             cerr << "unknown package:" << argv[2] << endl;
             return EXIT_FAILURE;
         }
-    
+
         printPackageInfo(pkg);
     } else {
         cerr << "unknown command:" << argv[1] << endl;
         return EXIT_FAILURE;
     }
-    
+
     while (http->hasActiveRequests()) {
         http->update();
     }