diff --git a/include/misc/Updater.h b/include/misc/Updater.h index cfc6292..c7af8cf 100644 --- a/include/misc/Updater.h +++ b/include/misc/Updater.h @@ -2,6 +2,8 @@ #include "misc/DataBuffer.h" +#include + namespace td { namespace utils { @@ -30,7 +32,7 @@ public: static void removeOldFile(); private: std::string getDownloadFileURL(); - std::uint32_t getLocalFileSize(); + std::time_t getLocalFileTimeStamp(); }; } // namespace utils diff --git a/src/misc/Updater.cpp b/src/misc/Updater.cpp index 7616ba5..af4d08a 100644 --- a/src/misc/Updater.cpp +++ b/src/misc/Updater.cpp @@ -19,11 +19,16 @@ bool Updater::checkUpdate() { httplib::Client client("thesims.freeboxos.fr", 30000); if (auto res = client.Head(newFileUrl.c_str())) { - - std::uint32_t distantFileSize = std::stol(res.value().get_header_value("Content-Length")); - std::uint32_t localFileSize = getLocalFileSize(); + std::string distantFileCreation = res.value().get_header_value("Last-Modified"); - if (distantFileSize != localFileSize) { + char formatedTime[100]; + std::time_t localFileTileStamp = getLocalFileTimeStamp(); + + std::strftime(formatedTime, sizeof(formatedTime), "%a, %d %b %Y %H:%M:%S GMT", std::gmtime(&localFileTileStamp)); + + std::string localFileCreation = formatedTime; + + if (distantFileCreation != localFileCreation) { return true; } return false; @@ -33,13 +38,23 @@ bool Updater::checkUpdate() { } } -std::uint32_t Updater::getLocalFileSize() { +std::time_t Updater::getLocalFileTimeStamp(){ + #ifdef _WIN32 std::string localFile = getLocalFilePath(); - if (localFile.empty()) return 0; + WIN32_FILE_ATTRIBUTE_DATA fileInfo; - std::ifstream in(localFile, std::ifstream::ate | std::ifstream::binary); - return in.tellg(); + if(GetFileAttributesEx(localFile.c_str(), GetFileExInfoStandard, &fileInfo) > 0){ + ULARGE_INTEGER ull; + ull.LowPart = fileInfo.ftCreationTime.dwLowDateTime; + ull.HighPart = fileInfo.ftCreationTime.dwHighDateTime; + + time_t lastModified = ull.QuadPart / 10000000ULL - 11644473600ULL; + + return lastModified; + } + #endif + return 0; } std::string Updater::getDownloadFileURL() {