iw4x-client/src/Components/Modules/Changelog.cpp

60 lines
1.1 KiB
C++
Raw Normal View History

2022-02-27 07:53:44 -05:00
#include <STDInclude.hpp>
2017-02-04 12:42:12 -05:00
namespace Components
{
2017-02-04 15:52:49 -05:00
std::mutex Changelog::Mutex;
std::vector<std::string> Changelog::Lines;
2017-02-04 12:42:12 -05:00
2017-02-04 15:52:49 -05:00
void Changelog::LoadChangelog()
2017-02-04 12:42:12 -05:00
{
2022-11-23 10:31:48 -05:00
std::lock_guard _(Mutex);
Lines.clear();
2022-11-23 10:31:48 -05:00
const auto data = Utils::Cache::GetFile("/develop/CHANGELOG.md");
2017-02-04 12:42:12 -05:00
2017-02-04 15:52:49 -05:00
if (data.empty())
2017-02-04 12:42:12 -05:00
{
2022-11-23 10:31:48 -05:00
Lines.emplace_back("^1Unable to get changelog.");
return;
2017-02-04 12:42:12 -05:00
}
2022-11-23 10:31:48 -05:00
auto buffer = Utils::String::Split(data, '\n');
for (auto& line : buffer)
2017-02-04 15:52:49 -05:00
{
2017-02-04 12:42:12 -05:00
Utils::String::Replace(line, "\r", "");
}
2022-11-23 10:31:48 -05:00
Lines = buffer;
2017-02-04 12:42:12 -05:00
}
unsigned int Changelog::GetChangelogCount()
{
2022-11-23 10:31:48 -05:00
return Lines.size();
2017-02-04 12:42:12 -05:00
}
// Omit column here
2022-11-23 10:31:48 -05:00
const char* Changelog::GetChangelogText(unsigned int item, [[maybe_unused]] int column)
2017-02-04 12:42:12 -05:00
{
2022-11-23 10:31:48 -05:00
std::lock_guard _(Mutex);
if (item < Lines.size())
2017-02-04 12:42:12 -05:00
{
2022-11-23 10:31:48 -05:00
return Utils::String::VA("%s", Lines[item].data());
2017-02-04 12:42:12 -05:00
}
return "";
}
2022-11-23 10:31:48 -05:00
void Changelog::SelectChangelog([[maybe_unused]] unsigned int index)
2017-02-04 15:52:49 -05:00
{
// Don't do anything in here
}
2017-02-04 12:42:12 -05:00
Changelog::Changelog()
{
if (Dedicated::IsEnabled()) return;
2017-02-04 12:42:12 -05:00
// Changelog
2017-02-06 15:23:15 -05:00
UIFeeder::Add(62.0f, Changelog::GetChangelogCount, Changelog::GetChangelogText, Changelog::SelectChangelog);
2017-02-04 12:42:12 -05:00
}
}