feat(updater): changed size check to time check
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "misc/DataBuffer.h"
|
#include "misc/DataBuffer.h"
|
||||||
|
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
namespace utils {
|
namespace utils {
|
||||||
|
|
||||||
@@ -30,7 +32,7 @@ public:
|
|||||||
static void removeOldFile();
|
static void removeOldFile();
|
||||||
private:
|
private:
|
||||||
std::string getDownloadFileURL();
|
std::string getDownloadFileURL();
|
||||||
std::uint32_t getLocalFileSize();
|
std::time_t getLocalFileTimeStamp();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace utils
|
} // namespace utils
|
||||||
|
|||||||
@@ -19,11 +19,16 @@ bool Updater::checkUpdate() {
|
|||||||
|
|
||||||
httplib::Client client("thesims.freeboxos.fr", 30000);
|
httplib::Client client("thesims.freeboxos.fr", 30000);
|
||||||
if (auto res = client.Head(newFileUrl.c_str())) {
|
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"));
|
char formatedTime[100];
|
||||||
std::uint32_t localFileSize = getLocalFileSize();
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
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();
|
std::string localFile = getLocalFilePath();
|
||||||
|
|
||||||
if (localFile.empty()) return 0;
|
WIN32_FILE_ATTRIBUTE_DATA fileInfo;
|
||||||
|
|
||||||
std::ifstream in(localFile, std::ifstream::ate | std::ifstream::binary);
|
if(GetFileAttributesEx(localFile.c_str(), GetFileExInfoStandard, &fileInfo) > 0){
|
||||||
return in.tellg();
|
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() {
|
std::string Updater::getDownloadFileURL() {
|
||||||
|
|||||||
Reference in New Issue
Block a user