Пример #1
0
void WriteThread::checkSum()
{
	//QByteArray blockArray;
	QCryptographicHash hash(QCryptographicHash::Sha1);
	endDetected=false;
	lastGoodPosition=0;
	file.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();
			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();
		return;
	}
	if(stopIt)
	{
/*		if(putInPause)
			emit isInPause();*/
		stopIt=false;
		return;
	}
	emit checksumFinish(hash.result());
	ULTRACOPIER_DEBUGCONSOLE(DebugLevel_Notice,"["+QString::number(id)+"] stop the read");
}
Пример #2
0
void WriteThread::checkSum()
{
    //QByteArray blockArray;
    QCryptographicHash hash(QCryptographicHash::Sha1);
    endDetected=false;
    lastGoodPosition=0;
    #ifdef ULTRACOPIER_PLUGIN_SPEED_SUPPORT
    numberOfBlockCopied=0;
    #endif
    if(!file.seek(0))
    {
        errorString_internal=file.errorString();
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("[")+QString::number(id)+QStringLiteral("] ")+QStringLiteral("Unable to seek after open: %1, error: %2").arg(file.fileName()).arg(errorString_internal));
        emit error();
        return;
    }
    int sizeReaden=0;
    do
    {
        if(putInPause)
        {
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Information,QStringLiteral("[")+QString::number(id)+QStringLiteral("] write put in pause"));
            if(stopIt)
                return;
            pauseMutex.acquire();
            if(stopIt)
                return;
        }
        //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()+QStringLiteral(" (")+QString::number(file.error())+QStringLiteral(")");
            ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("[")+QString::number(id)+QStringLiteral("] ")+QStringLiteral("file.error()!=QFile::NoError: %1, error: %2").arg(QString::number(file.error())).arg(errorString_internal));
            emit error();
            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();
        }
    }
    while(sizeReaden>0 && !stopIt);
    if(lastGoodPosition>(quint64)file.size())
    {
        errorString_internal=tr("File truncated during read, possible data change");
        ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Warning,QStringLiteral("[")+QString::number(id)+QStringLiteral("] ")+QStringLiteral("Source truncated during the read: %1 (%2)").arg(file.errorString()).arg(QString::number(file.error())));
        emit error();
        return;
    }
    if(stopIt)
    {
/*		if(putInPause)
            emit isInPause();*/
        stopIt=false;
        return;
    }
    emit checksumFinish(hash.result());
    ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("[")+QString::number(id)+QStringLiteral("] stop the read"));
}