2010-12-08 08:26:18 +01:00
|
|
|
#ifndef NUSDOWNLOADER_H
|
|
|
|
#define NUSDOWNLOADER_H
|
|
|
|
|
2010-12-10 04:50:08 +01:00
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
#include "includes.h"
|
|
|
|
#include "tiktmd.h"
|
|
|
|
|
|
|
|
#define SHOPPING_USER_AGENT "Opera/9.00 (Nintendo Wii; U; ; 1038-58; Wii Shop Channel/1.0; en)"
|
|
|
|
#define UPDATING_USER_AGENT "wii libnup/1.0"
|
|
|
|
#define VIRTUAL_CONSOLE_USER_AGENT "libec-3.0.7.06111123"
|
|
|
|
#define WIICONNECT24_USER_AGENT "WiiConnect24/1.0FC4plus1 (build 061114161108)"
|
|
|
|
#define NUS_BASE_URL "http://ccs.shop.wii.com/ccs/download/"
|
|
|
|
|
2010-12-08 09:47:19 +01:00
|
|
|
#define TITLE_LATEST_VERSION 0xffff
|
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
IDX_CETK = 0x9000,
|
|
|
|
IDX_TMD
|
|
|
|
};
|
|
|
|
|
|
|
|
//struct used to keep all the data about a NUS request together
|
|
|
|
//when a finished job is returned, the data list will be the TMD, then the ticket, then all the contents
|
|
|
|
struct NusJob
|
|
|
|
{
|
|
|
|
quint64 tid;
|
|
|
|
quint16 version;
|
|
|
|
bool decrypt;
|
|
|
|
QList<QByteArray> data;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct downloadJob
|
|
|
|
{
|
|
|
|
QString tid;
|
|
|
|
QString name;
|
|
|
|
quint16 index;
|
|
|
|
QByteArray data;
|
|
|
|
};
|
|
|
|
|
|
|
|
//class to download titles from nintendo update servers
|
|
|
|
class NusDownloader : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit NusDownloader( QObject *parent = 0, const QString &cPath = QString() );
|
|
|
|
|
|
|
|
//set the path used to cache files
|
|
|
|
void SetCachePath( const QString &cPath = QString() );
|
|
|
|
|
|
|
|
//get a title from NUS. if version is 0, get the latest one
|
|
|
|
void GetTitle( NusJob job );
|
|
|
|
void GetTitles( QList<NusJob> jobs );
|
2010-12-08 09:47:19 +01:00
|
|
|
void Get( quint64 tid, bool decrypt, quint16 version = TITLE_LATEST_VERSION );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//TODO! this function is far from complete
|
|
|
|
//starts getting all the titles involved for a given update
|
2010-12-08 19:07:57 +01:00
|
|
|
//expects strings like "4.2u" and "3.4e" ( any of the updates listed below should be working )
|
2010-12-08 08:26:18 +01:00
|
|
|
//returns false if it doesnt know the IOS for the given string
|
|
|
|
// The boot2 update is not uncluded in this. ask for it separately if you want it
|
|
|
|
bool GetUpdate( const QString & upd, bool decrypt = true );
|
|
|
|
|
|
|
|
//get a list of titles for a given update
|
|
|
|
//if a title is not available on NUS, a substitute is given instead ( a later version of the same title )
|
2010-12-09 12:30:25 +01:00
|
|
|
//to keep people from bulk DLing and installing and messing something up, any boot2 upudate will NOT be included
|
|
|
|
//in the list, ask for it specifically. IOS35 is added in all updates for use in sneek
|
2010-12-08 08:26:18 +01:00
|
|
|
//lists are created from wiimpersonator logs when available. otherwise they come from examining game update partitions
|
2010-12-09 12:30:25 +01:00
|
|
|
|
2010-12-08 19:07:57 +01:00
|
|
|
static QMap< quint64, quint16 > List20u();
|
2010-12-08 08:26:18 +01:00
|
|
|
static QMap< quint64, quint16 > List30u();
|
|
|
|
static QMap< quint64, quint16 > List31u();
|
|
|
|
static QMap< quint64, quint16 > List32u();
|
|
|
|
static QMap< quint64, quint16 > List33u();
|
|
|
|
static QMap< quint64, quint16 > List34u();
|
|
|
|
static QMap< quint64, quint16 > List40u();
|
|
|
|
static QMap< quint64, quint16 > List41u();
|
|
|
|
static QMap< quint64, quint16 > List42u();
|
|
|
|
static QMap< quint64, quint16 > List43u();
|
|
|
|
|
2010-12-08 19:07:57 +01:00
|
|
|
static QMap< quint64, quint16 > List21e();
|
|
|
|
static QMap< quint64, quint16 > List30e();
|
2010-12-08 08:26:18 +01:00
|
|
|
static QMap< quint64, quint16 > List31e();
|
2010-12-08 19:07:57 +01:00
|
|
|
//static QMap< quint64, quint16 > List32e();
|
2010-12-17 00:37:30 +01:00
|
|
|
static QMap< quint64, quint16 > List33e();
|
2010-12-08 08:26:18 +01:00
|
|
|
static QMap< quint64, quint16 > List34e();
|
|
|
|
static QMap< quint64, quint16 > List40e();
|
|
|
|
static QMap< quint64, quint16 > List41e();
|
|
|
|
static QMap< quint64, quint16 > List42e();
|
|
|
|
static QMap< quint64, quint16 > List43e();
|
|
|
|
|
2010-12-08 19:07:57 +01:00
|
|
|
static QMap< quint64, quint16 > List35k();
|
|
|
|
static QMap< quint64, quint16 > List41k();
|
|
|
|
static QMap< quint64, quint16 > List42k();
|
|
|
|
static QMap< quint64, quint16 > List43k();
|
|
|
|
|
|
|
|
static QMap< quint64, quint16 > List20j();
|
|
|
|
//static QMap< quint64, quint16 > List30j();
|
2010-12-08 08:26:18 +01:00
|
|
|
static QMap< quint64, quint16 > List31j();
|
2010-12-08 19:07:57 +01:00
|
|
|
//static QMap< quint64, quint16 > List32j();
|
2010-12-17 00:37:30 +01:00
|
|
|
static QMap< quint64, quint16 > List33j();
|
2010-12-08 08:26:18 +01:00
|
|
|
static QMap< quint64, quint16 > List34j();
|
|
|
|
static QMap< quint64, quint16 > List40j();
|
|
|
|
static QMap< quint64, quint16 > List41j();
|
|
|
|
static QMap< quint64, quint16 > List42j();
|
2010-12-08 19:07:57 +01:00
|
|
|
static QMap< quint64, quint16 > List43j();
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
//helper function to create a job
|
|
|
|
downloadJob CreateJob( QString name, quint16 index );
|
|
|
|
|
|
|
|
//path on the PC to try and get files from and save to to avoid downloading deplicates from NUS
|
|
|
|
QString cachePath;
|
|
|
|
|
|
|
|
//get data from the cache and put it in the job's data
|
|
|
|
//uses the version from currentJob
|
|
|
|
QByteArray GetDataFromCache( downloadJob job );
|
|
|
|
|
|
|
|
//saves downloaded data to the HDD for later use
|
|
|
|
bool SaveDataToCache( const QString &path, const QByteArray &stuff );
|
|
|
|
|
|
|
|
//check the tmd and try to ticket
|
|
|
|
void ReadTmdAndGetTicket( QByteArray ba );
|
|
|
|
|
|
|
|
bool DecryptCheckHashAndAppendData( const QByteArray &encData, quint16 idx );
|
|
|
|
|
|
|
|
//triggered when a file is done downloading
|
|
|
|
void FileIsFinishedDownloading( downloadJob job );
|
|
|
|
|
|
|
|
//send a fail message about the current job and skip to the next
|
|
|
|
void CurrentJobErrored( const QString &str );
|
|
|
|
|
|
|
|
//print info about a job to qDebug()
|
|
|
|
void DbgJoB( NusJob job );
|
|
|
|
|
|
|
|
//get the path for a file in the local cache
|
|
|
|
QString GetCachePath( quint32 idx );
|
|
|
|
|
|
|
|
//list of stuff to do
|
|
|
|
QList<NusJob>jobList;
|
|
|
|
|
|
|
|
//variables to keep track of the current downloading title
|
|
|
|
NusJob currentJob;
|
|
|
|
Tmd curTmd;
|
|
|
|
|
|
|
|
//variables for actually downloading something from the interwebz
|
|
|
|
QNetworkAccessManager manager;
|
|
|
|
QQueue< downloadJob > downloadQueue;
|
|
|
|
QNetworkReply *currentDownload;
|
|
|
|
QTime downloadTime;
|
|
|
|
QString currentJobText;
|
|
|
|
downloadJob dlJob;
|
|
|
|
|
|
|
|
//should be true if this object is busy getting a title and false if all work is done, or a fatal error
|
|
|
|
bool running;
|
|
|
|
|
|
|
|
//used to help in sending the overall progress done, should be reset on fatal error or when all jobs are done
|
|
|
|
quint32 totalJobs;
|
|
|
|
|
|
|
|
//used to help in sending the progress for the current title
|
|
|
|
quint32 totalTitleSize;
|
|
|
|
quint32 TitleSizeDownloaded();
|
|
|
|
|
2010-12-09 12:30:25 +01:00
|
|
|
//remember the ticked key for repeated use
|
2010-12-08 08:26:18 +01:00
|
|
|
QByteArray decKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void SendError( const QString &message, NusJob job );//send an errer and the title the error is about
|
|
|
|
//send an errer and the title the error is about, no more jobs will be done, and the SendDone signal will not be emited
|
2010-12-09 12:30:25 +01:00
|
|
|
void SendFatalErrorError( const QString &message, NusJob job );//currently not used
|
2010-12-08 08:26:18 +01:00
|
|
|
void SendDone();//message that all jobs are done
|
|
|
|
|
|
|
|
//send progress about the currently downloading job
|
|
|
|
void SendDownloadProgress( int );
|
|
|
|
|
|
|
|
//send progress about the overall progress
|
|
|
|
void SendTotalProgress( int );
|
|
|
|
|
|
|
|
//send progress info about the current title
|
|
|
|
void SendTitleProgress( int );
|
|
|
|
|
|
|
|
//sends a completed job to whoever is listening
|
|
|
|
void SendData( NusJob );
|
|
|
|
|
|
|
|
//a file is done downloading
|
|
|
|
void finished();
|
|
|
|
|
|
|
|
//send pretty text about what is happening
|
|
|
|
void SendText( QString );
|
|
|
|
|
|
|
|
//maybe this one is redundant
|
|
|
|
//void SendJobFinished( downloadJob );
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
void StartNextJob();
|
|
|
|
void GetNextItemForCurrentTitle();
|
|
|
|
|
|
|
|
//slots for actually downloading something from online
|
|
|
|
void StartDownload();
|
|
|
|
void downloadProgress( qint64 bytesReceived, qint64 bytesTotal );
|
|
|
|
void downloadFinished();
|
|
|
|
void downloadReadyRead();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // NUSDOWNLOADER_H
|