Download assets for 1.6 on application start (background task).
This commit is contained in:
parent
4f73091bb5
commit
0adf1828b0
@ -33,12 +33,12 @@ public:
|
||||
trimmedf.remove(0, base_length + 1);
|
||||
if(m_whitelist.contains(trimmedf))
|
||||
{
|
||||
//qDebug() << trimmedf << " gets to live";
|
||||
// qDebug() << trimmedf << " gets to live";
|
||||
}
|
||||
else
|
||||
{
|
||||
// DO NOT TOLERATE JUNK
|
||||
//qDebug() << trimmedf << " dies";
|
||||
// qDebug() << trimmedf << " dies";
|
||||
QFile f (filename);
|
||||
f.remove();
|
||||
}
|
||||
@ -74,15 +74,7 @@ private:
|
||||
ThreadedDeleter deleterThread;
|
||||
};
|
||||
|
||||
class Private
|
||||
{
|
||||
public:
|
||||
JobListQueue dl;
|
||||
JobListPtr index_job;
|
||||
JobListPtr files_job;
|
||||
};
|
||||
|
||||
OneSixAssets::OneSixAssets(QObject* parent):QObject(parent), d(new Private) {}
|
||||
|
||||
void OneSixAssets::fetchFinished()
|
||||
{
|
||||
@ -90,7 +82,7 @@ void OneSixAssets::fetchFinished()
|
||||
QString fprefix ( "assets/" );
|
||||
QStringList nuke_whitelist;
|
||||
|
||||
JobPtr firstJob = d->index_job->getFirstJob();
|
||||
JobPtr firstJob = index_job->getFirstJob();
|
||||
auto DlJob = firstJob.dynamicCast<DownloadJob>();
|
||||
QByteArray ba = DlJob->m_data;
|
||||
|
||||
@ -132,13 +124,26 @@ void OneSixAssets::fetchFinished()
|
||||
if ( sizeStr == "0" )
|
||||
continue;
|
||||
|
||||
QString filename = fprefix + keyStr;
|
||||
QFile check_file ( filename );
|
||||
QString client_etag = "nonsense";
|
||||
// if there already is a file and md5 checking is in effect and it can be opened
|
||||
if ( check_file.exists() && check_file.open ( QIODevice::ReadOnly ) )
|
||||
{
|
||||
// check the md5 against the expected one
|
||||
client_etag = QCryptographicHash::hash ( check_file.readAll(), QCryptographicHash::Md5 ).toHex().constData();
|
||||
check_file.close();
|
||||
}
|
||||
|
||||
QString trimmedEtag = etagStr.remove ( '"' );
|
||||
job->add ( DownloadJob::create ( QUrl ( prefix + keyStr ),fprefix + keyStr, trimmedEtag ) );
|
||||
nuke_whitelist.append ( keyStr );
|
||||
if(trimmedEtag != client_etag)
|
||||
job->add ( DownloadJob::create ( net_manager, QUrl ( prefix + keyStr ), filename ) );
|
||||
|
||||
}
|
||||
job->add ( JobPtr ( new NukeAndPaveJob ( fprefix, nuke_whitelist ) ) );
|
||||
d->files_job.reset ( job );
|
||||
d->dl.enqueue ( d->files_job );
|
||||
files_job.reset ( job );
|
||||
dl.enqueue ( files_job );
|
||||
}
|
||||
void OneSixAssets::fetchStarted()
|
||||
{
|
||||
@ -150,8 +155,8 @@ void OneSixAssets::start()
|
||||
job->add ( DownloadJob::create ( QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" ) ) );
|
||||
connect ( job, SIGNAL ( finished() ), SLOT ( fetchFinished() ) );
|
||||
connect ( job, SIGNAL ( started() ), SLOT ( fetchStarted() ) );
|
||||
d->index_job.reset ( job );
|
||||
d->dl.enqueue ( d->index_job );
|
||||
index_job.reset ( job );
|
||||
dl.enqueue ( index_job );
|
||||
}
|
||||
|
||||
#include "OneSixAssets.moc"
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <QObject>
|
||||
#include <QSharedPointer>
|
||||
#include "dlqueue.h"
|
||||
|
||||
class Private;
|
||||
|
||||
@ -15,7 +14,10 @@ public slots:
|
||||
void fetchFinished();
|
||||
void fetchStarted();
|
||||
public:
|
||||
explicit OneSixAssets ( QObject* parent = 0 );
|
||||
void start();
|
||||
QSharedPointer<Private> d;
|
||||
private:
|
||||
QSharedPointer<QNetworkAccessManager> net_manager {new QNetworkAccessManager()};
|
||||
JobListQueue dl;
|
||||
JobListPtr index_job;
|
||||
JobListPtr files_job;
|
||||
};
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "BaseInstance.h"
|
||||
#include "InstanceFactory.h"
|
||||
#include "MinecraftProcess.h"
|
||||
#include "OneSixAssets.h"
|
||||
|
||||
#include "instancemodel.h"
|
||||
#include "instancedelegate.h"
|
||||
@ -144,16 +145,20 @@ MainWindow::MainWindow ( QWidget *parent ) :
|
||||
instList.at(0)->setName("TEST ITEM");
|
||||
*/
|
||||
|
||||
//FIXME: WTF
|
||||
if (!MinecraftVersionList::getMainList().isLoaded())
|
||||
{
|
||||
m_versionLoadTask = MinecraftVersionList::getMainList().getLoadTask();
|
||||
startTask(m_versionLoadTask);
|
||||
}
|
||||
|
||||
//FIXME: WTF X 2
|
||||
if (!LWJGLVersionList::get().isLoaded())
|
||||
{
|
||||
LWJGLVersionList::get().loadList();
|
||||
}
|
||||
//FIXME: I guess you get the idea. This is a quick hack.
|
||||
assets_downloader = new OneSixAssets();
|
||||
assets_downloader->start();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -162,6 +167,7 @@ MainWindow::~MainWindow()
|
||||
delete proxymodel;
|
||||
delete model;
|
||||
delete drawer;
|
||||
delete assets_downloader;
|
||||
}
|
||||
|
||||
void MainWindow::instanceActivated ( QModelIndex index )
|
||||
|
@ -28,6 +28,7 @@ class KCategorizedView;
|
||||
class KCategoryDrawer;
|
||||
class MinecraftProcess;
|
||||
class ConsoleWindow;
|
||||
class OneSixAssets;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
@ -128,6 +129,7 @@ private:
|
||||
InstanceList instList;
|
||||
MinecraftProcess *proc;
|
||||
ConsoleWindow *console;
|
||||
OneSixAssets *assets_downloader;
|
||||
|
||||
// A pointer to the instance we are actively doing stuff with.
|
||||
// This is set when the user launches an instance and is used to refer to that
|
||||
|
@ -9,9 +9,22 @@ class LIBUTIL_EXPORT DownloadJob : public Job
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DownloadJob(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString());
|
||||
DownloadJob(QUrl url,
|
||||
QString rel_target_path = QString(),
|
||||
QString expected_md5 = QString()
|
||||
);
|
||||
static JobPtr create(QUrl url, QString rel_target_path = QString(), QString expected_md5 = QString());
|
||||
|
||||
DownloadJob(QSharedPointer<QNetworkAccessManager> net_mgr,
|
||||
QUrl url,
|
||||
QString rel_target_path = QString(),
|
||||
QString expected_md5 = QString()
|
||||
);
|
||||
static JobPtr create(QSharedPointer<QNetworkAccessManager> net_mgr,
|
||||
QUrl url,
|
||||
QString rel_target_path = QString(),
|
||||
QString expected_md5 = QString()
|
||||
);
|
||||
|
||||
public:
|
||||
static bool ensurePathExists(QString filenamepath);
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "include/dlqueue.h"
|
||||
|
||||
DownloadJob::DownloadJob ( QUrl url, QString target_path, QString expected_md5 )
|
||||
DownloadJob::DownloadJob (QUrl url,
|
||||
QString target_path,
|
||||
QString expected_md5 )
|
||||
:Job()
|
||||
{
|
||||
m_url = url;
|
||||
@ -11,13 +13,41 @@ DownloadJob::DownloadJob ( QUrl url, QString target_path, QString expected_md5 )
|
||||
m_save_to_file = m_target_path.size();
|
||||
m_status = Job_NotStarted;
|
||||
m_opened_for_saving = false;
|
||||
m_manager.reset(new QNetworkAccessManager());
|
||||
}
|
||||
|
||||
JobPtr DownloadJob::create ( QUrl url, QString target_path, QString expected_md5 )
|
||||
JobPtr DownloadJob::create (QUrl url,
|
||||
QString target_path,
|
||||
QString expected_md5 )
|
||||
{
|
||||
return JobPtr ( new DownloadJob ( url, target_path, expected_md5 ) );
|
||||
}
|
||||
|
||||
DownloadJob::DownloadJob (QSharedPointer<QNetworkAccessManager> net_mgr,
|
||||
QUrl url,
|
||||
QString target_path,
|
||||
QString expected_md5 )
|
||||
:Job()
|
||||
{
|
||||
m_url = url;
|
||||
m_target_path = target_path;
|
||||
m_expected_md5 = expected_md5;
|
||||
|
||||
m_check_md5 = m_expected_md5.size();
|
||||
m_save_to_file = m_target_path.size();
|
||||
m_status = Job_NotStarted;
|
||||
m_opened_for_saving = false;
|
||||
m_manager = net_mgr;
|
||||
}
|
||||
|
||||
JobPtr DownloadJob::create (QSharedPointer<QNetworkAccessManager> net_mgr,
|
||||
QUrl url,
|
||||
QString target_path,
|
||||
QString expected_md5 )
|
||||
{
|
||||
return JobPtr ( new DownloadJob ( net_mgr, url, target_path, expected_md5 ) );
|
||||
}
|
||||
|
||||
bool DownloadJob::ensurePathExists(QString filenamepath)
|
||||
{
|
||||
QFileInfo a ( filenamepath );
|
||||
@ -27,7 +57,6 @@ bool DownloadJob::ensurePathExists(QString filenamepath)
|
||||
|
||||
void DownloadJob::start()
|
||||
{
|
||||
m_manager.reset ( new QNetworkAccessManager() );
|
||||
if ( m_save_to_file )
|
||||
{
|
||||
QString filename = m_target_path;
|
||||
|
Loading…
Reference in New Issue
Block a user