2013-04-08 07:02:00 -07:00
|
|
|
#include "QueryAction.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
using namespace mmm;
|
|
|
|
|
|
|
|
QueryAction::QueryAction(): Action() {
|
|
|
|
_local = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryAction::QueryAction(bool local): Action() {
|
|
|
|
_local = local;
|
|
|
|
}
|
|
|
|
|
|
|
|
QueryAction::~QueryAction() {}
|
|
|
|
|
|
|
|
void QueryAction::run() {
|
|
|
|
std::cout << "Starting Query" << std::endl;
|
2013-04-08 16:00:51 -07:00
|
|
|
try {
|
|
|
|
std::string home = getenv("HOME");
|
|
|
|
std::string confpath = home + "/.3m/config";
|
|
|
|
mmm::ConfigFile config(confpath);
|
|
|
|
std::cout << "Config file loaded successfully!" << std::endl;
|
|
|
|
mmm::LocalModList lml(config);
|
|
|
|
std::cout << "Local modlist file loaded successfully!" << std::endl;
|
|
|
|
bool repoinfook = true;
|
|
|
|
mmm::RepositoryInfo ri;
|
|
|
|
try {
|
|
|
|
mmm::RepositoryInfo tmpri(config);
|
|
|
|
std::cout << "Local repository info file loaded successfully!" << std::endl;
|
|
|
|
ri = tmpri;
|
|
|
|
} catch(mmm::FileException &exc) {
|
|
|
|
std::cout << "FileException occured: " << exc.what() << ". That probably means no mod has been installed by 3m yet. Continuing..." << std::endl;
|
|
|
|
repoinfook = false;
|
|
|
|
} catch(mmm::ParseException &exc) {
|
|
|
|
throw exc;
|
|
|
|
}
|
2013-04-08 07:02:00 -07:00
|
|
|
if(_local) {
|
2013-04-08 16:00:51 -07:00
|
|
|
if(!repoinfook) {
|
|
|
|
std::cerr << "Error: local repoinfo file not loaded properly and local search requested! Exiting..." << std::endl;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if(parameters.empty()) {
|
|
|
|
ri.resetModDescriptionIterator();
|
|
|
|
while(!ri.modDescriptionsAtEnd()) {
|
|
|
|
mmm::RepositoryModDescription rmd = ri.getNextModDescription();
|
|
|
|
if(rmd.getName() != "" && rmd.getReleaseNr() > 0) {
|
|
|
|
std::cout << "LocalRepository/" << rmd.getName() << " (release: " << rmd.getReleaseNr() << ") [installed]" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(unsigned int i = 0; i < parameters.size(); i++) {
|
|
|
|
mmm::RepositoryModDescription rmd = ri.getModDescriptionByName(parameters[i]);
|
|
|
|
if(rmd.getName() != "" && rmd.getReleaseNr() > 0) {
|
|
|
|
std::cout << "LocalRepository/" << rmd.getName() << " (release: " << rmd.getReleaseNr() << ") [installed]" << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cout << parameters[i] << " not found!" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-08 07:02:00 -07:00
|
|
|
} else {
|
2013-04-08 16:00:51 -07:00
|
|
|
if(parameters.empty()) {
|
|
|
|
while(!lml.modDescriptionsAtEnd()) {
|
|
|
|
mmm::LocalModDescription lmd = lml.getNextModDescription();
|
|
|
|
if(lmd.getName() != "" && lmd.getReleaseNr() > 0 && lmd.getDescription() != "" && lmd.getRemoteModlistName() != "") {
|
|
|
|
std::cout << lmd.getRemoteModlistName() << "/" << lmd.getName() << " (release: " << lmd.getReleaseNr() << ")";
|
|
|
|
if(repoinfook) {
|
|
|
|
mmm::RepositoryModDescription rmd = ri.getModDescriptionByName(lmd.getName());
|
|
|
|
if(rmd.getName() != "") {
|
|
|
|
std::cout << " [installed: " << rmd.getReleaseNr() << "]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << std::endl << lmd.getDescription() << std::endl;
|
|
|
|
if(!lmd.dependenciesEmpty()) {
|
|
|
|
lmd.resetDependencyIterator();
|
|
|
|
std::string dep = lmd.getNextDependency();
|
|
|
|
if(dep != "" && dep != "none") {
|
|
|
|
std::cout << "Depends on: ";
|
|
|
|
while(!lmd.dependenciesEnd()) {
|
|
|
|
if(dep != "") {
|
|
|
|
std::cout << dep << " ";
|
|
|
|
dep = lmd.getNextDependency();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for(unsigned int i = 0; i < parameters.size(); i++) {
|
2013-04-12 01:30:44 -07:00
|
|
|
mmm::LocalModDescription lmd;
|
|
|
|
std::string modname = "";
|
|
|
|
std::string modlistname = "";
|
|
|
|
for(unsigned int j = 0; j < parameters[i].length(); j++) {
|
|
|
|
if(parameters[i][j] == '/') {
|
|
|
|
modlistname = modname;
|
|
|
|
modname = "";
|
|
|
|
} else {
|
|
|
|
modname += parameters[i][j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(modlistname == "") {
|
|
|
|
lmd = lml.getModDescriptionByName(modname);
|
|
|
|
} else {
|
|
|
|
lmd = lml.getModDescriptionByNameFrom(modname, modlistname);
|
|
|
|
}
|
2013-04-08 16:00:51 -07:00
|
|
|
if(lmd.getName() != "" && lmd.getReleaseNr() > 0 && lmd.getDescription() != "" && lmd.getRemoteModlistName() != "") {
|
|
|
|
std::cout << lmd.getRemoteModlistName() << "/" << lmd.getName() << " (release: " << lmd.getReleaseNr() << ")";
|
|
|
|
if(repoinfook) {
|
|
|
|
mmm::RepositoryModDescription rmd = ri.getModDescriptionByName(lmd.getName());
|
|
|
|
if(rmd.getName() != "") {
|
|
|
|
std::cout << " [installed: " << rmd.getReleaseNr() << "]";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << std::endl << lmd.getDescription() << std::endl;
|
|
|
|
if(!lmd.dependenciesEmpty()) {
|
|
|
|
lmd.resetDependencyIterator();
|
|
|
|
std::string dep = lmd.getNextDependency();
|
|
|
|
if(dep != "" && dep != "none") {
|
|
|
|
std::cout << "Depends on: ";
|
|
|
|
while(!lmd.dependenciesEnd()) {
|
|
|
|
if(dep != "") {
|
|
|
|
std::cout << dep << " ";
|
|
|
|
dep = "";
|
|
|
|
dep = lmd.getNextDependency();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2013-04-12 01:30:44 -07:00
|
|
|
if(modlistname == "") {
|
|
|
|
std::cout << modname << " not found!" << std::endl;
|
|
|
|
} else {
|
|
|
|
std::cout << modname << " not found in " << modlistname << "!" << std::endl;
|
|
|
|
}
|
2013-04-08 16:00:51 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch(FileException &exc) {
|
|
|
|
std::cerr << "FileException occured: " << exc.what() << "! Exiting..." << std::endl;
|
|
|
|
return;
|
|
|
|
} catch(ParseException &exc) {
|
|
|
|
std::cerr << "ParseException occured: " << exc.what() << "! Exiting..." << std::endl;
|
|
|
|
return;
|
2013-04-08 07:02:00 -07:00
|
|
|
}
|
|
|
|
}
|