27namespace sharg::detail
64 version_checker() =
delete;
65 version_checker(version_checker
const &) =
default;
66 version_checker & operator=(version_checker
const &) =
default;
67 version_checker(version_checker &&) =
default;
68 version_checker & operator=(version_checker &&) =
default;
69 ~version_checker() =
default;
77 name{std::move(name_)}
79 assert(std::regex_match(name,
std::regex{
"^[a-zA-Z0-9_-]+$"}));
83 message_app_update.pop_back();
84 message_app_update.append(
"[APP VERSION INFO] :: Visit " + app_url +
" for updates.\n\n");
88 timestamp_filename = cookie_path / (name +
"_usr.timestamp");
90 timestamp_filename = cookie_path / (name +
"_dev.timestamp");
95 if (!version_.
empty() &&
98 version = versionMatch.
str(1);
135 std::ifstream version_file{cookie_path / (name +
".version")};
137 if (version_file.is_open())
142 if (line != unregistered_app)
143 srv_app_version = get_numbers_from_version_string(line);
150 srv_sharg_version = get_numbers_from_version_string(line);
152 version_file.close();
156 if (srv_sharg_version != empty_version)
160 if (sharg_version < srv_sharg_version)
165 if (srv_app_version != empty_version)
168 if (get_numbers_from_version_string(version) < srv_app_version)
173 if (get_numbers_from_version_string(version) > srv_app_version)
174 std::cerr << message_registered_app_update;
193 " " + out_file.
string() +
" "
194 +
std::string{
"https://seqan-update.informatik.uni-tuebingen.de/check/SeqAn-Sharg_"} +
208#if __x86_64__ || __ppc64__
216 "; exit [int] -not $?}\" > nul 2>&1";
233 tmp_path /=
".config";
251 path dummy = tmp_path /
"dummy.txt";
253 sharg::detail::safe_filesystem_entry file_guard{dummy};
255 bool is_open = file.is_open();
256 bool is_good = file.good();
258 file_guard.remove_no_throw();
260 if (!is_good || !is_open)
298 if (std::getenv(
"SHARG_NO_VERSION_CHECK") !=
nullptr)
302 return user_approval.
value();
310 if (timestamp_file.is_open())
314 if (get_time_diff_to_current(cookie_line) < 86400 )
321 if (cookie_line ==
"NEVER")
325 else if (cookie_line ==
"ALWAYS")
331 timestamp_file.close();
339 if (detail::is_terminal())
342#######################################################################
343 Automatic Update Notifications
344#######################################################################
346 This app can look for updates automatically in the background,
347 do you want to do that?
349 [a] Always perform version checks for this app (the default).
350 [n] Never perform version checks for this app.
351 [y] Yes, perform a version check now, and ask again tomorrow.
352 [s] Skip the version check now, but ask again tomorrow.
354 Please enter one of [a, n, y, s] and press [RETURN].
356 For more information, see:
357 https://docs.seqan.de/sharg/main_user/about_update_notifications.html
359#######################################################################
391#######################################################################
392 Automatic Update Notifications
393#######################################################################
394 This app performs automatic checks for updates. For more information
395 see: https://docs.seqan.de/sharg/main_user/about_update_notifications.html
396#######################################################################
407 "[SHARG VERSION INFO] :: A new Sharg version is available online.\n"
408 "[SHARG VERSION INFO] :: Please visit www.github.com/seqan/sharg-parser.git for an update\n"
409 "[SHARG VERSION INFO] :: or inform the developer of this app.\n"
410 "[SHARG VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n";
413 "[SHARG VERSION INFO] :: Thank you for using Sharg!\n"
414 "[SHARG VERSION INFO] :: Do you wish to register your app for update notifications?\n"
415 "[SHARG VERSION INFO] :: Just send an email to support@seqan.de with your app name and version number.\n"
416 "[SHARG VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n";
419 "[APP VERSION INFO] :: We noticed the app version you use is newer than the one registered with us.\n"
420 "[APP VERSION INFO] :: Please send us an email with the new version so we can correct it "
421 "(support@seqan.de)\n\n";
424 "[APP VERSION INFO] :: A new version of this application is now available.\n"
425 "[APP VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n";
429 static constexpr char const * home_env_name
443 std::regex version_regex{
"^[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+$"};
454 return "powershell.exe -NoLogo -NonInteractive -Command \"& {Invoke-WebRequest -erroraction 'silentlycontinue' "
457 if (!
system(
"/usr/bin/env -i wget --version > /dev/null 2>&1"))
458 return "/usr/bin/env -i wget --timeout=10 --tries=1 -q -O";
459 else if (!
system(
"/usr/bin/env -i curl --version > /dev/null 2>&1"))
460 return "/usr/bin/env -i curl --connect-timeout 10 -o";
463# if defined(__OpenBSD__)
464 return "/usr/bin/env -i ftp -w10 -Vo";
465# elif defined(__FreeBSD__)
466 return "/usr/bin/env -i fetch --timeout=10 -o";
474 double get_time_diff_to_current(
std::string const & str_time)
const
477 double curr = co::duration_cast<co::seconds>(co::system_clock::now().time_since_epoch()).count();
482 return curr - d_time;
492 if (!std::regex_match(str, version_regex))
506 template <
typename msg_type>
507 void write_cookie(msg_type && msg)
511 auto curr = co::duration_cast<co::seconds>(co::system_clock::now().time_since_epoch()).count();
515 if (timestamp_file.is_open())
517 timestamp_file << curr <<
'\n' << msg;
518 timestamp_file.close();
Provides auxiliary information.
The <charconv> header from C++17's standard library.
T create_directory(T... args)
update_notifications
Indicates whether application allows automatic update notifications by the sharg::parser.
Definition: auxiliary.hpp:29
@ off
Automatic update notifications should be disabled.
from_chars_result from_chars(char const *first, char const *last, floating_point_type &value, chars_format fmt=chars_format::general) noexcept
Parse a char sequence into an floating point value.
Definition: charconv:260
T regex_search(T... args)
Provides sharg::detail::safe_filesystem_entry.
T temp_directory_path(T... args)
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
#define SHARG_VERSION_MINOR
The minor version as MACRO.
Definition: version.hpp:20
#define SHARG_VERSION_PATCH
The patch version as MACRO.
Definition: version.hpp:22
constexpr std::size_t sharg_version
The full version as std::size_t.
Definition: version.hpp:63
#define SHARG_VERSION_MAJOR
The major version as MACRO.
Definition: version.hpp:18