[Changelog] Optimize changelog
This commit is contained in:
parent
7faf4a91cd
commit
59ae4b35c7
@ -2,64 +2,67 @@
|
|||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
std::vector<Changelog::changelogLine> Changelog::Line;
|
std::mutex Changelog::Mutex;
|
||||||
|
std::vector<std::string> Changelog::Lines;
|
||||||
|
|
||||||
void Changelog::LoadChangelog(UIScript::Token)
|
void Changelog::LoadChangelog()
|
||||||
{
|
{
|
||||||
if (!Changelog::Line.empty())
|
//if (!Changelog::Lines.empty())
|
||||||
return;
|
// return;
|
||||||
|
|
||||||
std::vector<std::string> changelog;
|
std::lock_guard<std::mutex> _(Changelog::Mutex);
|
||||||
Changelog::Line.clear();
|
Changelog::Lines.clear();
|
||||||
|
std::string data = Utils::Cache::GetFile("/iw4/changelog.txt");
|
||||||
|
|
||||||
|
if (data.empty())
|
||||||
{
|
{
|
||||||
std::string uncleaned = Utils::Cache::GetFile("/iw4/changelog.txt");
|
data = "^1Unable to get changelog.";
|
||||||
|
|
||||||
if (uncleaned.empty())
|
|
||||||
{
|
|
||||||
uncleaned = "^1Unable to get changelog.";
|
|
||||||
}
|
|
||||||
|
|
||||||
changelog = Utils::String::Explode(uncleaned, '\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto line : changelog)
|
Changelog::Lines = Utils::String::Explode(data, '\n');
|
||||||
|
|
||||||
|
for (auto& line : Changelog::Lines)
|
||||||
{
|
{
|
||||||
Changelog::changelogLine info;
|
|
||||||
|
|
||||||
Utils::String::Replace(line, "\r", "");
|
Utils::String::Replace(line, "\r", "");
|
||||||
info.line = line;
|
|
||||||
|
|
||||||
Changelog::Line.push_back(info);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Changelog::GetChangelogCount()
|
unsigned int Changelog::GetChangelogCount()
|
||||||
{
|
{
|
||||||
return Changelog::Line.size();
|
return Changelog::Lines.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Omit column here
|
// Omit column here
|
||||||
const char* Changelog::GetChangelogText(unsigned int item, int /*column*/)
|
const char* Changelog::GetChangelogText(unsigned int item, int /*column*/)
|
||||||
{
|
{
|
||||||
if (item < Changelog::Line.size())
|
std::lock_guard<std::mutex> _(Changelog::Mutex);
|
||||||
|
if (item < Changelog::Lines.size())
|
||||||
{
|
{
|
||||||
std::string info = Changelog::Line[item].line;
|
return Utils::String::VA("%s", Changelog::Lines[item].data());
|
||||||
|
|
||||||
return Utils::String::VA("%s", info.data());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Changelog::SelectChangelog(unsigned int index) { index; }
|
void Changelog::SelectChangelog(unsigned int /*index*/)
|
||||||
|
{
|
||||||
|
// Don't do anything in here
|
||||||
|
}
|
||||||
|
|
||||||
Changelog::Changelog()
|
Changelog::Changelog()
|
||||||
{
|
{
|
||||||
// UIScripts
|
std::lock_guard<std::mutex> _(Changelog::Mutex);
|
||||||
UIScript::Add("loadChangelog", Changelog::LoadChangelog);
|
Changelog::Lines.clear();
|
||||||
|
|
||||||
// Changelog
|
// Changelog
|
||||||
UIFeeder::Add(39.0f, Changelog::GetChangelogCount, Changelog::GetChangelogText, Changelog::SelectChangelog);
|
UIFeeder::Add(39.0f, Changelog::GetChangelogCount, Changelog::GetChangelogText, Changelog::SelectChangelog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Changelog::~Changelog()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> _(Changelog::Mutex);
|
||||||
|
Changelog::Lines.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,21 +6,17 @@ namespace Components
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Changelog();
|
Changelog();
|
||||||
|
~Changelog();
|
||||||
|
|
||||||
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
|
||||||
const char* getName() override { return "Changelog"; };
|
const char* getName() override { return "Changelog"; };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class changelogLine
|
static void LoadChangelog();
|
||||||
{
|
|
||||||
public:
|
|
||||||
std::string line;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::vector<changelogLine> Line;
|
static std::mutex Mutex;
|
||||||
|
static std::vector<std::string> Lines;
|
||||||
static void LoadChangelog(UIScript::Token);
|
|
||||||
|
|
||||||
static unsigned int GetChangelogCount();
|
static unsigned int GetChangelogCount();
|
||||||
static const char* GetChangelogText(unsigned int item, int column);
|
static const char* GetChangelogText(unsigned int item, int column);
|
||||||
|
@ -165,7 +165,7 @@ namespace Components
|
|||||||
News::Terminate = false;
|
News::Terminate = false;
|
||||||
News::Thread = std::thread([]()
|
News::Thread = std::thread([]()
|
||||||
{
|
{
|
||||||
//Changelog::LoadChangelog(UIScript::Token);
|
Changelog::LoadChangelog();
|
||||||
|
|
||||||
std::string data = Utils::Cache::GetFile("/iw4/motd.txt");
|
std::string data = Utils::Cache::GetFile("/iw4/motd.txt");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user