1 #include <simgear/io/HTTPClient.hxx>
2 #include <simgear/package/Catalog.hxx>
3 #include <simgear/package/Package.hxx>
4 #include <simgear/package/Install.hxx>
5 #include <simgear/package/Root.hxx>
6 #include <simgear/misc/sg_dir.hxx>
8 #include <boost/foreach.hpp>
12 using namespace simgear;
15 bool keepRunning = true;
17 int main(int argc, char** argv)
20 HTTP::Client* http = new HTTP::Client();
21 pkg::Root* root = new pkg::Root(Dir::current().path());
23 cout << "Package root is:" << Dir::current().path() << endl;
24 cout << "have " << pkg::Catalog::allCatalogs().size() << " catalog(s)" << endl;
26 root->setHTTPClient(http);
28 if (!strcmp(argv[1], "add")) {
29 std::string url(argv[2]);
30 pkg::Catalog::createFromUrl(root, url);
31 } else if (!strcmp(argv[1], "refresh")) {
33 } else if (!strcmp(argv[1], "install")) {
34 pkg::Package* pkg = root->getPackageById(argv[2]);
36 cerr << "unknown package:" << argv[2] << endl;
40 if (pkg->isInstalled()) {
41 cout << "package " << pkg->id() << " is already installed at " << pkg->install()->path() << endl;
45 pkg::Catalog* catalog = pkg->catalog();
46 cout << "Will install:" << pkg->id() << " from " << catalog->id() <<
47 "(" << catalog->description() << ")" << endl;
49 } else if (!strcmp(argv[1], "uninstall") || !strcmp(argv[1], "remove")) {
50 pkg::Package* pkg = root->getPackageById(argv[2]);
52 cerr << "unknown package:" << argv[2] << endl;
56 if (!pkg->isInstalled()) {
57 cerr << "package " << argv[2] << " not installed" << endl;
61 cout << "Will uninstall:" << pkg->id() << endl;
62 pkg->install()->uninstall();
63 } else if (!strcmp(argv[1], "update-all")) {
64 pkg::PackageList updates = root->packagesNeedingUpdate();
65 BOOST_FOREACH(pkg::Package* p, updates) {
66 root->scheduleToUpdate(p->install());
68 } else if (!strcmp(argv[1], "list-updated")) {
69 pkg::PackageList updates = root->packagesNeedingUpdate();
70 if (updates.empty()) {
71 cout << "no packages with updates" << endl;
75 cout << updates.size() << " packages have updates" << endl;
76 BOOST_FOREACH(pkg::Package* p, updates) {
77 cout << "\t" << p->id() << " " << p->getLocalisedProp("name") << endl;
80 cerr << "unknown command:" << argv[1] << endl;
84 while (http->hasActiveRequests()) {