RepositoryInfo after tests

master
Phitherek 2013-04-03 23:44:54 +02:00
parent 0d86fb997d
commit 8e728d5544
5 changed files with 152 additions and 6 deletions

View File

@ -4,7 +4,7 @@ ModListList: vector<ModListDescription> x
LocalModDescription: ModDescription + remoteModlist (inheritance) x
LocalModList: vector<LocalModDescription>, ConfigFile x
RepositoryModDescription: ModDescription + path (inheritance) x
RepositoryInfo: vector<RepositoryModDescription>, ConfigFile
RepositoryInfo: vector<RepositoryModDescription>, ConfigFile x
ModListDescription: name, server, modlistPath x
ModInfoDescription: name, server, modinfoPath x
ModInfo: ModInfoDescription, vector<ModDescription>
@ -14,4 +14,4 @@ SyncAction
InstallAction
UpdateAction
RemoveAction
InfoAction
InfoAction

View File

@ -1,6 +1,7 @@
#include "RepositoryInfo.h"
#include "3mExceptions.h"
#include <fstream>
#include <cstdlib>
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") {

View File

@ -44,3 +44,4 @@ public:
void write(); ///< A function that writes back the repository info file.
};
}
#endif

View File

@ -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

View File

@ -0,0 +1,142 @@
#include "../RepositoryInfo.h"
#include "../3mExceptions.h"
#include <iostream>
#include <cstdlib>
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;
}