2021-08-29 09:54:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Mahmoud Mandour <ma.mandourr@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2023-02-28 15:39:41 +00:00
|
|
|
#include <AK/String.h>
|
2024-10-29 09:18:14 +00:00
|
|
|
#include <LibCore/Environment.h>
|
2021-08-29 09:54:59 +00:00
|
|
|
#include <LibCore/Version.h>
|
|
|
|
|
|
|
|
namespace Core::Version {
|
|
|
|
|
2023-02-28 15:39:41 +00:00
|
|
|
ErrorOr<String> read_long_version_string()
|
2021-08-29 09:54:59 +00:00
|
|
|
{
|
2024-10-29 09:18:14 +00:00
|
|
|
auto validate_git_hash = [](auto hash) {
|
|
|
|
if (hash.length() < 4 || hash.length() > 40)
|
|
|
|
return false;
|
|
|
|
for (auto ch : hash) {
|
|
|
|
if (!is_ascii_hex_digit(ch))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto maybe_git_hash = Core::Environment::get("LADYBIRD_GIT_VERSION"sv);
|
|
|
|
|
|
|
|
if (maybe_git_hash.has_value() && validate_git_hash(maybe_git_hash.value()))
|
|
|
|
return MUST(String::formatted("Version 1.0-{}", maybe_git_hash.value()));
|
2024-02-07 17:53:38 +00:00
|
|
|
return "Version 1.0"_string;
|
2021-08-29 09:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|