* fix bug dealing with cache for NUS class

* add settings for example programs

git-svn-id: http://wiiqt.googlecode.com/svn/trunk@49 389f4c8b-5dfe-645f-db0e-df882bc27289
This commit is contained in:
giantpune@gmail.com 2011-01-08 19:14:47 +00:00
parent 644aa141bb
commit 38bff8d982
11 changed files with 283 additions and 57 deletions

View File

@ -13,6 +13,7 @@ NusDownloader::NusDownloader( QObject *parent, const QString &cPath ) : QObject(
//change the cache path //change the cache path
void NusDownloader::SetCachePath( const QString &cPath ) void NusDownloader::SetCachePath( const QString &cPath )
{ {
qDebug() << "NusDownloader::SetCachePath" << cPath;
cachePath = cPath; cachePath = cPath;
} }
@ -99,7 +100,7 @@ void NusDownloader::StartNextJob()
else else
{ {
dlJob = tmdJob; dlJob = tmdJob;
QTimer::singleShot( 500, this, SLOT( StartDownload() ) ); QTimer::singleShot( 50, this, SLOT( StartDownload() ) );
} }
} }
else//download the latest tmd to get the version else//download the latest tmd to get the version
@ -201,13 +202,11 @@ bool NusDownloader::SaveDataToCache( const QString &path, const QByteArray &stuf
qWarning() << "NusDownloader::SaveDataToCache -> bad path" << path << cachePath; qWarning() << "NusDownloader::SaveDataToCache -> bad path" << path << cachePath;
return false; return false;
} }
QString parent = path;//really ugly, but somehow still prettier than a recursing mkdir function QFileInfo fi( path );
parent.resize( parent.lastIndexOf( "/" ) ); QString parent = fi.absolutePath();
parent.remove( 0, cachePath.size() + 1 ); if( !QDir( parent ).exists() && !QDir().mkpath( parent ) )
QDir d( cachePath );
if( !d.exists() || !d.mkpath( parent ) )
{ {
qWarning() << "NusDownloader::SaveDataToCache -> cant create directory" << QString( d.absolutePath() + "/" + path ); qWarning() << "NusDownloader::SaveDataToCache -> cant create directory" << parent;
return false; return false;
} }
QFile f( path ); QFile f( path );

View File

