*nusDownloader:: fix cache bug caused be overzealous optimizations; add better error handeling when reading and saving data to/fromcache

*ohneschwanzenegger:: change possible misleading version text when overwriting a title
This commit is contained in:
giantpune 2011-05-28 06:05:34 +00:00
parent 3abb9f4b71
commit 530f360482
6 changed files with 54 additions and 26 deletions

View File

@ -48,6 +48,7 @@ bool NandBin::SetPath( const QString &path )
return ret;
}
const QString NandBin::FilePath()
{
if( !f.isOpen() )
@ -55,7 +56,6 @@ const QString NandBin::FilePath()
return QFileInfo( f ).absoluteFilePath();
}
//#if 0 // apparently you dont need any extra reserved blocks for the thing to boot?
bool NandBin::CreateNew( const QString &path, const QByteArray &keys, const QByteArray &first8, const QList<quint16> &badBlocks )
{
#ifndef NAND_BIN_CAN_WRITE
@ -158,7 +158,6 @@ bool NandBin::CreateNew( const QString &path, const QByteArray &keys, const QByt
return true;
#endif
}
//#endif
bool NandBin::Format( bool secure )
{
@ -1344,7 +1343,7 @@ bool NandBin::DeleteItem( QTreeWidgetItem *item )
return false;
}
qDebug() << "NandBin::DeleteItem" << item->text( 0 );
//qDebug() << "NandBin::DeleteItem" << item->text( 0 );
bool ok = false;
quint16 idx = item->text( 1 ).toInt( &ok );//get the index of the entry to remove
if( !ok || idx > 0x17fe )
@ -1428,7 +1427,7 @@ bool NandBin::DeleteItem( QTreeWidgetItem *item )
case 1:
{
//int q = 0;
qDebug() << "deleting clusters of" << item->text( 0 ) << idx;
//qDebug() << "deleting clusters of" << item->text( 0 ) << idx;
QList<quint16> toFree = GetFatsForFile( idx );
foreach( quint16 cl, toFree )
{

View File

@ -126,7 +126,19 @@ QByteArray NusDownloader::GetDataFromCache( const downloadJob &job )
}
QFile f( GetCachePath( job.index ) );
if( !f.exists() || !f.open( QIODevice::ReadOnly ) )
if( !f.exists() )
{
//qWarning() << "NusDownloader::GetDataFromCache -> file doesnt exist" << QFileInfo( f ).absoluteFilePath();
return QByteArray();
}
if( !f.size() )
{
f.remove();
qWarning() << "NusDownloader::GetDataFromCache -> file was 0 bytes" << QFileInfo( f ).absoluteFilePath();
return QByteArray();
}
if( !f.open( QIODevice::ReadOnly ) )
{
//qWarning() << "NusDownloader::GetDataFromCache -> file cant be opened for reading" << QFileInfo( f ).absoluteFilePath();
return QByteArray();
@ -178,7 +190,7 @@ void NusDownloader::ReadTmdAndGetTicket( const QByteArray &ba )
if( stuff.isEmpty() )
{
dlJob = tikJob;
QTimer::singleShot( 0, this, SLOT( StartDownload() ) );
QTimer::singleShot( 50, this, SLOT( StartDownload() ) );
}
else
{
@ -188,13 +200,20 @@ void NusDownloader::ReadTmdAndGetTicket( const QByteArray &ba )
//AesSetKey( t.DecryptedKey() );
//add the ticket data to the return
currentJob.data << stuff;
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );
QTimer::singleShot( 50, this, SLOT( GetNextItemForCurrentTitle() ) );
}
}
//save data downloaded from the internet to local HDD for future downloads
bool NusDownloader::SaveDataToCache( const QString &path, const QByteArray &stuff )
{
//qDebug() << "NusDownloader::SaveDataToCache ->" << path;
if( !stuff.size() )
{
qWarning() << "NusDownloader::SaveDataToCache -> !size" << path;
return false;
}
//make sure there is all the parent folders needed to hold this folder
if( path.count( "/" ) < 4 || !path.startsWith( cachePath + "/" ))
{
@ -219,9 +238,16 @@ bool NusDownloader::SaveDataToCache( const QString &path, const QByteArray &stuf
qWarning() << "NusDownloader::SaveDataToCache -> can't create file" << path;
return false;
}
f.write( stuff );//probably should check the return values on these. but if they dont go right, then the person has bigger things to worry about
if( f.write( stuff ) != stuff.size() )
{
f.close();
f.remove();
qWarning() << "NusDownloader::SaveDataToCache -> error writing data to" << path;
return false;
}
f.flush();
f.close();
qDebug() << "saved" << hex << stuff.size() << "bytes to" << path;
//qDebug() << "saved" << hex << stuff.size() << "bytes to" << path;
return true;
}
@ -240,7 +266,7 @@ void NusDownloader::CurrentJobErrored( const QString &str )
{
qWarning() << "NusDownloader::CurrentJobErrored ->" << str;
emit SendError( str, currentJob );
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );
QTimer::singleShot( 50, this, SLOT( StartNextJob() ) );
}
//get the next content for the current title
@ -286,7 +312,7 @@ void NusDownloader::GetNextItemForCurrentTitle()
}
//qDebug() << "hash matched for index" << alreadyHave;
if( alreadyHave + 1 < qFromBigEndian( curTmd.payload()->num_contents ) )
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
QTimer::singleShot( 50, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
else
{
@ -294,7 +320,7 @@ void NusDownloader::GetNextItemForCurrentTitle()
emit SendTotalProgress( progress );
emit SendTitleProgress( 100 );
emit SendData( currentJob );
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );//start next job
QTimer::singleShot( 50, this, SLOT( StartNextJob() ) );//start next job
}
}
}
@ -371,7 +397,7 @@ bool NusDownloader::DecryptCheckHashAndAppendData( const QByteArray &encData, qu
}
//something is done downloading
void NusDownloader::FileIsFinishedDownloading( const downloadJob &job )
void NusDownloader::FileIsFinishedDownloading( downloadJob job )
{
//qDebug() << "NusDownloader::FileIsFinishedDownloading" << job.index;
if( job.data.isEmpty() )
@ -401,7 +427,8 @@ void NusDownloader::FileIsFinishedDownloading( const downloadJob &job )
//add the ticket data to the return
currentJob.data << job.data;
//start downloading the contents
GetNextItemForCurrentTitle();
//GetNextItemForCurrentTitle();
QTimer::singleShot( 50, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
cPath = GetCachePath( job.index );
}
@ -433,11 +460,11 @@ void NusDownloader::FileIsFinishedDownloading( const downloadJob &job )
emit SendTotalProgress( progress );
emit SendTitleProgress( 100 );
emit SendData( currentJob );
QTimer::singleShot( 0, this, SLOT( StartNextJob() ) );//move on to next job
QTimer::singleShot( 50, this, SLOT( StartNextJob() ) );//move on to next job
}
else
QTimer::singleShot( 0, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
QTimer::singleShot( 50, this, SLOT( GetNextItemForCurrentTitle() ) );//next content
cPath = GetCachePath( job.index );
}
@ -457,7 +484,7 @@ void NusDownloader::StartDownload()
//qDebug() << "NusDownloader::StartDownload" << dlJob.index;
emit SendDownloadProgress( 0 );
QString dlUrl = NUS_BASE_URL + dlJob.tid + "/" + dlJob.name;
qDebug() << "url" << dlUrl;
//qDebug() << "url" << dlUrl;
currentJobText = dlUrl;
QUrl url( dlUrl );

