feat(updater): changed size check to time check
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -19,11 +19,16 @@ bool Updater::checkUpdate() {
|
||||
|
||||
httplib::Client client("thesims.freeboxos.fr", 30000);
|
||||
if (auto res = client.Head(newFileUrl.c_str())) {
|
||||
std::string distantFileCreation = res.value().get_header_value("Last-Modified");
|
||||
|
||||
std::uint32_t distantFileSize = std::stol(res.value().get_header_value("Content-Length"));
|
||||
std::uint32_t localFileSize = getLocalFileSize();
|
||||
char formatedTime[100];
|
||||
std::time_t localFileTileStamp = getLocalFileTimeStamp();
|
||||
|
||||
if (distantFileSize != localFileSize) {
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user