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"
|
2011-01-02 07:15:26 +01:00
|
|
|
#include "tools.h"
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
#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/"
|
|
|
|
|
2011-01-02 07:15:26 +01:00
|
|
|
|
2010-12-08 09:47:19 +01:00
|
|
|
|
2010-12-08 08:26:18 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
IDX_CETK = 0x9000,
|
|
|
|
IDX_TMD
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2010-12-23 17:17:46 +01:00
|
|
|
void GetTitle( const NusJob &job );
|
|
|
|
void GetTitles( const 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 )
|
2011-01-02 07:15:26 +01:00
|
|
|
//to keep people from bulk DLing and installing and messing something up, any boot2 update will NOT be included
|
2011-05-15 19:22:42 +02:00
|
|
|
//in the list, ask for it specifically.
|
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
|
|
|
|
2011-05-15 19:22:42 +02:00
|
|
|
static QMap< quint64, quint16 > List20u();//* there are no games ive seen that contain this update. this is just a guess
|
|
|
|
static QMap< quint64, quint16 > List22u();
|
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();
|
|
|
|
|
2011-05-15 19:22:42 +02:00
|
|
|
static QMap< quint64, quint16 > List20e();//* there are no games ive seen that contain this update. this is just a guess
|
|
|
|
static QMap< quint64, quint16 > List21e();
|
|
|
|
static QMap< quint64, quint16 > List22e(); //* there are no games ive seen that contain this update. this is just a guess
|
2010-12-08 19:07:57 +01:00
|
|
|
static QMap< quint64, quint16 > List30e();
|
2010-12-08 08:26:18 +01:00
|
|
|
static QMap< quint64, quint16 > List31e();
|
2011-05-15 19:22:42 +02:00
|
|
|
static QMap< quint64, quint16 > List32e(); //* there are no games ive seen that contain this update, i have only copied 3.1e and changed the system menu
|
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();
|
|
|
|
|
2011-05-15 19:22:42 +02:00
|
|
|
static QMap< quint64, quint16 > List20j();
|
|
|
|
static QMap< quint64, quint16 > List22j();//* there are no games ive seen that contain this update, i have only copied 2.1e and changed the system menu
|
|
|
|
static QMap< quint64, quint16 > List30j();
|
2010-12-08 08:26:18 +01:00
|
|
|
static QMap< quint64, quint16 > List31j();
|
2011-05-15 19:22:42 +02:00
|
|
|
static QMap< quint64, quint16 > List32j();//* there are no games ive seen that contain this update, i have only copied 3.1j and changed the system menu
|
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
|
2010-12-23 17:17:46 +01:00
|
|
|
downloadJob CreateJob( const QString &name, quint16 index );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//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
|
2011-05-15 19:22:42 +02:00
|
|
|
QByteArray GetDataFromCache( const downloadJob &job );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//saves downloaded data to the HDD for later use
|
|
|
|
bool SaveDataToCache( const QString &path, const QByteArray &stuff );
|
|
|
|
|
|
|
|
//check the tmd and try to ticket
|
2010-12-23 17:17:46 +01:00
|
|
|
void ReadTmdAndGetTicket( const QByteArray &ba );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
bool DecryptCheckHashAndAppendData( const QByteArray &encData, quint16 idx );
|
|
|
|
|
|
|
|
//triggered when a file is done downloading
|
2011-05-28 08:05:34 +02:00
|
|
|
//! dont use const reference here, as the job is really a variable which is reused
|
|
|
|
//! for every download
|
|
|
|
void FileIsFinishedDownloading( downloadJob job );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//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()
|
2011-05-15 19:22:42 +02:00
|
|
|
void DbgJoB( const NusJob &job );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//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
|
2011-05-17 21:02:45 +02:00
|
|
|
void SendFatalErrorError( const QString &message, const 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
|
2011-05-17 21:02:45 +02:00
|
|
|
void SendData( const NusJob & );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//a file is done downloading
|
|
|
|
void finished();
|
|
|
|
|
|
|
|
//send pretty text about what is happening
|
2011-05-17 21:02:45 +02:00
|
|
|
void SendText( const QString & );
|
2010-12-08 08:26:18 +01:00
|
|
|
|
|
|
|
//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
|