From 4ca46015ed33b5908479e8fe7efcd3e4599266cf Mon Sep 17 00:00:00 2001 From: casey langen Date: Wed, 28 Jun 2017 10:34:28 -0700 Subject: [PATCH] This should round off update testing -- also use the XFERINFOFUNCTION to abort the update check if canceled. --- CHANGELOG.txt | 7 +++++-- src/musikbox/app/util/UpdateCheck.cpp | 19 +++++++++++++++---- src/musikbox/app/util/UpdateCheck.h | 4 ++-- src/plugins/httpdatastream/HttpDataStream.cpp | 1 - 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index ff95d6c5e..56d8d6709 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,7 +3,7 @@ user-facing: * added first-class support for browse playlists: - - press `5` in browse view to view playlists + - press `5` in library browse view to switch to playlists - press `M-r` to rename the selected playlist - press `M-s` to save the selected playlist - highlight the left pane, and press `DEL` (`BACKSPACE` on macos) to delete @@ -12,7 +12,10 @@ user-facing: - press `M-down` (`CTRL-DOWN` on macos) to move the selected track down - highlight the right pane, and press `DEL` (`BACKSPACE` on macos) to delete the selected track from the playlist -* added view titles in library browse mode +* added view titles in library browse mode, now playing, and search views +* added auto-update check functionality to notify users when a new version is + available. also added manual update check to settings +* rearranged some items on the settings screen -------------------------------------------------------------------------------- diff --git a/src/musikbox/app/util/UpdateCheck.cpp b/src/musikbox/app/util/UpdateCheck.cpp index c297e53b8..68a1f1f4d 100644 --- a/src/musikbox/app/util/UpdateCheck.cpp +++ b/src/musikbox/app/util/UpdateCheck.cpp @@ -84,7 +84,7 @@ static inline std::string getUserAgent() { % PLATFORM); } -size_t UpdateCheck::curlWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata) { +size_t UpdateCheck::CurlWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata) { if (ptr && userdata) { UpdateCheck* context = static_cast(userdata); @@ -97,6 +97,16 @@ size_t UpdateCheck::curlWriteCallback(char *ptr, size_t size, size_t nmemb, void return size * nmemb; } +int UpdateCheck::CurlTransferCallback( + void *ptr, curl_off_t downTotal, curl_off_t downNow, curl_off_t upTotal, curl_off_t upNow) +{ + UpdateCheck* context = static_cast(ptr); + if (context->cancel) { + return -1; /* kill the stream */ + } + return 0; /* ok! */ +} + UpdateCheck::UpdateCheck() { this->curl = nullptr; } @@ -118,17 +128,18 @@ bool UpdateCheck::Run(Callback callback) { curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curl, CURLOPT_AUTOREFERER, 1); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(curl, CURLOPT_USERAGENT, getUserAgent().c_str()); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &curlWriteCallback); curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 3000); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 7500); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 500); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, this); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &CurlWriteCallback); + curl_easy_setopt(curl, CURLOPT_XFERINFODATA, this); + curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, &CurlTransferCallback); this->thread.reset(new std::thread([this] { bool needsUpdate = false; diff --git a/src/musikbox/app/util/UpdateCheck.h b/src/musikbox/app/util/UpdateCheck.h index b16c0fc19..fc60dbeff 100644 --- a/src/musikbox/app/util/UpdateCheck.h +++ b/src/musikbox/app/util/UpdateCheck.h @@ -55,8 +55,8 @@ namespace musik { namespace box { private: void Reset(); - static size_t curlWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata); - + static size_t CurlWriteCallback(char *ptr, size_t size, size_t nmemb, void *userdata); + static int CurlTransferCallback(void *ptr, curl_off_t downTotal, curl_off_t downNow, curl_off_t upTotal, curl_off_t upNow); virtual void ProcessMessage(musik::core::runtime::IMessage &message); std::recursive_mutex mutex; diff --git a/src/plugins/httpdatastream/HttpDataStream.cpp b/src/plugins/httpdatastream/HttpDataStream.cpp index be2d86f6d..cf87ae219 100755 --- a/src/plugins/httpdatastream/HttpDataStream.cpp +++ b/src/plugins/httpdatastream/HttpDataStream.cpp @@ -259,7 +259,6 @@ bool HttpDataStream::Open(const char *uri, unsigned int options) { curl_easy_setopt(this->curlEasy, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(this->curlEasy, CURLOPT_AUTOREFERER, 1); curl_easy_setopt(this->curlEasy, CURLOPT_FAILONERROR, 1); - curl_easy_setopt(this->curlEasy, CURLOPT_NOPROGRESS, 1); curl_easy_setopt(this->curlEasy, CURLOPT_USERAGENT, "musikcube HttpDataStream"); curl_easy_setopt(this->curlEasy, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(this->curlEasy, CURLOPT_WRITEHEADER, this);