FILE *tfile;
int numaccounts;
int accountactive;
+ errno = 0;
tfile = fopen(filename.c_str(), "rb" );
void Account::saveFile(string filename, Account* accountactive)
{
FILE *tfile;
+ errno = 0;
tfile = fopen(filename.c_str(), "wb" );
if (tfile) {
vector<string> ListCampaigns()
{
+ errno = 0;
DIR *campaigns = opendir(Folders::getResourcePath("Campaigns").c_str());
struct dirent *campaign = NULL;
if (!campaigns) {
- perror("Problem while loading campaigns");
- cerr << "campaign folder was : " << Folders::getResourcePath("Campaigns") << endl;
+ perror(("Problem while loading campaigns from " + Folders::getResourcePath("Campaigns")).c_str());
exit(EXIT_FAILURE);
}
vector<string> campaignNames;
int mapvers;
FILE *tfile;
+ errno = 0;
tfile = fopen( Folders::getResourcePath("Maps/"+name).c_str(), "rb" );
if (tfile) {
pause_sound(stream_firesound);
newscreenheight = screenheight;
if (newscreenheight < 0)
newscreenheight = screenheight;
+ errno = 0;
ofstream opstream(Folders::getConfigFilePath());
if (opstream.fail()) {
perror(("Couldn't save config file " + Folders::getConfigFilePath()).c_str());
bool LoadSettings()
{
+ errno = 0;
ifstream ipstream(Folders::getConfigFilePath(), std::ios::in);
if ( ipstream.fail() ) {
perror(("Couldn't read config file " + Folders::getConfigFilePath()).c_str());
#include "Folders.h"
#include <cstring>
+#include <sys/stat.h>
const std::string Folders::dataDir = DATADIR;
std::string Folders::getScreenshotDir()
{
- /* TODO - create folder if missing */
- return getUserDataPath() + "/Screenshots";
+ std::string screenshotDir = getUserDataPath() + "/Screenshots";
+ makeDirectory(screenshotDir);
+ return screenshotDir;
}
std::string Folders::getResourcePath(std::string filepath)
std::string Folders::getUserDataPath()
{
- return getGenericDirectory("XDG_DATA_HOME", ".local/share");
+ std::string userDataPath = getGenericDirectory("XDG_DATA_HOME", ".local/share");
+ makeDirectory(userDataPath);
+ return userDataPath;
}
std::string Folders::getConfigFilePath()
{
- return getGenericDirectory("XDG_CONFIG_HOME", ".config") + "/config.txt";
+ std::string configFolder = getGenericDirectory("XDG_CONFIG_HOME", ".config");
+ makeDirectory(configFolder);
+ return configFolder + "/config.txt";
}
/* Generic code for XDG ENVVAR test and fallback */
if((path != NULL) && (strlen(path) != 0)) {
ret = std::string(path) + '/' + fallback + "/lugaru";
} else {
- ret = "";
+ ret = ".";
}
}
return ret;
}
+
+bool Folders::makeDirectory(std::string path) {
+ errno = 0;
+ int status = mkdir(path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+ if (status == 0) {
+ return true;
+ } else if(errno == EEXIST) {
+ return true;
+ } else {
+ return false;
+ }
+}