1 // Copyright (C) 2013 James Turner - zakalawe@mac.com
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #include <simgear/io/HTTPClient.hxx>
19 #include <simgear/package/Catalog.hxx>
20 #include <simgear/package/Package.hxx>
21 #include <simgear/package/Install.hxx>
22 #include <simgear/package/Root.hxx>
23 #include <simgear/misc/sg_dir.hxx>
25 #include <boost/foreach.hpp>
29 using namespace simgear;
32 bool keepRunning = true;
34 int main(int argc, char** argv)
37 HTTP::Client* http = new HTTP::Client();
38 pkg::Root* root = new pkg::Root(Dir::current().path());
40 cout << "Package root is:" << Dir::current().path() << endl;
41 cout << "have " << pkg::Catalog::allCatalogs().size() << " catalog(s)" << endl;
43 root->setHTTPClient(http);
45 if (!strcmp(argv[1], "add")) {
46 std::string url(argv[2]);
47 pkg::Catalog::createFromUrl(root, url);
48 } else if (!strcmp(argv[1], "refresh")) {
50 } else if (!strcmp(argv[1], "install")) {
51 pkg::Package* pkg = root->getPackageById(argv[2]);
53 cerr << "unknown package:" << argv[2] << endl;
57 if (pkg->isInstalled()) {
58 cout << "package " << pkg->id() << " is already installed at " << pkg->install()->path() << endl;
62 pkg::Catalog* catalog = pkg->catalog();
63 cout << "Will install:" << pkg->id() << " from " << catalog->id() <<
64 "(" << catalog->description() << ")" << endl;
66 } else if (!strcmp(argv[1], "uninstall") || !strcmp(argv[1], "remove")) {
67 pkg::Package* pkg = root->getPackageById(argv[2]);
69 cerr << "unknown package:" << argv[2] << endl;
73 if (!pkg->isInstalled()) {
74 cerr << "package " << argv[2] << " not installed" << endl;
78 cout << "Will uninstall:" << pkg->id() << endl;
79 pkg->install()->uninstall();
80 } else if (!strcmp(argv[1], "update-all")) {
81 pkg::PackageList updates = root->packagesNeedingUpdate();
82 BOOST_FOREACH(pkg::Package* p, updates) {
83 root->scheduleToUpdate(p->install());
85 } else if (!strcmp(argv[1], "list-updated")) {
86 pkg::PackageList updates = root->packagesNeedingUpdate();
87 if (updates.empty()) {
88 cout << "no packages with updates" << endl;
92 cout << updates.size() << " packages have updates" << endl;
93 BOOST_FOREACH(pkg::Package* p, updates) {
94 cout << "\t" << p->id() << " " << p->getLocalisedProp("name") << endl;
97 cerr << "unknown command:" << argv[1] << endl;
101 while (http->hasActiveRequests()) {