-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.cpp
77 lines (61 loc) · 1.81 KB
/
utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "utils.h"
#include <sstream>
#include <iostream>
#include <iomanip>
#include <stdexcept>
#include <filesystem>
namespace ASI
{
std::tm parseDateTime(const std::string & s)
{
std::istringstream ss(s);
std::tm t = {};
ss >> std::get_time(&t, "%Y-%m-%dT%H:%M:%S");
if (ss.fail())
{
throw std::runtime_error("Failed to parse " + s + " as time");
}
return t;
}
std::string getFilename(const std::string & folder, const std::string & ext, const size_t channel, const std::tm & date)
{
const std::filesystem::path rootPath(folder);
std::stringstream filename;
filename << "CCTV_" << channel << "_";
filename << std::put_time(&date, "%Y-%m-%d_%H_%M");
filename << ext;
const std::filesystem::path filePath = rootPath / filename.str();
const std::string result = filePath;
return filePath;
}
std::string getLiveFilename(const std::string & folder, const std::string & ext, const size_t channel)
{
const std::filesystem::path rootPath(folder);
std::stringstream filename;
filename << "CCTV_" << channel << "_live" << ext;
const std::filesystem::path filePath = rootPath / filename.str();
const std::string result = filePath;
return filePath;
}
std::string getPictureFilename(const std::string & folder, const std::string & ext, const size_t channel)
{
const std::filesystem::path rootPath(folder);
std::stringstream filename;
filename << "CCTV_" << channel << ext;
const std::filesystem::path filePath = rootPath / filename.str();
const std::string result = filePath;
return filePath;
}
std::string getEnvVar(const std::string & var)
{
const char * val = std::getenv(var.c_str());
if (val)
{
return val;
}
else
{
return std::string();
}
}
}