This commit is contained in:
2026-02-24 11:17:48 +03:00
parent a1f3e04fad
commit a0e54c0e18
8 changed files with 79 additions and 44 deletions

View File

@@ -75,7 +75,7 @@ void SendSystem::updateFiles(QList<FileData> fileSendList, QList<FileData> delet
}
else
{
slot_sendFileBlock_V3(data.path);
slot_sendFileBlock_forQtClient(data.path);
}
if(slot_getIsSendingStopped())
@@ -184,9 +184,9 @@ void SendSystem::slot_sendXmlAnswer(QByteArray array, PacketType packetType)
}
}
void SendSystem::slot_sendDocs(QString docsPath)
void SendSystem::slot_sendDocs_forQtClient(QString docsPath)
{
slot_sendFileBlock(docsPath);
slot_sendFileBlock_forQtClient(docsPath);
}
void SendSystem::slot_sendNeedUpdate(bool flag, quint64 size, quint64 fileCount, quint64 deleteCount)
@@ -224,7 +224,7 @@ void SendSystem::slot_sendDeleteBlock(QString path)
waitWrittenData("sendDeleteBlock");
}
void SendSystem::slot_sendFileBlock(QString path)
void SendSystem::slot_sendFileBlock_forGUI(QString path)
{
//qDebug() << "SendSystem::sendFileBlock path: " << path;
@@ -283,7 +283,7 @@ void SendSystem::slot_sendFileBlock(QString path)
countSend = 0;
}
void SendSystem::slot_sendFileBlock_V3(QString path)
void SendSystem::slot_sendFileBlock_forQtClient(QString path)
{
//qDebug() << "SendSystem::sendFileBlock path: " << path;
@@ -421,51 +421,85 @@ void SendSystem::slot_sendFileBlockByteArray(QByteArray array, PacketType packet
}
}
void SendSystem::slot_sendFileBlockWithRename(QString path, QString newName)
void SendSystem::slot_sendFileBlockWithRename_Hash_forQtClient(QString path, QString newName)
{
//qDebug() << "SendSystem::sendFileBlockWithRename thread ID " << QThread::currentThreadId();
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
if(slot_getIsSendingStopped())
{ //Поведение на случай отключения клиента
Logger::instance().log("Client: " + client->getLogin() + " isSendingStopped", LogLevel::ERROR);
return;
}
QFile file(Tools::createRootPath(path));
QFileInfo fileInfo(file);
fileSize = fileInfo.size();
if(fileSize == 0){
Logger::instance().log("Client: " + client->getLogin() + " WARNING! Zero size " + fileInfo.fileName(),LogLevel::ERROR);
if (fileSize == 0)
{
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File zero size " + fileInfo.fileName(), LogLevel::ERROR);
Logger::instance().log(path, LogLevel::ERROR);
return;
}
if(!file.open(QFile::ReadOnly))
{
Logger::instance().log("Client: " + client->getLogin() + " ERROR! File not open: " + fileInfo.fileName(), LogLevel::ERROR);
Logger::instance().log(path, LogLevel::ERROR);
return;
}
QString pathForSend = Tools::createFolderPath(path) + "/" + staticDataFolderName + newName;
countSend = 0;
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
stream << PacketType::TYPE_FILE;
stream << pathForSend << fileSize;
waitWrittenData("sendFileBlockWithRename");
if(slot_getIsSendingStopped()) { //Поведение на случай отключения клиента
connect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
file.close();
return;
}
//socket->waitForBytesWritten();
if(file.open(QFile::ReadOnly)){
while(!file.atEnd()){
QByteArray data = file.read(sendFileBlockSize);
stream << data;
waitWrittenData("sendFileBlockWithRename");
countSend++;
while(!file.atEnd())
{
if(socket->state() == QAbstractSocket::UnconnectedState)
{
Logger::instance().log("Client: " + client->getLogin() + " UnconnectedState", LogLevel::ERROR);
break;
}
Logger::instance().log("Send file " + fileInfo.fileName());
qint64 readBytes = file.read(buffer, sendFileBlockSize);
if(readBytes <= 0)
break;
flWaitWritenToSocket = true;
while(!socket->write(buffer, readBytes))
{
qCritical() << "socket->write ERROR. size " + QString::number(readBytes);
int i = 0;
i++;
}
while(flWaitWritenToSocket)
{
QCoreApplication::processEvents(); // Обеспечиваем обработку сообщений
int i = 0;
i++;
}
waitWrittenData(QString("sendFileBlock:data (readBytes %1, num %2) ").arg(QString::number(readBytes), QString::number(countSend)) + fileInfo.fileName());
countSend++;
}
disconnect(this->socket, &QTcpSocket::bytesWritten, this, &SendSystem::slot_BytesWrittenToSocket);
file.close();
countSend = 0;
waitWrittenData("sendFileBlockWithRename");
//waitWrittenData("sendFileBlockWithRename");
//socket->waitForReadyRead(100);
slot_sendNotify(commandHashCompleteClient);