const int networkStatus = OS::network_status();
if(networkStatus == OS::NETWORK_TYPE_NON)
{
- log("Operating system reports that the computer is currently offline !!!");
- setProgress(m_maxProgress);
- setStatus(UpdateStatus_ErrorNoConnection);
- return;
+ if (!MUtils::OS::arguments().contains("--ignore-network-status"))
+ {
+ log("Operating system reports that the computer is currently offline !!!");
+ setProgress(m_maxProgress);
+ setStatus(UpdateStatus_ErrorNoConnection);
+ return;
+ }
}
msleep(500);
args << "-e" << QString("%1://%2/;auto").arg(url.scheme(), url.host());
args << "-o" << output.fileName() << url.toString();
- return invokeCurl(args, output.absolutePath(), DOWNLOAD_TIMEOUT);
+ return execCurl(args, output.absolutePath(), DOWNLOAD_TIMEOUT);
}
bool MUtils::UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMsec)
args << "-A" << USER_AGENT_STR;
args << "-o" << OS::null_device() << QString("http://%1/").arg(hostname);
- return invokeCurl(args, temp_folder(), timeoutMsec);
+ return execCurl(args, temp_folder(), timeoutMsec);
}
-bool MUtils::UpdateChecker::invokeCurl(const QStringList &args, const QString &workingDir, const int timeout)
+bool MUtils::UpdateChecker::checkSignature(const QString &file, const QString &signature)
{
- QProcess process;
- init_process(process, workingDir, true, NULL, m_environment.data());
-
- QEventLoop loop;
- connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
- connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), &loop, SLOT(quit()));
- connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
-
- QTimer timer;
- timer.setSingleShot(true);
- connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
-
- process.start(m_binaryCurl, args);
- if (!process.waitForStarted())
+ if (QFileInfo(file).absolutePath().compare(QFileInfo(signature).absolutePath(), Qt::CaseInsensitive) != 0)
{
+ qWarning("CheckSignature: File and signature should be in same folder!");
return false;
}
- bool bAborted = false;
- timer.start(qMax((timeout + (timeout / 2)), 1500));
-
- while (process.state() != QProcess::NotRunning)
+ QString keyRingPath(m_binaryKeys);
+ bool removeKeyring = false;
+ if (QFileInfo(file).absolutePath().compare(QFileInfo(m_binaryKeys).absolutePath(), Qt::CaseInsensitive) != 0)
{
- loop.exec();
- while (process.canReadLine())
- {
- const QString line = QString::fromLatin1(process.readLine()).simplified();
- if ((!line.isEmpty()) && line.compare(QLatin1String("<")) && line.compare(QLatin1String(">")))
- {
- log(line);
- }
- }
- const bool bCancelled = MUTILS_BOOLIFY(m_cancelled);
- if (bAborted = (bCancelled || ((!timer.isActive()) && (!process.waitForFinished(125)))))
+ keyRingPath = make_temp_file(QFileInfo(file).absolutePath(), "gpg");
+ removeKeyring = true;
+ if (!QFile::copy(m_binaryKeys, keyRingPath))
{
- log(bCancelled ? "CANCELLED BY USER !!!" : "PROCESS TIMEOUT !!!", "");
- qWarning("WARNING: cURL process %s!", bCancelled ? "cancelled" : "timed out");
- break; /*abort process*/
+ qWarning("CheckSignature: Failed to copy the key-ring file!");
+ return false;
}
}
- timer.stop();
- timer.disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+ QStringList args;
+ args << QStringList() << "--homedir" << ".";
+ args << "--keyring" << QFileInfo(keyRingPath).fileName();
+ args << QFileInfo(signature).fileName();
+ args << QFileInfo(file).fileName();
- if (bAborted)
+ const int exitCode = execProcess(m_binaryGnuPG, args, QFileInfo(file).absolutePath(), DOWNLOAD_TIMEOUT);
+ if (exitCode != INT_MAX)
{
- process.kill();
- process.waitForFinished(-1);
+ log(QString().sprintf("Exited with code %d", exitCode));
}
- while (process.canReadLine())
+ if (removeKeyring)
{
- const QString line = QString::fromLatin1(process.readLine()).simplified();
- if ((!line.isEmpty()) && line.compare(QLatin1String("<")) && line.compare(QLatin1String(">")))
- {
- log(line);
- }
+ remove_file(keyRingPath);
}
- if (!bAborted)
+ return (exitCode == 0); /*completed*/
+}
+
+bool MUtils::UpdateChecker::execCurl(const QStringList &args, const QString &workingDir, const int timeout)
+{
+ const int exitCode = execProcess(m_binaryCurl, args, workingDir, timeout + (timeout / 2));
+ if (exitCode != INT_MAX)
{
- const int exitCode = process.exitCode();
switch (exitCode)
{
case -1:
case 28: log(QLatin1String("ERROR: Operation timed out !!!"), ""); break;
default: log(QString().sprintf("ERROR: Terminated with unknown code %d", exitCode), ""); break;
}
- return (exitCode == 0);
}
-
- return false; /*aborted*/
+
+ return (exitCode == 0); /*completed*/
}
-bool MUtils::UpdateChecker::checkSignature(const QString &file, const QString &signature)
+int MUtils::UpdateChecker::execProcess(const QString &programFile, const QStringList &args, const QString &workingDir, const int timeout)
{
- if (QFileInfo(file).absolutePath().compare(QFileInfo(signature).absolutePath(), Qt::CaseInsensitive) != 0)
- {
- qWarning("CheckSignature: File and signature should be in same folder!");
- return false;
- }
-
- QString keyRingPath(m_binaryKeys);
- bool removeKeyring = false;
- if (QFileInfo(file).absolutePath().compare(QFileInfo(m_binaryKeys).absolutePath(), Qt::CaseInsensitive) != 0)
- {
- keyRingPath = make_temp_file(QFileInfo(file).absolutePath(), "gpg");
- removeKeyring = true;
- if (!QFile::copy(m_binaryKeys, keyRingPath))
- {
- qWarning("CheckSignature: Failed to copy the key-ring file!");
- return false;
- }
- }
-
QProcess process;
- init_process(process, QFileInfo(file).absolutePath());
+ init_process(process, workingDir, true, NULL, m_environment.data());
QEventLoop loop;
connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), &loop, SLOT(quit()));
connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
- process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(keyRingPath).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
+ QTimer timer;
+ timer.setSingleShot(true);
+ connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+ process.start(programFile, args);
if (!process.waitForStarted())
{
- if (removeKeyring)
- {
- remove_file(keyRingPath);
- }
- return false;
+ log("PROCESS FAILED TO START !!!", "");
+ qWarning("WARNING: %s process could not be created!", MUTILS_UTF8(QFileInfo(programFile).fileName()));
+ return INT_MAX; /*failed to start*/
}
+ bool bAborted = false;
+ timer.start(qMax(timeout, 1500));
+
while (process.state() != QProcess::NotRunning)
{
loop.exec();
while (process.canReadLine())
{
const QString line = QString::fromLatin1(process.readLine()).simplified();
- if (!line.isEmpty())
+ if ((!line.isEmpty()) && line.compare(QLatin1String("<")) && line.compare(QLatin1String(">")))
{
log(line);
}
}
+ const bool bCancelled = MUTILS_BOOLIFY(m_cancelled);
+ if (bAborted = (bCancelled || ((!timer.isActive()) && (!process.waitForFinished(125)))))
+ {
+ log(bCancelled ? "CANCELLED BY USER !!!" : "PROCESS TIMEOUT !!!", "");
+ qWarning("WARNING: %s process %s!", MUTILS_UTF8(QFileInfo(programFile).fileName()), bCancelled ? "cancelled" : "timed out");
+ break; /*abort process*/
+ }
}
- if (removeKeyring)
+ timer.stop();
+ timer.disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+
+ if (bAborted)
{
- remove_file(keyRingPath);
+ process.kill();
+ process.waitForFinished(-1);
+ }
+
+ while (process.canReadLine())
+ {
+ const QString line = QString::fromLatin1(process.readLine()).simplified();
+ if ((!line.isEmpty()) && line.compare(QLatin1String("<")) && line.compare(QLatin1String(">")))
+ {
+ log(line);
+ }
}
- log(QString().sprintf("Exited with code %d", process.exitCode()));
- return (process.exitCode() == 0);
+ return bAborted ? INT_MAX : process.exitCode();
}
////////////////////////////////////////////////////////////