feat(updater): changed size check to time check

This commit is contained in:
2021-11-14 14:05:24 +01:00
parent fec62d5961
commit a775a9e4c8
2 changed files with 26 additions and 9 deletions

View File

@@ -2,6 +2,8 @@
#include "misc/DataBuffer.h"
#include <ctime>
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

View File

@@ -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() {