diff --git a/CHANGELOG.md b/CHANGELOG.md index 404d88070..1c55ed252 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,4 +12,8 @@ If such a setting is enabled, glfwSwapInterval will have no effect." said GLFW. # 1.1.1 -- Added networking libraries curl, cpr (additional zlib, mbedtls for linux builds) \ No newline at end of file +- Added networking libraries curl, cpr (additional zlib, mbedtls for linux builds) + +# 1.2.1 +- Added Check for updates functionality in menu bar help -> Check for updates +- Preparing for release v1.2.1 (which has all above features since v1.0.1) diff --git a/Enigma.log b/Enigma.log index d60e88330..db01a6f68 100644 --- a/Enigma.log +++ b/Enigma.log @@ -1,17 +1,20 @@ -[2021-02-19 19:11:32] [info] Enigma: [ OpenGL Info ] +[2021-02-20 20:04:55] [info] Enigma: [ OpenGL Info ] Manufacturer: Intel Renderer: Intel(R) HD Graphics 4600 Version: 3.3.0 - Build 20.19.15.5126 -[2021-02-19 19:11:33] [trace] Enigma: __cdecl Enigma::MainMenuScene::MainMenuScene(void) noexcept -[2021-02-19 19:11:33] [trace] Enigma: void __cdecl Enigma::MainMenuScene::OnCreate(void) -[2021-02-19 19:11:33] [trace] Enigma: void __cdecl Enigma::MainMenuScene::LoadImGuiFonts(void) -[2021-02-19 19:11:33] [trace] Enigma: Loading Fonts... -[2021-02-19 19:11:33] [trace] Enigma: Loaded Montserrat-Medium.ttf, 18px -[2021-02-19 19:11:33] [trace] Enigma: Loaded Audiowide-Regular.ttf, 60px -[2021-02-19 19:11:33] [trace] Enigma: Loaded Audiowide-Regular.ttf, 45px -[2021-02-19 19:11:33] [trace] Enigma: Loaded Audiowide-Regular.ttf, 20px -[2021-02-19 19:11:33] [trace] Enigma: Loaded Montserrat-Medium.ttf, 12px -[2021-02-19 19:11:33] [trace] Enigma: Loaded Montserrat-Medium.ttf, 45px -[2021-02-19 19:11:33] [trace] Enigma: Loaded Montserrat-Medium.ttf, 20px -[2021-02-19 19:11:39] [trace] Enigma: void __cdecl Enigma::MainMenuScene::OnDestroy(void) +[2021-02-20 20:04:55] [trace] Enigma: __cdecl Enigma::MainMenuScene::MainMenuScene(void) noexcept +[2021-02-20 20:04:55] [trace] Enigma: void __cdecl Enigma::MainMenuScene::OnCreate(void) +[2021-02-20 20:04:55] [trace] Enigma: void __cdecl Enigma::MainMenuScene::LoadImGuiFonts(void) +[2021-02-20 20:04:55] [trace] Enigma: Loading Fonts... +[2021-02-20 20:04:55] [trace] Enigma: Loaded Montserrat-Medium.ttf, 18px +[2021-02-20 20:04:55] [trace] Enigma: Loaded Audiowide-Regular.ttf, 60px +[2021-02-20 20:04:55] [trace] Enigma: Loaded Audiowide-Regular.ttf, 45px +[2021-02-20 20:04:55] [trace] Enigma: Loaded Audiowide-Regular.ttf, 20px +[2021-02-20 20:04:55] [trace] Enigma: Loaded Montserrat-Medium.ttf, 12px +[2021-02-20 20:04:55] [trace] Enigma: Loaded Montserrat-Medium.ttf, 45px +[2021-02-20 20:04:55] [trace] Enigma: Loaded Montserrat-Medium.ttf, 20px +[2021-02-20 20:04:56] [trace] Enigma: void __cdecl Enigma::MainMenuScene::OnCheckForUpdatesMenuButtonPressed(void) +[2021-02-20 20:04:56] [trace] Enigma: Getting latest release info... +[2021-02-20 20:05:00] [info] Enigma: You are using the latest Enigma version v1.0.0 +[2021-02-20 20:05:01] [trace] Enigma: void __cdecl Enigma::MainMenuScene::OnDestroy(void) diff --git a/Source/Core/Version.hpp b/Source/Core/Version.hpp index ec60f498f..d8c7e9612 100644 --- a/Source/Core/Version.hpp +++ b/Source/Core/Version.hpp @@ -4,9 +4,9 @@ namespace Enigma { - static constexpr const char ENIGMA_VERSION[] = "1.1.1"; + static constexpr const char ENIGMA_VERSION[] = "1.2.1"; - static constexpr const char* ENIGMA_LICENCE = + static constexpr const char* ENIGMA_LICENSE = "The MIT License (MIT)\n" "Copyright (c) Bader Eddine Ouaich and other contributors\n" "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n" @@ -14,5 +14,14 @@ namespace Enigma "THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."; } - +/* +https://semver.org/ +https://www.geeksforgeeks.org/introduction-semantic-versioning/ +Given a version number MAJOR.MINOR.PATCH, increment the: +- 1. MAJOR version when you make incompatible API changes (e.g. installer-users have to modify their infrastructure (phone/tablet/PC/web-server/firewall config/etc) in some way) +- 2. MINOR version when you add functionality in a backwards compatible manner (e.g. passing additional data to an already-provisioned API or adding any end-user functionality that does not affect the installation-requirements) +- 3. PATCH version when you make backwards compatible bug fixes (e.g. fixing any end-user bug that does not affect the installation requirements) +Additional labels for pre-release and build metadata are available +as extensions to the MAJOR.MINOR.PATCH format. +*/ #endif // !ENIGMA_VERSION_H diff --git a/Source/Main.cpp b/Source/Main.cpp index cc0ebfe16..3c686e7f0 100644 --- a/Source/Main.cpp +++ b/Source/Main.cpp @@ -15,24 +15,8 @@ #include #endif -//#include -#include -// - int main(int argc, char* argv[]) { - //Test - const auto& current_version = Enigma::ENIGMA_VERSION; - cpr::Response r = cpr::Get(cpr::Url{ Enigma::Constants::Links::ENIGMA_GITHUB_API_LATEST_RELEASE }); - if (r.status_code == cpr::status::HTTP_OK) - { - std::cout << "r.status_code " << r.status_code << std::endl; // 200 - std::cout << "r.header " << r.header["content-type"] << std::endl; // application/json; charset=utf-8 - std::cout << "r.text " << r.text << std::endl; - } - return 0; - - // Initialize Enigma Logger Enigma::Logger::Initialize(); #if !ENIGMA_TEST @@ -40,9 +24,7 @@ int main(int argc, char* argv[]) if (argc > 1) { std::unique_ptr _Cli = std::make_unique(argc, argv); - auto ret = _Cli->Run(); - Enigma::Logger::Shutdown(); - return ret; + return _Cli->Run(); } // Application Entry else @@ -55,8 +37,6 @@ int main(int argc, char* argv[]) std::unique_ptr _App = std::make_unique(window_settings); // Run Application _App->Run(); - // Shutdown Logger - Enigma::Logger::Shutdown(); // Exit return EXIT_SUCCESS; } @@ -64,9 +44,6 @@ int main(int argc, char* argv[]) { // Exit abnormally ENIGMA_CRITICAL(e.what()); - // Shutdown Logger - Enigma::Logger::Shutdown(); - // Exit return EXIT_FAILURE; } diff --git a/Source/Networking/CheckForUpdates.hpp b/Source/Networking/CheckForUpdates.hpp index 77948bf09..1ff4bd3db 100644 --- a/Source/Networking/CheckForUpdates.hpp +++ b/Source/Networking/CheckForUpdates.hpp @@ -6,46 +6,114 @@ #include #include -#include -//Constants::Links::ENIGMA_LATEST_RELEASE_GITHUB_API -constexpr const auto URL = "https://api.github.com/repos/BaderEddineOuaich/Enigma/releases/latest"; -//TODO +#include + +#include // cpr (cURL c++ wrapper) +#include // nlohmann-json +using namespace nlohmann; + NS_ENIGMA_BEGIN class ENIGMA_API CheckForUpdates final { - struct ReleaseInfo +public: + struct LatestReleaseInfo { + + String name; // "name": "Enigma Release (Windows x64, Linux x64)", String tag_name; // version e.g v1.0.0 String created_at;//"created_at": "2021-02-06T11:41:26Z", String published_at; //"published_at" : "2021-02-06T12:16:37Z", + String body; // "body": "Enigma first stable release for Windows x64 and Linux x64 using:\r\n- Crypto++ v8.4.0\r\n- GLFW v3.3.2\r\n- ImGui v1.79\r\n- spdlog v1.8.0\r\n- and other libraries" + String tarball_url; // "tarball_url": "https://api.github.com/repos/BaderEddineOuaich/Enigma/tarball/v1.0.0", + String zipball_url; // "zipball_url" : "https://api.github.com/repos/BaderEddineOuaich/Enigma/zipball/v1.0.0", + + LatestReleaseInfo() + : + tag_name(""), + name(""), + created_at(""), + published_at(""), + body(""), + tarball_url(""), + zipball_url("") + {} + + ~LatestReleaseInfo() + { + tag_name.clear(); + created_at.clear(); + published_at.clear(); + body.clear(); + } + + static std::unique_ptr FromJson(const json& obj) + { +#define CC1(a, b) a##b +#define CC(a, b) CC1(a, b) +#define ASSIGN_IF(var, field, get_type, json_type) \ + if(!obj[field].is_null() && CC(obj[field].is_, json_type)()) \ + (var) = obj[field].get(); + + std::unique_ptr info = std::make_unique(); + ASSIGN_IF(info->name, "name", String, string); + ASSIGN_IF(info->tag_name, "tag_name", String, string); + ASSIGN_IF(info->created_at, "created_at", String, string); + ASSIGN_IF(info->published_at, "published_at", String, string); + ASSIGN_IF(info->body, "body", String, string); + ASSIGN_IF(info->tarball_url, "tarball_url", String, string); + ASSIGN_IF(info->zipball_url, "zipball_url", String, string); + return info; - std::vector> assets; // {name, url.zip} - String linux_asset_url; // browser_download_url https://github.com/BaderEddineOuaich/Enigma/releases/download/v1.0.0/Enigma-v1.0.0-Linux-x64.zip - String windows_asset_url; // browser_download_url https://github.com/BaderEddineOuaich/Enigma/releases/download/v1.0.0/Enigma-v1.0.0-Windows-x64.zip +#undef ASSIGN_IF +#undef CC1 +#undef CC + } + + String toString() noexcept + { + std::ostringstream oss; + if (!name.empty()) + oss << "name: " << name << " "; + if (!tag_name.empty()) + oss << "tag name: " << tag_name << " "; + if (!created_at.empty()) + oss << "created at: " << created_at << " "; + if (!published_at.empty()) + oss << "published at: " << published_at << " "; + if (!body.empty()) + oss << "body: " << body << " "; + if (!tarball_url.empty()) + oss << "tarball_url: " << tarball_url << " "; + if (!zipball_url.empty()) + oss << "zipball_url: " << zipball_url << " "; + return oss.str(); + } + + }; + public: - static bool IsNewVersionAvailable() + static std::unique_ptr GetLatestReleaseInfo() { - const auto current_version = ENIGMA_VERSION; - cpr::Response r = cpr::Get(cpr::Url{ URL } - //,cpr::Authentication{ "user", "pass" }, - //cpr::Parameters{ {"anon", "true"}, {"key", "value"} } - ); - if (r.status_code == cpr::status::HTTP_OK) + try { - //ENIGMA_INFO(""); - //std::cout << "r.status_code" << r.status_code << std::endl; // 200 - //std::cout << "r.header" << r.header["content-type"] << std::endl; // application/json; charset=utf-8 - //std::cout << "r.text" << r.text << std::endl; + cpr::Url url = Constants::Links::ENIGMA_GITHUB_API_LATEST_RELEASE; + cpr::Response response = cpr::Get(url); + if (response.status_code == cpr::status::HTTP_OK) + { + json data = json::parse(response.text); + return LatestReleaseInfo::FromJson(data); + } + else + ENIGMA_WARN("Failed to get latest release info with status code {0}", response.status_code); } - - return false; + catch (const std::exception& e) + { + ENIGMA_WARN("Failed to get latest release info with exception {0}", e.what()); + } + return nullptr; } - static ReleaseInfo GetLatestReleaseInfo() - { - return {}; - } }; NS_ENIGMA_END diff --git a/Source/Scenes/MainMenuScene.cpp b/Source/Scenes/MainMenuScene.cpp index 38a7e73db..f909408d8 100644 --- a/Source/Scenes/MainMenuScene.cpp +++ b/Source/Scenes/MainMenuScene.cpp @@ -7,6 +7,7 @@ #include "DecryptTextScene.hpp" #include +#include NS_ENIGMA_BEGIN @@ -81,6 +82,7 @@ void MainMenuScene::OnImGuiDraw() if (ImGui::BeginMenu("Help")) { if (ImGui::MenuItem("Report issue")) { this->OnReportIssueMenuButtonPressed(); } + if (ImGui::MenuItem("Check for updates")) { this->OnCheckForUpdatesMenuButtonPressed(); } if (ImGui::MenuItem("About")) { this->OnAboutMenuButtonPressed(); } ImGui::EndMenu(); } @@ -289,13 +291,43 @@ void MainMenuScene::OnReportIssueMenuButtonPressed() #endif } +void MainMenuScene::OnCheckForUpdatesMenuButtonPressed() +{ + ENIGMA_TRACE(ENIGMA_CURRENT_FUNCTION); + + ENIGMA_TRACE("Getting latest release info..."); + const auto info = CheckForUpdates::GetLatestReleaseInfo(); + if (!info) + return; + + const auto current_version = "v" + String(Enigma::ENIGMA_VERSION); + std::ostringstream oss{}; + if (info->tag_name == current_version) + { + oss << "You are using the latest Enigma version " << current_version; + } + else + { + oss << "New version is available!\n" + << "# Name: " << info->name << '\n' + << "# Version: " << info->tag_name << '\n' + << "# Created At: " << info->created_at << '\n' + << "# Published At: " << info->published_at << '\n' + << "# What's new ?: " << info->body << '\n' + << "# .tar release download url: " << info->tarball_url << '\n' + << "# .zip release download url: " << info->zipball_url << '\n'; + } + (void)DialogUtils::Info(oss.str()); + ENIGMA_INFO(oss.str()); +} + void MainMenuScene::OnAboutMenuButtonPressed() { // Show about dialog std::ostringstream oss{}; oss << "# Version: \n" << ENIGMA_VERSION << "\n\n" << "# Github Repository: \n" << Constants::Links::ENIGMA_GITHUB_REPOSITORY << "\n\n" - << "# Licence: \n" << ENIGMA_LICENCE; + << "# License: \n" << ENIGMA_LICENSE; (void)DialogUtils::Info(oss.str()); } diff --git a/Source/Scenes/MainMenuScene.hpp b/Source/Scenes/MainMenuScene.hpp index 9df227453..31469b148 100644 --- a/Source/Scenes/MainMenuScene.hpp +++ b/Source/Scenes/MainMenuScene.hpp @@ -25,6 +25,7 @@ class MainMenuScene : public Enigma::Scene void OnDecryptTextButtonPressed(); // Menu void OnReportIssueMenuButtonPressed(); + void OnCheckForUpdatesMenuButtonPressed(); void OnAboutMenuButtonPressed(); private: /* Initializers */