Commit c69e9fa6 authored by Gerhard Stein's avatar Gerhard Stein

Downloader improvements

parent c1f3198e
......@@ -342,7 +342,7 @@ public:
DIR* handle = opendir(abs_path.c_str());
if(!handle) return ret;
while((entry = readdir(handle)) != 0) {
//If file is not self-directory or parent-directory
//If file is nkaution vom mieterot self-directory or parent-directory
if(entry->d_name[0] != '.' || (entry->d_name[1] != '\0' && (entry->d_name[1] != '.' || entry->d_name[2] != '\0'))) {
filename = abs_path + "/" + entry->d_name;
if(stat(filename.c_str(), &s) == 0)
......
......@@ -101,6 +101,9 @@ void GsButton::drawNoStyle(SDL_Rect& lRect)
if(mEnabled)
{
auto lightRatio = mLightRatio;
if( mPressed || mSelected )
{
// Try to highlight the border color a bit more by determing which one dominates the most
......@@ -115,15 +118,21 @@ void GsButton::drawNoStyle(SDL_Rect& lRect)
else if(blue > green && blue > red )
blue <<= 1;
if(mPressed)
{
red <<= 1;
blue >>= 1;
lightRatio <<= 1;
}
// If want to highlight the button set the color
borderColor = blitsfc.mapRGBA( red, green, blue, 0xFF);
lComp = 0xFF - (mLightRatio*(0xFF-0xCF)/255);
lComp = 0xFF - (lightRatio*(0xFF-0xCF)/255);
}
else
{
lComp = 0xFF - (mLightRatio*(0xFF-0xDF)/255);
lComp = 0xFF - (lightRatio*(0xFF-0xDF)/255);
}
}
else
......
......@@ -14,8 +14,6 @@
#include <string>
#include <memory>
#include <map>
//#include <engine/CEvent.h>
//#include <common/CBehaviorEngine.h>
#include <graphics/GsSurface.h>
......
......@@ -13,6 +13,7 @@
#include <base/InputEvents.h>
#include <base/utils/Geometry.h>
class CGUIControl
{
public:
......@@ -68,7 +69,9 @@ public:
void setDown( const bool value )
{ mHovered = value; }
{
mHovered = value;
}
virtual bool sendEvent(const InputCommands command) { return false; }
......@@ -98,6 +101,14 @@ protected:
static int mTwirliconID;
/**
* @brief mHoverTriggers This is for touch friendly devices were there is no device
*/
#ifdef ANDROID
static const bool mHoverTriggers = true;
#else
static const bool mHoverTriggers = false;
#endif
};
......
......@@ -146,17 +146,29 @@ void CGUITextSelectionList::processLogic()
if( mousePos.x > x_innerbound_min && mousePos.y > y_innerbound_min)
{
if(mHovered)
if(mHoverTriggers)
{
mHoverSelection = newselection;
if(mHovered)
{
mHoverSelection = newselection;
mPressedSelection = newselection;
mReleasedSelection = newselection;
}
}
if(mPressed)
else
{
mPressedSelection = newselection;
}
if(mReleased)
{
mReleasedSelection = newselection;
if(mHovered)
{
mHoverSelection = newselection;
}
if(mPressed)
{
mPressedSelection = newselection;
}
if(mReleased)
{
mReleasedSelection = newselection;
}
}
}
}
......
......@@ -23,8 +23,8 @@ const curl_off_t STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES = 1024 * 1024 * 1024;
#define MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL 3
struct myprogress {
double lastruntime;
CURL *curl;
double lastruntime;
CURL *curl;
};
int *progressPtr;
......@@ -38,33 +38,35 @@ static int xferinfo(void *p,
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;
struct myprogress *myp = (struct myprogress *)p;
CURL *curl = myp->curl;
double curtime = 0;
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime);
curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &curtime);
/* under certain circumstances it may be desirable for certain functionality
/* under certain circumstances it may be desirable for certain functionality
to only run every N seconds, in order to do this the transaction time can
be used */
if((curtime - myp->lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL)
{
myp->lastruntime = curtime;
}
if(dltotal > 0)
{
const int newProgress = gDlfrom + ((gDlto-gDlfrom)*dlnow)/dltotal;
*progressPtr = newProgress;
}
if(dlnow > STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES)
{
return 1;
}
return 0;
if((curtime - myp->lastruntime) >= MINIMAL_PROGRESS_FUNCTIONALITY_INTERVAL)
{
myp->lastruntime = curtime;
}
if(dltotal > 0)
{
const int newProgress = gDlfrom + ((gDlto-gDlfrom)*dlnow)/dltotal;
*progressPtr = newProgress;
}
if(dlnow > STOP_DOWNLOAD_AFTER_THIS_MANY_BYTES)
{
return 1;
}
return 0;
}
/* for libcurl older than 7.32.0 (CURLOPT_PROGRESSFUNCTION) */
......@@ -142,9 +144,11 @@ int downloadFile(const std::string &filename, int &progress,
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
res = curl_easy_perform(curl);
// TODO: Put into central log
// output any error to the central CG Log
if(res != CURLE_OK)
fprintf(stderr, "%s\n", curl_easy_strerror(res));
{
gLogging.textOut(RED,"%s<br>", curl_easy_strerror(res));
}
/* always cleanup */
curl_easy_cleanup(curl);
......@@ -173,7 +177,7 @@ bool GameDownloader::loadCatalogue(const std::string &catalogueFile)
for( auto &gameNode : pt.get_child("Catalogue") )
{
// No comments ...
// Filter the comments ...
if(gameNode.first == "<xmlcomment>")
continue;
......@@ -331,15 +335,25 @@ int GameDownloader::handle()
// TODO: Now the downloaded stuff must be extracted to the games directory
// At this point the file should be available
const std::string destDir = JoinPaths(gamesPath,gameName);
const std::string destDir = JoinPaths(gamesPath, gameName);
if( IsFileAvailable(downloadGamePath) )
{
// Create subdirectory
CreateRecDir( destDir );
unzipFile(downloadGamePath.c_str(), destDir.c_str());
const int retVal = unzipFile(downloadGamePath.c_str(), destDir.c_str());
const std::string brokenPath = downloadGamePath + "_broken";
// TODO: if unpacking files fails, we should delete it.
// If unpacking files fails, we should delete it.
if(retVal != 0)
{
Rename(downloadGamePath, brokenPath);
}
else
{
gLogging.ftextOut( GREEN, "File \"%s\" extracted succesfully.\n<br>", downloadGamePath.c_str() );
}
}
else
{
......
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