47 lines
956 B
C++
47 lines
956 B
C++
#include "Util.h"
|
|
#include <array>
|
|
#include <ctime>
|
|
#include <filesystem/path.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
|
|
|
|
namespace CameraRecorder {
|
|
namespace Util {
|
|
|
|
std::string GetDateTimeString(bool omitSeparator)
|
|
{
|
|
std::array<char, 17> buffer;
|
|
buffer.fill(0);
|
|
std::time_t t = std::time(nullptr);
|
|
std::tm* tm = std::localtime(&t);
|
|
|
|
if (omitSeparator)
|
|
strftime(buffer.data(), sizeof(buffer), "%Y%m%d%H%M%S", tm);
|
|
else
|
|
strftime(buffer.data(), sizeof(buffer), "%Y%m%d-%H%M%S", tm);
|
|
|
|
return buffer.data();
|
|
}
|
|
|
|
bool FolderExists(const std::string& path)
|
|
{
|
|
struct stat info;
|
|
if (stat(path.c_str(), &info) != 0)
|
|
return false;
|
|
else if (info.st_mode & S_IFDIR)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
void CreateFolder(const std::string& path)
|
|
{
|
|
int status = mkdir(path.c_str(), 0777);
|
|
if ((status < 0) && (errno != EEXIST))
|
|
throw std::runtime_error("Can't create folder.");
|
|
}
|
|
|
|
} // namespace Util
|
|
} // namespace CameraRecorder
|