</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
+ <ClCompile Include="src\Global.cpp" />
<ClCompile Include="src\UpdateChecker.cpp" />
</ItemGroup>
<ItemGroup>
+ <ClInclude Include="include\MUtils\Global.h" />
<ClInclude Include="include\Mutils\UpdateChecker.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\</IntDir>
+ <TargetName>libMUtils-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\</IntDir>
+ <TargetName>libMUtils-1</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_Static|Win32'">
<OutDir>$(SolutionDir)\bin\$(Platform)\$(Configuration)\</OutDir>
<IntDir>$(SolutionDir)\obj\$(Platform)\$(Configuration)\</IntDir>
+ <TargetName>libMUtils-1</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<ClCompile Include="src\UpdateChecker.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\Global.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\Mutils\UpdateChecker.h">
<Filter>Header Files</Filter>
</ClInclude>
+ <ClInclude Include="include\MUtils\Global.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
</ItemGroup>
</Project>
\ No newline at end of file
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// MuldeR's Utilities for Qt
+// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+// http://www.gnu.org/licenses/lgpl-2.1.txt
+//////////////////////////////////////////////////////////////////////////////////
+
+#pragma once
+
+#include <QString>
+
+///////////////////////////////////////////////////////////////////////////////
+
+namespace MUtils
+{
+ //Random
+ void seed_rand(void);
+ QString rand_str(const bool &bLong = false);
+ quint32 next_rand32(void);
+ quint64 next_rand64(void);
+}
///////////////////////////////////////////////////////////////////////////////
-namespace MUtils {
-
+namespace MUtils
+{
class UpdateCheckerInfo
{
friend class UpdateChecker;
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// MuldeR's Utilities for Qt
+// Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+// http://www.gnu.org/licenses/lgpl-2.1.txt
+//////////////////////////////////////////////////////////////////////////////////
+
+#if _MSC_VER
+#define _CRT_RAND_S 1
+#endif
+
+#include <MUtils/Global.h>
+
+//CRT
+#include <cstdlib>
+#include <ctime>
+#include <process.h>
+
+///////////////////////////////////////////////////////////////////////////////
+// Random Support
+///////////////////////////////////////////////////////////////////////////////
+
+//Robert Jenkins' 96 bit Mix Function
+static unsigned int mix_function(const unsigned int x, const unsigned int y, const unsigned int z)
+{
+ unsigned int a = x;
+ unsigned int b = y;
+ unsigned int c = z;
+
+ a=a-b; a=a-c; a=a^(c >> 13);
+ b=b-c; b=b-a; b=b^(a << 8 );
+ c=c-a; c=c-b; c=c^(b >> 13);
+ a=a-b; a=a-c; a=a^(c >> 12);
+ b=b-c; b=b-a; b=b^(a << 16);
+ c=c-a; c=c-b; c=c^(b >> 5 );
+ a=a-b; a=a-c; a=a^(c >> 3 );
+ b=b-c; b=b-a; b=b^(a << 10);
+ c=c-a; c=c-b; c=c^(b >> 15);
+
+ return a ^ b ^ c;
+}
+
+void MUtils::seed_rand(void)
+{
+ qsrand(mix_function(clock(), time(NULL), _getpid()));
+}
+
+quint32 MUtils::next_rand32(void)
+{
+ quint32 rnd = 0xDEADBEEF;
+
+#ifdef _CRT_RAND_S
+ if(rand_s(&rnd) == 0)
+ {
+ return rnd;
+ }
+#endif //_CRT_RAND_S
+
+ for(size_t i = 0; i < sizeof(quint32); i++)
+ {
+ rnd = (rnd << 8) ^ qrand();
+ }
+
+ return rnd;
+}
+
+quint64 MUtils::next_rand64(void)
+{
+ return (quint64(next_rand32()) << 32) | quint64(next_rand32());
+}
+
+QString MUtils::rand_str(const bool &bLong)
+{
+ if(!bLong)
+ {
+ return QString::number(next_rand64(), 16).rightJustified(16, QLatin1Char('0'));
+ }
+ return QString("%1%2").arg(rand_str(false), rand_str(false));
+}
//////////////////////////////////////////////////////////////////////////////////
#include <MUtils/UpdateChecker.h>
+#include <MUtils/Global.h>
#include <QStringList>
#include <QFile>
m_success = false;
m_updateInfo->resetInfo();
+ seed_rand();
setProgress(0);
// ----- Test Internet Connection ----- //
hostList << QString::fromLatin1(known_hosts[i]);
}
- lamexp_seed_rand();
-
while(!(hostList.isEmpty() || (connectionScore >= MIN_CONNSCORE) || (maxConnectTries < 1)))
{
- switch(tryContactHost(hostList.takeAt(lamexp_rand() % hostList.count())))
+ switch(tryContactHost(hostList.takeAt(next_rand32() % hostList.count())))
{
case 01: connectionScore += 1; break;
case 02: connectionScore += 2; break;
default: maxConnectTries -= 1; break;
}
setProgress(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1));
- lamexp_sleep(64);
+ msleep(64);
}
if(connectionScore < MIN_CONNSCORE)
mirrorList << QString::fromLatin1(update_mirrors_prim[index]);
}
- 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, lamexp_rand() % len);
+ mirrorList.swap(i % len, next_rand32() % len);
}
}
}
else
{
- lamexp_sleep(64);
+ msleep(64);
}
}
QString currentHost = hostList.takeFirst();
qDebug("Testing: %s", currentHost.toLatin1().constData());
log("", "Testing:", currentHost, "");
- QString outFile = QString("%1/%2.htm").arg(lamexp_temp_folder2(), lamexp_rand_str());
+ QString outFile = QString("%1/%2.htm").arg(temp_folder(), rand_str());
bool httpOk = false;
if(!getFile(currentHost, outFile, 0, &httpOk))
{
int UpdateChecker::tryContactHost(const QString &url)
{
int result = -1; bool httpOkay = false;
- const QString outFile = QString("%1/%2.htm").arg(lamexp_temp_folder2(), lamexp_rand_str());
+ const QString outFile = QString("%1/%2.htm").arg(temp_folder(), rand_str());
log("", "Testing host:", url);
if(getFile(url, outFile, 0, &httpOkay))
bool success = false;
log("", "Trying mirror:", url);
- const QString randPart = lamexp_rand_str();
- const QString outFileVers = QString("%1/%2.ver").arg(lamexp_temp_folder2(), randPart);
- const QString outFileSign = QString("%1/%2.sig").arg(lamexp_temp_folder2(), randPart);
+ const QString randPart = rand_str();
+ const QString outFileVers = QString("%1/%2.ver").arg(temp_folder(), randPart);
+ const QString outFileSign = QString("%1/%2.sig").arg(temp_folder(), randPart);
if(getUpdateInfo(url, outFileVers, outFileSign))
{
}
QProcess process;
- lamexp_init_process(process, output.absolutePath());
+ init_process(process, output.absolutePath());
QStringList args;
args << "-T" << "15" << "--no-cache" << "--no-dns-cache" << QString().sprintf("--max-redirect=%u", maxRedir);
}
QProcess process;
- lamexp_init_process(process, QFileInfo(file).absolutePath());
+ init_process(process, QFileInfo(file).absolutePath());
QEventLoop loop;
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
log("WARNING: Version info timestamp is missing!");
return false;
}
- else if(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS) < lamexp_current_date_safe())
+ else if(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS) < current_date_safe())
{
updateInfo->resetInfo();
log(QString::fromLatin1("WARNING: This version info has expired at %1!").arg(updateInfoDate.addMonths(VERSION_INFO_EXPIRES_MONTHS).toString(Qt::ISODate)));
return false;
}
- else if(lamexp_current_date_safe() < updateInfoDate)
+ else if(current_date_safe() < updateInfoDate)
{
log("Version info is from the future, take care!");
qWarning("Version info is from the future, take care!");