diff --git a/src/engine/helper/HL_File.cpp b/src/engine/helper/HL_File.cpp new file mode 100644 index 00000000..6cf2314b --- /dev/null +++ b/src/engine/helper/HL_File.cpp @@ -0,0 +1,31 @@ +#include "HL_File.h" +#include + +bool FileHelper::exists(const std::string& s) +{ + std::ifstream ifs(s); + return !ifs.bad(); +} + +bool FileHelper::exists(const char* s) +{ + return exists(std::string(s)); +} + +void FileHelper::remove(const std::string& s) +{ + ::remove(s.c_str()); +} + +void FileHelper::remove(const char* s) +{ + ::remove(s); +} + +std::string FileHelper::gettempname() +{ + char buffer[L_tmpnam]; + tmpnam(buffer); + + return buffer; +} diff --git a/src/engine/helper/HL_File.h b/src/engine/helper/HL_File.h new file mode 100644 index 00000000..e70eaa3f --- /dev/null +++ b/src/engine/helper/HL_File.h @@ -0,0 +1,18 @@ +#ifndef __HL_FILE_H +#define __HL_FILE_H + +#include + +class FileHelper +{ +public: + static bool exists(const std::string& s); + static bool exists(const char* s); + + static void remove(const std::string& s); + static void remove(const char* s); + + static std::string gettempname(); +}; + +#endif