diff options
Diffstat (limited to 'vmchooser/userSession.cxx')
-rw-r--r-- | vmchooser/userSession.cxx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/vmchooser/userSession.cxx b/vmchooser/userSession.cxx new file mode 100644 index 0000000..af11d4b --- /dev/null +++ b/vmchooser/userSession.cxx @@ -0,0 +1,74 @@ + + + +#include "inc/DataEntry.h" +#include "inc/functions.h" + +#include <cstdlib> +#include <cstring> +#include <string> +#include <iostream> +#include <fstream> + +using namespace std; + +/** + * @function saveSession: Saves chosen session to prechoose this session next time. + * + * @param dat: Pointer to the wanted Image/Linux Session + * @return void + * + */ +void saveSession(DataEntry* dat) { + + // get home folder + char* home = getenv("HOME"); + if(home == NULL) { + cout << "HOME is not set. Not storing session." << endl; + return; + } + + // build path + string fname = home; + fname.append("/.vmchooser"); + + // write file with ofstream + ofstream fout(fname.c_str(),ios::trunc); // overwrite file + fout << dat->short_description << endl; +} + + + +/** + * @function readSession: Read predefined session from users home folder + * + * @return: if not found, return null, else filename for Image XML/ Linux .desktop file + */ +char* readSession() { + + // read HOME variable + char* home = getenv("HOME"); + if(home==NULL) { + cout << "HOME is not set. Not reading session." << endl; + return NULL; + } + + // build file name + string fname = home; + fname.append("/.vmchooser"); + + // read presaved session with ifstream + ifstream fin(fname.c_str()); + string sessname; + getline(fin,sessname); + char* blub = (char*) malloc(sessname.size()); + strncpy(blub,sessname.c_str(),sessname.size()+1); + + if(!sessname.empty()) { + return blub; + } + else { + return NULL; + } + +} |