Implemented the current_date() function.
This commit is contained in:
parent
4128a25057
commit
b012aa0dbb
@ -22,6 +22,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ namespace MUtils
|
|||||||
//Get known Folder
|
//Get known Folder
|
||||||
const QString &known_folder(known_folder_t folder_id);
|
const QString &known_folder(known_folder_t folder_id);
|
||||||
|
|
||||||
|
//Current Date
|
||||||
|
QDate current_date(void);
|
||||||
|
|
||||||
//Error handling
|
//Error handling
|
||||||
void fatal_exit(const char* const errorMessage);
|
void fatal_exit(const char* const errorMessage);
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#define WIN32_LEAN_AND_MEAN 1
|
#define WIN32_LEAN_AND_MEAN 1
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <Objbase.h>
|
#include <Objbase.h>
|
||||||
|
#include <Psapi.h>
|
||||||
|
|
||||||
//Qt
|
//Qt
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
@ -158,6 +159,66 @@ const QString &MUtils::OS::known_folder(known_folder_t folder_id)
|
|||||||
return g_known_folders_map->operator[](folderId);
|
return g_known_folders_map->operator[](folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CURRENT DATA (SAFE)
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
QDate MUtils::OS::current_date(void)
|
||||||
|
{
|
||||||
|
const DWORD MAX_PROC = 1024;
|
||||||
|
QScopedArrayPointer<DWORD> processes(new DWORD[MAX_PROC]);
|
||||||
|
DWORD bytesReturned = 0;
|
||||||
|
|
||||||
|
if(!EnumProcesses(processes.data(), sizeof(DWORD) * MAX_PROC, &bytesReturned))
|
||||||
|
{
|
||||||
|
return QDate::currentDate();
|
||||||
|
}
|
||||||
|
|
||||||
|
const DWORD procCount = bytesReturned / sizeof(DWORD);
|
||||||
|
ULARGE_INTEGER lastStartTime;
|
||||||
|
memset(&lastStartTime, 0, sizeof(ULARGE_INTEGER));
|
||||||
|
|
||||||
|
for(DWORD i = 0; i < procCount; i++)
|
||||||
|
{
|
||||||
|
if(HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processes[i]))
|
||||||
|
{
|
||||||
|
FILETIME processTime[4];
|
||||||
|
if(GetProcessTimes(hProc, &processTime[0], &processTime[1], &processTime[2], &processTime[3]))
|
||||||
|
{
|
||||||
|
ULARGE_INTEGER timeCreation;
|
||||||
|
timeCreation.LowPart = processTime[0].dwLowDateTime;
|
||||||
|
timeCreation.HighPart = processTime[0].dwHighDateTime;
|
||||||
|
if(timeCreation.QuadPart > lastStartTime.QuadPart)
|
||||||
|
{
|
||||||
|
lastStartTime.QuadPart = timeCreation.QuadPart;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CloseHandle(hProc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FILETIME lastStartTime_fileTime;
|
||||||
|
lastStartTime_fileTime.dwHighDateTime = lastStartTime.HighPart;
|
||||||
|
lastStartTime_fileTime.dwLowDateTime = lastStartTime.LowPart;
|
||||||
|
|
||||||
|
FILETIME lastStartTime_localTime;
|
||||||
|
if(!FileTimeToLocalFileTime(&lastStartTime_fileTime, &lastStartTime_localTime))
|
||||||
|
{
|
||||||
|
memcpy(&lastStartTime_localTime, &lastStartTime_fileTime, sizeof(FILETIME));
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSTEMTIME lastStartTime_system;
|
||||||
|
if(!FileTimeToSystemTime(&lastStartTime_localTime, &lastStartTime_system))
|
||||||
|
{
|
||||||
|
memset(&lastStartTime_system, 0, sizeof(SYSTEMTIME));
|
||||||
|
lastStartTime_system.wYear = 1970; lastStartTime_system.wMonth = lastStartTime_system.wDay = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QDate currentDate = QDate::currentDate();
|
||||||
|
const QDate processDate = QDate(lastStartTime_system.wYear, lastStartTime_system.wMonth, lastStartTime_system.wDay);
|
||||||
|
return (currentDate >= processDate) ? currentDate : processDate;
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// FATAL EXIT
|
// FATAL EXIT
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -688,20 +688,22 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!updateInfoDate.isValid())
|
if(!updateInfoDate.isValid())
|
||||||
{
|
{
|
||||||
updateInfo->resetInfo();
|
updateInfo->resetInfo();
|
||||||
log("WARNING: Version info timestamp is missing!");
|
log("WARNING: Version info timestamp is missing!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS) < current_date_safe())
|
|
||||||
|
const QDate currentDate = OS::current_date();
|
||||||
|
if(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS) < currentDate)
|
||||||
{
|
{
|
||||||
updateInfo->resetInfo();
|
updateInfo->resetInfo();
|
||||||
log(QString::fromLatin1("WARNING: This version info has expired at %1!").arg(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS).toString(Qt::ISODate)));
|
log(QString::fromLatin1("WARNING: This version info has expired at %1!").arg(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS).toString(Qt::ISODate)));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if(current_date_safe() < updateInfoDate)
|
else if(currentDate < updateInfoDate)
|
||||||
{
|
{
|
||||||
log("Version info is from the future, take care!");
|
log("Version info is from the future, take care!");
|
||||||
qWarning("Version info is from the future, take care!");
|
qWarning("Version info is from the future, take care!");
|
||||||
|
Loading…
Reference in New Issue
Block a user