RepositoryInfo after tests
This commit is contained in:
parent
0d86fb997d
commit
8e728d5544
4
OBJECTS
4
OBJECTS
@ -4,7 +4,7 @@ ModListList: vector<ModListDescription> x
|
|||||||
LocalModDescription: ModDescription + remoteModlist (inheritance) x
|
LocalModDescription: ModDescription + remoteModlist (inheritance) x
|
||||||
LocalModList: vector<LocalModDescription>, ConfigFile x
|
LocalModList: vector<LocalModDescription>, ConfigFile x
|
||||||
RepositoryModDescription: ModDescription + path (inheritance) x
|
RepositoryModDescription: ModDescription + path (inheritance) x
|
||||||
RepositoryInfo: vector<RepositoryModDescription>, ConfigFile
|
RepositoryInfo: vector<RepositoryModDescription>, ConfigFile x
|
||||||
ModListDescription: name, server, modlistPath x
|
ModListDescription: name, server, modlistPath x
|
||||||
ModInfoDescription: name, server, modinfoPath x
|
ModInfoDescription: name, server, modinfoPath x
|
||||||
ModInfo: ModInfoDescription, vector<ModDescription>
|
ModInfo: ModInfoDescription, vector<ModDescription>
|
||||||
@ -14,4 +14,4 @@ SyncAction
|
|||||||
InstallAction
|
InstallAction
|
||||||
UpdateAction
|
UpdateAction
|
||||||
RemoveAction
|
RemoveAction
|
||||||
InfoAction
|
InfoAction
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "RepositoryInfo.h"
|
#include "RepositoryInfo.h"
|
||||||
#include "3mExceptions.h"
|
#include "3mExceptions.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <cstdlib>
|
||||||
using namespace mmm;
|
using namespace mmm;
|
||||||
|
|
||||||
RepositoryInfo::RepositoryInfo() {
|
RepositoryInfo::RepositoryInfo() {
|
||||||
@ -27,7 +28,7 @@ while(!rifile.eof()) {
|
|||||||
if(action == "detect") {
|
if(action == "detect") {
|
||||||
if(line[0] == '{') {
|
if(line[0] == '{') {
|
||||||
std::string name = "";
|
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];
|
name += line[i];
|
||||||
}
|
}
|
||||||
tmprid.setName(name);
|
tmprid.setName(name);
|
||||||
@ -61,7 +62,7 @@ while(!rifile.eof()) {
|
|||||||
}
|
}
|
||||||
} else if(line[0] == '[') {
|
} else if(line[0] == '[') {
|
||||||
std::string tmpact = "";
|
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];
|
tmpact += line[i];
|
||||||
}
|
}
|
||||||
if(tmpact == "release" || tmpact == "path") {
|
if(tmpact == "release" || tmpact == "path") {
|
||||||
@ -91,7 +92,7 @@ while(!rifile.eof()) {
|
|||||||
rifile.close();
|
rifile.close();
|
||||||
throw ParseException(rifn, msg);
|
throw ParseException(rifn, msg);
|
||||||
} else {
|
} else {
|
||||||
tmprid.setReleaseNr(line.c_str());
|
tmprid.setReleaseNr(atoi(line.c_str()));
|
||||||
action = "parse";
|
action = "parse";
|
||||||
}
|
}
|
||||||
} else if(action == "path") {
|
} else if(action == "path") {
|
||||||
|
@ -44,3 +44,4 @@ public:
|
|||||||
void write(); ///< A function that writes back the repository info file.
|
void write(); ///< A function that writes back the repository info file.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
@ -5,11 +5,13 @@ all:
|
|||||||
${CXX} ${CXXFLAGS} -o LocalModDescriptionTest LocalModDescriptionTest.cpp ../LocalModDescription.cpp ../ModDescription.cpp
|
${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 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 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:
|
debug:
|
||||||
${CXX} ${CXXFLAGS} -o ConfigFileTest ConfigFileTest.cpp ../ConfigFile.cpp ../3mExceptions.cpp -g
|
${CXX} ${CXXFLAGS} -o ConfigFileTest ConfigFileTest.cpp ../ConfigFile.cpp ../3mExceptions.cpp -g
|
||||||
${CXX} ${CXXFLAGS} -o ModDescriptionTest ModDescriptionTest.cpp ../ModDescription.cpp -g
|
${CXX} ${CXXFLAGS} -o ModDescriptionTest ModDescriptionTest.cpp ../ModDescription.cpp -g
|
||||||
${CXX} ${CXXFLAGS} -o LocalModDescriptionTest LocalModDescriptionTest.cpp ../LocalModDescription.cpp ../ModDescription.cpp
|
${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 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 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:
|
clean:
|
||||||
rm -rf ConfigFileTest ModDescriptionTest LocalModDescriptionTest ModListListTest LocalModListTest
|
rm -rf ConfigFileTest ModDescriptionTest LocalModDescriptionTest ModListListTest LocalModListTest RepositoryInfoTest
|
||||||
|
142
tests/RepositoryInfoTest.cpp
Normal file
142
tests/RepositoryInfoTest.cpp
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user