S_New4/accountManager.cpp
2019-07-06 20:47:29 +02:00

53 lines
1.4 KiB
C++

#include "accountManager.h"
AccountManager::AccountManager(std::string pathToFile)
: lastReturnedAccount(0)
{
std::ifstream ifs(pathToFile);
if(!ifs.is_open()) {
perror("Konnte Accounts Datei nicht öffnen");
exit(12);
}
std::string line;
while (std::getline(ifs, line)) {
Account account;
size_t Delimeter = line.find("/");
if(Delimeter == std::string::npos) {
account.Email = line;
account.Password = line;
} else {
account.Email = std::string(line).erase(Delimeter, line.length() - Delimeter);
account.Password = line.erase(0, Delimeter + 1);
}
if(account.Email == "" || account.Password == "")
continue;
else
accounts.push_back(account);
}
}
Account AccountManager::getNextAccount()
{
lastReturnedAccount++;
if( lastReturnedAccount >= accounts.size() )
lastReturnedAccount=0;
return accounts.at(lastReturnedAccount);
}
bool AccountManager::isDirExist(const std::string& path)
{
struct stat info;
if (stat(path.c_str(), &info) != 0) {
return false;
}
return (info.st_mode & S_IFDIR) != 0;
}
bool AccountManager::createDir(std::string path, std::string atLinux)
{
return system(std::string("mkdir " + atLinux + "'" + path +"'").c_str()); // -p if is linux
}