From 2b42e6ae980dc83ad3efe7efe2ac8140907e0c69 Mon Sep 17 00:00:00 2001 From: Alex Spataru Date: Sun, 26 Jun 2016 18:32:40 -0600 Subject: [PATCH] Handle hard-coded HTML redirections automatically --- etc/scripts/format-code.bat | 2 +- etc/scripts/format-code.sh | 2 +- src/Downloader.cpp | 13 ++++++++++-- src/Updater.cpp | 3 ++- tests/Test_Downloader.h | 33 ++++++++++++++++++++++++++++++ tests/Test_QSimpleUpdater.h | 33 ++++++++++++++++++++++++++++++ tests/Test_Updater.h | 33 ++++++++++++++++++++++++++++++ tests/Tests.pro | 36 +++++++++++++++++++++++++++++++++ tests/main.cpp | 40 +++++++++++++++++++++++++++++++++++++ 9 files changed, 190 insertions(+), 5 deletions(-) mode change 100755 => 100644 etc/scripts/format-code.bat mode change 100755 => 100644 etc/scripts/format-code.sh create mode 100755 tests/Test_Downloader.h create mode 100755 tests/Test_QSimpleUpdater.h create mode 100755 tests/Test_Updater.h create mode 100755 tests/Tests.pro create mode 100755 tests/main.cpp diff --git a/etc/scripts/format-code.bat b/etc/scripts/format-code.bat old mode 100755 new mode 100644 index bf3672b..8f4f36b --- a/etc/scripts/format-code.bat +++ b/etc/scripts/format-code.bat @@ -9,7 +9,7 @@ title Code Formatter cd /d %~dp0 :: 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 echo. diff --git a/etc/scripts/format-code.sh b/etc/scripts/format-code.sh old mode 100755 new mode 100644 index ad1b9aa..9bfc1b2 --- a/etc/scripts/format-code.sh +++ b/etc/scripts/format-code.sh @@ -1,2 +1,2 @@ # 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 diff --git a/src/Downloader.cpp b/src/Downloader.cpp index 87c1865..ce77420 100755 --- a/src/Downloader.cpp +++ b/src/Downloader.cpp @@ -101,6 +101,8 @@ void Downloader::startDownload (const QUrl& url) { /* Update UI when download progress changes or download finishes */ connect (m_reply, SIGNAL (downloadProgress (qint64, qint64)), this, SLOT (updateProgress (qint64, qint64))); + connect (m_reply, SIGNAL (redirected (QUrl)), + this, SLOT (startDownload (QUrl))); connect (m_reply, SIGNAL (finished()), this, SLOT (onDownloadFinished())); @@ -189,9 +191,14 @@ void Downloader::onDownloadFinished() { QByteArray data = m_reply->readAll(); if (!data.isEmpty()) { - QStringList list = m_reply->url().toString().split ("/"); - QFile file (QDir::tempPath() + "/" + list.at (list.count() - 1)); + QString name = m_reply->url().toString().split ("/").last(); + /* Handle HTML redirections automatically */ + if (data.startsWith ("url().toString(), m_filePath); } + /* Open downloaded update */ + m_reply->close(); installUpdate(); } } diff --git a/src/Updater.cpp b/src/Updater.cpp index 1e1ec81..75449c0 100644 --- a/src/Updater.cpp +++ b/src/Updater.cpp @@ -312,7 +312,8 @@ void Updater::setUpdateAvailable (const bool& available) { QDesktopServices::openUrl (QUrl (m_openUrl)); 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 QDesktopServices::openUrl (QUrl (downloadUrl())); diff --git a/tests/Test_Downloader.h b/tests/Test_Downloader.h new file mode 100755 index 0000000..1515931 --- /dev/null +++ b/tests/Test_Downloader.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015-2016 Alex Spataru + * + * 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 +#include + +class Test_Downloader : public QObject { + Q_OBJECT +}; + +#endif diff --git a/tests/Test_QSimpleUpdater.h b/tests/Test_QSimpleUpdater.h new file mode 100755 index 0000000..7bba295 --- /dev/null +++ b/tests/Test_QSimpleUpdater.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015-2016 Alex Spataru + * + * 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 +#include + +class Test_QSimpleUpdater : public QObject { + Q_OBJECT +}; + +#endif diff --git a/tests/Test_Updater.h b/tests/Test_Updater.h new file mode 100755 index 0000000..14eef67 --- /dev/null +++ b/tests/Test_Updater.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2015-2016 Alex Spataru + * + * 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 +#include + +class Test_Updater : public QObject { + Q_OBJECT +}; + +#endif diff --git a/tests/Tests.pro b/tests/Tests.pro new file mode 100755 index 0000000..029f87f --- /dev/null +++ b/tests/Tests.pro @@ -0,0 +1,36 @@ +# +# Copyright (c) 2016 Alex Spataru +# +# 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 diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100755 index 0000000..37db880 --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015-2016 Alex Spataru + * + * 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(); +}