added more functionality to ConfigFile
parent
3aa1273512
commit
cfddf41464
|
@ -3,6 +3,13 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
using namespace mmm;
|
using namespace mmm;
|
||||||
|
|
||||||
|
ConfigFile::ConfigFile() {
|
||||||
|
_path = "";
|
||||||
|
_localpath = "";
|
||||||
|
_modlist = "";
|
||||||
|
_repoinfo = "";
|
||||||
|
}
|
||||||
|
|
||||||
ConfigFile::ConfigFile(std::string path) {
|
ConfigFile::ConfigFile(std::string path) {
|
||||||
std::ifstream conf(path.c_str());
|
std::ifstream conf(path.c_str());
|
||||||
if(!conf) {
|
if(!conf) {
|
||||||
|
@ -95,6 +102,10 @@ std::string& ConfigFile::getRepoInfo() {
|
||||||
return _repoinfo;
|
return _repoinfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigFile::setPath(std::string path) {
|
||||||
|
_path = path;
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigFile::write() {
|
void ConfigFile::write() {
|
||||||
std::ofstream conf(_path.c_str());
|
std::ofstream conf(_path.c_str());
|
||||||
if(!conf) {
|
if(!conf) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ private:
|
||||||
std::string _modlist;
|
std::string _modlist;
|
||||||
std::string _repoinfo;
|
std::string _repoinfo;
|
||||||
public:
|
public:
|
||||||
|
ConfigFile(); ///< A default constructor of an empty object
|
||||||
ConfigFile(std::string path); ///< \brief A constructor from file path.
|
ConfigFile(std::string path); ///< \brief A constructor from file path.
|
||||||
///< Tries to open the config file and parse it. It throws FileException or ParseException.
|
///< Tries to open the config file and parse it. It throws FileException or ParseException.
|
||||||
/// \param path Path to the config file.
|
/// \param path Path to the config file.
|
||||||
|
@ -29,6 +30,8 @@ public:
|
||||||
///< \return A reference to local modlist file path.
|
///< \return A reference to local modlist file path.
|
||||||
std::string& getRepoInfo(); ///< \brief A function returning a reference to local repoinfo file path.
|
std::string& getRepoInfo(); ///< \brief A function returning a reference to local repoinfo file path.
|
||||||
///< \return A reference to local repoinfo file path
|
///< \return A reference to local repoinfo file path
|
||||||
|
void setPath(std::string path); ///< \brief A function setting the path of config file.
|
||||||
|
///< \param path A path to config file.
|
||||||
void write(); ///< A function that writes the changes to config file.
|
void write(); ///< A function that writes the changes to config file.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,58 @@ conf.write();
|
||||||
cout << "All OK! Thank you for testing!" << endl;
|
cout << "All OK! Thank you for testing!" << endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
} catch(mmm::FileException& exc) {
|
} catch(mmm::FileException& exc) {
|
||||||
cout << "File exception occured: " << exc.what() << endl;
|
cerr << "File exception occured: " << exc.what() << endl;
|
||||||
return 1;
|
cout << "Failed to open file, creating new..." << endl;
|
||||||
|
mmm::ConfigFile conf;
|
||||||
|
conf.setPath(path);
|
||||||
|
string localpath, modlist, repoinfo;
|
||||||
|
cout << "Enter new localpath: " << endl;
|
||||||
|
cin >> localpath;
|
||||||
|
cout << "modlist: " << endl;
|
||||||
|
cin >> modlist;
|
||||||
|
cout << "repoinfo: " << endl;
|
||||||
|
cin >> repoinfo;
|
||||||
|
conf.getLocalPath() = localpath;
|
||||||
|
conf.getModList() = modlist;
|
||||||
|
conf.getRepoInfo() = repoinfo;
|
||||||
|
cout << "Generating the config file..." << endl;
|
||||||
|
try {
|
||||||
|
conf.write();
|
||||||
|
cout << "All OK! Thank you for testing!" << endl;
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
} catch(mmm::FileException& exc) {
|
||||||
|
cerr << "File exception occured: " << exc.what() << endl;
|
||||||
|
return 1;
|
||||||
} catch(mmm::ParseException& exc) {
|
} catch(mmm::ParseException& exc) {
|
||||||
cout << "Parse exception occured: " << exc.what() << endl;
|
cerr << "Parse exception occured: " << exc.what() << endl;
|
||||||
return 2;
|
return 2;
|
||||||
|
}
|
||||||
|
} catch(mmm::ParseException& exc) {
|
||||||
|
cerr << "Parse exception occured: " << exc.what() << endl;
|
||||||
|
cout << "Failed to parse file, creating new..." << endl;
|
||||||
|
mmm::ConfigFile conf;
|
||||||
|
conf.setPath(path);
|
||||||
|
string localpath, modlist, repoinfo;
|
||||||
|
cout << "Enter new localpath: " << endl;
|
||||||
|
cin >> localpath;
|
||||||
|
cout << "modlist: " << endl;
|
||||||
|
cin >> modlist;
|
||||||
|
cout << "repoinfo: " << endl;
|
||||||
|
cin >> repoinfo;
|
||||||
|
conf.getLocalPath() = localpath;
|
||||||
|
conf.getModList() = modlist;
|
||||||
|
conf.getRepoInfo() = repoinfo;
|
||||||
|
cout << "Generating the config file..." << endl;
|
||||||
|
try {
|
||||||
|
conf.write();
|
||||||
|
cout << "All OK! Thank you for testing!" << endl;
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
} catch(mmm::FileException& exc) {
|
||||||
|
cerr << "File exception occured: " << exc.what() << endl;
|
||||||
|
return 1;
|
||||||
|
} catch(mmm::ParseException& exc) {
|
||||||
|
cerr << "Parse exception occured: " << exc.what() << endl;
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue