Merge branch 'github_downloader'
This commit is contained in:
128
JGE/include/Downloader.h
Normal file
128
JGE/include/Downloader.h
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
#ifndef DOWNLOADER_H
|
||||||
|
#define DOWNLOADER_H
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// This class handles download of remote resources (any kind of file)
|
||||||
|
// All the resources are stored locally in the userPath
|
||||||
|
// For every resources, the downloader verifies if the resource was modifed
|
||||||
|
// on the server before downloading the update. The Downloader maintains a catalogue
|
||||||
|
// of resource downloaded to be able to check if they need to be updated.
|
||||||
|
//
|
||||||
|
// The interface can be used completly synchronously by the application and some
|
||||||
|
// context or message loop is needed in the implementation of this interface
|
||||||
|
//
|
||||||
|
// Note that the Downloader could in theory by implemented on top of JNetwork.
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------------------
|
||||||
|
#include <string>
|
||||||
|
#include <ostream>
|
||||||
|
#include <istream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <map>
|
||||||
|
#include "Threading.h"
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
#include <QObject>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class DownloadRequest
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
: public QObject
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
#endif
|
||||||
|
void fileDownloaded();
|
||||||
|
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
|
||||||
|
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
signals:
|
||||||
|
void percentChanged(int percent);
|
||||||
|
void statusChanged(int);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef enum {
|
||||||
|
NOT_PRESENT,
|
||||||
|
DOWNLOADING,
|
||||||
|
DOWNLOADED,
|
||||||
|
DOWNLOAD_ERROR
|
||||||
|
} DownloadStatus;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
string mLocalPath;
|
||||||
|
string mRemoteResourceURL;
|
||||||
|
// previous one is the original, next one can change after redirection
|
||||||
|
string mRequestedRemoteResourceURL;
|
||||||
|
string mETag;
|
||||||
|
DownloadStatus mDownloadStatus;
|
||||||
|
bool mUpgradeAvailable;
|
||||||
|
size_t mTotalSize;
|
||||||
|
size_t mCurrentSize;
|
||||||
|
ofstream mFile;
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
QNetworkReply* mNetworkReply;
|
||||||
|
static QNetworkAccessManager networkAccessManager;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
DownloadRequest(string localPath="",
|
||||||
|
string remoteResourceURL="",
|
||||||
|
string ETag = "",
|
||||||
|
DownloadStatus downloadStatus=NOT_PRESENT,
|
||||||
|
size_t totalSize = 0,
|
||||||
|
size_t currentSize = 0);
|
||||||
|
~DownloadRequest();
|
||||||
|
static bool NetworkIsAccessible();
|
||||||
|
|
||||||
|
string getTempLocalPath() const { return (mLocalPath+".tmp"); };
|
||||||
|
string getLocalPath() const { return mLocalPath; };
|
||||||
|
string getRemoteResource() const { return mRemoteResourceURL; };
|
||||||
|
string getETag() const { return mETag; };
|
||||||
|
void startGet();
|
||||||
|
void startHead();
|
||||||
|
DownloadStatus getDownloadStatus() const { return mDownloadStatus; };
|
||||||
|
bool upgradeAvailable() const { return mUpgradeAvailable; };
|
||||||
|
void getSizes(size_t& totalSize, size_t¤tSize) {
|
||||||
|
totalSize = mTotalSize;
|
||||||
|
currentSize = mCurrentSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
friend ostream& operator<<(ostream& out, const DownloadRequest& d);
|
||||||
|
friend istream& operator>>(istream&, DownloadRequest&);
|
||||||
|
friend class Downloader;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class Downloader
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
Downloader(string globalRemoteURL="", string localCacheRecords="");
|
||||||
|
virtual ~Downloader();
|
||||||
|
static Downloader* mInstance;
|
||||||
|
string mGlobalRemoteURL;
|
||||||
|
string mLocalCacheRecords;
|
||||||
|
boost::mutex mMutex;
|
||||||
|
map<string, DownloadRequest*> mRequestMap;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static Downloader* GetInstance();
|
||||||
|
static void Release();
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
DownloadRequest* Get(string localPath, string remoteResourceURL="");
|
||||||
|
|
||||||
|
friend ostream& operator<<(ostream& out, const Downloader& d);
|
||||||
|
friend istream& operator>>(istream&, Downloader&);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DOWNLOADER_H
|
||||||
@@ -128,6 +128,7 @@ public:
|
|||||||
bool readIntoString(const string & FilePath, string & target);
|
bool readIntoString(const string & FilePath, string & target);
|
||||||
bool openForWrite(ofstream & File, const string & FilePath, ios_base::openmode mode = ios_base::out );
|
bool openForWrite(ofstream & File, const string & FilePath, ios_base::openmode mode = ios_base::out );
|
||||||
bool Rename(string from, string to);
|
bool Rename(string from, string to);
|
||||||
|
bool Remove(string aFile);
|
||||||
|
|
||||||
//Returns true if strFilename exists somewhere in the fileSystem
|
//Returns true if strFilename exists somewhere in the fileSystem
|
||||||
bool FileExists(const string& strFilename);
|
bool FileExists(const string& strFilename);
|
||||||
@@ -163,4 +164,4 @@ protected:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
298
JGE/src/Downloader.cpp
Normal file
298
JGE/src/Downloader.cpp
Normal file
@@ -0,0 +1,298 @@
|
|||||||
|
#include "DebugRoutines.h"
|
||||||
|
#include "JFileSystem.h"
|
||||||
|
#include "Downloader.h"
|
||||||
|
|
||||||
|
#define RECORDS_DEFAULT_FILE "cache/records.txt"
|
||||||
|
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
QNetworkAccessManager DownloadRequest::networkAccessManager;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DownloadRequest::DownloadRequest(string localPath,
|
||||||
|
string remoteResourceURL,
|
||||||
|
string ETag,
|
||||||
|
DownloadStatus downloadStatus,
|
||||||
|
size_t totalSize,
|
||||||
|
size_t currentSize):
|
||||||
|
mLocalPath(localPath),
|
||||||
|
mRemoteResourceURL(remoteResourceURL),
|
||||||
|
mRequestedRemoteResourceURL(remoteResourceURL),
|
||||||
|
mETag(ETag),
|
||||||
|
mDownloadStatus(downloadStatus),
|
||||||
|
mUpgradeAvailable(false),
|
||||||
|
mTotalSize(totalSize),
|
||||||
|
mCurrentSize(currentSize)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadRequest::~DownloadRequest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadRequest::startHead()
|
||||||
|
{
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
QNetworkRequest request(QUrl(QString(mRequestedRemoteResourceURL.c_str())));
|
||||||
|
request.setRawHeader("If-None-Match", mETag.c_str());
|
||||||
|
mNetworkReply = networkAccessManager.head(request);
|
||||||
|
connect(mNetworkReply, SIGNAL(finished()), SLOT(fileDownloaded()));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadRequest::startGet()
|
||||||
|
{
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
mNetworkReply = networkAccessManager.get(QNetworkRequest(QUrl(QString(mRequestedRemoteResourceURL.c_str()))));
|
||||||
|
#endif
|
||||||
|
mFile.close();
|
||||||
|
JFileSystem::GetInstance()->Remove(getTempLocalPath());
|
||||||
|
JFileSystem::GetInstance()->openForWrite(mFile, getTempLocalPath());
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
connect(mNetworkReply, SIGNAL(downloadProgress(qint64, qint64)),
|
||||||
|
SLOT(downloadProgress(qint64, qint64)));
|
||||||
|
connect(mNetworkReply, SIGNAL(finished()), SLOT(fileDownloaded()));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadRequest::fileDownloaded()
|
||||||
|
{
|
||||||
|
do {
|
||||||
|
QByteArray eTagByteArray = mNetworkReply->rawHeader("ETag");
|
||||||
|
if(!eTagByteArray.isEmpty()) {
|
||||||
|
string oldETag = mETag;
|
||||||
|
mETag = QString(eTagByteArray).toStdString();
|
||||||
|
if(oldETag!="" && oldETag != mETag)
|
||||||
|
mUpgradeAvailable = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// let's check some error
|
||||||
|
if(mNetworkReply->error() != QNetworkReply::NoError) {
|
||||||
|
DebugTrace(mNetworkReply->errorString().toStdString());
|
||||||
|
mDownloadStatus = DownloadRequest::DOWNLOAD_ERROR;
|
||||||
|
mFile.close();
|
||||||
|
JFileSystem::GetInstance()->Remove(getTempLocalPath());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if we're getting redirected
|
||||||
|
QVariant redirectionTarget = mNetworkReply->attribute(QNetworkRequest::RedirectionTargetAttribute);
|
||||||
|
if (!redirectionTarget.isNull()) {
|
||||||
|
QUrl newUrl = QUrl(mRequestedRemoteResourceURL.c_str()).resolved(redirectionTarget.toUrl());
|
||||||
|
DebugTrace(string("Redirect to ")+ newUrl.toString().toStdString());
|
||||||
|
|
||||||
|
mRequestedRemoteResourceURL = newUrl.toString().toStdString();
|
||||||
|
mNetworkReply->deleteLater();
|
||||||
|
if(mFile.is_open())
|
||||||
|
startGet();
|
||||||
|
else
|
||||||
|
startHead();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mFile.is_open())
|
||||||
|
{
|
||||||
|
QByteArray byteArray = mNetworkReply->readAll();
|
||||||
|
mFile.write(byteArray.constData(), byteArray.size());
|
||||||
|
mFile.close();
|
||||||
|
if(!JFileSystem::GetInstance()->Rename(getTempLocalPath(), mLocalPath)) {
|
||||||
|
mDownloadStatus = DownloadRequest::DOWNLOAD_ERROR;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mDownloadStatus = DownloadRequest::DOWNLOADED;
|
||||||
|
} while(0);
|
||||||
|
|
||||||
|
Downloader::GetInstance()->Update();
|
||||||
|
mNetworkReply->deleteLater();
|
||||||
|
|
||||||
|
emit statusChanged((int)mDownloadStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DownloadRequest::downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
|
||||||
|
{
|
||||||
|
QByteArray byteArray = mNetworkReply->readAll();
|
||||||
|
mFile.write(byteArray.constData(), byteArray.size());
|
||||||
|
mCurrentSize = bytesReceived;
|
||||||
|
mTotalSize = bytesTotal;
|
||||||
|
int percent = 0;
|
||||||
|
if(bytesTotal)
|
||||||
|
percent = (bytesReceived/bytesTotal)*100;
|
||||||
|
emit percentChanged(percent);
|
||||||
|
}
|
||||||
|
|
||||||
|
Downloader* Downloader::mInstance = 0;
|
||||||
|
|
||||||
|
Downloader::Downloader(string globalRemoteURL, string localcacheRecords):
|
||||||
|
mGlobalRemoteURL(globalRemoteURL),
|
||||||
|
mLocalCacheRecords(localcacheRecords)
|
||||||
|
{
|
||||||
|
JFileSystem::GetInstance()->MakeDir("cache");
|
||||||
|
|
||||||
|
izfstream downloadRecords;
|
||||||
|
if(mLocalCacheRecords.empty())
|
||||||
|
mLocalCacheRecords = RECORDS_DEFAULT_FILE;
|
||||||
|
if(JFileSystem::GetInstance()->openForRead(downloadRecords, mLocalCacheRecords))
|
||||||
|
{// File exists, let's read it.
|
||||||
|
downloadRecords >> (*this);
|
||||||
|
}
|
||||||
|
JFileSystem::GetInstance()->CloseFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
Downloader::~Downloader()
|
||||||
|
{
|
||||||
|
map<string, DownloadRequest*>::iterator ite;
|
||||||
|
for(ite = mRequestMap.begin(); ite != mRequestMap.end(); ite++)
|
||||||
|
{
|
||||||
|
delete (*ite).second;
|
||||||
|
}
|
||||||
|
mRequestMap.erase(mRequestMap.begin(), mRequestMap.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
Downloader* Downloader::GetInstance()
|
||||||
|
{
|
||||||
|
if(!mInstance)
|
||||||
|
{
|
||||||
|
mInstance = new Downloader();
|
||||||
|
}
|
||||||
|
return mInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Downloader::Release()
|
||||||
|
{
|
||||||
|
if(mInstance)
|
||||||
|
{
|
||||||
|
delete mInstance;
|
||||||
|
mInstance = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DownloadRequest::NetworkIsAccessible()
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
#ifdef QT_CONFIG
|
||||||
|
networkAccessManager.setNetworkAccessible(QNetworkAccessManager::Accessible);
|
||||||
|
result = networkAccessManager.networkAccessible();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
DownloadRequest* Downloader::Get(string localPath, string remoteResourceURL)
|
||||||
|
{
|
||||||
|
map<string, DownloadRequest*>::iterator ite = mRequestMap.find(localPath);
|
||||||
|
if(ite == mRequestMap.end())
|
||||||
|
{ // request does not exist, let's create it
|
||||||
|
DownloadRequest* request = new DownloadRequest(localPath, remoteResourceURL);
|
||||||
|
std::pair<std::map<string,DownloadRequest*>::iterator,bool> ret;
|
||||||
|
ret = mRequestMap.insert ( std::pair<string,DownloadRequest*>(localPath, request) );
|
||||||
|
if (ret.second==false) {
|
||||||
|
DebugTrace("Downloader::Get Error inserting request in Map");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
ite = ret.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now, we can check the server
|
||||||
|
if((*ite).second->getDownloadStatus() == DownloadRequest::NOT_PRESENT ||
|
||||||
|
(*ite).second->upgradeAvailable())
|
||||||
|
{ // File is not here or an update is available, let's get it
|
||||||
|
(*ite).second->startGet();
|
||||||
|
(*ite).second->mDownloadStatus = DownloadRequest::DOWNLOADING;
|
||||||
|
}
|
||||||
|
else if ((*ite).second->getDownloadStatus() == DownloadRequest::DOWNLOADED)
|
||||||
|
{ // File is here, let's check if there is some update without blocking the playback
|
||||||
|
(*ite).second->startHead();
|
||||||
|
}
|
||||||
|
|
||||||
|
return (*ite).second;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Downloader::Update()
|
||||||
|
{
|
||||||
|
ofstream downloadRecords;
|
||||||
|
if(JFileSystem::GetInstance()->openForWrite(downloadRecords, mLocalCacheRecords))
|
||||||
|
{
|
||||||
|
downloadRecords << (*this);
|
||||||
|
}
|
||||||
|
downloadRecords.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, const DownloadRequest& d)
|
||||||
|
{
|
||||||
|
// HEAD request fails, so this line erase cache record after upgrade check :(
|
||||||
|
// if(d.getDownloadStatus() == DownloadRequest::DOWNLOADED)
|
||||||
|
{
|
||||||
|
out << "localPath=" << d.mLocalPath << endl;
|
||||||
|
out << "remoteResource=" << d.mRemoteResourceURL << endl;
|
||||||
|
out << "ETag=" << d.mETag << endl;
|
||||||
|
out << "upgradeAvailable=" << d.mUpgradeAvailable <<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
istream& operator>>(istream& in, DownloadRequest& d)
|
||||||
|
{
|
||||||
|
string s;
|
||||||
|
|
||||||
|
while(std::getline(in, s))
|
||||||
|
{
|
||||||
|
size_t limiter = s.find("=");
|
||||||
|
string areaS;
|
||||||
|
if (limiter != string::npos)
|
||||||
|
{
|
||||||
|
areaS = s.substr(0, limiter);
|
||||||
|
if (areaS.compare("localPath") == 0)
|
||||||
|
{
|
||||||
|
d.mLocalPath = s.substr(limiter + 1);
|
||||||
|
}
|
||||||
|
else if (areaS.compare("remoteResource") == 0)
|
||||||
|
{
|
||||||
|
d.mRemoteResourceURL = s.substr(limiter + 1);
|
||||||
|
d.mRequestedRemoteResourceURL = d.mRemoteResourceURL;
|
||||||
|
}
|
||||||
|
else if (areaS.compare("ETag") == 0)
|
||||||
|
{
|
||||||
|
d.mETag = s.substr(limiter + 1);
|
||||||
|
d.mDownloadStatus = DownloadRequest::DOWNLOADED;
|
||||||
|
}
|
||||||
|
else if (areaS.compare("upgradeAvailable") == 0)
|
||||||
|
{
|
||||||
|
d.mUpgradeAvailable = (bool)atoi(s.substr(limiter + 1).c_str());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
|
ostream& operator<<(ostream& out, const Downloader& d)
|
||||||
|
{
|
||||||
|
map<string, DownloadRequest*>::const_iterator ite;
|
||||||
|
for(ite = d.mRequestMap.begin(); ite != d.mRequestMap.end(); ite++)
|
||||||
|
{
|
||||||
|
out << (*(*ite).second) << endl;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
istream& operator>>(istream& in, Downloader& d)
|
||||||
|
{
|
||||||
|
while(!in.eof())
|
||||||
|
{
|
||||||
|
DownloadRequest* downloadRequest = new DownloadRequest();
|
||||||
|
in >> (*downloadRequest);
|
||||||
|
|
||||||
|
if(!downloadRequest->getLocalPath().empty() &&
|
||||||
|
!downloadRequest->getRemoteResource().empty() &&
|
||||||
|
!downloadRequest->getETag().empty()) {
|
||||||
|
d.mRequestMap[downloadRequest->getLocalPath()] = downloadRequest;
|
||||||
|
} else {
|
||||||
|
delete downloadRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return in;
|
||||||
|
}
|
||||||
|
|
||||||
@@ -557,7 +557,13 @@ bool JFileSystem::Rename(string _from, string _to)
|
|||||||
string from = mUserFSPath + _from;
|
string from = mUserFSPath + _from;
|
||||||
string to = mUserFSPath + _to;
|
string to = mUserFSPath + _to;
|
||||||
std::remove(to.c_str());
|
std::remove(to.c_str());
|
||||||
return rename(from.c_str(), to.c_str()) ? true: false;
|
return (rename(from.c_str(), to.c_str()) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JFileSystem::Remove(string aFile)
|
||||||
|
{
|
||||||
|
string toRemove = mUserFSPath + aFile;
|
||||||
|
return (std::remove(toRemove.c_str()) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int JFileSystem::GetFileSize(izfstream & file)
|
int JFileSystem::GetFileSize(izfstream & file)
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
#include <QtDeclarative>
|
#include <QtDeclarative>
|
||||||
#include "qmlapplicationviewer.h"
|
#include "qmlapplicationviewer.h"
|
||||||
#endif //QT_WIDGET
|
#endif //QT_WIDGET
|
||||||
#include "filedownloader.h"
|
#include "Downloader.h"
|
||||||
#include "GameApp.h"
|
#include "GameApp.h"
|
||||||
#include "corewrapper.h"
|
#include "corewrapper.h"
|
||||||
|
|
||||||
QWidget* g_glwidget = NULL;
|
WagicCore* g_glwidget = NULL;
|
||||||
|
|
||||||
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
static const struct { LocalKeySym keysym; JButton keycode; } gDefaultBindings[] =
|
||||||
{
|
{
|
||||||
@@ -69,18 +69,25 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
#endif //QT_WIDGET
|
#endif //QT_WIDGET
|
||||||
|
|
||||||
if(argc >= 2 && string(argv[1]) == "testsuite")
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
result += WagicCore::runTestSuite();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
app->setApplicationName(WagicCore::getApplicationName());
|
app->setApplicationName(WagicCore::getApplicationName());
|
||||||
FileDownloader fileDownloader(USERDIR, WAGIC_RESOURCE_NAME);
|
DownloadRequest* downloadRequest = NULL;
|
||||||
|
#ifdef WAGIC_RESOURCE_URL
|
||||||
|
Downloader*downloader = Downloader::GetInstance();
|
||||||
|
downloadRequest = downloader->Get(
|
||||||
|
"core.zip",
|
||||||
|
WAGIC_RESOURCE_URL
|
||||||
|
);
|
||||||
|
#endif
|
||||||
#ifdef QT_WIDGET
|
#ifdef QT_WIDGET
|
||||||
g_glwidget = new WagicCore();
|
g_glwidget = new WagicCore();
|
||||||
g_glwidget->connect(&fileDownloader, SIGNAL(finished(int)), SLOT(start(int)));
|
if(!downloadRequest || downloadRequest->getDownloadStatus() == DownloadRequest::DOWNLOADED)
|
||||||
|
{
|
||||||
|
g_glwidget->start(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g_glwidget->connect(downloadRequest, SIGNAL(statusChanged(int)), SLOT(start(int)));
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
qmlRegisterType<WagicCore>("CustomComponents", 1, 0, "WagicCore");
|
qmlRegisterType<WagicCore>("CustomComponents", 1, 0, "WagicCore");
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,20 @@ extern "C" void Java_org_libsdl_app_SDLActivity_nativeResume(
|
|||||||
{
|
{
|
||||||
if (!g_engine)
|
if (!g_engine)
|
||||||
return;
|
return;
|
||||||
g_engine->Resume();
|
g_engine->Resume();
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "Wagic_Version.h"
|
||||||
|
extern "C" jstring Java_org_libsdl_app_SDLActivity_getResourceName(
|
||||||
|
JNIEnv* env, jclass cls)
|
||||||
|
{
|
||||||
|
return env->NewStringUTF (WAGIC_RESOURCE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" jstring Java_org_libsdl_app_SDLActivity_getResourceUrl(
|
||||||
|
JNIEnv* env, jclass cls)
|
||||||
|
{
|
||||||
|
return env->NewStringUTF (WAGIC_RESOURCE_URL);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,6 @@ public class SDLActivity extends Activity implements OnKeyListener
|
|||||||
public Boolean mErrorHappened = false;
|
public Boolean mErrorHappened = false;
|
||||||
public final static String RES_FOLDER = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/";
|
public final static String RES_FOLDER = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/";
|
||||||
public static String RES_FILENAME = "core_0184.zip";
|
public static String RES_FILENAME = "core_0184.zip";
|
||||||
public static final String RES_URL = "http://wagic.googlecode.com/files/";
|
|
||||||
|
|
||||||
public String systemFolder = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/";
|
public String systemFolder = Environment.getExternalStorageDirectory().getPath() + "/Wagic/Res/";
|
||||||
private String userFolder;
|
private String userFolder;
|
||||||
@@ -307,7 +306,7 @@ public class SDLActivity extends Activity implements OnKeyListener
|
|||||||
|
|
||||||
private void startDownload()
|
private void startDownload()
|
||||||
{
|
{
|
||||||
String url = RES_URL + RES_FILENAME;
|
String url = getResourceUrl();
|
||||||
if (!checkStorageState())
|
if (!checkStorageState())
|
||||||
{
|
{
|
||||||
Log.e(TAG, "Error in initializing storage space.");
|
Log.e(TAG, "Error in initializing storage space.");
|
||||||
@@ -437,7 +436,7 @@ public class SDLActivity extends Activity implements OnKeyListener
|
|||||||
mContext = this.getApplicationContext();
|
mContext = this.getApplicationContext();
|
||||||
// get the current version of the app to set the core filename
|
// get the current version of the app to set the core filename
|
||||||
String versionCodeString = getApplicationCode();
|
String versionCodeString = getApplicationCode();
|
||||||
RES_FILENAME = "core_" + versionCodeString + ".zip";
|
RES_FILENAME = getResourceName();
|
||||||
|
|
||||||
StorageOptions.determineStorageOptions();
|
StorageOptions.determineStorageOptions();
|
||||||
checkStorageLocationPreference();
|
checkStorageLocationPreference();
|
||||||
@@ -525,6 +524,9 @@ public class SDLActivity extends Activity implements OnKeyListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// C functions we call
|
// C functions we call
|
||||||
|
public static native String getResourceUrl();
|
||||||
|
public static native String getResourceName();
|
||||||
|
|
||||||
public static native void nativeInit();
|
public static native void nativeInit();
|
||||||
|
|
||||||
public static native void nativeQuit();
|
public static native void nativeQuit();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<property file="build.properties" />
|
<property file="build.properties" />
|
||||||
<property file="build.number.properties" />
|
<property file="build.number.properties" />
|
||||||
<property environment="env"/>
|
<property environment="env"/>
|
||||||
|
|
||||||
<path id="groovy.class.path" >
|
<path id="groovy.class.path" >
|
||||||
<fileset dir="${groovy.dir}" />
|
<fileset dir="${groovy.dir}" />
|
||||||
</path>
|
</path>
|
||||||
@@ -90,7 +90,8 @@ Author: Michael Nguyen
|
|||||||
#define WAGIC_RESOURCE_VERSION VERSION_FILE(WAGIC_VERSION_MAJOR, WAGIC_VERSION_MEDIUM, WAGIC_VERSION_MINOR)
|
#define WAGIC_RESOURCE_VERSION VERSION_FILE(WAGIC_VERSION_MAJOR, WAGIC_VERSION_MEDIUM, WAGIC_VERSION_MINOR)
|
||||||
#define WAGIC_VERSION_STRING VERSION_STRINGIFY(WAGIC_VERSION)
|
#define WAGIC_VERSION_STRING VERSION_STRINGIFY(WAGIC_VERSION)
|
||||||
#define WAGIC_CORE_VERSION_STRING "core_" VERSION_STRINGIFY(WAGIC_RESOURCE_VERSION)
|
#define WAGIC_CORE_VERSION_STRING "core_" VERSION_STRINGIFY(WAGIC_RESOURCE_VERSION)
|
||||||
#define WAGIC_RESOURCE_NAME WAGIC_CORE_VERSION_STRING ".zip"
|
#define WAGIC_RESOURCE_NAME "Wagic-core.zip"
|
||||||
|
#define WAGIC_RESOURCE_URL "https://github.com/WagicProject/wagic/releases/download/${env.RELEASE_NAME}/" WAGIC_RESOURCE_NAME
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -283,6 +283,7 @@ HEADERS += \
|
|||||||
|
|
||||||
# JGE, could probably be moved outside
|
# JGE, could probably be moved outside
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
../../JGE/src/Downloader.cpp\
|
||||||
../../JGE/src/Encoding.cpp\
|
../../JGE/src/Encoding.cpp\
|
||||||
../../JGE/src/JAnimator.cpp\
|
../../JGE/src/JAnimator.cpp\
|
||||||
../../JGE/src/JApp.cpp\
|
../../JGE/src/JApp.cpp\
|
||||||
@@ -320,6 +321,7 @@ SOURCES += \
|
|||||||
../../JGE/src/zipFS/zstream.cpp
|
../../JGE/src/zipFS/zstream.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
../../JGE/include/Downloader.h\
|
||||||
../../JGE/include/Threading.h\
|
../../JGE/include/Threading.h\
|
||||||
../../JGE/include/decoder_prx.h\
|
../../JGE/include/decoder_prx.h\
|
||||||
../../JGE/include/DebugRoutines.h\
|
../../JGE/include/DebugRoutines.h\
|
||||||
|
|||||||
@@ -5,6 +5,16 @@ echo PSPDEV = $PSPDEV
|
|||||||
echo psp-config = `psp-config --psp-prefix`
|
echo psp-config = `psp-config --psp-prefix`
|
||||||
echo ls = `ls`
|
echo ls = `ls`
|
||||||
echo pwd = `pwd`
|
echo pwd = `pwd`
|
||||||
|
# computing potential release name
|
||||||
|
if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
|
||||||
|
if [ "$TRAVIS_BRANCH" == "alphas" ]; then
|
||||||
|
RELEASE_NAME = "alpha-${TRAVIS_BUILD_NUMBER}"
|
||||||
|
else if [ "$TRAVIS_BRANCH" == "master" ]; then
|
||||||
|
RELEASE_NAME = "latest-master"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# updating versions with the TRAVIS build numbers
|
# updating versions with the TRAVIS build numbers
|
||||||
cd projects/mtg/
|
cd projects/mtg/
|
||||||
|
|||||||
@@ -10,28 +10,28 @@ if [ "$TRAVIS_BRANCH" == "alphas" ]; then
|
|||||||
-H "Accept: application/vnd.github.manifold-preview" \
|
-H "Accept: application/vnd.github.manifold-preview" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @core.zip \
|
--data-binary @core.zip \
|
||||||
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-core-${TRAVIS_BUILD_NUMBER}.zip"
|
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-core.zip"
|
||||||
|
|
||||||
echo -e "Uploading android package\n"
|
echo -e "Uploading android package\n"
|
||||||
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
||||||
-H "Accept: application/vnd.github.manifold-preview" \
|
-H "Accept: application/vnd.github.manifold-preview" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @projects/mtg/Android/bin/Wagic-debug.apk \
|
--data-binary @projects/mtg/Android/bin/Wagic-debug.apk \
|
||||||
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-android-${TRAVIS_BUILD_NUMBER}.apk"
|
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-android.apk"
|
||||||
|
|
||||||
echo -e "Uploading PSP package\n"
|
echo -e "Uploading PSP package\n"
|
||||||
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
||||||
-H "Accept: application/vnd.github.manifold-preview" \
|
-H "Accept: application/vnd.github.manifold-preview" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @projects/mtg/psprelease.zip \
|
--data-binary @projects/mtg/psprelease.zip \
|
||||||
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-psp-${TRAVIS_BUILD_NUMBER}.zip"
|
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-psp.zip"
|
||||||
|
|
||||||
echo -e "Uploading Windows package\n"
|
echo -e "Uploading Windows package\n"
|
||||||
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
||||||
-H "Accept: application/vnd.github.manifold-preview" \
|
-H "Accept: application/vnd.github.manifold-preview" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @build/win-cross/win-cross.zip \
|
--data-binary @build/win-cross/win-cross.zip \
|
||||||
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-windows-${TRAVIS_BUILD_NUMBER}.zip"
|
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-windows.zip"
|
||||||
|
|
||||||
echo -e "Done uploading\n"
|
echo -e "Done uploading\n"
|
||||||
fi
|
fi
|
||||||
@@ -71,28 +71,28 @@ if [ "$TRAVIS_BRANCH" == "master" ]; then
|
|||||||
-H "Accept: application/vnd.github.manifold-preview" \
|
-H "Accept: application/vnd.github.manifold-preview" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @core.zip \
|
--data-binary @core.zip \
|
||||||
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-core-${TRAVIS_BUILD_NUMBER}.zip"
|
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-core.zip"
|
||||||
|
|
||||||
echo -e "Uploading android package\n"
|
echo -e "Uploading android package\n"
|
||||||
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
||||||
-H "Accept: application/vnd.github.manifold-preview" \
|
-H "Accept: application/vnd.github.manifold-preview" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @projects/mtg/Android/bin/Wagic-debug.apk \
|
--data-binary @projects/mtg/Android/bin/Wagic-debug.apk \
|
||||||
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-android-${TRAVIS_BUILD_NUMBER}.apk"
|
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-android.apk"
|
||||||
|
|
||||||
echo -e "Uploading PSP package\n"
|
echo -e "Uploading PSP package\n"
|
||||||
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
||||||
-H "Accept: application/vnd.github.manifold-preview" \
|
-H "Accept: application/vnd.github.manifold-preview" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @projects/mtg/psprelease.zip \
|
--data-binary @projects/mtg/psprelease.zip \
|
||||||
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-psp-${TRAVIS_BUILD_NUMBER}.zip"
|
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-psp.zip"
|
||||||
|
|
||||||
echo -e "Uploading Windows package\n"
|
echo -e "Uploading Windows package\n"
|
||||||
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
curl -X POST -H "Authorization: token ${GH_TOKEN}" \
|
||||||
-H "Accept: application/vnd.github.manifold-preview" \
|
-H "Accept: application/vnd.github.manifold-preview" \
|
||||||
-H "Content-Type: application/zip" \
|
-H "Content-Type: application/zip" \
|
||||||
--data-binary @build/win-cross/win-cross.zip \
|
--data-binary @build/win-cross/win-cross.zip \
|
||||||
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-windows-${TRAVIS_BUILD_NUMBER}.zip"
|
"https://uploads.github.com/repos/WagicProject/wagic/releases/${IDDI}/assets?name=Wagic-windows.zip"
|
||||||
|
|
||||||
echo -e "Done uploading\n"
|
echo -e "Done uploading\n"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user