forked from markus/S_New4
fange an pfade zu dateien zu ändern & replace errno
This commit is contained in:
parent
2aaf9a5acb
commit
50a366829b
@ -1,33 +1,51 @@
|
|||||||
#include "parameterManager.h"
|
#include "parameterManager.h"
|
||||||
|
|
||||||
void setPaths(Settings &settings)
|
int setPaths(Settings &settings)
|
||||||
{
|
{
|
||||||
//Path settings
|
//Path settings
|
||||||
std::string executablePathTo = getexepath();
|
std::string CacheDir, SettingsDir;
|
||||||
|
|
||||||
//Entferne alles nach dem lestzten pathSymbol
|
#ifdef linux
|
||||||
executablePathTo.erase(executablePathTo.find_last_of(settings.pathSymbol) + 1 , executablePathTo.length() - ( executablePathTo.find_last_of(settings.pathSymbol) + 1) );
|
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(!dirExists(CacheDir)) {
|
||||||
if(createDirIsOk(executablePathTo + "src" + settings.pathSymbol))
|
if(!createDirIsOk(CacheDir)) {
|
||||||
std::cout << " => Erfolgreich Ordner '" << executablePathTo << "src' erstellt." << std::endl;
|
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.cookieFilePath = CacheDir + "S_New4_cookies";
|
||||||
settings.accountFilePath = executablePathTo + "Accounts";
|
settings.accountNumberPath = CacheDir + "Account_Number";
|
||||||
settings.accountNumberPath = executablePathTo + "Account_Number";
|
|
||||||
settings.serienListPath = executablePathTo + "SerienListe";
|
|
||||||
settings.defaultsFilePath = executablePathTo + "Defaults";
|
|
||||||
|
|
||||||
|
settings.accountFilePath = SettingsDir + "Accounts";
|
||||||
|
settings.serienListPath = SettingsDir + "SerienListe";
|
||||||
|
settings.defaultsFilePath = SettingsDir + "Defaults";
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int manageParameter(Settings &settings, int argc, char **argv)
|
int manageParameter(Settings &settings, int argc, char **argv)
|
||||||
{
|
{
|
||||||
//Path settings
|
//Path settings
|
||||||
setPathSymbol(settings);
|
setPathSymbol(settings);
|
||||||
setPaths(settings);
|
if(setPaths(settings) != 0)
|
||||||
|
return -1;
|
||||||
if(loadDefaulOptions(settings) != 0)
|
if(loadDefaulOptions(settings) != 0)
|
||||||
return 28;
|
return 28;
|
||||||
|
|
||||||
@ -95,7 +113,7 @@ int loadDefaulOptions(Settings &settings)
|
|||||||
if(!ifs.is_open()) {
|
if(!ifs.is_open()) {
|
||||||
std::ofstream ofs(settings.defaultsFilePath);
|
std::ofstream ofs(settings.defaultsFilePath);
|
||||||
if(!ofs.is_open()) {
|
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;
|
return 89;
|
||||||
} else {
|
} else {
|
||||||
std::cout << " => Erstelle Defaults-Datei: " << settings.defaultsFilePath << std::endl;
|
std::cout << " => Erstelle Defaults-Datei: " << settings.defaultsFilePath << std::endl;
|
||||||
@ -120,7 +138,7 @@ int loadDefaulOptions(Settings &settings)
|
|||||||
}
|
}
|
||||||
ifs.open(settings.defaultsFilePath);
|
ifs.open(settings.defaultsFilePath);
|
||||||
if(!ifs.is_open()) {
|
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;
|
return 97;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -847,7 +865,7 @@ void unterOption_clean(Settings * settings, int argc, char **argv)
|
|||||||
unsigned count = 0;
|
unsigned count = 0;
|
||||||
if(fileExists(settings->cookieFilePath)) {
|
if(fileExists(settings->cookieFilePath)) {
|
||||||
if(remove(settings->cookieFilePath.c_str()) != 0) {
|
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;
|
return;
|
||||||
} else
|
} else
|
||||||
count++;
|
count++;
|
||||||
|
@ -70,7 +70,7 @@ std::string getProgramName();
|
|||||||
std::string getexepath();
|
std::string getexepath();
|
||||||
|
|
||||||
void setPathSymbol(Settings &settings);
|
void setPathSymbol(Settings &settings);
|
||||||
void setPaths(Settings &settings);
|
int 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);
|
||||||
|
Loading…
Reference in New Issue
Block a user