#include <pwd.h>
#endif
#if _WIN32
-#include <Windows.h>
-#include <WinBase.h>
+#include <windows.h>
#endif
-const std::string Folders::dataDir = DATADIR;
+const std::string Folders::dataDir = DATA_DIR;
std::string Folders::getScreenshotDir()
{
std::string Folders::getGenericDirectory(const char* ENVVAR, const std::string fallback) {
const char* path = getenv(ENVVAR);
std::string ret;
- if((path != NULL) && (strlen(path) != 0)) {
+ if ((path != NULL) && (strlen(path) != 0)) {
ret = std::string(path) + "/lugaru";
} else {
- path = getHomeDirectory();
- if((path != NULL) && (strlen(path) != 0)) {
- ret = std::string(path) + '/' + fallback + "/lugaru";
+ const char* homedir = getHomeDirectory();
+ if ((homedir != NULL) && (strlen(homedir) != 0)) {
+ ret = std::string(homedir) + '/' + fallback + "/lugaru";
} else {
ret = ".";
}
bool Folders::makeDirectory(std::string path) {
#ifdef _WIN32
int status = CreateDirectory(path.c_str(), NULL);
- if(status != 0) {
+ if (status != 0) {
return true;
} else if(GetLastError() == ERROR_ALREADY_EXISTS) {
return true;
}
#endif
}
+
+FILE* Folders::openMandatoryFile(std::string filename, const char* mode)
+{
+ FILE* tfile = fopen(filename.c_str(), mode);
+ if (tfile == NULL) {
+ throw FileNotFoundException(filename);
+ }
+ return tfile;
+}