diff --git a/src/Config.h b/src/Config.h index e124992d..3ce9d561 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 6 #define VER_LAMEXP_TYPE Beta #define VER_LAMEXP_PATCH 2 -#define VER_LAMEXP_BUILD 1141 +#define VER_LAMEXP_BUILD 1145 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Dialog_About.cpp b/src/Dialog_About.cpp index 68ab5bef..59d8ad43 100644 --- a/src/Dialog_About.cpp +++ b/src/Dialog_About.cpp @@ -135,23 +135,25 @@ AboutDialog::AboutDialog(SettingsModel *settings, QWidget *parent, bool firstSta //Show about dialog for the first time? if(!firstStart) { + lamexp_seed_rand(); + acceptButton->hide(); declineButton->hide(); aboutQtButton->show(); closeButton->show(); - + QPixmap disque(":/images/Disque.png"); QRect screenGeometry = QApplication::desktop()->availableGeometry(); m_disque = new QLabel(this, Qt::Window | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); m_disque->installEventFilter(this); m_disque->setStyleSheet("background:transparent;"); m_disque->setAttribute(Qt::WA_TranslucentBackground); - m_disque->setGeometry(qrand() % (screenGeometry.width() - disque.width()), qrand() % (screenGeometry.height() - disque.height()), disque.width(), disque.height()); + m_disque->setGeometry(static_cast(lamexp_rand() % static_cast(screenGeometry.width() - disque.width())), static_cast(lamexp_rand() % static_cast(screenGeometry.height() - disque.height())), disque.width(), disque.height()); m_disque->setPixmap(disque); m_disque->setWindowOpacity(0.01); m_disque->show(); - m_disqueFlags[0] = (qrand() > (RAND_MAX/2)); - m_disqueFlags[1] = (qrand() > (RAND_MAX/2)); + m_disqueFlags[0] = (lamexp_rand() > (UINT_MAX/2)); + m_disqueFlags[1] = (lamexp_rand() > (UINT_MAX/2)); m_disqueTimer = new QTimer; connect(m_disqueTimer, SIGNAL(timeout()), this, SLOT(moveDisque())); m_disqueTimer->setInterval(10); diff --git a/src/Dialog_MainWindow.cpp b/src/Dialog_MainWindow.cpp index 1ae20074..cccd16d8 100644 --- a/src/Dialog_MainWindow.cpp +++ b/src/Dialog_MainWindow.cpp @@ -1171,10 +1171,6 @@ void MainWindow::windowShown(void) if(reinterpret_cast(res) > 32) break; } } - else - { - MoveFileEx(QWCHAR(QDir::toNativeSeparators(QFileInfo(QApplication::applicationFilePath()).canonicalFilePath())), NULL, MOVEFILE_DELAY_UNTIL_REBOOT | MOVEFILE_REPLACE_EXISTING); - } QApplication::quit(); return; } diff --git a/src/Dialog_Update.cpp b/src/Dialog_Update.cpp index acea2d74..0261c17e 100644 --- a/src/Dialog_Update.cpp +++ b/src/Dialog_Update.cpp @@ -39,10 +39,8 @@ #include #include -#include #include #include -#include /////////////////////////////////////////////////////////////////////////////// @@ -425,10 +423,10 @@ void UpdateDialog::checkForUpdates(void) hostList << QString::fromLatin1(known_hosts[i]); } - qsrand(lamexp_mix(clock(), time(NULL), _getpid())); + lamexp_seed_rand(); while(!hostList.isEmpty()) { - QString currentHost = hostList.takeAt(qrand() % hostList.count()); + QString currentHost = hostList.takeAt(lamexp_rand() % hostList.count()); if(connectionScore < MIN_CONNSCORE) { m_logFile->append(QStringList() << "" << "Testing host:" << currentHost << ""); @@ -486,13 +484,13 @@ void UpdateDialog::checkForUpdates(void) mirrorList << QString::fromLatin1(update_mirrors_prim[index]); } - qsrand(lamexp_mix(clock(), time(NULL), _getpid())); + lamexp_seed_rand(); if(const int len = mirrorList.count()) { const int rounds = len * 1097; for(int i = 0; i < rounds; i++) { - mirrorList.swap(i % len, qrand() % len); + mirrorList.swap(i % len, lamexp_rand() % len); } } diff --git a/src/Global.cpp b/src/Global.cpp index 7fe95628..3b6aa333 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -472,7 +472,7 @@ LONG WINAPI lamexp_exception_handler(__in struct _EXCEPTION_POINTERS *ExceptionI /* * Invalid parameters handler */ -void lamexp_invalid_param_handler(const wchar_t*, const wchar_t*, const wchar_t*, unsigned int, uintptr_t) +void lamexp_invalid_param_handler(const wchar_t* exp, const wchar_t* fun, const wchar_t* fil, unsigned int, uintptr_t) { if(GetCurrentThreadId() != g_main_thread_id) { @@ -2210,7 +2210,7 @@ QStringList lamexp_available_codepages(bool noAliases) * Robert Jenkins' 96 bit Mix Function * Source: http://www.concentric.net/~Ttwang/tech/inthash.htm */ -unsigned int lamexp_mix(const unsigned int x, const unsigned int y, const unsigned int z) +static unsigned int lamexp_mix(const unsigned int x, const unsigned int y, const unsigned int z) { unsigned int a = x; unsigned int b = y; @@ -2229,6 +2229,39 @@ unsigned int lamexp_mix(const unsigned int x, const unsigned int y, const unsign return c; } +/* + * Seeds the random number generator + * Note: Altough rand_s() doesn't need a seed, this must be called pripr to lamexp_rand(), just to to be sure! + */ +void lamexp_seed_rand(void) +{ + qsrand(lamexp_mix(clock(), time(NULL), _getpid())); +} + +/* + * Returns a randum number + * Note: This function uses rand_s() if available, but falls back to qrand() otherwise + */ +unsigned int lamexp_rand(void) +{ + unsigned int rnd = 0; + if(const lamexp_os_version_t* osVer = lamexp_get_os_version()) + { + if(LAMEXP_MIN_OS_VER(osVer, 5, 1)) + { + if(rand_s(&rnd) == 0) + { + return rnd; + } + } + } + for(size_t i = 0; i < sizeof(unsigned int); i++) + { + rnd = (rnd << 8) ^ qrand(); + } + return rnd; +} + /* * Entry point checks */ diff --git a/src/Global.h b/src/Global.h index 982ae057..a6a6b10f 100644 --- a/src/Global.h +++ b/src/Global.h @@ -25,6 +25,7 @@ #include "Targetver.h" //inlcude C standard library +#define _CRT_RAND_S #include #include @@ -155,7 +156,8 @@ bool lamexp_themes_enabled(void); void lamexp_blink_window(QWidget *poWindow, unsigned int count = 10, unsigned int delay = 150); const QString lamexp_clean_filename(const QString &str); const QString lamexp_clean_filepath(const QString &str); -unsigned int lamexp_mix(const unsigned int x, const unsigned int y, const unsigned int z); +void lamexp_seed_rand(void); +unsigned int lamexp_rand(void); //Debug-only functions SIZE_T lamexp_dbg_private_bytes(void);