Download assets for 1.6 on application start (background task).
This commit is contained in:
		@@ -33,12 +33,12 @@ public:
 | 
				
			|||||||
			trimmedf.remove(0, base_length + 1);
 | 
								trimmedf.remove(0, base_length + 1);
 | 
				
			||||||
			if(m_whitelist.contains(trimmedf))
 | 
								if(m_whitelist.contains(trimmedf))
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				//qDebug() << trimmedf << " gets to live";
 | 
									// qDebug() << trimmedf << " gets to live";
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			else
 | 
								else
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				// DO NOT TOLERATE JUNK
 | 
									// DO NOT TOLERATE JUNK
 | 
				
			||||||
				//qDebug() << trimmedf << " dies";
 | 
									// qDebug() << trimmedf << " dies";
 | 
				
			||||||
				QFile f (filename);
 | 
									QFile f (filename);
 | 
				
			||||||
				f.remove();
 | 
									f.remove();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
@@ -74,15 +74,7 @@ private:
 | 
				
			|||||||
	ThreadedDeleter deleterThread;
 | 
						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()
 | 
					void OneSixAssets::fetchFinished()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -90,7 +82,7 @@ void OneSixAssets::fetchFinished()
 | 
				
			|||||||
	QString fprefix ( "assets/" );
 | 
						QString fprefix ( "assets/" );
 | 
				
			||||||
	QStringList nuke_whitelist;
 | 
						QStringList nuke_whitelist;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	JobPtr firstJob = d->index_job->getFirstJob();
 | 
						JobPtr firstJob = index_job->getFirstJob();
 | 
				
			||||||
	auto DlJob = firstJob.dynamicCast<DownloadJob>();
 | 
						auto DlJob = firstJob.dynamicCast<DownloadJob>();
 | 
				
			||||||
	QByteArray ba = DlJob->m_data;
 | 
						QByteArray ba = DlJob->m_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -132,13 +124,26 @@ void OneSixAssets::fetchFinished()
 | 
				
			|||||||
		if ( sizeStr == "0" )
 | 
							if ( sizeStr == "0" )
 | 
				
			||||||
			continue;
 | 
								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 ( '"' );
 | 
							QString trimmedEtag = etagStr.remove ( '"' );
 | 
				
			||||||
		job->add ( DownloadJob::create ( QUrl ( prefix + keyStr ),fprefix + keyStr, trimmedEtag ) );
 | 
					 | 
				
			||||||
		nuke_whitelist.append ( keyStr );
 | 
							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 ) ) );
 | 
						job->add ( JobPtr ( new NukeAndPaveJob ( fprefix, nuke_whitelist ) ) );
 | 
				
			||||||
	d->files_job.reset ( job );
 | 
						files_job.reset ( job );
 | 
				
			||||||
	d->dl.enqueue ( d->files_job );
 | 
						dl.enqueue ( files_job );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
