Commit e02fd852 authored by Gerhard Stein's avatar Gerhard Stein

Added cancel download button.

parent f818d32b
......@@ -673,6 +673,10 @@ void CGameLauncher::pumpEvent(const CEvent *evPtr)
mpGameStoreDialog = nullptr;
}
}
else if( dynamic_cast<const CancelDownloadEvent*>(evPtr))
{
mCancelDownload = true;
}
// Check Scroll events happening on this Launcher
......
......@@ -143,6 +143,7 @@ private:
std::shared_ptr<CGUIText> mpDDescriptionText;
std::shared_ptr<CGUITextSelectionList> mpDloadSelectionList;
std::shared_ptr<GsButton> mpDloadBack;
std::shared_ptr<GsButton> mpDloadCancel;
std::shared_ptr<GsButton> mpDloadDownload;
std::shared_ptr<CGUIBitmap> mpCurrentDownloadBmp;
std::vector< std::shared_ptr<GsBitmap> > mpDownloadPrevievBmpVec;
......@@ -180,6 +181,7 @@ private:
int m_start_level;
int mDownloadProgress = 0;
bool mCancelDownload = false;
ThreadPoolItem* mpGameDownloader;
......@@ -210,5 +212,8 @@ struct GMSwitchToGameLauncher : SwitchEngineEvent
struct CloseBoxEvent : CEvent
{};
struct CancelDownloadEvent : CEvent
{};
#endif /* CGAMELAUNCHER_H_ */
......@@ -9,15 +9,14 @@
#include "core/mode/CGameMode.h"
//extern std::vector<GameCatalogueEntry> geGameCatalogue;
// Here we take a look at the game the user still does not
// have and decide if the "New Stuff" will become selectable.
// If he has all the games, the button won't be shown.
void CGameLauncher::verifyGameStore()
{
int progress = 0;
GameDownloader gameDownloader(progress);
bool cancel = false;
GameDownloader gameDownloader(progress, cancel);
std::vector< std::string > missingList;
......@@ -36,7 +35,6 @@ void CGameLauncher::verifyGameStore()
void CGameLauncher::pullGame(const int selection)
{
assert(selection >= 0);
if(selection < 0)
......@@ -49,7 +47,10 @@ void CGameLauncher::pullGame(const int selection)
mDownloading = true;
mpDloadTitleText->setText("Downloading Game...");
mCancelDownload = false;
mpGameDownloader = threadPool->start(new GameDownloader(mDownloadProgress,
mCancelDownload,
gameFileName,
gameName), "Game Downloader started!");
......@@ -76,6 +77,7 @@ void CGameLauncher::ponderDownloadDialog()
if(mDownloading)
{
mpDloadSelectionList->enable(false);
mpDloadCancel->enable(true);
mpDloadBack->enable(false);
mpDloadDownload->enable(false);
}
......@@ -108,7 +110,8 @@ void CGameLauncher::setupDownloadDialog()
mDownloading = false;
int progress = 0;
GameDownloader gameDownloader(progress);
bool cancel = false;
GameDownloader gameDownloader(progress, cancel);
std::vector< std::string > missingList;
gameDownloader.checkForMissingGames( missingList );
......@@ -153,10 +156,14 @@ void CGameLauncher::setupDownloadDialog()
// Bottom Controls
mpDloadBack = std::dynamic_pointer_cast<GsButton>(
mpGameStoreDialog->addControl( new GsButton( "< Back", new CloseBoxEvent() ), GsRect<float>(0.065f, 0.865f, 0.3f, 0.07f) ) );
mpGameStoreDialog->addControl( new GsButton( "< Back", new CloseBoxEvent() ), GsRect<float>(0.065f, 0.865f, 0.2f, 0.07f) ) );
mpDloadCancel = std::dynamic_pointer_cast<GsButton>(
mpGameStoreDialog->addControl( new GsButton( "Cancel", new CancelDownloadEvent() ), GsRect<float>(0.400f, 0.865f, 0.2f, 0.07f) ) );
mpDloadCancel->enable(false);
mpDloadDownload = std::dynamic_pointer_cast<GsButton>(
mpGameStoreDialog->addControl( new GsButton( "Download", new GameStorePullGame() ), GsRect<float>(0.635f, 0.865f, 0.3f, 0.07f) ) );
mpGameStoreDialog->addControl( new GsButton( "Download", new GameStorePullGame() ), GsRect<float>(0.735f, 0.865f, 0.2f, 0.07f) ) );
mGameCatalogue = gameDownloader.getGameCatalogue();
......
......@@ -30,6 +30,7 @@ struct myprogress {
};
int *progressPtr;
bool *pCancelDownload;
int gDlto, gDlfrom;
......@@ -38,6 +39,9 @@ static int xferinfo(void *p,
curl_off_t dltotal, curl_off_t dlnow,
curl_off_t ultotal, curl_off_t ulnow)
{
if(*pCancelDownload)
return 2;
struct myprogress *myp = (struct myprogress *)p;
CURL *curl = myp->curl;
double curtime = 0;
......@@ -141,7 +145,7 @@ int downloadFile(const std::string &filename, int &progress,
res = curl_easy_perform(curl);
// TODO: Put into central log
if(res != CURLE_OK)
if(res != CURLE_OK)
fprintf(stderr, "%s\n", curl_easy_strerror(res));
/* always cleanup */
......@@ -247,6 +251,8 @@ int GameDownloader::handle()
{
int res = 0;
pCancelDownload = &mCancelDownload;
// Get the first path. We assume that one is writable
std::string searchPaths;
GetExactFileName(GetFirstSearchPath(), searchPaths);
......@@ -292,9 +298,16 @@ int GameDownloader::handle()
const std::string errStr = "Something went wrong with downloading \"" + gameFileName + "\"!";
gLogging.ftextOut(PURPLE, errStr.c_str() );
}
if(res != CURLE_OK)
{
remove(downloadGamePath.c_str());
}
}
mProgress = 1000;
return res;
......
......@@ -25,14 +25,18 @@ class GameDownloader : public Action
{
public:
GameDownloader(int &progress) :
mProgress(progress) {}
GameDownloader(int &progress,
bool &cancelDownload) :
mProgress(progress),
mCancelDownload(cancelDownload){}
GameDownloader(int &progress,
bool &cancelDownload,
const std::string &gameFileName,
const std::string &gameName) :
mProgress(progress),
mCancelDownload(cancelDownload),
mGameFileName(gameFileName),
mGameName(gameName) {}
......@@ -61,10 +65,12 @@ public:
private:
int &mProgress;
bool &mCancelDownload;
const std::string mGameFileName;
const std::string mGameName;
std::vector<GameCatalogueEntry> mGameCatalogue;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment