Handle hard-coded HTML redirections automatically
This commit is contained in:
parent
03ad9414dc
commit
2b42e6ae98
2
etc/scripts/format-code.bat
Executable file → Normal file
2
etc/scripts/format-code.bat
Executable file → Normal file
@ -9,7 +9,7 @@ title Code Formatter
|
|||||||
cd /d %~dp0
|
cd /d %~dp0
|
||||||
|
|
||||||
:: Style and format the source code recursively
|
:: Style and format the source code recursively
|
||||||
astyle --style=google --indent=spaces --align-pointer=type --remove-brackets --convert-tabs --close-templates --max-code-length=80 --max-instatement-indent=50 --lineend=windows --suffix=none --recursive ../../*.h ../../*.cpp ../../*.c
|
astyle --pad-oper --pad-first-paren-out --align-pointer=type --remove-brackets --convert-tabs --max-code-length=80 --style=google --lineend=windows --suffix=none --recursive ../../*.h ../../*.cpp ../../*.c
|
||||||
|
|
||||||
:: Notify the user that we have finished
|
:: Notify the user that we have finished
|
||||||
echo.
|
echo.
|
||||||
|
2
etc/scripts/format-code.sh
Executable file → Normal file
2
etc/scripts/format-code.sh
Executable file → Normal file
@ -1,2 +1,2 @@
|
|||||||
# Style and format recursively
|
# Style and format recursively
|
||||||
astyle --style=google --indent=spaces --align-pointer=type --remove-brackets --convert-tabs --close-templates --max-code-length=80 --max-instatement-indent=50 --lineend=windows --suffix=none --recursive ../../*.h ../../*.cpp ../../*.c
|
astyle --pad-oper --pad-first-paren-out --align-pointer=type --remove-brackets --convert-tabs --max-code-length=80 --style=google --lineend=windows --suffix=none --recursive ../../*.h ../../*.cpp ../../*.c
|
||||||
|
@ -101,6 +101,8 @@ void Downloader::startDownload (const QUrl& url) {
|
|||||||
/* Update UI when download progress changes or download finishes */
|
/* Update UI when download progress changes or download finishes */
|
||||||
connect (m_reply, SIGNAL (downloadProgress (qint64, qint64)),
|
connect (m_reply, SIGNAL (downloadProgress (qint64, qint64)),
|
||||||
this, SLOT (updateProgress (qint64, qint64)));
|
this, SLOT (updateProgress (qint64, qint64)));
|
||||||
|
connect (m_reply, SIGNAL (redirected (QUrl)),
|
||||||
|
this, SLOT (startDownload (QUrl)));
|
||||||
connect (m_reply, SIGNAL (finished()),
|
connect (m_reply, SIGNAL (finished()),
|
||||||
this, SLOT (onDownloadFinished()));
|
this, SLOT (onDownloadFinished()));
|
||||||
|
|
||||||
@ -189,9 +191,14 @@ void Downloader::onDownloadFinished() {
|
|||||||
QByteArray data = m_reply->readAll();
|
QByteArray data = m_reply->readAll();
|
||||||
|
|
||||||
if (!data.isEmpty()) {
|
if (!data.isEmpty()) {
|
||||||
QStringList list = m_reply->url().toString().split ("/");
|
QString name = m_reply->url().toString().split ("/").last();
|
||||||
QFile file (QDir::tempPath() + "/" + list.at (list.count() - 1));
|
|
||||||
|
|
||||||
|
/* Handle HTML redirections automatically */
|
||||||
|
if (data.startsWith ("<html") || data.startsWith ("<!DOCTYPE html"))
|
||||||
|
name.append (".html");
|
||||||
|
|
||||||
|
/* Save downloaded data to disk */
|
||||||
|
QFile file (QDir::tempPath() + "/" + name);
|
||||||
if (file.open (QIODevice::WriteOnly)) {
|
if (file.open (QIODevice::WriteOnly)) {
|
||||||
file.write (data);
|
file.write (data);
|
||||||
file.close();
|
file.close();
|
||||||
@ -200,6 +207,8 @@ void Downloader::onDownloadFinished() {
|
|||||||
emit downloadFinished (m_reply->url().toString(), m_filePath);
|
emit downloadFinished (m_reply->url().toString(), m_filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Open downloaded update */
|
||||||
|
m_reply->close();
|
||||||
installUpdate();
|
installUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,8 @@ void Updater::setUpdateAvailable (const bool& available) {
|
|||||||
QDesktopServices::openUrl (QUrl (m_openUrl));
|
QDesktopServices::openUrl (QUrl (m_openUrl));
|
||||||
|
|
||||||
else if (downloaderEnabled())
|
else if (downloaderEnabled())
|
||||||
m_downloader->startDownload (downloadUrl());
|
m_downloader->startDownload (
|
||||||
|
QUrl ("https://github.com/WinT-3794/QDriverStation/releases/download/v16.06.2-stable/qdriverstation-16.06.2-setup.zip"));
|
||||||
|
|
||||||
else
|
else
|
||||||
QDesktopServices::openUrl (QUrl (downloadUrl()));
|
QDesktopServices::openUrl (QUrl (downloadUrl()));
|
||||||
|
33
tests/Test_Downloader.h
Executable file
33
tests/Test_Downloader.h
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016 Alex Spataru <alex_spataru@outlook.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEST_DOWNLOADER_H
|
||||||
|
#define TEST_DOWNLOADER_H
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
#include <Downloader.h>
|
||||||
|
|
||||||
|
class Test_Downloader : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
33
tests/Test_QSimpleUpdater.h
Executable file
33
tests/Test_QSimpleUpdater.h
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016 Alex Spataru <alex_spataru@outlook.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEST_QSIMPLEUPDATER_H
|
||||||
|
#define TEST_QSIMPLEUPDATER_H
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
#include <QSimpleUpdater.h>
|
||||||
|
|
||||||
|
class Test_QSimpleUpdater : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
33
tests/Test_Updater.h
Executable file
33
tests/Test_Updater.h
Executable file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016 Alex Spataru <alex_spataru@outlook.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEST_UPDATER_H
|
||||||
|
#define TEST_UPDATER_H
|
||||||
|
|
||||||
|
#include <QtTest>
|
||||||
|
#include <Updater.h>
|
||||||
|
|
||||||
|
class Test_Updater : public QObject {
|
||||||
|
Q_OBJECT
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
36
tests/Tests.pro
Executable file
36
tests/Tests.pro
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#
|
||||||
|
# Copyright (c) 2016 Alex Spataru <alex_spataru@outlook.com>
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
# THE SOFTWARE.
|
||||||
|
#
|
||||||
|
|
||||||
|
QT += testlib
|
||||||
|
TARGET = QSimpleUpdater_Test
|
||||||
|
|
||||||
|
include ($$PWD/../QSimpleUpdater.pri)
|
||||||
|
|
||||||
|
INCLUDEPATH += $$PWD/../src
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/main.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/Test_Downloader.h \
|
||||||
|
$$PWD/Test_QSimpleUpdater.h \
|
||||||
|
$$PWD/Test_Updater.h
|
40
tests/main.cpp
Executable file
40
tests/main.cpp
Executable file
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015-2016 Alex Spataru <alex_spataru@outlook.com>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Test_Updater.h"
|
||||||
|
#include "Test_Downloader.h"
|
||||||
|
#include "Test_QSimpleUpdater.h"
|
||||||
|
|
||||||
|
int main (int argc, char* argv[]) {
|
||||||
|
QApplication app (argc, argv);
|
||||||
|
|
||||||
|
app.setApplicationName ("QSimpleUpdater Tests");
|
||||||
|
app.setOrganizationName ("The QSimpleUpdater Library");
|
||||||
|
|
||||||
|
QTest::qExec (new Test_Updater, argc, argv);
|
||||||
|
QTest::qExec (new Test_Downloader, argc, argv);
|
||||||
|
QTest::qExec (new Test_QSimpleUpdater, argc, argv);
|
||||||
|
|
||||||
|
QTimer::singleShot (1000, Qt::PreciseTimer, qApp, SLOT (quit()));
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user