@ -15,6 +15,8 @@ NandWindow::NandWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::N
ui->progressBar->setVisible( false ); ui->progressBar->setVisible( false );
ui->statusBar->addPermanentWidget( ui->progressBar, 0 ); ui->statusBar->addPermanentWidget( ui->progressBar, 0 );
LoadSettings();
QFontMetrics fm( fontMetrics() ); QFontMetrics fm( fontMetrics() );
ui->treeWidget->header()->resizeSection( 0, fm.width( QString( 22, 'W' ) ) );//name ui->treeWidget->header()->resizeSection( 0, fm.width( QString( 22, 'W' ) ) );//name
ui->treeWidget->header()->resizeSection( 1, fm.width( "WWWWW" ) );//entry # ui->treeWidget->header()->resizeSection( 1, fm.width( "WWWWW" ) );//entry #
@ -34,9 +36,42 @@ NandWindow::NandWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::N
NandWindow::~NandWindow() NandWindow::~NandWindow()
{ {
SaveSettings();
delete ui; delete ui;
} }
void NandWindow::SaveSettings()
{
QSettings s( QSettings::IniFormat, QSettings::UserScope, "WiiQt", "examples", this );
s.beginGroup( "nandExtract" );
//window geometry
s.setValue( "size", size() );
s.setValue( "pos", pos() );
s.setValue( "usage", ui->actionShow_Usage->isChecked() );
//if the usage is visible, remember its size
int uSize = ui->splitter->sizes().at( 0 ) + 23;//WTF? why do i need to add 20ish here
if( ui->actionShow_Usage->isChecked() )
s.setValue( "usage_size", uSize );
s.endGroup();
}
void NandWindow::LoadSettings()
{
QSettings s( QSettings::IniFormat, QSettings::UserScope, "WiiQt", "examples", this );
//settings specific to this program
s.beginGroup( "nandExtract" );
resize( s.value("size", QSize( 1180, 654 ) ).toSize() );
move( s.value("pos", QPoint( 2, 72 ) ).toPoint() );
int top = s.value( "usage_size", 200 ).toInt();
ui->splitter->setSizes( QList< int >() << top << ( height() - top ) );
ui->actionShow_Usage->setChecked( s.value( "usage", true ).toBool() );
s.endGroup();
}
void NandWindow::SetUpBlockMap() void NandWindow::SetUpBlockMap()
{ {
ui->graphicsView_blocks->setScene( &gv ); ui->graphicsView_blocks->setScene( &gv );

View File

@ -37,6 +37,9 @@ private:
QList<quint16> ToBlocks( QList<quint16> clusters ); QList<quint16> ToBlocks( QList<quint16> clusters );
void SaveSettings();
void LoadSettings();
public slots: public slots:

View File

@ -26,9 +26,6 @@ MainWindow::MainWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::M
ui->pushButton_nandPath->setMinimumWidth( max ); ui->pushButton_nandPath->setMinimumWidth( max );
ui->pushButton_wad->setMinimumWidth( max ); ui->pushButton_wad->setMinimumWidth( max );
Wad::SetGlobalCert( QByteArray( (const char*)&certs_dat, CERTS_DAT_SIZE ) ); Wad::SetGlobalCert( QByteArray( (const char*)&certs_dat, CERTS_DAT_SIZE ) );
//connect to the nus object so we can respond to what it is saying with pretty stuff in the gui //connect to the nus object so we can respond to what it is saying with pretty stuff in the gui
@ -42,28 +39,102 @@ MainWindow::MainWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::M
//TODO, really get these paths from settings //TODO, really get these paths from settings
#ifdef Q_WS_WIN /*#ifdef Q_WS_WIN
QString cachePath = "../../NUS_cache"; QString cachePath = "../../NUS_cache";
#else #else
QString cachePath = "../NUS_cache"; QString cachePath = "../NUS_cache";
#endif #endif
QString nandPath = "./dump"; QString nandPath = "./dump";
ui->lineEdit_cachePath->setText( cachePath ); ui->lineEdit_cachePath->setText( cachePath );
ui->lineEdit_nandPath->setText( nandPath ); ui->lineEdit_nandPath->setText( nandPath );
ui->lineEdit_extractPath->setText( "./downloaded" ); ui->lineEdit_extractPath->setText( "./downloaded" );*/
LoadSettings();
//nand.SetPath( nandPath ); //nand.SetPath( nandPath );
nus.SetCachePath( cachePath ); //nus.SetCachePath( cachePath );
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
SaveSettings();
delete ui; delete ui;
} }
void MainWindow::SaveSettings()
{
QSettings s( QSettings::IniFormat, QSettings::UserScope, "WiiQt", "examples", this );
//settings specific to this program
s.beginGroup( "nusDownloader" );
//window geometry
s.setValue( "size", size() );
s.setValue( "pos", pos() );
//which radio button is selected
quint8 val = 0;
if( ui->radioButton_folder->isChecked() )
val = 1;
else if( ui->radioButton_wad->isChecked() )
val = 2;
s.setValue( "radio", val );
s.setValue( "folder", ui->lineEdit_extractPath->text() );
s.setValue( "nuswads", ui->lineEdit_wad->text() );
s.endGroup();
//settings shared in multiple programs
//paths
s.beginGroup( "paths" );
s.setValue( "nusCache", ui->lineEdit_cachePath->text() );
s.endGroup();
}
#ifdef Q_WS_WIN
#define PATH_PREFIX QString("../..")
#else
#define PATH_PREFIX QString("..")
#endif
void MainWindow::LoadSettings()
{
QSettings s( QSettings::IniFormat, QSettings::UserScope, "WiiQt", "examples", this );
//settings specific to this program
s.beginGroup( "nusDownloader" );
resize( s.value("size", QSize( 585, 457 ) ).toSize() );
move( s.value("pos", QPoint( 2, 72 ) ).toPoint() );
quint8 radio = s.value( "radio", 0 ).toInt();
if( radio == 1 )
ui->radioButton_folder->setChecked( true );
else if( radio == 2 )
ui->radioButton_wad->setChecked( true );
ui->lineEdit_extractPath->setText( s.value( "folder", PATH_PREFIX + "/downloaded" ).toString() );
ui->lineEdit_wad->setText( s.value( "nuswads", PATH_PREFIX + "/wads" ).toString() );
s.endGroup();
//settings shared in multiple programs
s.beginGroup( "paths" );
QString cachePath = s.value( "nusCache", PATH_PREFIX + "/NUS_cache" ).toString();
QString nandPath = s.value( "sneek" ).toString();
ui->lineEdit_cachePath->setText( cachePath );
ui->lineEdit_nandPath->setText( nandPath );
if( !nandPath.isEmpty() )
nand.SetPath( QFileInfo( nandPath ).absoluteFilePath() );
if( !cachePath.isEmpty() )
nus.SetCachePath( QFileInfo( cachePath ).absoluteFilePath() );
s.endGroup();
}
//some slots to respond to the NUS downloader //some slots to respond to the NUS downloader
void MainWindow::GetError( const QString &message, NusJob job ) void MainWindow::GetError( const QString &message, NusJob job )
{ {
@ -251,7 +322,8 @@ void MainWindow::on_pushButton_GetTitle_clicked()
//ui->progressBar_dl->setValue( 0 ); //ui->progressBar_dl->setValue( 0 );
//ui->progressBar_title->setValue( 0 ); //ui->progressBar_title->setValue( 0 );
//ui->progressBar_whole->setValue( 0 ); //ui->progressBar_whole->setValue( 0 );
nus.SetCachePath( ui->lineEdit_cachePath->text() ); nus.SetCachePath( QFileInfo( ui->lineEdit_cachePath->text() ).absoluteFilePath() );
if( wholeUpdate ) if( wholeUpdate )
{ {
if( !nus.GetUpdate( ui->lineEdit_tid->text(), decrypt ) ) if( !nus.GetUpdate( ui->lineEdit_tid->text(), decrypt ) )

View File

@ -29,6 +29,10 @@ private:
void SaveJobToFolder( NusJob job ); void SaveJobToFolder( NusJob job );
void SaveJobToWad( NusJob job ); void SaveJobToWad( NusJob job );
//settings
void SaveSettings();
void LoadSettings();
public slots: public slots:

View File

@ -55,26 +55,58 @@ MainWindow::MainWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::M
connect( &nand, SIGNAL( SendError( const QString & ) ), this, SLOT( GetError( const QString & ) ) ); connect( &nand, SIGNAL( SendError( const QString & ) ), this, SLOT( GetError( const QString & ) ) );
connect( &nand, SIGNAL( SendText( QString ) ), ui->statusBar, SLOT( showMessage( QString ) ) ); connect( &nand, SIGNAL( SendText( QString ) ), ui->statusBar, SLOT( showMessage( QString ) ) );
//TODO, really get these paths from settings LoadSettings();
#ifdef Q_WS_WIN ui->lineEdit_nandPath->setText( "./testNand.bin" );
QString cachePath = "../../NUS_cache";
#else
QString cachePath = "../NUS_cache";
#endif
QString nandPath = "./testNand.bin";
ui->lineEdit_cachePath->setText( cachePath );
ui->lineEdit_nandPath->setText( nandPath );
nus.SetCachePath( cachePath );
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
SaveSettings();
delete ui; delete ui;
} }
void MainWindow::SaveSettings()
{
QSettings s( QSettings::IniFormat, QSettings::UserScope, "WiiQt", "examples", this );
//settings specific to this program
s.beginGroup( "ohneschwanzenegger" );
s.setValue( "size", size() );
s.setValue( "pos", pos() );
s.endGroup();
//settings shared in multiple programs
//paths
s.beginGroup( "paths" );
s.setValue( "nusCache", ui->lineEdit_cachePath->text() );
s.endGroup();
}
#ifdef Q_WS_WIN
#define PATH_PREFIX QString("../..")
#else
#define PATH_PREFIX QString("..")
#endif
void MainWindow::LoadSettings()
{
QSettings s( QSettings::IniFormat, QSettings::UserScope, "WiiQt", "examples", this );
//settings specific to this program
s.beginGroup( "ohneschwanzenegger" );
resize( s.value("size", QSize( 654, 507 ) ).toSize() );
move( s.value("pos", QPoint( 2, 72 ) ).toPoint() );
s.endGroup();
s.beginGroup( "paths" );
QString cachePath = s.value( "nusCache", PATH_PREFIX + "/NUS_cache" ).toString();
ui->lineEdit_cachePath->setText( cachePath );
if( !cachePath.isEmpty() )
nus.SetCachePath( QFileInfo( cachePath ).absoluteFilePath() );
s.endGroup();
}
//some slots to respond to the NUS downloader //some slots to respond to the NUS downloader
void MainWindow::GetError( const QString &message, NusJob job ) void MainWindow::GetError( const QString &message, NusJob job )
{ {

View File

@ -46,6 +46,9 @@ private:
quint16 CreateIfNeeded( const QString &path, quint32 uid, quint16 gid, quint8 attr, quint8 user_perm, quint8 group_perm, quint8 other_perm ); quint16 CreateIfNeeded( const QString &path, quint32 uid, quint16 gid, quint8 attr, quint8 user_perm, quint8 group_perm, quint8 other_perm );
bool InstallSharedContent( const QByteArray stuff, const QByteArray hash = QByteArray() ); bool InstallSharedContent( const QByteArray stuff, const QByteArray hash = QByteArray() );
void SaveSettings();
void LoadSettings();
public slots: public slots:
//slots for getting info from the NUS downloader //slots for getting info from the NUS downloader
void GetError( const QString &message, NusJob job ); void GetError( const QString &message, NusJob job );

View File

@ -115,7 +115,7 @@ void NewNandBin::on_buttonBox_accepted()
} }
//add cert.sys //add cert.sys
quint16 handle = nand.CreateEntry( "/sys/cert.sys", 0, 0, NAND_FILE, NAND_RW, NAND_RW, NAND_READ ); quint16 handle = nand.CreateEntry( "/sys/cert.sys", 0, 0, NAND_FILE, NAND_RW, NAND_RW, NAND_READ );
if( !handle || !nand.SetData( "/sys/cert.sys", QByteArray( (const char*)&certs_dat, CERTS_DAT_SIZE ) ) ) if( !handle || !nand.SetData( handle, QByteArray( (const char*)&certs_dat, CERTS_DAT_SIZE ) ) )
{ {
qWarning() << "NewNandBin::on_buttonBox_accepted -> error creating cert in the new nand"; qWarning() << "NewNandBin::on_buttonBox_accepted -> error creating cert in the new nand";
return; return;

View File

@ -1,10 +1,10 @@
#include <QtGui/QApplication> #include "../WiiQt/includes.h"
#include "mainwindow.h" #include "mainwindow.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Q_INIT_RESOURCE( rc ); Q_INIT_RESOURCE( rc );
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;
w.show(); w.show();

View File

@ -10,15 +10,6 @@
#include "quazip.h" #include "quazip.h"
#include "quazipfile.h" #include "quazipfile.h"
//TODO... get these from settings and dont use global variables
#ifdef Q_WS_MAC
static QString sneekPath = "/Volumes/VMware Shared Folders/host-c/QtWii/test";
#else
//static QString sneekPath = "/media/SDHC_4GB";
static QString sneekPath = "../../test";
#endif
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), bannerthread( this ) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), bannerthread( this )
{ {
ui->setupUi(this); ui->setupUi(this);
@ -30,10 +21,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
ClearPcGuiInfo(); ClearPcGuiInfo();
progressBar.setVisible( false ); progressBar.setVisible( false );
ui->statusBar->addPermanentWidget( &progressBar, 0 ); ui->statusBar->addPermanentWidget( &progressBar, 0 );
ngID = 0; LoadSettings();
ngKeyID = 0;
//sneekIconTimer.setInterval( 150 );//delay of icon image animation
connect( &bannerthread, SIGNAL( SendProgress( int ) ), this, SLOT( GetProgressUpdate( int ) ) ); connect( &bannerthread, SIGNAL( SendProgress( int ) ), this, SLOT( GetProgressUpdate( int ) ) );
connect( &bannerthread, SIGNAL( SendDone( int ) ), this, SLOT( LoadThreadIsDone( int ) ) ); connect( &bannerthread, SIGNAL( SendDone( int ) ), this, SLOT( LoadThreadIsDone( int ) ) );
@ -43,21 +31,92 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect( &sneekIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextSneekIcon() ) ); connect( &sneekIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextSneekIcon() ) );
connect( &pcIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextPcIcon() ) ); connect( &pcIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextPcIcon() ) );
//GetSavesFromSneek( "/media/WiiFat500" ); //start loading saves if there is a path
//GetSavesFromSneek( sneekPath ); if( !sneekPath.isEmpty() )
//GetSavesFromPC( "./saveBackups" ); {
initialStartup = true;
GetSavesFromSneek( sneekPath );
}
else if( !pcPath.isEmpty() )
GetSavesFromPC( pcPath );
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
SaveSettings();
delete ui; delete ui;
} }
//save/load settings
void MainWindow::SaveSettings()
{
QSettings s( QSettings::IniFormat, QSettings::UserScope, "WiiQt", "examples", this );
//settings specific to this program
s.beginGroup( "savetoy" );
//window geometry
s.setValue( "size", size() );
s.setValue( "pos", pos() );
//save backup location
s.setValue( "pcPath", pcPath );
//current view
s.setValue( "tab", ui->tabWidget->currentIndex() );
s.endGroup();
//settings shared in multiple programs
//keys
s.beginGroup( "keys" );
s.setValue( "ngID", ngID );
s.setValue( "ngKeyID", ngKeyID );
s.setValue( "ngSig", ngSig.toHex() );
s.setValue( "ngMac", ngMac.toHex() );
s.setValue( "ngPriv", ngPriv.toHex() );
s.endGroup();
//paths
s.beginGroup( "paths" );
s.setValue( "sneek", sneekPath );
s.endGroup();
}
void MainWindow::LoadSettings()
{
QSettings s( QSettings::IniFormat, QSettings::UserScope, "WiiQt", "examples", this );
//settings specific to this program
s.beginGroup( "savetoy" );
//window geometry
resize( s.value("size", QSize( 949, 535 ) ).toSize() );
move( s.value("pos", QPoint( 284, 295 ) ).toPoint() );
//save backup location
pcPath = s.value( "pcPath" ).toString();
ui->tabWidget->setCurrentIndex( s.value( "tab", 0 ).toInt() );
s.endGroup();
//settings shared in multiple programs
//keys
s.beginGroup( "keys" );
ngID = s.value( "ngID", 0 ).toInt();
ngKeyID = s.value( "ngKeyID", 0 ).toInt();
ngSig = QByteArray::fromHex( s.value( "ngSig", QByteArray() ).toString().toLatin1() );
ngMac = QByteArray::fromHex( s.value( "ngMac", QByteArray() ).toString().toLatin1() );
ngPriv = QByteArray::fromHex( s.value( "ngPriv", QByteArray() ).toString().toLatin1() );
s.endGroup();
//paths
s.beginGroup( "paths" );
sneekPath = s.value( "sneek" ).toString();
s.endGroup();
}
//get the saves from a nand directory //get the saves from a nand directory
void MainWindow::GetSavesFromSneek( const QString &path ) void MainWindow::GetSavesFromSneek( const QString &path )
{ {
qDebug() << "MainWindow::GetSavesFromSneek" << path; //qDebug() << "MainWindow::GetSavesFromSneek" << path;
if( !QFileInfo( path ).exists() ) if( !QFileInfo( path ).exists() )
return; return;
@ -138,7 +197,20 @@ void MainWindow::GetProgressUpdate( int i )
//something is done working. respond somehow //something is done working. respond somehow
void MainWindow::LoadThreadIsDone( int type ) void MainWindow::LoadThreadIsDone( int type )
{ {
Q_UNUSED( type ); switch( type )
{
case LOAD_SNEEK:
if( initialStartup )
{
initialStartup = false;
if( !pcPath.isEmpty() )
GetSavesFromPC( pcPath );
}
break;
default:
break;
}
progressBar.setVisible( false ); progressBar.setVisible( false );
} }
@ -537,11 +609,11 @@ void MainWindow::on_actionSet_NG_Keys_triggered()
ngPriv = d.ngPriv; ngPriv = d.ngPriv;
ngSig = d.ngSig; ngSig = d.ngSig;
qDebug() << "accepted"; qDebug() << "accepted";
qDebug() << hex << d.ngID //qDebug() << hex << d.ngID
<< "\n" << d.ngKeyID // << "\n" << d.ngKeyID
<< "\n" << d.ngMac.toHex() // << "\n" << d.ngMac.toHex()
<< "\n" << d.ngPriv.toHex() // << "\n" << d.ngPriv.toHex()
<< "\n" << d.ngSig.toHex(); // << "\n" << d.ngSig.toHex();
} }
//PC list item changed //PC list item changed