View File

@ -121,7 +121,9 @@ private:
bool DecryptCheckHashAndAppendData( const QByteArray &encData, quint16 idx );
//triggered when a file is done downloading
void FileIsFinishedDownloading( const downloadJob &job );
//! dont use const reference here, as the job is really a variable which is reused
//! for every download
void FileIsFinishedDownloading( downloadJob job );
//send a fail message about the current job and skip to the next
void CurrentJobErrored( const QString &str );

View File

@ -685,7 +685,7 @@ bool MainWindow::InstallNUSItem( NusJob job )
{
//nand.WriteMetaData();
UpdateTree();
ShowMessage( tr( "Deleted old TMD and private contents for<br>%1" ).arg( title ) );
ShowMessage( tr( "Deleted old TMD and private contents for<br>%1" ).arg( job.tid, 16, 16, QChar( '0' ) ) );
}
cnt = t.Count();
@ -982,7 +982,7 @@ void MainWindow::on_actionFormat_triggered()
//wipe all user-created entries from uid.sys
QByteArray uidData = uid.Data();
QBuffer buf( &uidData );
buf.open( QIODevice::ReadWrite );
buf.open( QIODevice::ReadOnly );
quint64 tid;
quint16 titles = 0;

View File

@ -3,7 +3,7 @@
#include "../WiiQt/uidmap.h"
#include "../WiiQt/tools.h"
NewNandBin::NewNandBin( QWidget *parent, QList<quint16> badBlocks ) : QDialog(parent), ui(new Ui::NewNandBin), nand( this )
NewNandBin::NewNandBin( QWidget *parent, const QList<quint16> &badBlocks ) : QDialog(parent), ui(new Ui::NewNandBin), nand( this )
{
dir = QDir::currentPath();
ui->setupUi(this);
@ -204,7 +204,7 @@ void NewNandBin::on_buttonBox_accepted()
ret = ui->lineEdit_dest->text();
}
QString NewNandBin::GetNewNandPath( QWidget *parent, QList<quint16> badBlocks )
QString NewNandBin::GetNewNandPath( QWidget *parent, const QList<quint16> &badBlocks )
{
NewNandBin d( parent, badBlocks );
if( !d.exec() )
@ -339,7 +339,7 @@ void NewNandBin::on_pushButton_oldNand_clicked()
QByteArray NewNandBin::GetCleanUid( QByteArray old )
{
QBuffer buf( &old );
buf.open( QIODevice::ReadWrite );
buf.open( QIODevice::ReadOnly );
quint64 tid;
quint16 titles = 0;

View File

@ -13,10 +13,10 @@ class NewNandBin : public QDialog
Q_OBJECT
public:
explicit NewNandBin( QWidget *parent = 0, QList<quint16>badBlocks = QList<quint16>() );
explicit NewNandBin( QWidget *parent = 0, const QList<quint16> &badBlocks = QList<quint16>() );
~NewNandBin();
static QString GetNewNandPath( QWidget *parent = 0, QList<quint16>badBlocks = QList<quint16>() );
static QString GetNewNandPath( QWidget *parent = 0, const QList<quint16> &badBlocks = QList<quint16>() );
private:
Ui::NewNandBin *ui;
@ -32,7 +32,7 @@ private:
QByteArray uidSys;
bool CreateDefaultEntries();
QByteArray GetCleanUid( QByteArray old );
QByteArray GetCleanUid( QByteArray old );
private slots:
void on_pushButton_oldNand_clicked();