diff --git a/WiiQt/nusdownloader.cpp b/WiiQt/nusdownloader.cpp index 31af949..20576ee 100644 --- a/WiiQt/nusdownloader.cpp +++ b/WiiQt/nusdownloader.cpp @@ -13,6 +13,7 @@ NusDownloader::NusDownloader( QObject *parent, const QString &cPath ) : QObject( //change the cache path void NusDownloader::SetCachePath( const QString &cPath ) { + qDebug() << "NusDownloader::SetCachePath" << cPath; cachePath = cPath; } @@ -99,7 +100,7 @@ void NusDownloader::StartNextJob() else { dlJob = tmdJob; - QTimer::singleShot( 500, this, SLOT( StartDownload() ) ); + QTimer::singleShot( 50, this, SLOT( StartDownload() ) ); } } 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; return false; } - QString parent = path;//really ugly, but somehow still prettier than a recursing mkdir function - parent.resize( parent.lastIndexOf( "/" ) ); - parent.remove( 0, cachePath.size() + 1 ); - QDir d( cachePath ); - if( !d.exists() || !d.mkpath( parent ) ) + QFileInfo fi( path ); + QString parent = fi.absolutePath(); + if( !QDir( parent ).exists() && !QDir().mkpath( parent ) ) { - qWarning() << "NusDownloader::SaveDataToCache -> cant create directory" << QString( d.absolutePath() + "/" + path ); + qWarning() << "NusDownloader::SaveDataToCache -> cant create directory" << parent; return false; } QFile f( path ); diff --git a/nandExtract/nandwindow.cpp b/nandExtract/nandwindow.cpp index bac1416..c814eb6 100755 --- a/nandExtract/nandwindow.cpp +++ b/nandExtract/nandwindow.cpp @@ -15,6 +15,8 @@ NandWindow::NandWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::N ui->progressBar->setVisible( false ); ui->statusBar->addPermanentWidget( ui->progressBar, 0 ); + LoadSettings(); + QFontMetrics fm( fontMetrics() ); ui->treeWidget->header()->resizeSection( 0, fm.width( QString( 22, 'W' ) ) );//name 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() { + SaveSettings(); 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() { ui->graphicsView_blocks->setScene( &gv ); diff --git a/nandExtract/nandwindow.h b/nandExtract/nandwindow.h index c3b8047..a16ad24 100755 --- a/nandExtract/nandwindow.h +++ b/nandExtract/nandwindow.h @@ -37,6 +37,9 @@ private: QList ToBlocks( QList clusters ); + void SaveSettings(); + void LoadSettings(); + public slots: diff --git a/nand_dump/mainwindow.cpp b/nand_dump/mainwindow.cpp index d550e40..0d602fb 100644 --- a/nand_dump/mainwindow.cpp +++ b/nand_dump/mainwindow.cpp @@ -26,9 +26,6 @@ MainWindow::MainWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::M ui->pushButton_nandPath->setMinimumWidth( max ); ui->pushButton_wad->setMinimumWidth( max ); - - - 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 @@ -42,28 +39,102 @@ MainWindow::MainWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::M //TODO, really get these paths from settings -#ifdef Q_WS_WIN +/*#ifdef Q_WS_WIN QString cachePath = "../../NUS_cache"; #else QString cachePath = "../NUS_cache"; #endif QString nandPath = "./dump"; - ui->lineEdit_cachePath->setText( cachePath ); ui->lineEdit_nandPath->setText( nandPath ); - ui->lineEdit_extractPath->setText( "./downloaded" ); + ui->lineEdit_extractPath->setText( "./downloaded" );*/ + + LoadSettings(); //nand.SetPath( nandPath ); - nus.SetCachePath( cachePath ); + //nus.SetCachePath( cachePath ); } MainWindow::~MainWindow() { + SaveSettings(); 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 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_title->setValue( 0 ); //ui->progressBar_whole->setValue( 0 ); - nus.SetCachePath( ui->lineEdit_cachePath->text() ); + nus.SetCachePath( QFileInfo( ui->lineEdit_cachePath->text() ).absoluteFilePath() ); + if( wholeUpdate ) { if( !nus.GetUpdate( ui->lineEdit_tid->text(), decrypt ) ) diff --git a/nand_dump/mainwindow.h b/nand_dump/mainwindow.h index 2553b57..bbd9275 100644 --- a/nand_dump/mainwindow.h +++ b/nand_dump/mainwindow.h @@ -29,6 +29,10 @@ private: void SaveJobToFolder( NusJob job ); void SaveJobToWad( NusJob job ); + //settings + void SaveSettings(); + void LoadSettings(); + public slots: diff --git a/ohneschwanzenegger/mainwindow.cpp b/ohneschwanzenegger/mainwindow.cpp index 86f5813..94c7b1d 100644 --- a/ohneschwanzenegger/mainwindow.cpp +++ b/ohneschwanzenegger/mainwindow.cpp @@ -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( SendText( QString ) ), ui->statusBar, SLOT( showMessage( QString ) ) ); - //TODO, really get these paths from settings -#ifdef Q_WS_WIN - 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 ); + LoadSettings(); + ui->lineEdit_nandPath->setText( "./testNand.bin" ); } MainWindow::~MainWindow() { + SaveSettings(); 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 void MainWindow::GetError( const QString &message, NusJob job ) { diff --git a/ohneschwanzenegger/mainwindow.h b/ohneschwanzenegger/mainwindow.h index d677a6d..8ec2b89 100644 --- a/ohneschwanzenegger/mainwindow.h +++ b/ohneschwanzenegger/mainwindow.h @@ -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 ); bool InstallSharedContent( const QByteArray stuff, const QByteArray hash = QByteArray() ); + void SaveSettings(); + void LoadSettings(); + public slots: //slots for getting info from the NUS downloader void GetError( const QString &message, NusJob job ); diff --git a/ohneschwanzenegger/newnandbin.cpp b/ohneschwanzenegger/newnandbin.cpp index aefb633..2cb1990 100644 --- a/ohneschwanzenegger/newnandbin.cpp +++ b/ohneschwanzenegger/newnandbin.cpp @@ -115,7 +115,7 @@ void NewNandBin::on_buttonBox_accepted() } //add cert.sys 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"; return; diff --git a/saveToy/main.cpp b/saveToy/main.cpp index 3f61ad5..16b9ad0 100644 --- a/saveToy/main.cpp +++ b/saveToy/main.cpp @@ -1,10 +1,10 @@ -#include +#include "../WiiQt/includes.h" #include "mainwindow.h" int main(int argc, char *argv[]) { Q_INIT_RESOURCE( rc ); - QApplication a(argc, argv); + QApplication a(argc, argv); MainWindow w; w.show(); diff --git a/saveToy/mainwindow.cpp b/saveToy/mainwindow.cpp index 42a38d7..f94f7a1 100644 --- a/saveToy/mainwindow.cpp +++ b/saveToy/mainwindow.cpp @@ -10,15 +10,6 @@ #include "quazip.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 ) { ui->setupUi(this); @@ -30,10 +21,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ClearPcGuiInfo(); progressBar.setVisible( false ); ui->statusBar->addPermanentWidget( &progressBar, 0 ); - ngID = 0; - ngKeyID = 0; - - //sneekIconTimer.setInterval( 150 );//delay of icon image animation + LoadSettings(); connect( &bannerthread, SIGNAL( SendProgress( int ) ), this, SLOT( GetProgressUpdate( 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( &pcIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextPcIcon() ) ); - //GetSavesFromSneek( "/media/WiiFat500" ); - //GetSavesFromSneek( sneekPath ); - //GetSavesFromPC( "./saveBackups" ); + //start loading saves if there is a path + if( !sneekPath.isEmpty() ) + { + initialStartup = true; + GetSavesFromSneek( sneekPath ); + } + else if( !pcPath.isEmpty() ) + GetSavesFromPC( pcPath ); } MainWindow::~MainWindow() { + SaveSettings(); 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 void MainWindow::GetSavesFromSneek( const QString &path ) { - qDebug() << "MainWindow::GetSavesFromSneek" << path; + //qDebug() << "MainWindow::GetSavesFromSneek" << path; if( !QFileInfo( path ).exists() ) return; @@ -138,7 +197,20 @@ void MainWindow::GetProgressUpdate( int i ) //something is done working. respond somehow 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 ); } @@ -537,11 +609,11 @@ void MainWindow::on_actionSet_NG_Keys_triggered() ngPriv = d.ngPriv; ngSig = d.ngSig; qDebug() << "accepted"; - qDebug() << hex << d.ngID - << "\n" << d.ngKeyID - << "\n" << d.ngMac.toHex() - << "\n" << d.ngPriv.toHex() - << "\n" << d.ngSig.toHex(); + //qDebug() << hex << d.ngID + // << "\n" << d.ngKeyID + // << "\n" << d.ngMac.toHex() + // << "\n" << d.ngPriv.toHex() + // << "\n" << d.ngSig.toHex(); } //PC list item changed diff --git a/saveToy/mainwindow.h b/saveToy/mainwindow.h index e383a94..8c7e2a8 100644 --- a/saveToy/mainwindow.h +++ b/saveToy/mainwindow.h @@ -15,7 +15,7 @@ class MainWindow : public QMainWindow Q_OBJECT public: - explicit MainWindow(QWidget *parent = 0); + explicit MainWindow( QWidget *parent = 0 ); ~MainWindow(); private: @@ -37,6 +37,7 @@ private: //basepath used for local save backups QString pcPath; + QString sneekPath; //get available filename for backup save inside pcPath QString GetSaveName( quint64 tid ); @@ -56,14 +57,19 @@ private: 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 ); - //clear the data on teh right of the screen + //clear the data on the right of the screen void ClearSneekGuiInfo(); void ClearPcGuiInfo(); + //save/load settings + void SaveSettings(); + void LoadSettings(); + bool initialStartup; + private slots: void on_pushButton_pcInstall_clicked(); - void on_actionSet_Local_Path_triggered(); + void on_actionSet_Local_Path_triggered(); void on_pushButton_pcDelete_clicked(); void on_comboBox_pcSelect_currentIndexChanged(int index); void on_listWidget_pcSaves_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous);