Skip to content

Commit

Permalink
version 1.2.1
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
baderouaich committed Feb 20, 2021
1 parent cce75c7 commit 1491224
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 67 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- 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)
29 changes: 16 additions & 13 deletions Enigma.log
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 12 additions & 3 deletions Source/Core/Version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@

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"
"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n"
"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
25 changes: 1 addition & 24 deletions Source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,16 @@
#include <Enigma.hpp>
#endif

//#include <Networking/CheckForUpdates.hpp>
#include <cpr/cpr.h>
//

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
// Command Line Interface Entry
if (argc > 1)
{
std::unique_ptr<Enigma::CLI> _Cli = std::make_unique<Enigma::CLI>(argc, argv);
auto ret = _Cli->Run();
Enigma::Logger::Shutdown();
return ret;
return _Cli->Run();
}
// Application Entry
else
Expand All @@ -55,18 +37,13 @@ int main(int argc, char* argv[])
std::unique_ptr<Enigma::Application> _App = std::make_unique<Enigma::Application>(window_settings);
// Run Application
_App->Run();
// Shutdown Logger
Enigma::Logger::Shutdown();
// Exit
return EXIT_SUCCESS;
}
catch (const std::exception& e)
{
// Exit abnormally
ENIGMA_CRITICAL(e.what());
// Shutdown Logger
Enigma::Logger::Shutdown();
// Exit
return EXIT_FAILURE;
}

Expand Down
118 changes: 93 additions & 25 deletions Source/Networking/CheckForUpdates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,114 @@
#include <Core/Version.hpp>
#include <Logger/Logger.hpp>

#include <cpr/cpr.h>
//Constants::Links::ENIGMA_LATEST_RELEASE_GITHUB_API
constexpr const auto URL = "https://api.github.com/repos/BaderEddineOuaich/Enigma/releases/latest";
//TODO
#include <memory>

#include <cpr/cpr.h> // cpr (cURL c++ wrapper)
#include <json.hpp> // 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("<unknown>"),
name("<unknown>"),
created_at("<unknown>"),
published_at("<unknown>"),
body("<unknown>"),
tarball_url("<unknown>"),
zipball_url("<unknown>")
{}

~LatestReleaseInfo()
{
tag_name.clear();
created_at.clear();
published_at.clear();
body.clear();
}

static std::unique_ptr<LatestReleaseInfo> 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<get_type>();

std::unique_ptr<LatestReleaseInfo> info = std::make_unique<LatestReleaseInfo>();
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<std::pair<String, String>> 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<LatestReleaseInfo> 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

Expand Down
34 changes: 33 additions & 1 deletion Source/Scenes/MainMenuScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "DecryptTextScene.hpp"

#include <Utility/DialogUtils.hpp>
#include <Networking/CheckForUpdates.hpp>

NS_ENIGMA_BEGIN

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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());

}
Expand Down
1 change: 1 addition & 0 deletions Source/Scenes/MainMenuScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MainMenuScene : public Enigma::Scene
void OnDecryptTextButtonPressed();
// Menu
void OnReportIssueMenuButtonPressed();
void OnCheckForUpdatesMenuButtonPressed();
void OnAboutMenuButtonPressed();

private: /* Initializers */
Expand Down

0 comments on commit 1491224

Please sign in to comment.