finished and tested QueryAction class, corrected some bugs
This commit is contained in:
parent
930c0bca21
commit
bdf849156c
@ -185,7 +185,7 @@ while(!lmfile.eof()) {
|
||||
}
|
||||
lmfile.close();
|
||||
_modlistIterator = -1;
|
||||
_modlistAtEnd = true;
|
||||
_modlistAtEnd = false;
|
||||
}
|
||||
|
||||
LocalModList::~LocalModList() {
|
||||
|
111
QueryAction.cpp
111
QueryAction.cpp
@ -15,9 +15,116 @@ QueryAction::~QueryAction() {}
|
||||
|
||||
void QueryAction::run() {
|
||||
std::cout << "Starting Query" << std::endl;
|
||||
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;
|
||||
}
|
||||
if(_local) {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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++) {
|
||||
mmm::LocalModDescription lmd = lml.getModDescriptionByName(parameters[i]);
|
||||
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 {
|
||||
std::cout << parameters[i] << " not found!" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include "3mExceptions.h"
|
||||
#include "ModDescription.h"
|
||||
#include "LocalModDescription.h"
|
||||
#include "RepositoryInfo.h"
|
||||
#include "RepositoryModDescription.h"
|
||||
#include "LocalModList.h"
|
||||
#include "Action.h"
|
||||
#include <string>
|
||||
|
17
tests/LocalQueryActionTest.cpp
Normal file
17
tests/LocalQueryActionTest.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "../QueryAction.h"
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
mmm::QueryAction act(true);
|
||||
if(argc > 1) {
|
||||
for(int i = 1; i < argc; i++) {
|
||||
std::string arg = "";
|
||||
arg += argv[i];
|
||||
act.insertParameter(arg);
|
||||
}
|
||||
}
|
||||
act.run();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -9,6 +9,8 @@ all:
|
||||
${CXX} ${CXXFLAGS} -o ModInfoTest ModInfoTest.cpp ../ModInfo.cpp ../ModInfoDescription.cpp ../ModDescription.cpp ../3mExceptions.cpp -lnetsocketpp
|
||||
${CXX} ${CXXFLAGS} -o ModListTest ModListTest.cpp ../ModList.cpp ../ModListDescription.cpp ../ModInfo.cpp ../ModInfoDescription.cpp ../ModDescription.cpp ../3mExceptions.cpp -lnetsocketpp
|
||||
${CXX} ${CXXFLAGS} -o SyncActionTest SyncActionTest.cpp ../SyncAction.cpp ../Action.cpp ../ConfigFile.cpp ../ModListList.cpp ../3mExceptions.cpp ../ModList.cpp ../ModInfo.cpp ../ModListDescription.cpp ../ModInfoDescription.cpp ../ModDescription.cpp ../LocalModDescription.cpp ../LocalModList.cpp -lnetsocketpp
|
||||
${CXX} ${CXXFLAGS} -o QueryActionTest QueryActionTest.cpp ../QueryAction.cpp ../Action.cpp ../ConfigFile.cpp ../3mExceptions.cpp ../LocalModList.cpp ../LocalModDescription.cpp ../ModDescription.cpp ../RepositoryInfo.cpp ../RepositoryModDescription.cpp
|
||||
${CXX} ${CXXFLAGS} -o LocalQueryActionTest LocalQueryActionTest.cpp ../QueryAction.cpp ../Action.cpp ../ConfigFile.cpp ../3mExceptions.cpp ../LocalModList.cpp ../LocalModDescription.cpp ../ModDescription.cpp ../RepositoryInfo.cpp ../RepositoryModDescription.cpp
|
||||
debug:
|
||||
${CXX} ${CXXFLAGS} -o ConfigFileTest ConfigFileTest.cpp ../ConfigFile.cpp ../3mExceptions.cpp -g
|
||||
${CXX} ${CXXFLAGS} -o ModDescriptionTest ModDescriptionTest.cpp ../ModDescription.cpp -g
|
||||
@ -19,5 +21,7 @@ debug:
|
||||
${CXX} ${CXXFLAGS} -o ModInfoTest ModInfoTest.cpp ../ModInfo.cpp ../ModInfoDescription.cpp ../ModDescription.cpp ../3mExceptions.cpp -lnetsocketpp -g
|
||||
${CXX} ${CXXFLAGS} -o ModListTest ModListTest.cpp ../ModList.cpp ../ModListDescription.cpp ../ModInfo.cpp ../ModInfoDescription.cpp ../ModDescription.cpp ../3mExceptions.cpp -lnetsocketpp -g
|
||||
${CXX} ${CXXFLAGS} -o SyncActionTest SyncActionTest.cpp ../SyncAction.cpp ../Action.cpp ../ConfigFile.cpp ../ModListList.cpp ../3mExceptions.cpp ../ModList.cpp ../ModInfo.cpp ../ModListDescription.cpp ../ModInfoDescription.cpp ../ModDescription.cpp ../LocalModDescription.cpp ../LocalModList.cpp -lnetsocketpp -g
|
||||
${CXX} ${CXXFLAGS} -o QueryActionTest QueryActionTest.cpp ../QueryAction.cpp ../Action.cpp ../ConfigFile.cpp ../3mExceptions.cpp ../LocalModList.cpp ../LocalModDescription.cpp ../ModDescription.cpp ../RepositoryInfo.cpp ../RepositoryModDescription.cpp -g
|
||||
${CXX} ${CXXFLAGS} -o LocalQueryActionTest LocalQueryActionTest.cpp ../QueryAction.cpp ../Action.cpp ../ConfigFile.cpp ../3mExceptions.cpp ../LocalModList.cpp ../LocalModDescription.cpp ../ModDescription.cpp ../RepositoryInfo.cpp ../RepositoryModDescription.cpp -g
|
||||
clean:
|
||||
rm -rf ConfigFileTest ModDescriptionTest LocalModDescriptionTest ModListListTest LocalModListTest RepositoryInfoTest ModInfoTest ModListTest SyncActionTest
|
||||
rm -rf ConfigFileTest ModDescriptionTest LocalModDescriptionTest ModListListTest LocalModListTest RepositoryInfoTest ModInfoTest ModListTest SyncActionTest QueryActionTest LocalQueryActionTest
|
||||
|
17
tests/QueryActionTest.cpp
Normal file
17
tests/QueryActionTest.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "../QueryAction.h"
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
mmm::QueryAction act;
|
||||
if(argc > 1) {
|
||||
for(int i = 1; i < argc; i++) {
|
||||
std::string arg = "";
|
||||
arg += argv[i];
|
||||
act.insertParameter(arg);
|
||||
}
|
||||
}
|
||||
act.run();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user