Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added new function to detect the current date. Slightly more robust a…

…gainst manipulations.
  • Loading branch information...
commit cb042bbf3cec16e9f514a6b9de52c45d7c532695 1 parent f689ce5
@lordmulder authored
View
4 LameXP_VS2012.vcxproj
@@ -149,7 +149,7 @@ copy /Y "$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\bin\Win32\*.manifes
</ClCompile>
<Link>
<AdditionalOptions>"/MANIFESTDEPENDENCY:type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27 processorArchitecture=%27*%27" %(AdditionalOptions)</AdditionalOptions>
- <AdditionalDependencies>QtCore4.lib;QtGui4.lib;Winmm.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;QKeccakHash_VS2012.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>QtCore4.lib;QtGui4.lib;Winmm.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2012.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress>
<Version>
</Version>
@@ -222,7 +222,7 @@ del "$(TargetDir)imageformats\q???d4.dll"
</ClCompile>
<Link>
<AdditionalOptions>"/MANIFESTDEPENDENCY:type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27 processorArchitecture=%27*%27" %(AdditionalOptions)</AdditionalOptions>
- <AdditionalDependencies>QtCore.lib;QtGui.lib;QtSvg.lib;qtmain.lib;qsvg.lib;qico.lib;qtga.lib;Winmm.lib;imm32.lib;ws2_32.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;QKeccakHash_VS2012.lib;EncodePointer.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>QtCore.lib;QtGui.lib;QtSvg.lib;qtmain.lib;qsvg.lib;qico.lib;qtga.lib;Winmm.lib;imm32.lib;ws2_32.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2012.lib;EncodePointer.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress>
<AdditionalLibraryDirectories>$(SolutionDir)\etc\Prerequisites\qt4_static\lib;$(SolutionDir)\etc\Prerequisites\qt4_static\plugins\imageformats;$(SolutionDir)\etc\Prerequisites\EncodePointer\lib;$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\lib\Win32;$(SolutionDir)\etc\Prerequisites\keccak\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
View
2  src/Config.h
@@ -30,7 +30,7 @@
#define VER_LAMEXP_MINOR_LO 7
#define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 7
-#define VER_LAMEXP_BUILD 1221
+#define VER_LAMEXP_BUILD 1223
///////////////////////////////////////////////////////////////////////////////
// Tool versions (minimum expected versions!)
View
12 src/Dialog_About.cpp
@@ -473,7 +473,7 @@ void AboutDialog::initInformationTab(void)
const QString copyrightStr = QString().sprintf
(
"Copyright (C) 2004-%04d LoRd_MuldeR &lt;MuldeR2@GMX.de&gt;. Some rights reserved.",
- qMax(lamexp_version_date().year(), QDate::currentDate().year())
+ qMax(lamexp_version_date().year(), lamexp_current_date_safe().year())
);
QString aboutText;
@@ -484,25 +484,27 @@ void AboutDialog::initInformationTab(void)
aboutText += QString("%1<br>").arg(NOBR(tr("Please visit %1 for news and updates!").arg(LINK(lamexp_website_url()))));
#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
+ const QDate currentDate = lamexp_current_date_safe();
if(LAMEXP_DEBUG)
{
- int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0);
+ int daysLeft = qMax(currentDate.daysTo(lamexp_version_expires()), 0);
aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(QString("!!! --- DEBUG BUILD --- Expires at: %1 &middot; Days left: %2 --- DEBUG BUILD --- !!!").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft))));
}
else if(lamexp_version_demo())
{
- int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0);
+ int daysLeft = qMax(currentDate.daysTo(lamexp_version_expires()), 0);
aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(tr("Note: This demo (pre-release) version of LameXP will expire at %1. Still %2 days left.").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft))));
}
#else
+ const QDate currentDate = lamexp_current_date_safe();
if(LAMEXP_DEBUG)
{
- int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0i64);
+ int daysLeft = qMax(currentDate.daysTo(lamexp_version_expires()), 0i64);
aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(QString("!!! --- DEBUG BUILD --- Expires at: %1 &middot; Days left: %2 --- DEBUG BUILD --- !!!").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft))));
}
else if(lamexp_version_demo())
{
- int daysLeft = qMax(QDate::currentDate().daysTo(lamexp_version_expires()), 0i64);
+ int daysLeft = qMax(currentDate.daysTo(lamexp_version_expires()), 0i64);
aboutText += QString("<hr><font color=\"crimson\">%1</font>").arg(NOBR(tr("Note: This demo (pre-release) version of LameXP will expire at %1. Still %2 days left.").arg(lamexp_version_expires().toString(Qt::ISODate), QString::number(daysLeft))));
}
#endif
View
6 src/Dialog_MainWindow.cpp
@@ -1273,7 +1273,7 @@ void MainWindow::windowShown(void)
//Check for expiration
if(lamexp_version_demo())
{
- if(QDate::currentDate() >= lamexp_version_expires())
+ if(lamexp_current_date_safe() >= lamexp_version_expires())
{
qWarning("Binary has expired !!!");
PlaySound(MAKEINTRESOURCE(IDR_WAVE_WHAMMY), GetModuleHandle(NULL), SND_RESOURCE | SND_SYNC);
@@ -1300,7 +1300,7 @@ void MainWindow::windowShown(void)
}
//Update reminder
- if(QDate::currentDate() >= lamexp_version_date().addYears(1))
+ if(lamexp_current_date_safe() >= lamexp_version_date().addYears(1))
{
qWarning("Binary is more than a year old, time to update!");
int ret = QMessageBox::warning(this, tr("Urgent Update"), NOBR(tr("Your version of LameXP is more than a year old. Time for an update!")), tr("Check for Updates"), tr("Exit Program"), tr("Ignore"));
@@ -1326,7 +1326,7 @@ void MainWindow::windowShown(void)
else if(m_settings->autoUpdateEnabled())
{
QDate lastUpdateCheck = QDate::fromString(m_settings->autoUpdateLastCheck(), Qt::ISODate);
- if(!firstRun && (!lastUpdateCheck.isValid() || QDate::currentDate() >= lastUpdateCheck.addDays(14)))
+ if(!firstRun && (!lastUpdateCheck.isValid() || lamexp_current_date_safe() >= lastUpdateCheck.addDays(14)))
{
if(QMessageBox::information(this, tr("Update Reminder"), NOBR(lastUpdateCheck.isValid() ? tr("Your last update check was more than 14 days ago. Check for updates now?") : tr("Your did not check for LameXP updates yet. Check for updates now?")), tr("Check for Updates"), tr("Postpone")) == 0)
{
View
4 src/Dialog_Update.cpp
@@ -840,13 +840,13 @@ bool UpdateDialog::parseVersionInfo(const QString &file, UpdateInfo *updateInfo)
m_logFile->append("WARNING: Version info timestamp is missing!");
return false;
}
- else if(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS) < QDate::currentDate())
+ else if(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS) < lamexp_current_date_safe())
{
updateInfo->resetInfo();
m_logFile->append(QString::fromLatin1("WARNING: This version info has expired at %1!").arg(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS).toString(Qt::ISODate)));
return false;
}
- else if(QDate::currentDate() < updateInfoDate)
+ else if(lamexp_current_date_safe() < updateInfoDate)
{
m_logFile->append("Version info is from the future, take care!");
qWarning("Version info is from the future, take care!");
View
70 src/Global.cpp
@@ -71,10 +71,8 @@
#include <Objbase.h>
#include <PowrProf.h>
-//Debug only includes
-#if LAMEXP_DEBUG
+//Process API
#include <Psapi.h>
-#endif
//Initialize static Qt plugins
#ifdef QT_NODLL
@@ -2252,6 +2250,69 @@ unsigned int lamexp_rand(void)
}
/*
+ * Determines the current date, resistant against certain manipulations
+ */
+QDate lamexp_current_date_safe(void)
+{
+ const DWORD MAX_PROC = 1024;
+ DWORD *processes = new DWORD[MAX_PROC];
+ DWORD bytesReturned = 0;
+
+ if(!EnumProcesses(processes, sizeof(DWORD) * MAX_PROC, &bytesReturned))
+ {
+ LAMEXP_DELETE_ARRAY(processes);
+ 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++)
+ {
+ HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processes[i]);
+ if(hProc)
+ {
+ 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);
+ }
+ }
+
+ LAMEXP_DELETE_ARRAY(processes);
+
+ 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;
+}
+
+/*
* Entry point checks
*/
static DWORD lamexp_entry_check(void);
@@ -2329,6 +2390,9 @@ void lamexp_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessag
TerminateProcess(GetCurrentProcess(), -1);
}
}
+
+ Sleep(30000);
+ TerminateProcess(GetCurrentProcess(), -1);
}
/*
View
1  src/Global.h
@@ -158,6 +158,7 @@ const QString lamexp_clean_filename(const QString &str);
const QString lamexp_clean_filepath(const QString &str);
void lamexp_seed_rand(void);
unsigned int lamexp_rand(void);
+QDate lamexp_current_date_safe(void);
void lamexp_fatal_exit(const wchar_t* exitMessage, const wchar_t* errorBoxMessage = NULL);
//Debug-only functions
View
7 src/Main.cpp
@@ -57,7 +57,7 @@ static int lamexp_main(int argc, char* argv[])
//Print version info
qDebug("LameXP - Audio Encoder Front-End v%d.%02d %s (Build #%03d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build());
- qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(lamexp_version_date().year(),QDate::currentDate().year()));
+ qDebug("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.", qMax(lamexp_version_date().year(), lamexp_current_date_safe().year()));
qDebug("Built on %s at %s with %s for Win-%s.\n", lamexp_version_date().toString(Qt::ISODate).toLatin1().constData(), lamexp_version_time(), lamexp_version_compiler(), lamexp_version_arch());
//print license info
@@ -98,9 +98,10 @@ static int lamexp_main(int argc, char* argv[])
//Check for expiration
if(lamexp_version_demo())
{
- if(QDate::currentDate().addDays(1) < lamexp_version_date())
+ const QDate currentDate = lamexp_current_date_safe();
+ if(currentDate.addDays(1) < lamexp_version_date())
{
- qFatal("System's date (%s) is before LameXP build date (%s). Huh?", QDate::currentDate().toString(Qt::ISODate).toLatin1().constData(), lamexp_version_date().toString(Qt::ISODate).toLatin1().constData());
+ qFatal("System's date (%s) is before LameXP build date (%s). Huh?", currentDate.toString(Qt::ISODate).toLatin1().constData(), lamexp_version_date().toString(Qt::ISODate).toLatin1().constData());
}
qWarning(QString("Note: This demo (pre-release) version of LameXP will expire at %1.\n").arg(lamexp_version_expires().toString(Qt::ISODate)).toLatin1().constData());
}
Please sign in to comment.
Something went wrong with that request. Please try again.