Commit cb754285 authored by gerstrong@gmail.com's avatar gerstrong@gmail.com

Catalogue downloader running in the background.

parent 999e1ce0
......@@ -35,7 +35,7 @@ string(REGEX REPLACE "[\r\n]" "" CG_VERSION "${CG_VERSION}")
# Since shell script get_version is not processed properly on windows, we have to define manually here.
# TODO: Better system for defining the version
IF(WIN32)
set(CG_VERSION "2.2.6")
set(CG_VERSION "2.2.7")
endif()
# Generate the README file with the correct version string
......
......@@ -7,8 +7,8 @@
*
*/
#ifndef __OLX__THREADPOOL_H__
#define __OLX__THREADPOOL_H__
#ifndef THREADPOOL_H__
#define THREADPOOL_H__
#include <set>
#include <string>
......@@ -90,5 +90,5 @@ struct _ThreadFuncWrapper {
_ThreadFuncWrapper<T>::Wrapper<&memberfunc>::startThread(this, name)
#endif
#endif // THREADPOOL_H__
v2.2.7:
-------
- Optimized Catalog Downloader. Now it downloads in the background
- Retry option added, when downloading catalogue fails or is not yet finished
v2.2.6:
-------
- Bug fixes
......
......@@ -75,7 +75,14 @@ m_start_level(start_level)
}
CGameLauncher::~CGameLauncher()
{}
{
if(mp_Thread)
{
int ret = 0;
threadPool->finalizeIfReady(mp_Thread, &ret);
mp_Thread = nullptr;
}
}
////
// Initialization Routine
......@@ -526,12 +533,13 @@ void CGameLauncher::showMessageBox(const std::string &text)
}
auto *pRetryButton = new GsButton("Retry", new GMSwitchToGameLauncher());
mpMsgDialog->addControl(pRetryButton, GsRect<float>(0.2f, 0.85f, 0.2f, 0.05f));
auto *pOkButton = new GsButton("Ok", new CloseBoxEvent());
mpMsgDialog->addControl(pOkButton, GsRect<float>(0.4f, 0.85f, 0.2f, 0.05f));
mpMsgDialog->addControl(pOkButton, GsRect<float>(0.6f, 0.85f, 0.2f, 0.05f));
pOkButton->select(true);
mpMsgDialog->setCurrentControl(pOkButton);
}
......
......@@ -68,7 +68,7 @@ public:
const int start_game_no = -1,
const int start_level = -1);
~CGameLauncher();
~CGameLauncher() override;
typedef std::vector<std::string> DirList;
......@@ -186,7 +186,7 @@ private:
int mDownloadProgress = 0;
bool mCancelDownload = false;
ThreadPoolItem* mpGameDownloader;
ThreadPoolItem* mpGameDownloadThread = nullptr;
bool scanSubDirectories(const std::string& path,
const size_t maxdepth,
......@@ -200,6 +200,11 @@ private:
void getLabels();
std::string scanLabels(const std::string& path);
void putLabels();
int m_DownloadProgress = 0;
bool m_DownloadCancel = false;
ThreadPoolItem *mp_Thread = nullptr;
};
......
......@@ -3,6 +3,7 @@
#include <widgets/GsButton.h>
#include <base/GsApp.h>
#include <base/utils/FindFile.h>
#include <base/utils/ThreadPool.h>
#include <sstream>
......@@ -15,37 +16,35 @@
// If he has all the games, the button won't be shown.
void CGameLauncher::verifyGameStore()
{
int progress = 0;
bool cancel = false;
GameDownloader gameDownloader(progress, cancel);
m_DownloadProgress = 0;
m_DownloadCancel = false;
GameDownloader *pGameDownloader;
pGameDownloader = new GameDownloader(m_DownloadProgress, m_DownloadCancel);
std::vector< std::string > missingList;
// Try to download the catalogue file
gameDownloader.downloadCatalogue();
// First try
pGameDownloader->checkForMissingGames( missingList );
// First try
gameDownloader.checkForMissingGames( missingList );
if(!gameDownloader.hasCatalog())
if(!pGameDownloader->hasCatalog())
{
std::stringstream ss;
const auto cataFile = gameDownloader.catalogFName();
const auto cataFile = pGameDownloader->catalogFName();
const auto searchPath = GetFirstSearchPath();
ss << "You seem not to have a game catalog.\n";
ss << "The file is called " << "\"" << cataFile << "\" \n";
ss << "You might want to download \n";
ss << "and copy one into:\n";
ss << "I can try to download it or \n";
ss << "you copy one into:\n";
ss << "\"" << searchPath << "\".\n";
ss << "\"+ More\" button is disabled...\n";
ss << "For now \"+ More\" button is disabled...\n";
std::string msg(ss.str());
showMessageBox(msg);
showMessageBox(msg);
}
......@@ -54,14 +53,30 @@ void CGameLauncher::verifyGameStore()
GsButton *downloadBtn = new GsButton( "+ More", new GMDownloadDlgOpen() );
mLauncherDialog.addControl( downloadBtn, GsRect<float>(0.125f, 0.865f, 0.25f, 0.07f) );
}
/*else
{
GsButton *cataLogBtn = new GsButton( "Catalogue", new GMDownloadDlgOpen() );
mLauncherDialog.addControl( cataLogBtn, GsRect<float>(0.125f, 0.865f, 0.25f, 0.07f) );
}*/
mGameCatalogue = pGameDownloader->getGameCatalogue();
mGameCatalogue = gameDownloader.getGameCatalogue();
// Try to download the catalogue file, in the background
if(!mp_Thread)
{
pGameDownloader->setupDownloadCatalogue(true);
mp_Thread = threadPool->start(pGameDownloader, "Loading catalogue file in the background");
}
else
{
if(mp_Thread)
{
int ret;
if(threadPool->finalizeIfReady(mp_Thread, &ret))
{
mp_Thread = nullptr;
}
}
else
{
delete pGameDownloader;
}
}
}
......@@ -84,7 +99,7 @@ void CGameLauncher::pullGame(const int selection)
mpDloadProgressCtrl->enableFancyAnimation(true);
mpGameDownloader = threadPool->start(new GameDownloader(mDownloadProgress,
mpGameDownloadThread = threadPool->start(new GameDownloader(mDownloadProgress,
mCancelDownload,
gameFileName,
gameName),
......@@ -125,7 +140,7 @@ void CGameLauncher::ponderDownloadDialog()
// When everything is done, The launcher should be restarted, for searching new games.
if( mFinishedDownload &&
mpGameDownloader->finished &&
mpGameDownloadThread->finished &&
mpDloadProgressCtrl->finished() )
{
mpGameStoreDialog = nullptr;
......
......@@ -423,6 +423,12 @@ int GameDownloader::handle()
pCancelDownload = &mCancelDownload;
if(mDownloadCatalogue)
{
downloadCatalogue();
return res;
}
// Get the first path. We assume that one is writable
std::string searchPaths;
GetExactFileName(GetFirstSearchPath(), searchPaths);
......@@ -492,11 +498,8 @@ int GameDownloader::handle()
{
remove(downloadGamePath.c_str());
}
}
mProgress = 1000;
return res;
......
......@@ -97,11 +97,17 @@ public:
std::string catalogFName() const
{ return mCatalogFName; }
void setupDownloadCatalogue(const bool value)
{
mDownloadCatalogue = value;
}
private:
int &mProgress;
bool &mCancelDownload;
bool mCataFound = false;
bool mDownloadCatalogue = false;
const std::string mGameFileName;
const std::string mGameName;
......
#ifndef CG_VERSION_H
#define CG_VERSION_H
#define CGVERSION "2.2.6-Release"
#define CGVERSIONCODE 226000
#define CGVERSION "2.2.7-Release"
#define CGVERSIONCODE 227000
#endif
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