diff --git a/nandExtract/black.png b/nandExtract/black.png index 060039d..512bae2 100755 Binary files a/nandExtract/black.png and b/nandExtract/black.png differ diff --git a/nandExtract/blue.png b/nandExtract/blue.png index 974f56e..4fbfe36 100755 Binary files a/nandExtract/blue.png and b/nandExtract/blue.png differ diff --git a/nandExtract/green.png b/nandExtract/green.png index e83e3b9..62d6ffb 100755 Binary files a/nandExtract/green.png and b/nandExtract/green.png differ diff --git a/nandExtract/grey.png b/nandExtract/grey.png index 803096b..cc0ee27 100755 Binary files a/nandExtract/grey.png and b/nandExtract/grey.png differ diff --git a/nandExtract/nandwindow.cpp b/nandExtract/nandwindow.cpp index 3c00a2a..4a5303a 100755 --- a/nandExtract/nandwindow.cpp +++ b/nandExtract/nandwindow.cpp @@ -1,39 +1,18 @@ #include "nandwindow.h" #include "ui_nandwindow.h" +#include "../WiiQt/tools.h" NandWindow::NandWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::NandWindow ), nThread( this ) { ui->setupUi( this ); - freeSpace = 0; //setup the block map - ui->graphicsView_blocks->setScene( &gv ); - ui->graphicsView_blocks->setAlignment( Qt::AlignRight ); - ui->graphicsView_blocks->setRenderHint( QPainter::Antialiasing ); - - QPixmap blue( ":/blue.png" ); - QPixmap green( ":/green.png" ); - QPixmap pink( ":/pink.png" ); - QPixmap grey( ":/grey.png" ); - - quint16 i = 0; - for( quint16 y = 0; y < 352; y += 11 ) - { - for( quint16 x = 0; x < 1408; x += 11 ) - { - pmi[ i ] = new QGraphicsPixmapItem( grey ); - pmi[ i ]->setPos( x, y ); - gv.addItem( pmi[ i ] );//items belong to this now. no need to delete them - - i++; - } - } + SetUpBlockMap(); //put the progressbar on the status bar ui->progressBar->setVisible( false ); ui->statusBar->addPermanentWidget( ui->progressBar, 0 ); - //ui->treeWidget->header()->resizeSection( 0, 300 );//name QFontMetrics fm( fontMetrics() ); ui->treeWidget->header()->resizeSection( 0, fm.width( QString( 22, 'W' ) ) );//name ui->treeWidget->header()->resizeSection( 1, fm.width( "WWWWW" ) );//entry # @@ -44,13 +23,11 @@ NandWindow::NandWindow( QWidget *parent ) : QMainWindow( parent ), ui( new Ui::N ui->treeWidget->header()->resizeSection( 6, fm.width( "WWWWW" ) );//mode ui->treeWidget->header()->resizeSection( 7, fm.width( "WWWWW" ) );//attr - - //connect( &nandBin, SIGNAL( SendError( QString ) ), this, SLOT( GetError( QString ) ) ); - //connect( &nandBin, SIGNAL( SendText( QString ) ), this, SLOT( GetStatusUpdate( QString ) ) ); connect( &nThread, SIGNAL( SendError( QString ) ), this, SLOT( GetError( QString ) ) ); connect( &nThread, SIGNAL( SendText( QString ) ), this, SLOT( GetStatusUpdate( QString ) ) ); connect( &nThread, SIGNAL( SendExtractDone() ), this, SLOT( ThreadIsDone() ) ); connect( &nThread, SIGNAL( SendProgress( int ) ), ui->progressBar, SLOT( setValue( int ) ) ); + } NandWindow::~NandWindow() @@ -58,6 +35,80 @@ NandWindow::~NandWindow() delete ui; } +void NandWindow::SetUpBlockMap() +{ + ui->graphicsView_blocks->setScene( &gv ); + + QPixmap grey( ":/grey.png" ); + + quint16 i = 0; + for( quint16 y = 0; y < 288; y += 9 ) //create all the blocks and make them grey + { + for( quint16 x = 0; x < 1152; x += 9 ) + { + pmi[ i ] = new QGraphicsPixmapItem( grey ); + pmi[ i ]->setPos( x, y ); + gv.addItem( pmi[ i ] );//items belong to this now. no need to delete them + + i++; + } + } + QFontMetrics fm( fontMetrics() ); + + quint16 y = 288; + quint16 x = 10; + quint16 x2 = 200; + quint8 spacing = 5; + + fileSize = new QGraphicsTextItem(); + fileSize->setPos( x, y ); + nandSize = new QGraphicsTextItem(); + nandSize->setPos( x + 400, y ); + + y += fm.height() + 2; + + QGraphicsTextItem *badText = new QGraphicsTextItem( tr( "Bad" ) ); + QGraphicsTextItem *freeText = new QGraphicsTextItem( tr( "Free" ) ); + QGraphicsTextItem *usedText = new QGraphicsTextItem( tr( "Used" ) ); + QGraphicsTextItem *used2Text = new QGraphicsTextItem( tr( "Selected file" ) ); + QGraphicsTextItem *resText = new QGraphicsTextItem( tr( "Reserved" ) ); + + QGraphicsPixmapItem *greySquare = new QGraphicsPixmapItem( grey ); + QGraphicsPixmapItem *blackSquare = new QGraphicsPixmapItem( QPixmap( ":/black.png" ) ); + QGraphicsPixmapItem *blueSquare = new QGraphicsPixmapItem( QPixmap( ":/blue.png" ) ); + QGraphicsPixmapItem *greenSquare = new QGraphicsPixmapItem( QPixmap( ":/green.png" ) ); + QGraphicsPixmapItem *pinkSquare = new QGraphicsPixmapItem( QPixmap( ":/pink.png" ) ); + + greySquare->setPos( x, y + fm.height() / 2 ); + freeText->setPos( greySquare->pos().x() + 8 + spacing, y ); + greenSquare->setPos( x2, y + fm.height() / 2 ); + usedText->setPos( greenSquare->pos().x() + 8 + spacing, y ); + y += fontMetrics().height() + 2; + + blackSquare->setPos( x, y + fm.height() / 2 ); + badText->setPos( blackSquare->pos().x() + 8 + spacing, y ); + pinkSquare->setPos( x2, y + fm.height() / 2 ); + used2Text->setPos( pinkSquare->pos().x() + 8 + spacing, y ); + y += fontMetrics().height() + 2; + + blueSquare->setPos( x, y + fm.height() / 2 ); + resText->setPos( blueSquare->pos().x() + 8 + spacing, y ); + + gv.addItem( fileSize ); + gv.addItem( nandSize ); + gv.addItem( badText ); + gv.addItem( freeText ); + gv.addItem( usedText ); + gv.addItem( used2Text ); + gv.addItem( resText ); + gv.addItem( greySquare ); + gv.addItem( blackSquare ); + gv.addItem( blueSquare ); + gv.addItem( greenSquare ); + gv.addItem( pinkSquare ); + +} + void NandWindow::ThreadIsDone() { qDebug() << "NandWindow::ThreadIsDone"; @@ -172,7 +223,7 @@ void NandWindow::on_actionOpen_Nand_triggered() void NandWindow::GetBlocksfromNand() { blocks.clear(); - freeSpace = 0; + quint32 freeSpace = 0; QList clusters = nThread.GetFats(); if( !clusters.size() == 0x8000 ) @@ -180,30 +231,33 @@ void NandWindow::GetBlocksfromNand() QMessageBox::warning( this, tr( "Error" ), tr( "Expected 0x8000 clusters from the nand, but got %1 instead!" ).arg( clusters.size(), 0, 16 ), QMessageBox::Ok ); return; } - //QString str; + for( quint16 i = 0; i < 0x8000; i += 8 )//first cluster of each block. { quint16 thisBlock = clusters.at( i ); - //str += QString( "%1 " ).arg( thisBlock, 4, 16 ); if( thisBlock == 0xFFFC || thisBlock == 0xFFFD ) { - //qDebug() << "adding" << hex << thisBlock; blocks << thisBlock; continue; } - bool used = 0; + bool used = false; for( quint16 j = i; j < i + 8; j++ )//each individual cluster { - thisBlock = clusters.at( i ); - if( thisBlock == 0xFFFE ) - freeSpace += 0x800; + if( clusters.at( j ) == 0xFFFE ) + freeSpace += 0x4000; else used = true; } blocks << ( used ? 1 : 0xfffe ); // just put 1 for used blocks } + quint32 used = 0x20000000 - freeSpace; + float per = (float)((float)used/(float)0x20000000) * 100.0f; + float usedMb = (float)((float)used/(float)0x100000); + + nandSize->setHtml( QString( "%1Mib ( %2 % ) used" ).arg( usedMb, 3, 'f', 2 ).arg( per, 3, 'f', 2 ) ); + } @@ -320,7 +374,34 @@ void NandWindow::on_treeWidget_currentItemChanged( QTreeWidgetItem* current, QTr return; } - QList blocks = ToBlocks( nThread.GetFatsForFile( entry ) ); - //qDebug() << "blocks for" << current->text( 0 ) << blocks; + QList clusters = nThread.GetFatsForFile( entry ); + QList blocks = ToBlocks( clusters ); + DrawBlockMap( blocks ); + float size = current->text( 2 ).toInt( &ok, 16 ); + if( !ok ) + { + qDebug() << "error converting" << current->text( 2 ) << "to int"; + return; + } + QString unit = "bytes"; + if( size > 1024 ) + { + unit = "KiB"; + size /= 1024.0f; + } + if( size > 1024 ) + { + unit = "MiB"; + size /= 1024.0f; + } + QString clusterStr = clusters.size() == 1 ? tr( "%1 cluster" ).arg( 1 ) : tr( "%1 clusters" ).arg( clusters.size() ); + QString blockStr = blocks.size() == 1 ? tr( "%1 block" ).arg( 1 ) : tr( "%1 blocks" ).arg( blocks.size() ); + QString sizeStr = QString( "( %1 %2 )" ).arg( size, 0, 'f', 2 ).arg( unit ); + + + fileSize->setHtml( QString( "%1 - %2 in %3 %4" ).arg( current->text( 0 ) ).arg( clusterStr ).arg( blockStr ).arg( sizeStr ) ); + //qDebug() << "blocks for" << current->text( 0 ) << blocks; + } + diff --git a/nandExtract/nandwindow.h b/nandExtract/nandwindow.h index 8df0f59..9261268 100755 --- a/nandExtract/nandwindow.h +++ b/nandExtract/nandwindow.h @@ -24,14 +24,21 @@ private: NandThread nThread; + void SetUpBlockMap(); + //changes the blocks in the blockmap with different colors void DrawBlockMap( QList newFile = QList() ); - QGraphicsScene gv;//scene to hold the blockmap images - QGraphicsPixmapItem *pmi[ 0x1000 ];//pointers to all the blocks in the display - //quint16 ClusterToBlock( quint16 cluster ); + QGraphicsScene gv; //scene to hold the blockmap images + QGraphicsPixmapItem *pmi[ 0x1000 ]; //pointers to all the blocks in the display - QList blocks; - quint32 freeSpace; + QGraphicsTextItem *nandSize; //pointers to the items to show info under the blockmap + QGraphicsTextItem *fileSize; + /*QGraphicsTextItem *badText; + QGraphicsTextItem *freeText; + QGraphicsTextItem *usedText; + QGraphicsTextItem *resText;*/ + + QList blocks; //hold a list of what the blocks in the nand are used for void GetBlocksfromNand(); QList ToBlocks( QList clusters ); @@ -48,6 +55,10 @@ private slots: void on_actionShow_Usage_triggered(); void on_actionOpen_Nand_triggered(); void on_treeWidget_customContextMenuRequested(QPoint pos); + //void ScaleBlockMap(); + +protected: + //void resizeEvent( QResizeEvent* event ); }; #endif // NANDWINDOW_H diff --git a/nandExtract/nandwindow.ui b/nandExtract/nandwindow.ui index a1d6b94..ae47522 100755 --- a/nandExtract/nandwindow.ui +++ b/nandExtract/nandwindow.ui @@ -6,85 +6,91 @@ 0 0 - 930 - 472 + 1180 + 654 NandWindow - + + + 0 + 2 - - 2 - - - - - Qt::CustomContextMenu + + + + Qt::Vertical - - - Name + + + Qt::CustomContextMenu - - - - Entry + + + Name + + + + + Entry + + + + + Size + + + + + uid + + + + + gid + + + + + x3 + + + + + Mode + + + + + Attr + + + + + + Qt::ScrollBarAlwaysOn - - - - Size + + false - - - - uid + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - gid + + QPainter::HighQualityAntialiasing|QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing - - - - x3 + + QGraphicsView::CacheBackground - - - - Mode - - - - - Attr - - + - - - - false - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - QPainter::Antialiasing|QPainter::HighQualityAntialiasing|QPainter::SmoothPixmapTransform|QPainter::TextAntialiasing - - - QGraphicsView::CacheBackground - - - - + @@ -104,7 +110,7 @@ 0 0 - 930 + 1180 27 @@ -141,6 +147,12 @@ + + true + + + true + Show Usage... @@ -151,5 +163,22 @@ - + + + actionShow_Usage + toggled(bool) + graphicsView_blocks + setVisible(bool) + + + -1 + -1 + + + 309 + 351 + + + + diff --git a/nandExtract/pink.png b/nandExtract/pink.png index 36afc61..138a116 100755 Binary files a/nandExtract/pink.png and b/nandExtract/pink.png differ