From ad80d4dce017837f5f5e2382e8ecbeb279886ca2 Mon Sep 17 00:00:00 2001 From: Mahmoud Mandour Date: Sun, 29 Aug 2021 11:51:42 +0200 Subject: [PATCH] LibCore+LibGUI: Define a Serenity version in LibCore Before, `AboutDialog` and `ArgsParser` read from a build-time created file called `/res/version.ini`. This caused problems with utilities unveiling specific paths leaving the version file unaccessible. This commit hard-codes a serenity version in `LibCore`, and use it in `ArgsParser` and `AboutDialog`. The previous version contained the hash of the last GIT commit, this is omitted for the default use for the sake of simplicity. --- Userland/Libraries/LibCore/ArgsParser.cpp | 13 ++----------- Userland/Libraries/LibCore/Version.h | 15 +++++++++++++++ Userland/Libraries/LibGUI/AboutDialog.cpp | 12 ++---------- 3 files changed, 19 insertions(+), 21 deletions(-) create mode 100644 Userland/Libraries/LibCore/Version.h diff --git a/Userland/Libraries/LibCore/ArgsParser.cpp b/Userland/Libraries/LibCore/ArgsParser.cpp index a10d16a555..54a362331f 100644 --- a/Userland/Libraries/LibCore/ArgsParser.cpp +++ b/Userland/Libraries/LibCore/ArgsParser.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include @@ -245,16 +245,7 @@ void ArgsParser::print_usage(FILE* file, const char* argv0) void ArgsParser::print_version(FILE* file) { - 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("{}.{}", major_version, minor_version); - if (auto git_version = version_config->read_entry("Version", "Git", ""); git_version != "") - builder.appendff(".g{}", git_version); - - outln(file, builder.to_string()); + outln(file, Core::Version::SERENITY_VERSION); } void ArgsParser::add_option(Option&& option) diff --git a/Userland/Libraries/LibCore/Version.h b/Userland/Libraries/LibCore/Version.h new file mode 100644 index 0000000000..fd4fcced5b --- /dev/null +++ b/Userland/Libraries/LibCore/Version.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2021, Mahmoud Mandour + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Core::Version { + +constexpr StringView SERENITY_VERSION = "Version 1.0"sv; + +} diff --git a/Userland/Libraries/LibGUI/AboutDialog.cpp b/Userland/Libraries/LibGUI/AboutDialog.cpp index 8af316bd0e..cae0fb8861 100644 --- a/Userland/Libraries/LibGUI/AboutDialog.cpp +++ b/Userland/Libraries/LibGUI/AboutDialog.cpp @@ -5,7 +5,7 @@ */ #include -#include +#include #include #include #include @@ -92,15 +92,7 @@ AboutDialog::~AboutDialog() String AboutDialog::version_string() const { - 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(); + return Core::Version::SERENITY_VERSION; } }