GIGA REFACTOR

This commit is contained in:
2022-03-02 18:51:42 +01:00
parent 553b2f6aad
commit 6df59b1487
92 changed files with 1807 additions and 1785 deletions

View File

@@ -13,18 +13,18 @@
namespace td {
namespace utils {
bool Updater::checkUpdate() {
bool Updater::CheckUpdate() {
httplib::Client client("thesims.freeboxos.fr", 30000);
if (auto res = client.Get("/Tower%20Defense/version")) {
std::string currentVersion = getCurrentVersion();
std::string currentVersion = GetCurrentVersion();
m_LastVersion = res.value().body;
// we only look at the first line
m_LastVersion = m_LastVersion.substr(0, m_LastVersion.find('\n'));
std::cout << "Current version : [" << getCurrentVersion() << "]\n";
std::cout << "Current version : [" << GetCurrentVersion() << "]\n";
std::cout << "Last version : [" << m_LastVersion << "]\n";
if (currentVersion != m_LastVersion) {
@@ -39,13 +39,13 @@ bool Updater::checkUpdate() {
return false;
}
bool Updater::canUpdate() {
return !getDownloadFileURL().empty();
bool Updater::CanUpdate() {
return !GetDownloadFileURL().empty();
}
std::string Updater::getDownloadFileURL() {
Os systemOs = getSystemOs();
Architecture systemArch = getSystemArchitecture();
std::string Updater::GetDownloadFileURL() {
Os systemOs = GetSystemOs();
Architecture systemArch = GetSystemArchitecture();
switch (systemOs) {
@@ -67,7 +67,7 @@ std::string Updater::getDownloadFileURL() {
}
}
std::string Updater::getLocalFilePath() {
std::string Updater::GetLocalFilePath() {
#ifdef _WIN32
char filePathBuffer[1024];
GetModuleFileName(nullptr, filePathBuffer, sizeof(filePathBuffer));
@@ -78,12 +78,12 @@ std::string Updater::getLocalFilePath() {
return "";
}
void Updater::downloadUpdate() {
void Updater::DownloadUpdate() {
if (m_DownloadComplete) return;
m_CancelDownload = false;
std::string newFileUrl = getDownloadFileURL();
std::string newFileUrl = GetDownloadFileURL();
httplib::Client client("thesims.freeboxos.fr", 30000);
@@ -105,25 +105,25 @@ void Updater::downloadUpdate() {
}
}
void Updater::removeOldFile() {
std::remove(std::string(getLocalFilePath() + "_old").c_str());
void Updater::RemoveOldFile() {
std::remove(std::string(GetLocalFilePath() + "_old").c_str());
}
bool Updater::writeFile() {
bool Updater::WriteFile() {
if (m_FileWrited || !m_DownloadComplete) return false;
if (!m_FileBuffer.WriteFile(getLocalFilePath() + "_recent"))
if (!m_FileBuffer.WriteFile(GetLocalFilePath() + "_recent"))
return false;
#ifdef _WIN32
std::rename(getLocalFilePath().c_str(), std::string(getLocalFilePath() + "_old").c_str());
std::rename(std::string(getLocalFilePath() + "_recent").c_str(), getLocalFilePath().c_str());
std::rename(GetLocalFilePath().c_str(), std::string(GetLocalFilePath() + "_old").c_str());
std::rename(std::string(GetLocalFilePath() + "_recent").c_str(), GetLocalFilePath().c_str());
#endif
m_FileWrited = true;
m_DownloadComplete = false;
clearCache();
ClearCache();
return true;
}