mirror of
https://github.com/martravi/wiiqt6.git
synced 2024-12-25 20:41:47 +01:00
* forgotten files
git-svn-id: http://wiiqt.googlecode.com/svn/trunk@16 389f4c8b-5dfe-645f-db0e-df882bc27289
This commit is contained in:
parent
cc7d47f3ab
commit
034e487a31
152
nandExtract/nandthread.cpp
Normal file
152
nandExtract/nandthread.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
#include "nandthread.h"
|
||||
|
||||
NandThread::NandThread( QObject *parent ) : QThread( parent )
|
||||
{
|
||||
abort = false;
|
||||
itemToExtract = NULL;
|
||||
|
||||
connect( &nandBin, SIGNAL( SendError( QString ) ), this, SLOT( GetError( QString ) ) );
|
||||
connect( &nandBin, SIGNAL( SendText( QString ) ), this, SLOT( GetStatusUpdate( QString ) ) );
|
||||
}
|
||||
|
||||
void NandThread::ForceQuit()
|
||||
{
|
||||
mutex.lock();
|
||||
abort = true;
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
NandThread::~NandThread()
|
||||
{
|
||||
mutex.lock();
|
||||
abort = true;
|
||||
condition.wakeOne();
|
||||
mutex.unlock();
|
||||
wait();
|
||||
|
||||
if( itemToExtract )
|
||||
delete itemToExtract;
|
||||
}
|
||||
|
||||
bool NandThread::IsRunning()
|
||||
{
|
||||
return isRunning();
|
||||
}
|
||||
|
||||
bool NandThread::SetPath( const QString &path )
|
||||
{
|
||||
if( isRunning() )
|
||||
{
|
||||
emit SendError( tr( "Wait till the current job is done" ) );
|
||||
return false;
|
||||
}
|
||||
return nandBin.SetPath( path );
|
||||
}
|
||||
|
||||
QTreeWidgetItem *NandThread::GetTree()
|
||||
{
|
||||
if( isRunning() )
|
||||
{
|
||||
emit SendError( tr( "Wait till the current job is done" ) );
|
||||
return NULL;
|
||||
}
|
||||
return nandBin.GetTree();
|
||||
}
|
||||
|
||||
bool NandThread::InitNand( QIcon dirs, QIcon files )
|
||||
{
|
||||
if( isRunning() )
|
||||
{
|
||||
emit SendError( tr( "Wait till the current job is done" ) );
|
||||
return false;
|
||||
}
|
||||
return nandBin.InitNand( dirs, files );
|
||||
}
|
||||
|
||||
const QList<quint16> NandThread::GetFats()
|
||||
{
|
||||
return nandBin.GetFats();
|
||||
}
|
||||
|
||||
const QList<quint16> NandThread::GetFatsForFile( quint16 i )
|
||||
{
|
||||
return nandBin.GetFatsForFile( i );
|
||||
}
|
||||
|
||||
void NandThread::Extract( QTreeWidgetItem *item, const QString &path )
|
||||
{
|
||||
if( isRunning() )
|
||||
{
|
||||
emit SendError( tr( "This thread is already doing something. Please wait." ) );
|
||||
return;
|
||||
}
|
||||
if( !item )
|
||||
{
|
||||
emit SendError( tr( "Oh Noez!! I was told to extract with a pointer to NULL :( ." ) );
|
||||
return;
|
||||
}
|
||||
abort = false;
|
||||
extractPath = path;
|
||||
itemToExtract = item->clone();
|
||||
|
||||
|
||||
|
||||
start( NormalPriority );
|
||||
}
|
||||
|
||||
void NandThread::run()
|
||||
{
|
||||
if( abort )
|
||||
{
|
||||
qDebug( "NandThread::run -> Thread abort" );
|
||||
return;
|
||||
}
|
||||
mutex.lock();
|
||||
if( extractPath.isEmpty() )
|
||||
{
|
||||
qDebug() << "NandThread::run -> its empty";
|
||||
return;
|
||||
}
|
||||
fileCnt = FileCount( itemToExtract );
|
||||
idx = 0;
|
||||
mutex.unlock();
|
||||
emit SendProgress( 0 );
|
||||
|
||||
nandBin.ExtractToDir( itemToExtract, extractPath );
|
||||
|
||||
delete itemToExtract;
|
||||
itemToExtract = NULL;
|
||||
emit SendProgress( 100 );
|
||||
emit SendExtractDone();
|
||||
}
|
||||
|
||||
quint32 NandThread::FileCount( QTreeWidgetItem *item )
|
||||
{
|
||||
if( item->text( 6 ) == "00" )//its a folder, recurse through it and count all the files
|
||||
{
|
||||
quint32 ret = 0;
|
||||
quint16 cnt = item->childCount();
|
||||
for( quint16 i = 0; i < cnt; i++ )
|
||||
{
|
||||
ret += FileCount( item->child( i ) ) ;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
//not a folder, must be a file. just return 1
|
||||
return 1;
|
||||
}
|
||||
|
||||
void NandThread::GetStatusUpdate( QString s )
|
||||
{
|
||||
emit SendText( s );
|
||||
emit SendProgress( (int)( ( (float)( idx++ ) / (float)fileCnt ) * (float)100 ) );
|
||||
}
|
||||
|
||||
//just send errors from the nand object to the mainwindow
|
||||
void NandThread::GetError( QString str )
|
||||
{
|
||||
emit SendError( str );
|
||||
}
|
||||
|
||||
|
||||
|
65
nandExtract/nandthread.h
Normal file
65
nandExtract/nandthread.h
Normal file
@ -0,0 +1,65 @@
|
||||
#ifndef NANDTHREAD_H
|
||||
#define NANDTHREAD_H
|
||||
|
||||
#include "../WiiQt/includes.h"
|
||||
#include "../WiiQt/nandbin.h"
|
||||
|
||||
|
||||
//TODO: this thread really isnt setup to be inturruptable. especially while it is extracting the full nand.bin
|
||||
class NandThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
NandThread( QObject *parent = 0 );
|
||||
~NandThread();
|
||||
|
||||
bool IsRunning();
|
||||
|
||||
//these just call the same function of the nand.bin object
|
||||
// dont use them if the thread is running ( it is busy extracting )
|
||||
// wait till after SendExtractDone() is emitted
|
||||
bool SetPath( const QString &path );
|
||||
QTreeWidgetItem *GetTree();
|
||||
bool InitNand( QIcon dirs = QIcon(), QIcon files = QIcon() );
|
||||
const QList<quint16> GetFats();
|
||||
const QList<quint16> GetFatsForFile( quint16 i );
|
||||
|
||||
|
||||
//extract some stuff from a nand.bin in a thread so the gui doesn't freeze up
|
||||
void Extract( QTreeWidgetItem *item, const QString &path );
|
||||
void ForceQuit();
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
signals:
|
||||
void SendProgress( int );
|
||||
void SendExtractDone();
|
||||
void SendText( QString );
|
||||
void SendError( QString );
|
||||
|
||||
private:
|
||||
QMutex mutex;
|
||||
QWaitCondition condition;
|
||||
|
||||
QString extractPath;
|
||||
QTreeWidgetItem *itemToExtract;
|
||||
NandBin nandBin;
|
||||
|
||||
|
||||
quint32 fileCnt;
|
||||
quint32 idx;
|
||||
|
||||
bool abort;
|
||||
|
||||
//count the number of files in a given folder
|
||||
quint32 FileCount( QTreeWidgetItem *item );
|
||||
|
||||
|
||||
public slots:
|
||||
void GetError( QString );
|
||||
void GetStatusUpdate( QString );
|
||||
};
|
||||
|
||||
#endif // NANDTHREAD_H
|
Loading…
Reference in New Issue
Block a user