- more changes to ease file handling
This commit is contained in:
parent
3164a7236d
commit
8c0f9510e6
|
|
@ -1,10 +1,18 @@
|
||||||
#include "HL_File.h"
|
#include "HL_File.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
#if defined(TARGET_LINUX) || defined(TARGET_OSX)
|
||||||
|
# include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
bool FileHelper::exists(const std::string& s)
|
bool FileHelper::exists(const std::string& s)
|
||||||
{
|
{
|
||||||
|
#if defined(TARGET_WIN)
|
||||||
std::ifstream ifs(s);
|
std::ifstream ifs(s);
|
||||||
return !ifs.bad();
|
return !ifs.bad();
|
||||||
|
#else
|
||||||
|
return (access(s.c_str(), R_OK) != -1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileHelper::exists(const char* s)
|
bool FileHelper::exists(const char* s)
|
||||||
|
|
@ -29,3 +37,33 @@ std::string FileHelper::gettempname()
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileHelper::isAbsolute(const std::string& s)
|
||||||
|
{
|
||||||
|
if (s.empty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return s.front() == '/' || s.front() == '\\';
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FileHelper::addTrailingSlash(const std::string& s)
|
||||||
|
{
|
||||||
|
if (s.empty())
|
||||||
|
return "/";
|
||||||
|
|
||||||
|
if (s.back() == '/' || s.back() == '\\')
|
||||||
|
return s;
|
||||||
|
|
||||||
|
return s + "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FileHelper::mergePathes(const std::string& s1, const std::string& s2)
|
||||||
|
{
|
||||||
|
std::string result(addTrailingSlash(s1));
|
||||||
|
if (isAbsolute(s2))
|
||||||
|
result += s2.substr(1, s2.size() - 1);
|
||||||
|
else
|
||||||
|
result += s2;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@ public:
|
||||||
static void remove(const char* s);
|
static void remove(const char* s);
|
||||||
|
|
||||||
static std::string gettempname();
|
static std::string gettempname();
|
||||||
|
static bool isAbsolute(const std::string& s);
|
||||||
|
|
||||||
|
static std::string addTrailingSlash(const std::string& s);
|
||||||
|
static std::string mergePathes(const std::string& s1, const std::string& s2);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue