Skip to content

Commit 2287326

Browse files
committed
Added download of custom content
1 parent 9011674 commit 2287326

11 files changed

+305
-22
lines changed

Diff for: .gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
[submodule "3rdparty/QtAwesome"]
55
path = 3rdparty/QtAwesome
66
url = git://github.com/gamecreature/QtAwesome
7+
[submodule "quazip"]
8+
path = quazip
9+
url = https://github.com/binaryking/quazip.git
10+
[submodule "3rdparty/quazip"]
11+
path = 3rdparty/quazip
12+
url = https://github.com/binaryking/quazip.git

Diff for: 3rdparty/CMakeLists.txt

+19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ add_library(QtAwesome OBJECT QtAwesome/QtAwesome/QtAwesome.cpp ${faresources})
99

1010
set_target_properties(QtAwesome PROPERTIES COMPILE_FLAGS "${Qt5Widgets_EXECUTABLE_COMPILE_FLAGS}")
1111

12+
13+
14+
15+
16+
include_directories(
17+
${CMAKE_CURRENT_SOURCE_DIR}/quazip/quazip
18+
${CMAKE_CURRENT_BINARY_DIR}/quazip/quazip
19+
${ZLIB_INCLUDE_DIR}
20+
)
21+
22+
file(GLOB SRCS "quazip/quazip/*.c" "quazip/quazip/*.cpp")
23+
file(GLOB PUBLIC_HEADERS "quazip/quazip/*.h")
24+
25+
# Must be added to enable export macro
26+
ADD_DEFINITIONS(-DQUAZIP_BUILD)
27+
28+
add_library(quazip OBJECT ${SRCS})
29+
#target_link_libraries(quazip Qt5::Core ${ZLIB_LIBRARY})
30+
1231
set(3rdparty_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/QtAwesome/QtAwesome CACHE INTERNAL "")
1332

1433
#target_link_libraries(QtAwesome Qt5::Widgets)

Diff for: 3rdparty/quazip

Submodule quazip added at cf36e59

Diff for: CMakeLists.txt

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ set(CMAKE_AUTOMOC ON)
1414
find_package(Qt5Widgets)
1515
find_package(Qt5Network)
1616
find_package(PkgConfig)
17+
find_package(ZLIB)
1718
#find_package(Boost COMPONENTS system REQUIRED)
1819

19-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
20+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
2021

2122
#pkg_check_modules(LIBTORRENT libtorrent-rasterbar)
2223
#string (REPLACE ";" " " LIBTORRENT_CFLAGS_STR "${LIBTORRENT_CFLAGS} -DBOOST_THREAD_USE_LIB")
2324
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBTORRENT_CFLAGS_STR}")
2425

2526
if(CMAKE_BUILD_TYPE MATCHES Release)
26-
add_definitions(-DQT_NO_DEBUG_OUTPUT)
27+
#add_definitions(-DQT_NO_DEBUG_OUTPUT)
2728
endif()
2829

2930
add_subdirectory(3rdparty)
@@ -41,19 +42,19 @@ else()
4142
set(BUILD_TYPE "")
4243
endif()
4344

44-
set(UTLauncher_VERSION "0.2.6" CACHE STRING "Version number" FORCE INTERNAL)
45+
set(UTLauncher_VERSION "0.3.0" CACHE STRING "Version number" FORCE INTERNAL)
4546
set_version_number(UTLauncher)
4647

4748
add_definitions(-DNO_DOWNLOAD -DVERSION_MAJOR=${UTLauncher_VERSION_MAJOR} -DVERSION_MINOR=${UTLauncher_VERSION_MINOR} -DVERSION_PATCH=${UTLauncher_VERSION_PATCH})
48-
add_executable(UTLauncher ${BUILD_TYPE} ${resources} ${rc_srcs} main.cpp utlauncher.cpp download.cpp utsplash.cpp bootstrap.cpp serverbrowser.cpp configdialog.cpp $<TARGET_OBJECTS:QtAwesome>)
49+
add_executable(UTLauncher ${BUILD_TYPE} ${resources} ${rc_srcs} main.cpp utlauncher.cpp download.cpp utsplash.cpp bootstrap.cpp serverbrowser.cpp configdialog.cpp $<TARGET_OBJECTS:QtAwesome> $<TARGET_OBJECTS:quazip>)
4950

5051

5152
if(STATIC_BUILD_WIN32)
5253
pkg_check_modules(QT5WIDGETS Qt5Widgets)
5354
add_definitions(-DSTATIC_PLUGIN_WINDOWS)
54-
target_link_libraries(UTLauncher Qt5::Widgets Qt5::QWindowsIntegrationPlugin Qt5::Network ${QT5WIDGETS_LDFLAGS})
55+
target_link_libraries(UTLauncher Qt5::Widgets Qt5::QWindowsIntegrationPlugin Qt5::Network ${QT5WIDGETS_LDFLAGS} ${ZLIB_LIBRARY})
5556
else()
56-
target_link_libraries(UTLauncher Qt5::Widgets Qt5::Network ${Boost_SYSTEM_LIBRARY})
57+
target_link_libraries(UTLauncher Qt5::Widgets Qt5::Network ${Boost_SYSTEM_LIBRARY} ${ZLIB_LIBRARY})
5758
endif()
5859

5960
install(TARGETS UTLauncher RUNTIME DESTINATION bin)

Diff for: bootstrap.h

