diff --git a/LocalModList.cpp b/LocalModList.cpp index 7f4eca0..5e38d8a 100644 --- a/LocalModList.cpp +++ b/LocalModList.cpp @@ -185,7 +185,7 @@ while(!lmfile.eof()) { } lmfile.close(); _modlistIterator = -1; -_modlistAtEnd = true; +_modlistAtEnd = false; } LocalModList::~LocalModList() { diff --git a/QueryAction.cpp b/QueryAction.cpp index 2863f25..17031b4 100644 --- a/QueryAction.cpp +++ b/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; } } diff --git a/QueryAction.h b/QueryAction.h index bad2439..a4c0032 100644 --- a/QueryAction.h +++ b/QueryAction.h @@ -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 diff --git a/tests/LocalQueryActionTest.cpp b/tests/LocalQueryActionTest.cpp new file mode 100644 index 0000000..fae79ff --- /dev/null +++ b/tests/LocalQueryActionTest.cpp @@ -0,0 +1,17 @@ +#include "../QueryAction.h" +#include +#include +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; +} diff --git a/tests/Makefile b/tests/Makefile index 1b1d919..1735be1 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -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 diff --git a/tests/QueryActionTest.cpp b/tests/QueryActionTest.cpp new file mode 100644 index 0000000..a4c433b --- /dev/null +++ b/tests/QueryActionTest.cpp @@ -0,0 +1,17 @@ +#include "../QueryAction.h" +#include +#include +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; +}