create dir function + cleanup

This commit is contained in:
Markus 2019-08-31 20:35:11 +02:00
parent 569a3206f6
commit 4f6c23ad64
7 changed files with 28 additions and 34 deletions

View File

@ -195,16 +195,3 @@ int AccountManager::setLastAccountNumber(size_t number)
return 0; return 0;
} }


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
}

View File

@ -16,17 +16,14 @@ class AccountManager
public: public:
AccountManager(std::string pathToFile, std::string pathToAccountNumberFile); AccountManager(std::string pathToFile, std::string pathToAccountNumberFile);
Account getNextAccount(); Account getNextAccount();

int writeDefault(std::string path);
size_t getLastAccountNumber(); size_t getLastAccountNumber();
int setLastAccountNumber(size_t number);

bool isDirExist(const std::string& path);
bool createDir(std::string path, std::string atLinux = "-p ");


private: private:
std::vector<Account> accounts; std::vector<Account> accounts;
std::string pathToAccountNumberFile; std::string pathToAccountNumberFile;
int setLastAccountNumber(size_t number);
int writeDefault(std::string path);

}; };


#endif // ACCOUNTMANAGER_H #endif // ACCOUNTMANAGER_H

View File

@ -1,7 +1,7 @@
#include "pageManager.h" #include "pageManager.h"


PageManager::PageManager(std::string sock5Proxy, std::string cookieFilePath) PageManager::PageManager(std::string sock5ProxyOnlyAddress, std::string cookieFilePath)
: sock5Proxy(sock5Proxy), cookieFilePath(cookieFilePath) : sock5Proxy("socks5://" + sock5ProxyOnlyAddress), cookieFilePath(cookieFilePath)
{ {
curl_global_init(CURL_GLOBAL_ALL); curl_global_init(CURL_GLOBAL_ALL);
} }

View File

@ -22,7 +22,7 @@ struct Reply {
class PageManager class PageManager
{ {
public: public:
PageManager(std::string sock5Proxy = "socks5://127.0.0.1:9150", std::string cookieFilePath = "/tmp/S_New4_cookies"); PageManager(std::string sock5ProxyOnlyAddress = "127.0.0.1:9150", std::string cookieFilePath = "/tmp/S_New4_cookies");
~PageManager(); ~PageManager();


void setProxy(std::string ip, int port); void setProxy(std::string ip, int port);

View File

@ -5,14 +5,13 @@ void setPaths(Settings &settings)
//Path settings //Path settings
std::string executablePathTo = getexepath(); std::string executablePathTo = getexepath();


//Entferne alles nach dem lestzten pathSymbol
executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) ); executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) );


if(!dirExists(executablePathTo + "src" + settings.pathSymbol)) { if(!dirExists(executablePathTo + "src" + settings.pathSymbol))
if(system(std::string("mkdir \"" + executablePathTo + "src" + settings.pathSymbol + "\"").c_str()) == 0) if(createDirIsOk(executablePathTo + "src" + settings.pathSymbol))
std::cout << " => Erfolgreich Ordner 'src' erstellt." << std::endl; std::cout << " => Erfolgreich Ordner '" << executablePathTo << "src' erstellt." << std::endl;
else
std::cout << " => Error: Ordner '" << executablePathTo << "src' konnte nicht erstellt werden." << std::endl;
}
if(dirExists(executablePathTo + "src" + settings.pathSymbol)) if(dirExists(executablePathTo + "src" + settings.pathSymbol))
executablePathTo+="src" + std::string(1, settings.pathSymbol); executablePathTo+="src" + std::string(1, settings.pathSymbol);


@ -932,7 +931,6 @@ bool fileExists (const std::string& name) {
return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode)); return (stat (name.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode));
} }



bool nothingExists(std::string path) bool nothingExists(std::string path)
{ {
struct stat buffer; struct stat buffer;
@ -950,6 +948,20 @@ bool isNumber(std::string number)
return (std::to_string(atoll(number.c_str())) == number) ? true : false; return (std::to_string(atoll(number.c_str())) == number) ? true : false;
} }


bool createDirIsOk(std::string path)
{
#ifdef linux
if(mkdir(path.c_str(), 0777) != 0) {
#endif
#ifdef _WIN32
if(mkdir(path.c_str()) != 0) {
#endif
perror((" => Error: Erstellen von dem Ordner" + path + " is fehlgeschlagen").c_str());
return false;
} else
return dirExists(path);
}



int setS5ProxytoSettings(Settings &settings, std::string Optarg) int setS5ProxytoSettings(Settings &settings, std::string Optarg)
{ {
@ -1010,5 +1022,3 @@ int setS5ProxytoSettings(Settings &settings, std::string Optarg)
return 0; return 0;
} }





View File

@ -74,6 +74,7 @@ void setPaths(Settings &settings);
bool fileExists (const std::string& name); bool fileExists (const std::string& name);
bool dirExists(std::string dir); bool dirExists(std::string dir);
bool nothingExists(std::string path); bool nothingExists(std::string path);
bool createDirIsOk(std::string path);


int unterOption_help(); int unterOption_help();



View File

@ -216,7 +216,7 @@ int ProgramManager::defaultModus(Settings *settings)
<< settings->cookieFilePath + std::to_string( i ) << "'." << std::endl; << settings->cookieFilePath + std::to_string( i ) << "'." << std::endl;
return 174; return 174;
} }
PageManager * pm = new PageManager("socks5://" + settings->proxy_ip + ":" + std::to_string(settings->proxy_port), settings->cookieFilePath + std::to_string( i )); PageManager * pm = new PageManager(settings->proxy_ip + ":" + std::to_string(settings->proxy_port), settings->cookieFilePath + std::to_string( i ));
pm->setDebugMode(settings->debugMode); pm->setDebugMode(settings->debugMode);


//pm->setProxy(settings->proxy_ip, settings->proxy_port); //pm->setProxy(settings->proxy_ip, settings->proxy_port);
@ -697,8 +697,7 @@ int ProgramManager::convertLink(std::string redirectLink, AccountManager * accou
+ "E" + std::string( (Folge < 10) ? "0" : "" ) + std::to_string( Folge ) ); + "E" + std::string( (Folge < 10) ? "0" : "" ) + std::to_string( Folge ) );
std::string green = ((settings->colorless) ? "" : "\033[32m"), std::string green = ((settings->colorless) ? "" : "\033[32m"),
red = ((settings->colorless) ? "" : "\033[31m"), red = ((settings->colorless) ? "" : "\033[31m"),
orange =((settings->colorless) ? "" : "\033[33m"), orange =((settings->colorless) ? "" : "\033[33m");
blue = ((settings->colorless) ? "" : "\033[34m");


if(redirectLink == "" && settings->modus == Modus::DEFAULT_MODUS) { if(redirectLink == "" && settings->modus == Modus::DEFAULT_MODUS) {
if(allLinks == "") { if(allLinks == "") {