Exemple #1
0
Updater::Updater(const UpdateInformation &information, QObject *parent) : QObject(parent),
	m_transfer(NULL),
	m_transfersCount(0),
	m_transfersSuccessful(true)
{
	const QString path(QStandardPaths::writableLocation(QStandardPaths::TempLocation) + QLatin1String("/OtterBrowser/"));
	QDir directory(path);

	if (!directory.exists())
	{
		QDir().mkdir(path);
	}
	else if (directory.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries).count() > 0)
	{
		directory.setNameFilters(QStringList(QLatin1String("*.*")));
		directory.setFilter(QDir::Files);

		for (int i = 0; i < directory.entryList().count(); ++i)
		{
			directory.remove(directory.entryList().at(i));
		}
	}

	clearUpdate();

	downloadFile(information.scriptUrl, path);

	m_transfer = downloadFile(information.fileUrl, path);
	m_transfer->setUpdateInterval(500);

	connect(m_transfer, SIGNAL(progressChanged(qint64,qint64)), this, SLOT(updateProgress(qint64,qint64)));
}
Exemple #2
0
void Updater::transferFinished()
{
	Transfer *transfer = qobject_cast<Transfer*>(sender());

	if (transfer)
	{
		const QString path = transfer->getTarget();

		if ((transfer->getState() == Transfer::FinishedState) && QFile::exists(path))
		{
			if (QFileInfo(path).suffix() == QLatin1String("xml"))
			{
				QFile file(SessionsManager::getWritableDataPath(QLatin1String("update.txt")));

				if (file.open(QIODevice::ReadWrite | QIODevice::Text))
				{
					QTextStream stream(&file);
					stream << path;

					file.close();
				}
			}
		}
		else
		{
			Console::addMessage(QCoreApplication::translate("main", "Unable to download update: %1\nError: %2").arg(transfer->getSource().url()).arg(transfer->getState()), OtherMessageCategory, ErrorMessageLevel);

			m_transfersSuccessful = false;
		}

		transfer->deleteLater();
	}
	else
	{
		m_transfersSuccessful = false;
	}

	++m_transfersCount;

	if (m_transfersCount == 2)
	{
		if (!m_transfersSuccessful)
		{
			clearUpdate();
		}

		emit finished(m_transfersSuccessful);

		deleteLater();
	}
}
Exemple #3
0
void Updater::transferFinished()
{
	Transfer *transfer(qobject_cast<Transfer*>(sender()));

	if (transfer)
	{
		const QString path(transfer->getTarget());

		if ((transfer->getState() == Transfer::FinishedState) && QFile::exists(path))
		{
			if (QFileInfo(path).suffix() == QLatin1String("xml"))
			{
				QXmlSchema schema;

				if (!schema.load(QUrl::fromLocalFile(SessionsManager::getReadableDataPath(QLatin1String("schemas/update.xsd")))) || !QXmlSchemaValidator(schema).validate(QUrl::fromLocalFile(path)))
				{
					Console::addMessage(QCoreApplication::translate("main", "Downloaded update script is not valid: %1").arg(path), Console::OtherCategory, Console::ErrorLevel);

					m_transfersSuccessful = false;
				}
				else
				{
					QFile file(SessionsManager::getWritableDataPath(QLatin1String("update.txt")));

					if (file.open(QIODevice::ReadWrite | QIODevice::Text))
					{
						QTextStream stream(&file);
						stream << path;

						file.close();
					}
				}
			}
		}
		else
		{
			Console::addMessage(QCoreApplication::translate("main", "Unable to download update: %1\nError: %2").arg(transfer->getSource().url()).arg(transfer->getState()), Console::OtherCategory, Console::ErrorLevel);

			m_transfersSuccessful = false;
		}

		transfer->deleteLater();
	}
	else
	{
		m_transfersSuccessful = false;
	}

	++m_transfersCount;

	if (m_transfersCount == 2)
	{
		if (!m_transfersSuccessful)
		{
			clearUpdate();
		}

		emit finished(m_transfersSuccessful);

		deleteLater();
	}
}