2013-03-18 23:55:04 +01:00
# include <iostream>
# include <cstdlib>
# include <string>
# include "../ConfigFile.h"
# include "../3mExceptions.h"
using namespace std ;
int main ( ) {
cout < < " 3m Tests: ConfigFile v. 0.1 (C) 2013 by Phitherek_ " < < endl ;
cout < < " Give me the settings path: " ;
string path ;
cin > > path ;
try {
mmm : : ConfigFile conf ( path ) ;
cout < < " Config parsed successfully! Here are the results: " < < endl < < " localpath: " < < conf . getLocalPath ( ) < < endl < < " modlist: " < < conf . getModList ( ) < < endl < < " repoinfo: " < < conf . getRepoInfo ( ) < < endl ;
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 ;
conf . write ( ) ;
cout < < " All OK! Thank you for testing! " < < endl ;
return EXIT_SUCCESS ;
} catch ( mmm : : FileException & exc ) {
2013-03-19 10:11:49 +01:00
cerr < < " File exception occured: " < < exc . what ( ) < < endl ;
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 ) {
cerr < < " Parse exception occured: " < < exc . what ( ) < < endl ;
return 2 ;
}
2013-03-18 23:55:04 +01:00
} catch ( mmm : : ParseException & exc ) {
2013-03-19 10:11:49 +01:00
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 ;
}
2013-03-18 23:55:04 +01:00
}
}