From b52e885cde3af00ee6fc088de056ef3daf189b42 Mon Sep 17 00:00:00 2001 From: DHrpcs3 Date: Sat, 7 May 2016 21:38:52 +0300 Subject: [PATCH] Added rpcs3 version object Removed _PRGVER_ macros --- Utilities/version.cpp | 65 +++++++++++++++++++++++++++++++++++++ Utilities/version.h | 71 +++++++++++++++++++++++++++++++++++++++++ rpcs3/Gui/AboutDialog.h | 3 +- rpcs3/Gui/MainFrame.cpp | 6 ++-- rpcs3/emucore.vcxproj | 4 +++ rpcs3/rpcs3_version.cpp | 10 ++++++ rpcs3/rpcs3_version.h | 9 ++++++ rpcs3/stdafx.h | 1 - 8 files changed, 164 insertions(+), 5 deletions(-) create mode 100644 Utilities/version.cpp create mode 100644 Utilities/version.h create mode 100644 rpcs3/rpcs3_version.cpp create mode 100644 rpcs3/rpcs3_version.h diff --git a/Utilities/version.cpp b/Utilities/version.cpp new file mode 100644 index 0000000000..dcbd910b4b --- /dev/null +++ b/Utilities/version.cpp @@ -0,0 +1,65 @@ +#include "stdafx.h" +#include "version.h" + +namespace utils +{ + std::string to_string(version_type type) + { + switch (type) + { + case version_type::pre_alpha: return "Pre-Alpha"; + case version_type::alpha: return "Alpha"; + case version_type::beta: return "Beta"; + case version_type::release_candidate: return "RC"; + case version_type::release: return "Release"; + } + + throw; + } + + version::version(std::uint8_t hi, std::uint8_t mid, std::uint8_t lo) + : m_hi(hi) + , m_mid(mid) + , m_lo(lo) + { + } + + version& version::type(version_type type, std::uint8_t type_index) + { + m_type = type; + m_type_index = type_index; + return *this; + } + + std::uint16_t version::to_hex() const + { + return (m_hi << 24) | (m_mid << 16) | (m_lo << 8) | ((std::uint8_t(m_type) & 0xf) << 4) | (m_type_index & 0xf); + } + + std::string version::to_string() const + { + std::string version = std::to_string(hi()) + "." + std::to_string(mid()); + + if (lo()) + { + version += "." + std::to_string(lo()); + } + + if (type() != version_type::release) + { + if (!postfix().empty()) + { + version += "-" + postfix(); + } + + version += " " + utils::to_string(type()); + + if (type_index() > 1) + { + version += " " + std::to_string(type_index()); + } + } + + return version; + } +} diff --git a/Utilities/version.h b/Utilities/version.h new file mode 100644 index 0000000000..af75c1f764 --- /dev/null +++ b/Utilities/version.h @@ -0,0 +1,71 @@ +#pragma once +#include +#include + +namespace utils +{ + enum class version_type : std::uint8_t + { + pre_alpha, + alpha, + beta, + release_candidate, + release + }; + + std::string to_string(version_type type); + + class version + { + std::uint8_t m_hi; + std::uint8_t m_mid; + std::uint8_t m_lo; + version_type m_type = version_type::release; + std::uint8_t m_type_index = 1; + std::string m_postfix; + + public: + version(std::uint8_t hi, std::uint8_t mid, std::uint8_t lo = 0); + + version& type(version_type type, std::uint8_t type_index = 1); + + std::uint8_t hi() const + { + return m_hi; + } + + std::uint8_t mid() const + { + return m_mid; + } + + std::uint8_t lo() const + { + return m_lo; + } + + version_type type() const + { + return m_type; + } + + std::string postfix() const + { + return m_postfix; + } + + version& postfix(const std::string& value) + { + m_postfix = value; + return *this; + } + + std::uint8_t type_index() const + { + return m_type_index; + } + + std::uint16_t to_hex() const; + std::string to_string() const; + }; +} diff --git a/rpcs3/Gui/AboutDialog.h b/rpcs3/Gui/AboutDialog.h index b8471ed69a..1fdae020ad 100644 --- a/rpcs3/Gui/AboutDialog.h +++ b/rpcs3/Gui/AboutDialog.h @@ -1,4 +1,5 @@ #pragma once +#include "rpcs3_version.h" class AboutDialog : public wxDialog { @@ -30,7 +31,7 @@ public: t_descr->SetForegroundColour(wxColor(255, 255, 255)); t_descr->SetPosition(wxPoint(12, 50)); - wxStaticText* t_version = new wxStaticText(this, wxID_ANY, wxString::Format(_PRGNAME_ " Version: " _PRGVER_ "-" RPCS3_GIT_VERSION)); + wxStaticText* t_version = new wxStaticText(this, wxID_ANY, std::string(_PRGNAME_ " Version: ") + rpcs3::version.to_string()); t_version->SetBackgroundColour(wxColor(100, 100, 100)); t_version->SetForegroundColour(wxColor(200, 200, 200)); t_version->SetPosition(wxPoint(12, 66)); diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index 8233aaf435..b7b4f403f8 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -2,7 +2,7 @@ #include "stdafx_gui.h" #include "rpcs3.h" #include "MainFrame.h" -#include "git-version.h" +#include "rpcs3_version.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" @@ -69,7 +69,7 @@ MainFrame::MainFrame() , m_sys_menu_opened(false) { - SetLabel(_PRGNAME_ " v" _PRGVER_ "-" RPCS3_GIT_VERSION); + SetLabel(std::string(_PRGNAME_ " v") + rpcs3::version.to_string()); wxMenuBar* menubar = new wxMenuBar(); @@ -158,7 +158,7 @@ MainFrame::MainFrame() wxGetApp().Bind(wxEVT_KEY_DOWN, &MainFrame::OnKeyDown, this); wxGetApp().Bind(wxEVT_DBG_COMMAND, &MainFrame::UpdateUI, this); - LOG_NOTICE(GENERAL, "%s", _PRGNAME_ " v" _PRGVER_ "-" RPCS3_GIT_VERSION); + LOG_NOTICE(GENERAL, "%s", (std::string(_PRGNAME_ " v") + rpcs3::version.to_string()).c_str()); LOG_NOTICE(GENERAL, ""); } diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index f2ee70cae5..886db41ffd 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -84,6 +84,7 @@ NotUsing + @@ -348,6 +349,7 @@ + Create @@ -379,6 +381,7 @@ + @@ -609,6 +612,7 @@ + diff --git a/rpcs3/rpcs3_version.cpp b/rpcs3/rpcs3_version.cpp new file mode 100644 index 0000000000..2874f882ad --- /dev/null +++ b/rpcs3/rpcs3_version.cpp @@ -0,0 +1,10 @@ +#include "stdafx.h" +#include "rpcs3_version.h" +#include "git-version.h" + +namespace rpcs3 +{ + const utils::version version = utils::version{ 0, 0, 1 } + .type(utils::version_type::pre_alpha) + .postfix(RPCS3_GIT_VERSION); +} diff --git a/rpcs3/rpcs3_version.h b/rpcs3/rpcs3_version.h new file mode 100644 index 0000000000..671fed850e --- /dev/null +++ b/rpcs3/rpcs3_version.h @@ -0,0 +1,9 @@ +#pragma once +#include +#include +#include + +namespace rpcs3 +{ + extern const utils::version version; +} diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index d29af71143..95857b0a30 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -42,7 +42,6 @@ using namespace std::literals; #define EXCEPTION(format_str, ...) fmt::exception("%s(): " format_str HERE, __FUNCTION__, ##__VA_ARGS__) #define _PRGNAME_ "RPCS3" -#define _PRGVER_ "0.0.0.9" #include "Utilities/types.h" #include "Utilities/Macro.h"