+12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <QFileInfo>
1111
#include <QJsonDocument>
1212
#include <QJsonObject>
13+
#include <QJsonArray>
1314
#include <QSettings>
1415
#include <QDir>
1516
#include <QFileDialog>
@@ -30,6 +31,8 @@ class Bootstrap : public QObject {
3031
QString releasePath;
3132
QString torrentFullFile;
3233
QSettings& settings;
34+
QSet<QString> stockMaps;
35+
3336

3437
QTimer bootstrapRedownloadTimer;
3538

@@ -55,6 +58,10 @@ private slots:
5558
return motd;
5659
}
5760

61+
bool isStockMap(QString map) const {
62+
return stockMaps.contains(map);
63+
}
64+
5865
Bootstrap(QSettings& _settings, QObject* parent = nullptr) : QObject(parent), settings(_settings) {
5966
download.setTarget("https://utlauncher.rushbase.net/bootstrap.json");
6067

@@ -85,6 +92,11 @@ private slots:
8592
downloadServers.download();
8693

8794
bootstrapRedownloadTimer.singleShot(15*60000, &download, SLOT(download()));
95+
stockMaps.clear();
96+
for(auto stockMap : json.value("stockMaps").toArray()) {
97+
auto mapString = stockMap.toString();
98+
stockMaps.insert(mapString);
99+
}
88100

89101
#ifdef NO_DOWNLOAD
90102
emit ready();

Diff for: download.cpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ Download::~Download() {
1616

1717

1818
void Download::setTarget(const QString &t) {
19+
1920
this->target = t;
2021
}
2122

2223
void Download::downloadFinished(QNetworkReply *data) {
24+
2325
emit done(data->readAll());
2426
}
2527

@@ -29,6 +31,7 @@ void Download::download() {
2931

3032
request.sslConfiguration().setProtocol(QSsl::AnyProtocol);
3133

34+
httpCode = 0;
3235
request.setRawHeader( "User-Agent" , QString("UTLauncher %1.%2.%3 / %4").arg(VERSION_MAJOR).arg(VERSION_MINOR).arg(VERSION_PATCH).arg(
3336
#if defined Q_OS_WINDOWS
3437
"Windows"
@@ -42,14 +45,28 @@ void Download::download() {
4245
).toUtf8() );
4346
QNetworkReply* reply = manager.get(request);
4447
QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
48+
4549
if(receivers(SIGNAL(chunk(QByteArray)))) {
4650
connect(reply, &QNetworkReply::readyRead, [=] {
47-
emit chunk(reply->readAll());
51+
if(httpCode == 200)
52+
emit chunk(reply->readAll());
4853
});
4954
}
55+
QObject::connect(reply, &QNetworkReply::metaDataChanged, [=]() {
56+
57+
auto statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
58+
if ( statusCode.isValid() ) {
59+
int replyCode = statusCode.toInt();
60+
httpCode = replyCode;
61+
if(replyCode != 200) {
62+
emit error(replyCode, reply->readAll());
63+
disconnect(this, SLOT(downloadProgress(qint64, qint64)));
64+
}
65+
return;
66+
}
67+
});
5068
QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), SLOT(downloadError(QNetworkReply::NetworkError)));
5169
QObject::connect(reply, SIGNAL(sslErrors(QList<QSslError>)), SLOT(downloadSslErrors(QList<QSslError>)));
52-
5370
}
5471

5572

@@ -64,5 +81,5 @@ void Download::downloadError(QNetworkReply::NetworkError error) {
6481
}
6582

6683
void Download::downloadProgress(qint64 recieved, qint64 total) {
67-
qDebug() << recieved << total;
84+
emit progress((double)recieved / total);
6885
}

Diff for: download.h

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class Download : public QObject {
1717
void setTarget(const QString& t);
1818

1919
private:
20+
int httpCode;
2021
QNetworkAccessManager manager;
2122
QString target;
2223

@@ -25,6 +26,7 @@ class Download : public QObject {
2526

2627
void progress(double progress);
2728
void chunk(QByteArray chunk);
29+
void error(int code, QByteArray data);
2830

2931
public slots:
3032
void download();

Diff for: main.cpp

+7-6
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS
99
QByteArray localMsg = msg.toLocal8Bit();
1010
switch (type) {
1111
case QtDebugMsg:
12-
fprintf(stderr, "Debug: %s\n\0 (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
12+
fprintf(stderr, "Debug: %s\n (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
1313
break;
1414
case QtWarningMsg:
15-
fprintf(stderr, "Warning: %s\n\0 (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
15+
fprintf(stderr, "Warning: %s\n (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
1616
break;
1717
case QtCriticalMsg:
18-
fprintf(stderr, "Critical: %s\n\0 (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
18+
fprintf(stderr, "Critical: %s\n (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
1919
break;
2020
case QtFatalMsg:
21-
fprintf(stderr, "Fatal: %s\n\0 (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
21+
fprintf(stderr, "Fatal: %s\n (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
2222
abort();
2323
}
2424
}
2525

26+
#include <QTextCodec>
27+
2628
int main(int argc, char** argv)
2729
{
2830
qInstallMessageHandler(myMessageOutput);
@@ -31,9 +33,8 @@ int main(int argc, char** argv)
3133
QCoreApplication::setOrganizationDomain("codecharm.co.uk");
3234
QCoreApplication::setApplicationName("UTLauncher");
3335

34-
// QApplication::setDesktopSettingsAware(false);
3536
UTLauncher app(argc, argv);
36-
37+
3738
return app.exec();
3839
}
3940

0 commit comments

Comments
 (0)