diff --git a/NEWS.md b/NEWS.md index 5130ac2..6601a03 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,9 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Added +- Check software version at startup + [#30](https://github.com/orontee/argos/issues/30) + ### Changed ### Removed diff --git a/README.md b/README.md index c1cf35f..6130995 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ e-book reader. Weather data is provided by [OpenWeather](https://openweathermap.org). +**The application is compatible with hardware running software version +≥6.** + Consult the [NEWS file](NEWS.md) for notable changes between versions. ## Install diff --git a/src/app.h b/src/app.h index 831c094..060937b 100644 --- a/src/app.h +++ b/src/app.h @@ -79,13 +79,26 @@ class App { } private: - static const int error_dialog_delay{3600}; + static const int error_dialog_delay{5000}; std::shared_ptr model; std::unique_ptr service; std::unique_ptr ui; - void setup() { this->ui = std::make_unique(this->model); } + void setup() { + const auto version = GetSoftwareVersion(); + try { + check_software_version(version); + } catch (const UnsupportedSoftwareVersion &error) { + Message(ICON_WARNING, T("Unsupported software version"), + T("The application isn't compatible with the software " + "version of this reader."), + error_dialog_delay); + this->exit(); + return; + } + this->ui = std::make_unique(this->model); + } void show() { if (not this->ui) diff --git a/src/errors.h b/src/errors.h index dab71e8..8598a76 100644 --- a/src/errors.h +++ b/src/errors.h @@ -78,4 +78,8 @@ struct InvalidLocation : std::runtime_error { struct UnsupportedUnitSystem : std::runtime_error { UnsupportedUnitSystem() : std::runtime_error{""} {} }; + +struct UnsupportedSoftwareVersion : std::runtime_error { + UnsupportedSoftwareVersion() : std::runtime_error{""} {} +}; } // namespace taranis diff --git a/src/l10n.h b/src/l10n.h index 6e6fdb4..58ae6e3 100644 --- a/src/l10n.h +++ b/src/l10n.h @@ -18,6 +18,11 @@ inline void initialize_translations() { "lisez la License publique générale GNU, version 3 ou ultérieure."); // app.h + AddTranslation("Unsupported software version", "Logiciel incompatible"); + AddTranslation("The application isn't compatible with the software version " + "of this reader.", + "L'application n'est pas compatible avec la version " + "logicielle de ce matériel."); AddTranslation("Network error", "Erreur réseau"); AddTranslation( "Failure while fetching weather data. Check your network connection.", diff --git a/src/util.h b/src/util.h index f255120..67992f4 100644 --- a/src/util.h +++ b/src/util.h @@ -3,8 +3,12 @@ #include #include #include +#include +#include +#include #include +#include "errors.h" #include "model.h" namespace taranis { @@ -18,13 +22,29 @@ normalize_precipitations(const std::vector &conditions, double max_number(double value_one, double value_two); -static inline void ltrim(std::string &s) { +inline void check_software_version(const std::string &version) { + // expected form V632.6.7.1405 + std::stringstream to_parse{version}; + std::string token; + if (std::getline(to_parse, token, '.')) { + std::getline(to_parse, token, '.'); + try { + if (std::stoi(token) >= 6) { + return; + } + } catch (const std::invalid_argument &error) { + } + } + throw UnsupportedSoftwareVersion{}; +} + +inline void ltrim(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](char ch) { return not std::isspace(ch) and ch != ','; })); } -static inline void rtrim(std::string &s) { +inline void rtrim(std::string &s) { s.erase( std::find_if(s.rbegin(), s.rend(), [](char ch) { return not std::isspace(ch) and ch != ','; })