fange an pfade zu dateien zu ändern & replace errno

This commit is contained in:
Markus 2019-09-04 10:42:20 +02:00
parent 2aaf9a5acb
commit 50a366829b
2 changed files with 37 additions and 19 deletions

View File

@ -1,33 +1,51 @@
#include "parameterManager.h"

void setPaths(Settings &settings)
int setPaths(Settings &settings)
{
//Path settings
std::string executablePathTo = getexepath();
std::string CacheDir, SettingsDir;

//Entferne alles nach dem lestzten pathSymbol
executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) );
#ifdef linux
CacheDir = std::string(getenv("HOME")) + "/.cache/S_New4/";
SettingsDir = std::string( getenv("HOME") ) + "/.config/S_New4/";
#endif
#ifdef __WIN32
CacheDir = std::string(getenv("AppData")) + "\\Local\\S_New4\\";
SettingsDir = std::string( getenv("AppData") ) + "\\Roaming\\S_New4\\";
#endif

if(!dirExists(executablePathTo + "src" + settings.pathSymbol))
if(createDirIsOk(executablePathTo + "src" + settings.pathSymbol))
std::cout << " => Erfolgreich Ordner '" << executablePathTo << "src' erstellt." << std::endl;
if(!dirExists(CacheDir)) {
if(!createDirIsOk(CacheDir)) {
std::cout << " => Error: Konnte Ordner nicht erstellen: " << CacheDir << std::endl;
return -1;
} else
std::cout << " => Erfolgreich Ordner '" << CacheDir << "' erstellt." << std::endl;

if(dirExists(executablePathTo + "src" + settings.pathSymbol))
executablePathTo+="src" + std::string(1, settings.pathSymbol);
}
if(!dirExists(SettingsDir)) {
if(!createDirIsOk(SettingsDir)) {
std::cout << " => Error: Konnte Ordner nicht erstellen: " << SettingsDir << std::endl;
return -1;
} else
std::cout << " => Erfolgreich Ordner '" << SettingsDir << "' erstellt." << std::endl;
}

settings.cookieFilePath = executablePathTo + "S_New4_cookies";
settings.accountFilePath = executablePathTo + "Accounts";
settings.accountNumberPath = executablePathTo + "Account_Number";
settings.serienListPath = executablePathTo + "SerienListe";
settings.defaultsFilePath = executablePathTo + "Defaults";
settings.cookieFilePath = CacheDir + "S_New4_cookies";
settings.accountNumberPath = CacheDir + "Account_Number";

settings.accountFilePath = SettingsDir + "Accounts";
settings.serienListPath = SettingsDir + "SerienListe";
settings.defaultsFilePath = SettingsDir + "Defaults";

return 0;
}

int manageParameter(Settings &settings, int argc, char **argv)
{
//Path settings
setPathSymbol(settings);
setPaths(settings);
if(setPaths(settings) != 0)
return -1;
if(loadDefaulOptions(settings) != 0)
return 28;

@ -95,7 +113,7 @@ int loadDefaulOptions(Settings &settings)
if(!ifs.is_open()) {
std::ofstream ofs(settings.defaultsFilePath);
if(!ofs.is_open()) {
std::cout << " => Error: Konnte Defaults-Datei nicht öffnen: " << errno << std::endl;
perror((" => Error: Konnte Defaults-Datei nicht öffnen: " + settings.defaultsFilePath).c_str());
return 89;
} else {
std::cout << " => Erstelle Defaults-Datei: " << settings.defaultsFilePath << std::endl;
@ -120,7 +138,7 @@ int loadDefaulOptions(Settings &settings)
}
ifs.open(settings.defaultsFilePath);
if(!ifs.is_open()) {
std::cout << " => Error: Konnte Defaults-Datei nach dem erstellen nicht öffnen: " << errno << std::endl;
perror((" => Error: Konnte Defaults-Datei nach dem erstellen nicht öffnen: " + settings.defaultsFilePath).c_str());
return 97;
}
}
@ -847,7 +865,7 @@ void unterOption_clean(Settings * settings, int argc, char **argv)
unsigned count = 0;
if(fileExists(settings->cookieFilePath)) {
if(remove(settings->cookieFilePath.c_str()) != 0) {
std::cout << " => Error: Das löschen von " << settings->cookieFilePath << " ist fehlgeschlagen: " << errno << std::endl;
perror(( " => Error: Das löschen von " + settings->cookieFilePath + " ist fehlgeschlagen: ").c_str());
return;
} else
count++;

View File

@ -70,7 +70,7 @@ std::string getProgramName();
std::string getexepath();

void setPathSymbol(Settings &settings);
void setPaths(Settings &settings);
int setPaths(Settings &settings);

bool fileExists (const std::string& name);
bool dirExists(std::string dir);