-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfilenamegenerator.cpp
142 lines (123 loc) · 3.62 KB
/
filenamegenerator.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "filenamegenerator.h"
fileNameGenerator::fileNameGenerator()
{
shortFilename = "unset";
directory = "unset";
extension = "unset";
}
void fileNameGenerator::setFlightFormat(bool useFlightFormat, QString flightNamePrefix="")
{
this->flightFormat = useFlightFormat;
if(flightFormat)
{
this->namePrefix = flightNamePrefix;
//this->extension = "";
}
}
void fileNameGenerator::setMainDirectory(QString basedir)
{
this->directory = basedir;
}
void fileNameGenerator::setFilenameExtension(QString extension)
{
this->extension = extension;
}
QString fileNameGenerator::getNewFullFilename(QString basedir, QString extension)
{
// This is what to call when you need a new filename.
this->directory = basedir;
this->extension = extension;
generate();
return getFullFilename();
}
QString fileNameGenerator::getNewFullFilename(QString basedir,
QString prefix,
QString postfix, QString extension)
{
// This is what to call when you need a new filename.
// If you want to generate a second filename usig the existing timestamp,
// then just call getFullFilename(prefix, postfix, extension) directly.
this->directory = basedir;
this->extension = extension;
generate();
return getFullFilename(prefix, postfix, extension);
}
QString fileNameGenerator::getNewFullFilename()
{
generate();
return getFullFilename();
}
QString fileNameGenerator::getFullFilename()
{
if(extension.isEmpty())
return directory + "/" + shortFilename;
else
return directory + "/" + shortFilename + "." + extension;
}
QString fileNameGenerator::getFullFilename(QString extension)
{
if(extension.isEmpty())
return directory + "/" + shortFilename;
else
return directory + "/" + shortFilename + "." + extension;
}
QString fileNameGenerator::getFullFilename(QString prefix, QString postfix, QString extension)
{
if(extension.isEmpty())
return directory + "/" + prefix + shortFilename + postfix;
else
return directory + "/" + prefix + shortFilename + postfix + "." + extension;
}
QString fileNameGenerator::getShortFilename()
{
if(extension.isEmpty())
return shortFilename;
else
return shortFilename + extension;
}
QString fileNameGenerator::getFilenameExtension()
{
return extension;
}
void fileNameGenerator::generate()
{
shortFilename = getTimeDatestring();
}
QString fileNameGenerator::getTimeDatestring()
{
// YYYY-MM-DD_HHMMSS UTC
QDateTime now = QDateTime::currentDateTimeUtc();
QString dateString;
if(flightFormat)
{
dateString.append(namePrefix);
dateString.append(now.toString("yyyyMMdd"));
dateString.append("t"); // t = "timezone" in datetime, so we must append it this way.
dateString.append(now.toString("hhmmss"));
} else {
// Older format:
dateString = now.toString("yyyy-MM-dd_hhmmss");
}
//qDebug() << __PRETTY_FUNCTION__ << "time string: " << dateString;
return dateString;
}
bool fileNameGenerator::createDirectory(QString directoryName)
{
if(directoryName.isEmpty())
{
qDebug() << "ERROR! GPS Base Directory requested for primary log is blank!";
return false;
}
QDir dir(directoryName);
if (!dir.exists())
dir.mkpath(".");
if(!dir.exists())
{
qDebug() << "ERROR! Could not create gps primary log directory " << directoryName;
}
return dir.exists();
}
bool fileNameGenerator::createDirectory()
{
return this->createDirectory(this->directory);
}