summaryrefslogtreecommitdiff
path: root/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp')
-rw-r--r--plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp100
1 files changed, 92 insertions, 8 deletions
diff --git a/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp b/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp
index fb97ec5..3c7bfc1 100644
--- a/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp
+++ b/plugins/CopyEngine/Ultracopier-0.3/ReadThread.cpp
@@ -33,6 +33,7 @@ void ReadThread::run()
connect(this,SIGNAL(internalStartRead()), this,SLOT(internalRead()), Qt::QueuedConnection);
connect(this,SIGNAL(internalStartClose()), this,SLOT(internalClose()), Qt::QueuedConnection);
connect(this,SIGNAL(checkIfIsWait()), this,SLOT(isInWait()), Qt::QueuedConnection);
+ connect(this,SIGNAL(internalStartChecksum()), this,SLOT(checkSum()), Qt::QueuedConnection);
exec();
}
@@ -69,6 +70,8 @@ void ReadThread::stop()
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] stop()");
stopIt=true;
+ if(isOpen.available()>0)
+ return;
emit internalStartClose();
}
@@ -114,7 +117,6 @@ bool ReadThread::seek(qint64 position)
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] start with: "+QString::number(position));
if(position>file.size())
return false;
- lastGoodPosition=position;
return file.seek(position);
}
@@ -128,6 +130,84 @@ void ReadThread::postOperation()
emit internalStartClose();
}
+void ReadThread::checkSum()
+{
+ QByteArray blockArray;
+ QCryptographicHash hash(QCryptographicHash::Sha1);
+ isInReadLoop=true;
+ lastGoodPosition=0;
+ seek(0);
+ int sizeReaden=0;
+ do
+ {
+ //read one block
+ #ifdef ULTRACOPIER_PLUGIN_DEBUG
+ stat=Read;
+ #endif
+ blockArray=file.read(blockSize);
+ #ifdef ULTRACOPIER_PLUGIN_DEBUG
+ stat=Idle;
+ #endif
+
+ if(file.error()!=QFile::NoError)
+ {
+ errorString_internal=tr("Unable to read the source file: ")+file.errorString()+" ("+QString::number(file.error())+")";
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"["+QString::number(id)+"] "+QString("file.error()!=QFile::NoError: %1, error: %2").arg(QString::number(file.error())).arg(errorString_internal));
+ emit error();
+ isInReadLoop=false;
+ return;
+ }
+ sizeReaden=blockArray.size();
+ if(sizeReaden>0)
+ {
+ #ifdef ULTRACOPIER_PLUGIN_DEBUG
+ stat=Checksum;
+ #endif
+ hash.addData(blockArray);
+ #ifdef ULTRACOPIER_PLUGIN_DEBUG
+ stat=Idle;
+ #endif
+
+ if(stopIt)
+ break;
+
+ lastGoodPosition+=blockArray.size();
+
+ //wait for limitation speed if stop not query
+ if(maxSpeed>0)
+ {
+ numberOfBlockCopied++;
+ if(numberOfBlockCopied>=MultiForBigSpeed)
+ {
+ numberOfBlockCopied=0;
+ waitNewClockForSpeed.acquire();
+ if(stopIt)
+ break;
+ }
+ }
+ }
+ }
+ while(sizeReaden>0 && !stopIt);
+ if(lastGoodPosition>file.size())
+ {
+ errorString_internal=tr("File truncated during the read, possible data change");
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"["+QString::number(id)+"] "+QString("Source truncated during the read: %1 (%2)").arg(file.errorString()).arg(QString::number(file.error())));
+ emit error();
+ isInReadLoop=false;
+ return;
+ }
+ isInReadLoop=false;
+ if(stopIt)
+ {
+ if(putInPause)
+ emit isInPause();
+ stopIt=false;
+ return;
+ }
+ emit checksumFinish(hash.result());
+ ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] stop the read");
+}
+
bool ReadThread::internalOpen(bool resetLastGoodPosition)
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] internalOpen source: "+name);
@@ -156,6 +236,7 @@ bool ReadThread::internalOpen(bool resetLastGoodPosition)
putInPause=false;
if(resetLastGoodPosition)
{
+ lastGoodPosition=0;
seek(0);
emit opened();
}
@@ -274,8 +355,6 @@ void ReadThread::internalRead()
break;
}
}
- /*if(lastGoodPosition>size)
- oversize=lastGoodPosition-size;*/
}
/*
if(lastGoodPosition>16*1024)
@@ -415,15 +494,21 @@ void ReadThread::fakeReadIsStopped()
emit readIsStopped();
}
+/// do the checksum
+void ReadThread::startCheckSum()
+{
+ emit internalStartChecksum();
+}
+
qint64 ReadThread::getLastGoodPosition()
{
- if(lastGoodPosition>file.size())
+ /*if(lastGoodPosition>file.size())
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Critical,"["+QString::number(id)+"] Bug, the lastGoodPosition is greater than the file size!");
return file.size();
}
- else
- return lastGoodPosition;
+ else*/
+ return lastGoodPosition;
}
//reopen after an error
@@ -448,8 +533,7 @@ bool ReadThread::internalReopen()
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Warning,"["+QString::number(id)+"] source file have changed since the last open, restart all");
//fix this function like the close function
- lastGoodPosition=0;
- if(internalOpen(false))
+ if(internalOpen(true))
{
emit resumeAfterErrorByRestartAll();
return true;