diff options
author | daniel-Jones <daniel@danieljon.es> | 2016-07-21 19:10:18 +0930 |
---|---|---|
committer | daniel-Jones <daniel@danieljon.es> | 2016-07-21 19:10:18 +0930 |
commit | b9224cb9de71995b9f89787d47b98f9bbb188d58 (patch) | |
tree | 8d45602c26d6ffc959da8df57d05dbf00bd1e9d5 /file_download.cpp | |
download | csgo_stats-b9224cb9de71995b9f89787d47b98f9bbb188d58.tar.gz csgo_stats-b9224cb9de71995b9f89787d47b98f9bbb188d58.zip |
first commit, basic program currently
Diffstat (limited to 'file_download.cpp')
-rw-r--r-- | file_download.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/file_download.cpp b/file_download.cpp new file mode 100644 index 0000000..c155f8b --- /dev/null +++ b/file_download.cpp @@ -0,0 +1,28 @@ +#include "file_download.h" + +file_download::file_download() +{ + +} + +int file_download::file_download::download_file(QString url, QString save_location) +{ + /* + * this function will download a given url/file to a location + * no file location will be interpreted as . (current directory) + */ + qDebug() << "downloading to " + save_location + " from " + url; + if (QFile::exists(save_location)) + QFile::remove(save_location); + QNetworkReply *reply = http.get(QNetworkRequest(url)); + QObject::connect(reply, SIGNAL(finished()),&loop, SLOT(quit())); + loop.exec(); + QFile file(save_location); + file.open(QIODevice::WriteOnly); + file.write(reply->readAll()); + delete reply; + if (QFile::exists(save_location) && file.size() > 0) + return 1; /* file downloaded - could just be a blank file at this point */ + else + return 0; /* file did not download */ +} |