View File

@ -15,7 +15,7 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow( QWidget *parent = 0 );
~MainWindow(); ~MainWindow();
private: private:
@ -37,6 +37,7 @@ private:
//basepath used for local save backups //basepath used for local save backups
QString pcPath; QString pcPath;
QString sneekPath;
//get available filename for backup save inside pcPath //get available filename for backup save inside pcPath
QString GetSaveName( quint64 tid ); QString GetSaveName( quint64 tid );
@ -56,14 +57,19 @@ private:
bool WriteZipFile( const QByteArray &dataBin, const QByteArray &desc, const QString &path ); bool WriteZipFile( const QByteArray &dataBin, const QByteArray &desc, const QString &path );
void AddNewPCSave( const QString &desc, const QString &tid, quint32 size, const QString &path, SaveBanner banner ); void AddNewPCSave( const QString &desc, const QString &tid, quint32 size, const QString &path, SaveBanner banner );
//clear the data on teh right of the screen //clear the data on the right of the screen
void ClearSneekGuiInfo(); void ClearSneekGuiInfo();
void ClearPcGuiInfo(); void ClearPcGuiInfo();
//save/load settings
void SaveSettings();
void LoadSettings();
bool initialStartup;
private slots: private slots:
void on_pushButton_pcInstall_clicked(); void on_pushButton_pcInstall_clicked();
void on_actionSet_Local_Path_triggered(); void on_actionSet_Local_Path_triggered();
void on_pushButton_pcDelete_clicked(); void on_pushButton_pcDelete_clicked();
void on_comboBox_pcSelect_currentIndexChanged(int index); void on_comboBox_pcSelect_currentIndexChanged(int index);
void on_listWidget_pcSaves_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous); void on_listWidget_pcSaves_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous);