Nix (Dev) 3.5.10
dev - 3.5.10 - 1af9301
Loading...
Searching...
No Matches
version.hpp
Go to the documentation of this file.
1#ifndef LIBS_BASIC_VERSION_HPP_
2#define LIBS_BASIC_VERSION_HPP_
3
4#include <iostream>
5#include <cstdio>
6#include <string>
7
8#include "core/assert.hpp"
9#include "core/defines.hpp"
11#include "third_party/HTTPRequest.hpp"
12#include "utils/stringUtils.hpp"
13
14#define RESET "\033[0m"
15#define BLACK "\033[30m" /* Black */
16#define RED "\033[31m" /* Red */
17#define GREEN "\033[32m" /* Green */
18#define YELLOW "\033[33m" /* Yellow */
19#define BLUE "\033[34m" /* Blue */
20#define MAGENTA "\033[35m" /* Magenta */
21#define CYAN "\033[36m" /* Cyan */
22#define WHITE "\033[37m" /* White */
23#define BOLD_BLACK "\033[1m\033[30m" /* Bold Black */
24#define BOLD_RED "\033[1m\033[31m" /* Bold Red */
25#define BOLD_GREEN "\033[1m\033[32m" /* Bold Green */
26#define BOLD_YELLOW "\033[1m\033[33m" /* Bold Yellow */
27#define BOLD_BLUE "\033[1m\033[34m" /* Bold Blue */
28#define BOLD_MAGENTA "\033[1m\033[35m" /* Bold Magenta */
29#define BOLD_CYAN "\033[1m\033[36m" /* Bold Cyan */
30#define BOLD_WHITE "\033[1m\033[37m" /* Bold White */
31#define SUB_WHITE "\033[4m\033[37m"
32
33namespace sedni
34{
35
37{
38public:
39 Version() = delete;
40 Version(const Version &other) = delete;
41 Version &operator=(const Version &other) = delete;
42 Version(Version &&other) = delete;
43 Version &operator=(Version &&other) = delete;
44 ~Version() = delete;
45
46 static std::string companyName()
47 {
48 return kPrvCompanyName;
49 }
50
51 static std::string developingMessage()
52 {
54 }
55
56 static std::string diamarVersion()
57 {
58 return kPrvDiamarVersion;
59 }
60
61 static std::string diamarEditorVersion()
62 {
64 }
65
66 static std::string diamarCodename()
67 {
68 return kPrvDiamarCodename;
69 }
70
71 static std::string diamarEditorName()
72 {
74 }
75
76 static std::string gitBuildData()
77 {
78 return kPrvGitBuildData;
79 }
80
81 static std::string gitBuildTimestamp()
82 {
83 return kPrvTimestamp;
84 }
85
86 static std::string gitCommit()
87 {
88 return kPrvGitCommit;
89 }
90
92 {
93 printf(_(BOLD_WHITE "\nNAME" RESET "\n"));
94 printf("\t%s\n", kPrvDiamarEditorName.c_str());
95 printf(_("\tVersion: "));
96 printf("%s\n\t%s\n", kPrvDiamarEditorVersion.c_str(), kPrvDevelopingMessage.c_str());
97 printf(_("\n" BOLD_WHITE "SYNOPSIS:" RESET "\n\t" BOLD_WHITE "editDiamar " RESET "[" SUB_WHITE "OPTIONS" RESET "]\n\n"));
98 printf(_(BOLD_WHITE "DESCRIPTION" RESET "\n\n"));
99 printf(_(BOLD_WHITE" \t-h,-help:" RESET "\n\t\thelp\n\n"));
100 printf(_(BOLD_WHITE "\t-v:" RESET "\n\t\tprogram's version\n\n"));
101 printf(_(BOLD_WHITE"\t-version:" RESET "\n\t\tprogram's information\n"));
102 printf("\n");
103 }
104
109 static void showDiamarEditorInfo(bool showInConsole = false)
110 {
111 std::string msg;
112
115
116 if (showInConsole)
117 {
118 printf("%s", msg.c_str());
119 }
120 else
122 }
123
128 {
129 printf("%s\n", kPrvDiamarEditorVersion.c_str());
130#ifndef NDEBUG
131 printf("%s\n", kPrvDevelopingMessage.c_str());
132#endif
133 }
134
135 static void showDiamarHelp()
136 {
137 printf(_(BOLD_WHITE "\nNAME" RESET "\n"));
138 printf("\t%s\n", kPrvDiamarName.c_str());
139 printf(_("\tVersion: "));
140 printf("%s\n\t%s\n", kPrvDiamarVersion.c_str(), kPrvDevelopingMessage.c_str());
141 printf(_("\n" BOLD_WHITE "SYNOPSIS:" RESET "\n\t" BOLD_WHITE "diamar " RESET "[" SUB_WHITE "OPTIONS" RESET "]\n\n"));
142 printf(_(BOLD_WHITE "DESCRIPTION" RESET "\n\n"));
143 printf(_(BOLD_WHITE " \t-h,-help:" RESET "\n\t\thelp\n\n"));
144 printf(_(BOLD_WHITE "\t-v:" RESET "\n\t\tprogram's version\n\n"));
145 printf(_(BOLD_WHITE "\t-version:" RESET "\n\t\tprogram's information\n"));
146 printf("\n");
147 }
148
153 static void showDiamarInfo(bool showInConsole = false)
154 {
155 std::string msg;
156
159
160 if (showInConsole)
161 {
162 printf("%s", msg.c_str());
163 }
164 else
165 {
167 }
168 }
169
173 static void showDiamarVersion()
174 {
175 printf("%s\n", kPrvDiamarVersion.c_str());
176#ifndef NDEBUG
177 printf("%s\n", kPrvDevelopingMessage.c_str());
178#endif
179 }
180
181 static bool isUpdateAvailable(std::optional<std::string> &version)
182 {
183 try
184 {
185 const auto currentVersion = sedni::Version::gitCommit();
186 auto httpRequest = http::Request("http://192.168.0.30/latest/version.txt");
187 const auto response = httpRequest.send();
188
189 if (response.status.code != http::Status::Code::Ok)
190 {
191 version = std::nullopt;
192 return false;
193 }
194
195 std::string receivedBody(response.body.begin(), response.body.end());
196 const auto splitted = iv::utils::splitOn(receivedBody, '\n');
197 const auto versionLine = std::find_if(splitted.begin(), splitted.end(), [](const std::string &line)
198 { return line.find("COMMIT") != std::string::npos; });
199 if (versionLine == splitted.end())
200 {
201 version = std::nullopt;
202 return false;
203 }
204
205 const auto versionString = iv::utils::splitOn(*versionLine, '=');
206 if (versionString.size() != 2)
207 {
208 version = std::nullopt;
209 return false;
210 }
211
212 version = versionString[1];
213
214 return version.value() != currentVersion;
215 }
216 catch (const std::exception &e)
217 {
218 std::cerr << e.what() << std::endl;
219 return false;
220 }
221 }
222
223private:
224 static std::string prvBuildMessageInfo(const std::string &programName, const std::string &version,
225 const std::string &codename, const std::string &buildNumber,
226 const std::string &sourceCommitId)
227 {
228 std::string message;
229
230 message = programName + " info:\n\t";
231 message += "Codename: " + codename + "\n\t";
232 message += _("Version: ") + version + "\n\t";
233 message += "Git:" + sourceCommitId + "\n\t";
234 message += _("Compiled date: ") + buildNumber + "\n";
235
236#ifndef NDEBUG
237 message += "\n" + kPrvDevelopingMessage + "\n";
238#endif
239
240 return message;
241 }
242
243 static inline const std::string kPrvCompanyName = "Sedni";
244
245 static inline const std::string kPrvDiamarName = "Diamar";
246 static inline const std::string kPrvDiamarVersion = "3.5.10";
247 static inline const std::string kPrvDiamarEditorName = "editDiamar";
248 static inline const std::string kPrvDiamarEditorVersion = "3.5.10";
249 static inline const std::string kPrvDiamarCodename = "Matsu";
250
251 static inline const std::string kPrvDevelopingMessage = _("[Version NOT distributable]");
252
253 static inline const std::string kPrvGitBuildData = "HEAD:1af93018";
254 static inline const std::string kPrvTimestamp = "2025-06-25";
255 static inline const std::string kPrvGitCommit = "";
256};
257
258} // namespace sedni
259
260#endif /* LIBS_BASIC_VERSION_HPP_ */
static void showInfoDialog(std::string_view msg)
Show a zenity dialog with the message.
Definition CLoggerZenity.cpp:81
Definition version.hpp:37
Version & operator=(Version &&other)=delete
static const std::string kPrvDevelopingMessage
Definition version.hpp:251
static const std::string kPrvDiamarEditorVersion
Definition version.hpp:248
static std::string diamarVersion()
Definition version.hpp:56
static const std::string kPrvDiamarCodename
Definition version.hpp:249
static const std::string kPrvGitBuildData
Definition version.hpp:253
static bool isUpdateAvailable(std::optional< std::string > &version)
Definition version.hpp:181
static void showDiamarInfo(bool showInConsole=false)
Definition version.hpp:153
static const std::string kPrvDiamarName
Definition version.hpp:245
static std::string prvBuildMessageInfo(const std::string &programName, const std::string &version, const std::string &codename, const std::string &buildNumber, const std::string &sourceCommitId)
Definition version.hpp:224
Version(Version &&other)=delete
static const std::string kPrvCompanyName
Definition version.hpp:243
Version()=delete
static void showDiamarEditorHelp()
Definition version.hpp:91
static std::string diamarEditorVersion()
Definition version.hpp:61
static std::string developingMessage()
Definition version.hpp:51
static void showDiamarEditorInfo(bool showInConsole=false)
Definition version.hpp:109
static std::string gitCommit()
Definition version.hpp:86
static void showDiamarHelp()
Definition version.hpp:135
static const std::string kPrvDiamarEditorName
Definition version.hpp:247
static void showDiamarEditorVersion()
Definition version.hpp:127
static std::string diamarCodename()
Definition version.hpp:66
static const std::string kPrvDiamarVersion
Definition version.hpp:246
static const std::string kPrvGitCommit
Definition version.hpp:255
static void showDiamarVersion()
Definition version.hpp:173
Version(const Version &other)=delete
static std::string gitBuildTimestamp()
Definition version.hpp:81
static std::string companyName()
Definition version.hpp:46
static const std::string kPrvTimestamp
Definition version.hpp:254
Version & operator=(const Version &other)=delete
~Version()=delete
static std::string diamarEditorName()
Definition version.hpp:71
static std::string gitBuildData()
Definition version.hpp:76
#define _(string)
Definition defines.hpp:169
void debugInfo(std::string_view message)
Definition assert.cpp:123
std::vector< StringType > splitOn(const StringType &str, const DelimiterType &delim)
Definition stringUtils.hpp:104
Definition matrix.h:9
#define SUB_WHITE
Definition version.hpp:31
#define BOLD_WHITE
Definition version.hpp:30
#define RESET
Definition version.hpp:14