* setting.txt dialog knows different regions

* make the button for selecting the NUS_Cache path actually do something in the 2 programs that use NUS
* default NUS_cache is up 2 directories in windoze
* allow reading bad blocks from a txt file when creating a blank nand
This commit is contained in:
giantpune@gmail.com 2010-12-22 00:25:08 +00:00
parent d0490cce4c
commit 30f8070e81
11 changed files with 143 additions and 23 deletions

View File

@ -2,7 +2,7 @@
#include "tools.h" #include "tools.h"
NusDownloader::NusDownloader( QObject *parent, const QString &cPath ) : QObject( parent ), cachePath( cPath ), curTmd( QByteArray() )//, manager( this ) NusDownloader::NusDownloader( QObject *parent, const QString &cPath ) : QObject( parent ), cachePath( cPath ), curTmd( QByteArray() )
{ {
currentJob.tid = 0; currentJob.tid = 0;
currentJob.version = 0; currentJob.version = 0;

View File

@ -2,7 +2,7 @@
#include "ui_settingtxtdialog.h" #include "ui_settingtxtdialog.h"
#include "tools.h" #include "tools.h"
SettingTxtDialog::SettingTxtDialog( QWidget *parent, const QByteArray &old ) : QDialog(parent), ui(new Ui::SettingTxtDialog) SettingTxtDialog::SettingTxtDialog( QWidget *parent, const QByteArray &old, qint8 region ) : QDialog(parent), ui(new Ui::SettingTxtDialog)
{ {
ui->setupUi( this ); ui->setupUi( this );
if( !old.isEmpty() ) if( !old.isEmpty() )
@ -62,6 +62,36 @@ SettingTxtDialog::SettingTxtDialog( QWidget *parent, const QByteArray &old ) : Q
} }
} }
} }
else
{
switch( region )
{
case SETTING_TXT_PAL:
ui->lineEdit_area->setText( "EUR" );
ui->lineEdit_model->setText( "RVL-001(EUR)" );
ui->lineEdit_code->setText( "LEH" );
ui->lineEdit_video->setText( "PAL" );
ui->lineEdit_game->setText( "EU" );
break;
case SETTING_TXT_JAP:
ui->lineEdit_area->setText( "JPN" );
ui->lineEdit_model->setText( "RVL-001(JPN)" );
ui->lineEdit_code->setText( "LJF" );
ui->lineEdit_video->setText( "NTSC" );
ui->lineEdit_game->setText( "JP" );
break;
case SETTING_TXT_KOR:
ui->lineEdit_area->setText( "KOR" );
ui->lineEdit_model->setText( "RVL-001(KOR)" );
ui->lineEdit_code->setText( "LKM" );
ui->lineEdit_video->setText( "NTSC" );
ui->lineEdit_game->setText( "KR" );
break;
case SETTING_TXT_USA://these are already the default values
default:
break;
}
}
} }
SettingTxtDialog::~SettingTxtDialog() SettingTxtDialog::~SettingTxtDialog()
@ -107,9 +137,9 @@ QByteArray SettingTxtDialog::LolCrypt( QByteArray ba )
return ret; return ret;
} }
QByteArray SettingTxtDialog::Edit( QWidget *parent, const QByteArray &old ) QByteArray SettingTxtDialog::Edit( QWidget *parent, const QByteArray &old, qint8 region )
{ {
SettingTxtDialog d( parent, old ); SettingTxtDialog d( parent, old, region );
if( d.exec() ) if( d.exec() )
return d.ret; return d.ret;
return QByteArray(); return QByteArray();

View File

@ -8,20 +8,29 @@
namespace Ui { namespace Ui {
class SettingTxtDialog; class SettingTxtDialog;
} }
enum
{
SETTING_TXT_JAP = 0,
SETTING_TXT_USA,
SETTING_TXT_PAL,
SETTING_TXT_KOR,
SETTING_TXT_UNK
};
class SettingTxtDialog : public QDialog class SettingTxtDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SettingTxtDialog( QWidget *parent = 0, const QByteArray &old = QByteArray() ); explicit SettingTxtDialog( QWidget *parent = 0, const QByteArray &old = QByteArray(), qint8 region = SETTING_TXT_UNK );
~SettingTxtDialog(); ~SettingTxtDialog();
//displays a dialog window with teh given parent. if any data is ginev as old, it will try to populate the dialog with that //displays a dialog window with the given parent. if any data is given as old, it will try to populate the dialog with that
// otherwise it will use the defaulte values // otherwise it will use the defaulte values
// returns empty if the user clicked cancel, or a bytearray containing an encrypted setting.txt if they clicked ok // returns empty if the user clicked cancel, or a bytearray containing an encrypted setting.txt if they clicked ok
// the data is ready for writing to a wii nand // the data is ready for writing to a wii nand
static QByteArray Edit( QWidget *parent = 0, const QByteArray &old = QByteArray() ); // if an empty byte array is given as old, a region can be specified to populate default values instaed
static QByteArray Edit( QWidget *parent = 0, const QByteArray &old = QByteArray(), qint8 region = SETTING_TXT_UNK );
static QByteArray LolCrypt( QByteArray ba ); static QByteArray LolCrypt( QByteArray ba );
private: private:

View File

@ -96,7 +96,7 @@
<item row="5" column="1"> <item row="5" column="1">
<widget class="QLineEdit" name="lineEdit_serno"> <widget class="QLineEdit" name="lineEdit_serno">
<property name="text"> <property name="text">
<string>622011873</string> <string>632011873</string>
</property> </property>
<property name="maxLength"> <property name="maxLength">
<number>9</number> <number>9</number>

View File

@ -22,7 +22,11 @@ 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
QString cachePath = "../../NUS_cache";
#else
QString cachePath = "../NUS_cache"; QString cachePath = "../NUS_cache";
#endif
QString nandPath = "./dump"; QString nandPath = "./dump";
@ -32,12 +36,7 @@ MainWindow::MainWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::M
//nand.SetPath( nandPath ); //nand.SetPath( nandPath );
nus.SetCachePath( cachePath ); nus.SetCachePath( cachePath );
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -92,7 +91,14 @@ void MainWindow::NusIsDone()
QByteArray set = nand.GetSettingTxt(); QByteArray set = nand.GetSettingTxt();
if( set.isEmpty() ) if( set.isEmpty() )
{ {
set = SettingTxtDialog::Edit( this ); quint8 reg = SETTING_TXT_UNK;
if( ui->lineEdit_tid->text().endsWith( "e", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_PAL;
if( ui->lineEdit_tid->text().endsWith( "j", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_JAP;
if( ui->lineEdit_tid->text().endsWith( "k", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_KOR;
set = SettingTxtDialog::Edit( this, QByteArray(), reg );
if( !set.isEmpty() ) if( !set.isEmpty() )
nand.SetSettingTxt( set ); nand.SetSettingTxt( set );
} }
@ -409,7 +415,7 @@ void MainWindow::SaveJobToFolder( NusJob job )
ShowMessage( tr( "Wrote title to %1" ).arg( fi.absoluteFilePath() + "/" + newFName ) ); ShowMessage( tr( "Wrote title to %1" ).arg( fi.absoluteFilePath() + "/" + newFName ) );
} }
//save a conpleted job to wad //save a completed job to wad
void MainWindow::SaveJobToWad( NusJob job ) void MainWindow::SaveJobToWad( NusJob job )
{ {
QString title = QString( "%1v%2" ).arg( job.tid, 16, 16, QChar( '0' ) ).arg( job.version ); QString title = QString( "%1v%2" ).arg( job.tid, 16, 16, QChar( '0' ) ).arg( job.version );
@ -463,3 +469,13 @@ void MainWindow::SaveJobToWad( NusJob job )
} }
void MainWindow::on_pushButton_CachePathBrowse_clicked()
{
QString f = QFileDialog::getExistingDirectory( this, tr( "Select NUS Cache base folder" ) );
if( f.isEmpty() )
return;
ui->lineEdit_cachePath->setText( f );
nus.SetCachePath( ui->lineEdit_cachePath->text() );
}

View File

@ -39,6 +39,7 @@ public slots:
private slots: private slots:
void on_pushButton_CachePathBrowse_clicked();
void on_actionFlush_triggered(); void on_actionFlush_triggered();
void on_actionSetting_txt_triggered(); void on_actionSetting_txt_triggered();
void on_actionImportWad_triggered(); void on_actionImportWad_triggered();

View File

@ -32,15 +32,16 @@ MainWindow::MainWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::M
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 //TODO, really get these paths from settings
#ifdef Q_WS_WIN
QString cachePath = "../../NUS_cache";
#else
QString cachePath = "../NUS_cache"; QString cachePath = "../NUS_cache";
#endif
QString nandPath = "./testNand.bin"; QString nandPath = "./testNand.bin";
//QString keyPath = "../keys.bin";
ui->lineEdit_cachePath->setText( cachePath ); ui->lineEdit_cachePath->setText( cachePath );
ui->lineEdit_nandPath->setText( nandPath ); ui->lineEdit_nandPath->setText( nandPath );
//ui->lineEdit_keys->setText( keyPath );
nus.SetCachePath( cachePath ); nus.SetCachePath( cachePath );
} }
@ -91,7 +92,14 @@ void MainWindow::NusIsDone()
QTreeWidgetItem *item = ItemFromPath( "/title/00000001/00000002/data/setting.txt" ); QTreeWidgetItem *item = ItemFromPath( "/title/00000001/00000002/data/setting.txt" );
if( !item ) if( !item )
{ {
QByteArray ba = SettingTxtDialog::Edit( this ); //call a dialog to create a new setting.txt quint8 reg = SETTING_TXT_UNK;
if( ui->lineEdit_tid->text().endsWith( "e", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_PAL;
if( ui->lineEdit_tid->text().endsWith( "j", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_JAP;
if( ui->lineEdit_tid->text().endsWith( "k", Qt::CaseInsensitive ) && ui->lineEdit_tid->text().size() == 4 )
reg = SETTING_TXT_KOR;
QByteArray ba = SettingTxtDialog::Edit( this, QByteArray(), reg ); //call a dialog to create a new setting.txt
if( !ba.isEmpty() ) //if the dialog returned anything ( cancel wasnt pressed ) write that new setting.txt to the nand if( !ba.isEmpty() ) //if the dialog returned anything ( cancel wasnt pressed ) write that new setting.txt to the nand
{ {
quint16 r = nand.CreateEntry( "/title/00000001/00000002/data/setting.txt", 0x1000, 1, NAND_FILE, NAND_READ, NAND_READ, NAND_READ ); quint16 r = nand.CreateEntry( "/title/00000001/00000002/data/setting.txt", 0x1000, 1, NAND_FILE, NAND_READ, NAND_READ, NAND_READ );
@ -201,6 +209,15 @@ void MainWindow::on_pushButton_nandPath_clicked()
return; return;
ui->lineEdit_nandPath->setText( f ); ui->lineEdit_nandPath->setText( f );
}
void MainWindow::on_pushButton_CachePathBrowse_clicked()
{
QString f = QFileDialog::getExistingDirectory( this, tr( "Select NUS Cache base folder" ) );
if( f.isEmpty() )
return;
ui->lineEdit_cachePath->setText( f );
nus.SetCachePath( ui->lineEdit_cachePath->text() ); nus.SetCachePath( ui->lineEdit_cachePath->text() );
} }

View File

@ -54,6 +54,7 @@ public slots:
void ReceiveTitleFromNus( NusJob job ); void ReceiveTitleFromNus( NusJob job );
private slots: private slots:
void on_pushButton_CachePathBrowse_clicked();
void on_actionAbout_triggered(); void on_actionAbout_triggered();
void on_pushButton_initNand_clicked(); void on_pushButton_initNand_clicked();
void on_actionNew_nand_from_keys_triggered(); void on_actionNew_nand_from_keys_triggered();

View File

@ -4,6 +4,7 @@
NewNandBin::NewNandBin( QWidget *parent, QList<quint16> badBlocks ) : QDialog(parent), ui(new Ui::NewNandBin), nand( this ) NewNandBin::NewNandBin( QWidget *parent, QList<quint16> badBlocks ) : QDialog(parent), ui(new Ui::NewNandBin), nand( this )
{ {
dir = QDir::currentPath();
ui->setupUi(this); ui->setupUi(this);
foreach( quint16 block, badBlocks ) foreach( quint16 block, badBlocks )
{ {
@ -20,26 +21,29 @@ NewNandBin::~NewNandBin()
void NewNandBin::on_pushButton_keys_clicked() void NewNandBin::on_pushButton_keys_clicked()
{ {
QString f = QFileDialog::getOpenFileName( this, tr( "Select Keys.bin" ) ); QString f = QFileDialog::getOpenFileName( this, tr( "Select Keys.bin" ), dir );
if( f.isEmpty() ) if( f.isEmpty() )
return; return;
ui->lineEdit_keys->setText( f ); ui->lineEdit_keys->setText( f );
dir = QFileInfo( f ).canonicalPath();
} }
void NewNandBin::on_pushButton_boot_clicked() void NewNandBin::on_pushButton_boot_clicked()
{ {
QString f = QFileDialog::getOpenFileName( this, tr( "Select Boot 1 & 2" ) ); QString f = QFileDialog::getOpenFileName( this, tr( "Select Boot 1 & 2" ), dir );
if( f.isEmpty() ) if( f.isEmpty() )
return; return;
ui->lineEdit_boot->setText( f ); ui->lineEdit_boot->setText( f );
dir = QFileInfo( f ).canonicalPath();
} }
void NewNandBin::on_pushButton_dest_clicked() void NewNandBin::on_pushButton_dest_clicked()
{ {
QString f = QFileDialog::getSaveFileName( this, tr( "Output file" ) ); QString f = QFileDialog::getSaveFileName( this, tr( "Output file" ), dir );
if( f.isEmpty() ) if( f.isEmpty() )
return; return;
ui->lineEdit_dest->setText( f ); ui->lineEdit_dest->setText( f );
dir = QFileInfo( f ).canonicalPath();
} }
QList<quint16> NewNandBin::BadBlocks() QList<quint16> NewNandBin::BadBlocks()
@ -62,7 +66,6 @@ void NewNandBin::on_pushButton_bb_add_clicked()
if( !BadBlocks().contains( val ) ) if( !BadBlocks().contains( val ) )
{ {
ui->listWidget_badBlocks->addItem( QString( "%1" ).arg( val ) ); ui->listWidget_badBlocks->addItem( QString( "%1" ).arg( val ) );
//QListWidgetItem *i = new QListWidgetItem( QString( "%1" ).arg( val ), ui->listWidget_badBlocks );
} }
} }
@ -121,3 +124,37 @@ QString NewNandBin::GetNewNandPath( QWidget *parent, QList<quint16> badBlocks )
return QString(); return QString();
return d.ret; return d.ret;
} }
//read bad blocks from a txt file
void NewNandBin::on_pushButton_badBlockFile_clicked()
{
QString f = QFileDialog::getOpenFileName( this, tr( "Select File with Bad Block List" ), dir );
if( f.isEmpty() )
return;
dir = QFileInfo( f ).canonicalPath();
QString str = QString( ReadFile( f ) );
if( str.isEmpty() )
{
qWarning() << "NewNandBin::on_pushButton_badBlockFile_clicked -> error reading file";
return;
}
ui->listWidget_badBlocks->clear();
str.replace( "\r\n", "\n" );
QStringList lines = str.split( "\n", QString::SkipEmptyParts );
foreach( QString line, lines )
{
if( line.size() > 5 )
continue;
bool ok = false;
if( ui->listWidget_badBlocks->findItems( line, Qt::MatchExactly ).size() )//this one is already in the list
continue;
quint16 bb = line.toInt( &ok );
if( !ok || bb < 8 || bb > 4079 )
continue;
ui->listWidget_badBlocks->addItem( line );
}
}

View File

@ -25,8 +25,10 @@ private:
NandBin nand; NandBin nand;
QString ret; QString ret;
QString dir;
private slots: private slots:
void on_pushButton_badBlockFile_clicked();
void on_buttonBox_accepted(); void on_buttonBox_accepted();
void on_pushButton_bb_rm_clicked(); void on_pushButton_bb_rm_clicked();
void on_pushButton_bb_add_clicked(); void on_pushButton_bb_add_clicked();

View File

@ -138,6 +138,13 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QPushButton" name="pushButton_badBlockFile">
<property name="text">
<string>From txt...</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">