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