void OneSixAssets::fetchStarted()
 | 
					void OneSixAssets::fetchStarted()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -150,8 +155,8 @@ void OneSixAssets::start()
 | 
				
			|||||||
	job->add ( DownloadJob::create ( QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" ) ) );
 | 
						job->add ( DownloadJob::create ( QUrl ( "http://s3.amazonaws.com/Minecraft.Resources/" ) ) );
 | 
				
			||||||
	connect ( job, SIGNAL ( finished() ), SLOT ( fetchFinished() ) );
 | 
						connect ( job, SIGNAL ( finished() ), SLOT ( fetchFinished() ) );
 | 
				
			||||||
	connect ( job, SIGNAL ( started() ), SLOT ( fetchStarted() ) );
 | 
						connect ( job, SIGNAL ( started() ), SLOT ( fetchStarted() ) );
 | 
				
			||||||
	d->index_job.reset ( job );
 | 
						index_job.reset ( job );
 | 
				
			||||||
	d->dl.enqueue ( d->index_job );
 | 
						dl.enqueue ( index_job );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "OneSixAssets.moc"
 | 
					#include "OneSixAssets.moc"
 | 
				
			||||||
@@ -1,6 +1,5 @@
 | 
				
			|||||||
#pragma once
 | 
					#pragma once
 | 
				
			||||||
#include <QObject>
 | 
					#include "dlqueue.h"
 | 
				
			||||||
#include <QSharedPointer>
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Private;
 | 
					class Private;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -15,7 +14,10 @@ public slots:
 | 
				
			|||||||
	void fetchFinished();
 | 
						void fetchFinished();
 | 
				
			||||||
	void fetchStarted();
 | 
						void fetchStarted();
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	explicit OneSixAssets ( QObject* parent = 0 );
 | 
					 | 
				
			||||||
	void start();
 | 
						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 "BaseInstance.h"
 | 
				
			||||||
#include "InstanceFactory.h"
 | 
					#include "InstanceFactory.h"
 | 
				
			||||||
#include "MinecraftProcess.h"
 | 
					#include "MinecraftProcess.h"
 | 
				
			||||||
 | 
					#include "OneSixAssets.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "instancemodel.h"
 | 
					#include "instancemodel.h"
 | 
				
			||||||
#include "instancedelegate.h"
 | 
					#include "instancedelegate.h"
 | 
				
			||||||
@@ -144,16 +145,20 @@ MainWindow::MainWindow ( QWidget *parent ) :
 | 
				
			|||||||
	instList.at(0)->setName("TEST ITEM");
 | 
						instList.at(0)->setName("TEST ITEM");
 | 
				
			||||||
	*/
 | 
						*/
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
 | 
						//FIXME: WTF
 | 
				
			||||||
	if (!MinecraftVersionList::getMainList().isLoaded())
 | 
						if (!MinecraftVersionList::getMainList().isLoaded())
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		m_versionLoadTask = MinecraftVersionList::getMainList().getLoadTask();
 | 
							m_versionLoadTask = MinecraftVersionList::getMainList().getLoadTask();
 | 
				
			||||||
		startTask(m_versionLoadTask);
 | 
							startTask(m_versionLoadTask);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						//FIXME: WTF X 2
 | 
				
			||||||
	if (!LWJGLVersionList::get().isLoaded())
 | 
						if (!LWJGLVersionList::get().isLoaded())
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		LWJGLVersionList::get().loadList();
 | 
							LWJGLVersionList::get().loadList();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						//FIXME: I guess you get the idea. This is a quick hack.
 | 
				
			||||||
 | 
						assets_downloader = new OneSixAssets();
 | 
				
			||||||
 | 
						assets_downloader->start();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MainWindow::~MainWindow()
 | 
					MainWindow::~MainWindow()
 | 
				
			||||||
@@ -162,6 +167,7 @@ MainWindow::~MainWindow()
 | 
				
			|||||||
	delete proxymodel;
 | 
						delete proxymodel;
 | 
				
			||||||
	delete model;
 | 
						delete model;
 | 
				
			||||||
	delete drawer;
 | 
						delete drawer;
 | 
				
			||||||
 | 
						delete assets_downloader;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MainWindow::instanceActivated ( QModelIndex index )
 | 
					void MainWindow::instanceActivated ( QModelIndex index )
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,7 @@ class KCategorizedView;
 | 
				
			|||||||
class KCategoryDrawer;
 | 
					class KCategoryDrawer;
 | 
				
			||||||
class MinecraftProcess;
 | 
					class MinecraftProcess;
 | 
				
			||||||
class ConsoleWindow;
 | 
					class ConsoleWindow;
 | 
				
			||||||
 | 
					class OneSixAssets;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Ui
 | 
					namespace Ui
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@@ -128,6 +129,7 @@ private:
 | 
				
			|||||||
	InstanceList instList;
 | 
						InstanceList instList;
 | 
				
			||||||
	MinecraftProcess *proc;
 | 
						MinecraftProcess *proc;
 | 
				
			||||||
	ConsoleWindow *console;
 | 
						ConsoleWindow *console;
 | 
				
			||||||
 | 
						OneSixAssets *assets_downloader;
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	// A pointer to the instance we are actively doing stuff with.
 | 
						// 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
 | 
						// 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
 | 
						Q_OBJECT
 | 
				
			||||||
public:
 | 
					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());
 | 
						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:
 | 
					public:
 | 
				
			||||||
	static bool ensurePathExists(QString filenamepath);
 | 
						static bool ensurePathExists(QString filenamepath);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,8 @@
 | 
				
			|||||||
#include "include/dlqueue.h"
 | 
					#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()
 | 
						:Job()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	m_url = url;
 | 
						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_save_to_file = m_target_path.size();
 | 
				
			||||||
	m_status = Job_NotStarted;
 | 
						m_status = Job_NotStarted;
 | 
				
			||||||
	m_opened_for_saving = false;
 | 
						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 ) );
 | 
						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)
 | 
					bool DownloadJob::ensurePathExists(QString filenamepath)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	QFileInfo a ( filenamepath );
 | 
						QFileInfo a ( filenamepath );
 | 
				
			||||||
@@ -27,7 +57,6 @@ bool DownloadJob::ensurePathExists(QString filenamepath)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void DownloadJob::start()
 | 
					void DownloadJob::start()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	m_manager.reset ( new QNetworkAccessManager() );
 | 
					 | 
				
			||||||
	if ( m_save_to_file )
 | 
						if ( m_save_to_file )
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		QString filename = m_target_path;
 | 
							QString filename = m_target_path;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user