代码拉取完成,页面将自动刷新
同步操作将从 caowai/qipmsg 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "filetransworker.h"
#include <QFile>
#include <QThread>
#include <QHostAddress>
#include <QFileInfo>
FileTransWorker::FileTransWorker(QObject *parent) : QObject(parent)
{
}
void FileTransWorker::fileTransStart()
{
QByteArray data;
qint64 ret = 0;
int wr_len = 0;
QFile file;
qint64 fileSend = 0;
qint64 fileSize = 0;
QTcpSocket *mSock = new QTcpSocket();
mSock->setSocketDescriptor(mHandle);
qDebug()<<"will trans File"<<mFilename<<"Sock"<<mHandle<<mSock->peerAddress().toString()<<mSock->peerPort();
if(nullptr != mSock
&& mSock->isValid()
&& false == mFileTranStopFlag
&& true == QFileInfo(mFilename).isFile()
)
{
//qDebug()<<"File"<<mFilename<<"Sock"<<mSock->peerAddress().toString()<<mSock->peerPort();
file.setFileName(mFilename);
fileSize = file.size();
if(file.open(QFile::ReadOnly))
{
while(false == mFileTranStopFlag
&& false == file.atEnd()
&& mSock->isValid())
{
data.clear();
data.resize(0);
data = file.read(8192);
if(data.length()>0)
{
wr_len = 0;
while(wr_len!=data.length())
{
ret = mSock->write(data.right(data.length()-wr_len),data.length()-wr_len);
if( -1 != ret)
{
wr_len+=ret;
fileSend+=ret;
if((fileSend*100/fileSize)!=mProgress)
{
mProgress = (fileSend*100/fileSize);
emit fileTransProgress(mFileId,mProgress);
}
mSock->waitForBytesWritten();
continue;
}
else
{
break;
}
}
if( -1 == ret)
{
emit fileTransError(mFileId,mProgress);
break;
}
}
else
{
emit fileTransError(mFileId,mProgress);
break;
}
}
file.close();
emit fileTransFinished(mFileId);
}
}
else
{
emit fileTransError(mFileId,mProgress);
}
if(mSock->state() == QTcpSocket::ConnectedState)
{
mSock->disconnectFromHost();
}
if(mSock->state() != QTcpSocket::UnconnectedState)
{
mSock->waitForDisconnected();
}
mSock->close();
delete mSock;
return;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。