From 7742f37c10edc309e5e45c8db9113bb40e1f6c2b Mon Sep 17 00:00:00 2001 From: Mahmoud Mandour Date: Sun, 29 Aug 2021 11:54:59 +0200 Subject: [PATCH] LibCore: Refactor a version-reading utility `ArgsParser` and `AboutDialog` had the same procedure to read the version from `/res/version.ini`. Now they use the `SERENITY_VERSION` string by default. This commit refactored the version-reading utility to the new `Core::Version` namespace. --- Userland/Libraries/LibCore/CMakeLists.txt | 1 + Userland/Libraries/LibCore/Version.cpp | 25 +++++++++++++++++++++++ Userland/Libraries/LibCore/Version.h | 2 ++ 3 files changed, 28 insertions(+) create mode 100644 Userland/Libraries/LibCore/Version.cpp diff --git a/Userland/Libraries/LibCore/CMakeLists.txt b/Userland/Libraries/LibCore/CMakeLists.txt index 1bf5af2204..311168677b 100644 --- a/Userland/Libraries/LibCore/CMakeLists.txt +++ b/Userland/Libraries/LibCore/CMakeLists.txt @@ -31,6 +31,7 @@ set(SOURCES Timer.cpp UDPServer.cpp UDPSocket.cpp + Version.cpp ) serenity_lib(LibCore core) diff --git a/Userland/Libraries/LibCore/Version.cpp b/Userland/Libraries/LibCore/Version.cpp new file mode 100644 index 0000000000..9857789871 --- /dev/null +++ b/Userland/Libraries/LibCore/Version.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2021, Mahmoud Mandour + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Core::Version { + +String read_long_version_string() +{ + auto version_config = Core::ConfigFile::open("/res/version.ini"); + auto major_version = version_config->read_entry("Version", "Major", "0"); + auto minor_version = version_config->read_entry("Version", "Minor", "0"); + + StringBuilder builder; + builder.appendff("Version {}.{}", major_version, minor_version); + if (auto git_version = version_config->read_entry("Version", "Git", ""); git_version != "") + builder.appendff(".g{}", git_version); + return builder.to_string(); +} + +} diff --git a/Userland/Libraries/LibCore/Version.h b/Userland/Libraries/LibCore/Version.h index fd4fcced5b..1ca7a18d1d 100644 --- a/Userland/Libraries/LibCore/Version.h +++ b/Userland/Libraries/LibCore/Version.h @@ -12,4 +12,6 @@ namespace Core::Version { constexpr StringView SERENITY_VERSION = "Version 1.0"sv; +String read_long_version_string(); + }