diff --git a/OBJECTS b/OBJECTS index 0f0a380..73c42b6 100644 --- a/OBJECTS +++ b/OBJECTS @@ -4,7 +4,7 @@ ModListList: vector x LocalModDescription: ModDescription + remoteModlist (inheritance) x LocalModList: vector, ConfigFile x RepositoryModDescription: ModDescription + path (inheritance) x -RepositoryInfo: vector, ConfigFile +RepositoryInfo: vector, ConfigFile x ModListDescription: name, server, modlistPath x ModInfoDescription: name, server, modinfoPath x ModInfo: ModInfoDescription, vector @@ -14,4 +14,4 @@ SyncAction InstallAction UpdateAction RemoveAction -InfoAction \ No newline at end of file +InfoAction diff --git a/RepositoryInfo.cpp b/RepositoryInfo.cpp index f872825..373d174 100644 --- a/RepositoryInfo.cpp +++ b/RepositoryInfo.cpp @@ -1,6 +1,7 @@ #include "RepositoryInfo.h" #include "3mExceptions.h" #include +#include using namespace mmm; RepositoryInfo::RepositoryInfo() { @@ -27,7 +28,7 @@ while(!rifile.eof()) { if(action == "detect") { if(line[0] == '{') { std::string name = ""; - for(int i = 1; line[i] != '}' && i < line.length(); i++) { + for(unsigned int i = 1; line[i] != '}' && i < line.length(); i++) { name += line[i]; } tmprid.setName(name); @@ -61,7 +62,7 @@ while(!rifile.eof()) { } } else if(line[0] == '[') { std::string tmpact = ""; - for(int i = 1; line[i] != ']' && i < line.length(); i++) { + for(unsigned int i = 1; line[i] != ']' && i < line.length(); i++) { tmpact += line[i]; } if(tmpact == "release" || tmpact == "path") { @@ -91,7 +92,7 @@ while(!rifile.eof()) { rifile.close(); throw ParseException(rifn, msg); } else { - tmprid.setReleaseNr(line.c_str()); + tmprid.setReleaseNr(atoi(line.c_str())); action = "parse"; } } else if(action == "path") { diff --git a/RepositoryInfo.h b/RepositoryInfo.h index 55a4743..c218de6 100644 --- a/RepositoryInfo.h +++ b/RepositoryInfo.h @@ -44,3 +44,4 @@ public: void write(); ///< A function that writes back the repository info file. }; } +#endif diff --git a/tests/Makefile b/tests/Makefile index 3f9e5c1..6d438fe 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,11 +5,13 @@ all: ${CXX} ${CXXFLAGS} -o LocalModDescriptionTest LocalModDescriptionTest.cpp ../LocalModDescription.cpp ../ModDescription.cpp ${CXX} ${CXXFLAGS} -o ModListListTest ModListListTest.cpp ../ModListList.cpp ../ModListDescription.cpp ../3mExceptions.cpp ${CXX} ${CXXFLAGS} -o LocalModListTest LocalModListTest.cpp ../LocalModList.cpp ../LocalModDescription.cpp ../ModDescription.cpp ../3mExceptions.cpp ../ConfigFile.cpp + ${CXX} ${CXXFLAGS} -o RepositoryInfoTest RepositoryInfoTest.cpp ../RepositoryModDescription.cpp ../ModDescription.cpp ../3mExceptions.cpp ../ConfigFile.cpp ../RepositoryInfo.cpp debug: ${CXX} ${CXXFLAGS} -o ConfigFileTest ConfigFileTest.cpp ../ConfigFile.cpp ../3mExceptions.cpp -g ${CXX} ${CXXFLAGS} -o ModDescriptionTest ModDescriptionTest.cpp ../ModDescription.cpp -g ${CXX} ${CXXFLAGS} -o LocalModDescriptionTest LocalModDescriptionTest.cpp ../LocalModDescription.cpp ../ModDescription.cpp ${CXX} ${CXXFLAGS} -o ModListListTest ModListListTest.cpp ../ModListList.cpp ../ModListDescription.cpp ../3mExceptions.cpp -g ${CXX} ${CXXFLAGS} -o LocalModListTest LocalModListTest.cpp ../LocalModList.cpp ../LocalModDescription.cpp ../ModDescription.cpp ../3mExceptions.cpp ../ConfigFile.cpp -g + ${CXX} ${CXXFLAGS} -o RepositoryInfoTest RepositoryInfoTest.cpp ../RepositoryModDescription.cpp ../ModDescription.cpp ../3mExceptions.cpp ../ConfigFile.cpp ../RepositoryInfo.cpp -g clean: - rm -rf ConfigFileTest ModDescriptionTest LocalModDescriptionTest ModListListTest LocalModListTest + rm -rf ConfigFileTest ModDescriptionTest LocalModDescriptionTest ModListListTest LocalModListTest RepositoryInfoTest diff --git a/tests/RepositoryInfoTest.cpp b/tests/RepositoryInfoTest.cpp new file mode 100644 index 0000000..ff14539 --- /dev/null +++ b/tests/RepositoryInfoTest.cpp @@ -0,0 +1,142 @@ +#include "../RepositoryInfo.h" +#include "../3mExceptions.h" +#include +#include +using namespace std; + +int main() { + string home = getenv("HOME"); + string confpath = home + "/.3m/config"; + mmm::ConfigFile conf; + try { + mmm::ConfigFile tmpconf(confpath); + conf = tmpconf; + } catch(mmm::FileException &exc) { + cerr << "FileException occured: " << exc.what() << endl; + return EXIT_FAILURE; + } catch(mmm::ParseException &exc) { + cerr << "ParseException occured: " << exc.what() << endl; + return EXIT_FAILURE; + } + mmm::RepositoryInfo ri; + bool newri = true; + try { + mmm::RepositoryInfo tmpri(conf); + newri = false; + ri = tmpri; + } catch(mmm::FileException &exc) { + cerr << "FileException occured: " << exc.what() << endl; + cout << "Exception occurred, creating empty repository info..." << endl; + + } catch(mmm::ParseException &exc) { + cerr << "ParseException occured: " << exc.what() << endl; + cout << "Exception occurred, creating empty repository info..." << endl; + } + if(newri) { + ri.setConfigFile(conf); + char action; + do { + cout << "Choose action: (l)ist all mods, (f)ind by name and list, (a)dd a mod, (r)emove mod by name, (s)ave and exit, (q)uit without saving" << endl; + cin >> action; + if(action == 'l') { + ri.resetModDescriptionIterator(); + while(!ri.modDescriptionsAtEnd()) { + mmm::RepositoryModDescription rmd = ri.getNextModDescription(); + if(rmd.getName() != "" && rmd.getReleaseNr() != 0 && rmd.getPath() != "") { + cout << "name: " << rmd.getName() << endl << "release: " << rmd.getReleaseNr() << endl << "path: " << rmd.getPath() << endl << endl; + } + } + } else if(action == 'f') { + std::string name; + cout << "Name of the mod: "; + cin >> name; + mmm::RepositoryModDescription rmd = ri.getModDescriptionByName(name); + if(rmd.getName() != "" && rmd.getReleaseNr() != 0 && rmd.getPath() != "") { + cout << "name: " << rmd.getName() << endl << "release: " << rmd.getReleaseNr() << endl << "path: " << rmd.getPath() << endl << endl; + } else { + cout << name << " not found!" << endl; + } + } else if(action == 'a') { + mmm::RepositoryModDescription rmd; + std::string name, path; + int release; + cout << "name: "; + cin >> name; + cout << "release: "; + cin >> release; + cout << "path: "; + cin >> path; + rmd.setName(name); + rmd.setReleaseNr(release); + rmd.setPath(path); + ri.insertModDescription(rmd); + } else if(action == 'r') { + std::string name; + cout << "Name of the mod: "; + cin >> name; + mmm::RepositoryModDescription rmd = ri.getModDescriptionByName(name); + if(rmd.getName() != "" && rmd.getReleaseNr() != 0 && rmd.getPath() != "") { + ri.deleteModDescription(name); + } else { + cout << name << " not found!" << endl; + } + } + } while(action != 's' && action != 'q'); + if(action == 's') { + ri.write(); + } + } else { + char action; + do { + cout << "Choose action: (l)ist all mods, (f)ind by name and list, (a)dd a mod, (r)emove mod by name, (s)ave and exit, (q)uit without saving" << endl; + cin >> action; + if(action == 'l') { + ri.resetModDescriptionIterator(); + while(!ri.modDescriptionsAtEnd()) { + mmm::RepositoryModDescription rmd = ri.getNextModDescription(); + if(rmd.getName() != "" && rmd.getReleaseNr() != 0 && rmd.getPath() != "") { + cout << "name: " << rmd.getName() << endl << "release: " << rmd.getReleaseNr() << endl << "path: " << rmd.getPath() << endl << endl; + } + } + } else if(action == 'f') { + std::string name; + cout << "Name of the mod: "; + cin >> name; + mmm::RepositoryModDescription rmd = ri.getModDescriptionByName(name); + if(rmd.getName() != "" && rmd.getReleaseNr() != 0 && rmd.getPath() != "") { + cout << "name: " << rmd.getName() << endl << "release: " << rmd.getReleaseNr() << endl << "path: " << rmd.getPath() << endl << endl; + } else { + cout << name << " not found!" << endl; + } + } else if(action == 'a') { + mmm::RepositoryModDescription rmd; + std::string name, path; + int release; + cout << "name: "; + cin >> name; + cout << "release: "; + cin >> release; + cout << "path: "; + cin >> path; + rmd.setName(name); + rmd.setReleaseNr(release); + rmd.setPath(path); + ri.insertModDescription(rmd); + } else if(action == 'r') { + std::string name; + cout << "Name of the mod: "; + cin >> name; + mmm::RepositoryModDescription rmd = ri.getModDescriptionByName(name); + if(rmd.getName() != "" && rmd.getReleaseNr() != 0 && rmd.getPath() != "") { + ri.deleteModDescription(name); + } else { + cout << name << " not found!" << endl; + } + } + } while(action != 's' && action != 'q'); + if(action == 's') { + ri.write(); + } + } + return EXIT_SUCCESS; +}