mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-29 06:35:40 +03:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 715d29a1ec | |||
| 6bde215bbe | |||
| eb95db696a | |||
| a3651496b7 | |||
| 52d077fe6b |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -60,3 +60,5 @@ debug/
|
||||
release/
|
||||
saves/
|
||||
build/
|
||||
|
||||
BUILDS/
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
#include "Core/recognizesystem.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||
QObject(parent),
|
||||
versionContainer(nullptr),
|
||||
dataParser(nullptr),
|
||||
postProcessorSystem(nullptr)
|
||||
postProcessorSystem(nullptr),
|
||||
client(nullptr)
|
||||
{
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
filePath.clear();
|
||||
filePath = "";
|
||||
fileSize = 0;
|
||||
sizeReceiveData = 0;
|
||||
tmpBlock.clear();
|
||||
@@ -17,66 +19,74 @@ RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||
void RecognizeSystem::initialize(DataParser *dataParser, VersionContainer *versionContainer,PostProcessorSystem *postProcessorSystem,Client *client)
|
||||
{
|
||||
this->versionContainer = versionContainer;
|
||||
this->postProcessorSystem = postProcessorSystem;
|
||||
this->dataParser = dataParser;
|
||||
this->postProcessorSystem = postProcessorSystem;
|
||||
this->client = client;
|
||||
}
|
||||
|
||||
void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
{
|
||||
qDebug() << "RecognizeThreadId " << QThread::currentThreadId();
|
||||
//qDebug() << "RecognizeThreadId " << QThread::currentThreadId();
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
while(socket->bytesAvailable())
|
||||
int cntBytesAvl = 0;
|
||||
while((cntBytesAvl = socket->bytesAvailable()) > 0)
|
||||
{
|
||||
if (socket->state() != QTcpSocket::ConnectedState)
|
||||
{
|
||||
qDebug() << "RecognizeSystem::recognize socket->state() != QTcpSocket::ConnectedState";
|
||||
return;
|
||||
}
|
||||
|
||||
if (socket->state() != QTcpSocket::ConnectedState) return;
|
||||
|
||||
if(packetType == PacketType::TYPE_NONE){ //определение первичного пакета
|
||||
|
||||
if(packetType == PacketType::TYPE_NONE) //определение первичного пакета
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> packetType;
|
||||
|
||||
if(!stream.commitTransaction())
|
||||
{
|
||||
emit sigSendDebugLog(Tools::getTime() + " CLIENT: packetType - FAIL commitTransaction");
|
||||
|
||||
if(socket->waitForReadyRead(TCP_READ_TIMEOUT)){
|
||||
emit sigSendDebugLog("ERROR: PACKET TYPE READ TIMEOUT");
|
||||
return;
|
||||
}
|
||||
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
//qDebug() << Tools::GetTime() << "CLIENT: type: " << packetType;
|
||||
if(packetType == PacketType::TYPE_FILE)
|
||||
socket->waitForReadyRead(10);
|
||||
else
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_FOLDER){ //создание папок
|
||||
|
||||
switch ((int)packetType)
|
||||
{
|
||||
case PacketType::TYPE_FOLDER: //создание папок
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> filePath;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
if(!stream.commitTransaction())
|
||||
{
|
||||
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||
continue;
|
||||
}
|
||||
|
||||
filePath = Tools::createReceiveFullPath(filePath,versionContainer->getServerVersionData());
|
||||
|
||||
QDir dir(filePath);
|
||||
if(!dir.exists()){
|
||||
if(dir.mkpath(filePath)){
|
||||
qDebug() << "Dir Created";
|
||||
if(!dir.exists())
|
||||
{
|
||||
if(dir.mkpath(filePath))
|
||||
{
|
||||
qDebug() << "Dir Created: " << filePath;
|
||||
}
|
||||
}
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
emit sigUpdateBytesAvailable();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
if(packetType == PacketType::TYPE_FILE) //загрузка файлов
|
||||
case PacketType::TYPE_FILE: //загрузка файлов
|
||||
{
|
||||
//ПОЛУЧЕНИЕ ПУТИ
|
||||
//ПОЛУЧЕНИЕ РАЗМЕРА ФАЙЛА
|
||||
@@ -86,15 +96,11 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
stream >> filePath;
|
||||
stream >> fileSize;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
if(!stream.commitTransaction())
|
||||
{
|
||||
emit sigSendDebugLog(Tools::getTime() + "CLIENT: filePath, fileSize - FAIL commitTransaction");
|
||||
|
||||
if (!socket->waitForReadyRead(TCP_READ_TIMEOUT)) {
|
||||
emit sigSendDebugLog(Tools::getTime() + "CLIENT: ERROR! readyRead timeout - filePath, fileSize!!!");
|
||||
return;
|
||||
}
|
||||
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
filePath = Tools::createReceiveFullPath(filePath,versionContainer->getServerVersionData());
|
||||
@@ -102,11 +108,10 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
emit sigSendDebugLog("CLIENT: filesize: " + QString::number(fileSize));
|
||||
emit sigSendDebugLog("CLIENT: filePath: " + filePath);
|
||||
|
||||
socket->waitForReadyRead(100);
|
||||
socket->waitForReadyRead(10);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
//ПОЛУЧЕНИЕ САМОГО ФАЙЛА
|
||||
emit sigSendDebugLog(Tools::getTime() + "AfterRead size and path BytesAvailable: " + socket->bytesAvailable());
|
||||
|
||||
@@ -117,47 +122,70 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
{
|
||||
file.remove(); //удаление файла, если он уже есть, но необходимо обновить
|
||||
emit sigSendDebugLog(Tools::getTime() + "Delete exist file: " + filePath);
|
||||
socket->waitForReadyRead(100);
|
||||
|
||||
//socket->waitForReadyRead(10);
|
||||
}
|
||||
|
||||
tmpBlock.clear();
|
||||
sizeReceiveData = 0;
|
||||
countSend = 0;
|
||||
|
||||
file.open(QFile::WriteOnly);
|
||||
|
||||
file.open(QFile::Append);
|
||||
if(! file.isOpen())
|
||||
QMessageBox::critical(nullptr, "P1", "isOpen false. File: " + file.fileName());
|
||||
|
||||
forever
|
||||
if(! file.isWritable())
|
||||
QMessageBox::critical(nullptr, "P2", "isWritable false. File: " + file.fileName());
|
||||
|
||||
while(true)
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> tmpBlock;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
|
||||
if(socket->state() == QAbstractSocket::UnconnectedState){
|
||||
postProcessorSystem->socketDisable();
|
||||
//emit sigSocketDisabled();
|
||||
return;
|
||||
}
|
||||
if(socket->waitForReadyRead(TCP_READ_TIMEOUT)){
|
||||
if(socket->bytesAvailable() <= 0)
|
||||
{
|
||||
socket->waitForReadyRead(10);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(fileSize - sizeReceiveData >= BLOCK_SIZE)
|
||||
tmpBlock = socket->read(BLOCK_SIZE);
|
||||
else
|
||||
tmpBlock = socket->read(fileSize - sizeReceiveData);
|
||||
|
||||
qint64 bytesReceived = tmpBlock.length();
|
||||
|
||||
if(bytesReceived <= 0)
|
||||
{
|
||||
//QMessageBox::critical(nullptr, "P3", "bytesReceived <= 0. File: " + file.fileName());
|
||||
continue;
|
||||
}
|
||||
|
||||
quint64 toFile = file.write(tmpBlock);
|
||||
emit sigSendDebugLog(Tools::getTime() + "CLIENT: toFile :" + toFile);
|
||||
|
||||
sizeReceiveData += toFile;
|
||||
sizeReceiveData += bytesReceived;
|
||||
countSend++;
|
||||
|
||||
qint64 toFile = file.write(tmpBlock);
|
||||
|
||||
if(toFile <= 0)
|
||||
{
|
||||
//emit sigUpdateBytesAvailable();
|
||||
QMessageBox::critical(nullptr, "P4", "write toFile <= 0. File: " + file.fileName());
|
||||
continue;
|
||||
}
|
||||
|
||||
tmpBlock.clear();
|
||||
|
||||
if(sizeReceiveData == fileSize){
|
||||
if(sizeReceiveData == fileSize)
|
||||
{
|
||||
emit sigSendDebugLog(Tools::getTime() + "FINAL Count send: " + QString::number(countSend));
|
||||
emit sigSendDebugLog(Tools::getTime() + "FINAL Size received: " + QString::number(sizeReceiveData));
|
||||
emit sigSendDebugLog(Tools::getTime() + "FINAL File size" + QString::number(fileSize));
|
||||
emit sigUpdateBytesAvailable();
|
||||
break;
|
||||
}
|
||||
else if(sizeReceiveData > fileSize)
|
||||
{
|
||||
QMessageBox::critical(nullptr, "P5", "sizeReceiveData > fileSize");
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
@@ -171,13 +199,16 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
sizeReceiveData = 0;
|
||||
countSend = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
if(packetType == PacketType::TYPE_DELETE) //удаление лишних файлов (рекурсивно удаляет все содежимое)
|
||||
case PacketType::TYPE_DELETE: //удаление лишних файлов (рекурсивно удаляет все содежимое)
|
||||
{
|
||||
stream.startTransaction();
|
||||
stream >> filePath;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
if(!stream.commitTransaction())
|
||||
{
|
||||
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -185,7 +216,6 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
|
||||
QFileInfo fileInfo(filePath);
|
||||
|
||||
|
||||
if(fileInfo.exists())
|
||||
{
|
||||
if(fileInfo.isFile())
|
||||
@@ -194,22 +224,19 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
file.remove();
|
||||
}
|
||||
|
||||
if(fileInfo.isDir()){
|
||||
if(fileInfo.isDir())
|
||||
{
|
||||
QDir dir(filePath);
|
||||
dir.removeRecursively();
|
||||
}
|
||||
|
||||
qDebug() << Tools::getTime() << "Deleted: " << filePath;
|
||||
}
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
continue;
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
if(packetType == PacketType::TYPE_NEEDUPDATE)
|
||||
{ //нужно обновление
|
||||
|
||||
case PacketType::TYPE_NEEDUPDATE: //нужно обновление
|
||||
{
|
||||
bool flag = false;
|
||||
quint64 size = 0;
|
||||
quint64 fileCount = 0;
|
||||
@@ -221,63 +248,78 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
stream >> fileCount;
|
||||
stream >> fileDelete;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
if(!stream.commitTransaction())
|
||||
{
|
||||
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||
continue;
|
||||
}
|
||||
|
||||
emit sigNeedUpdate(flag,size,fileCount,fileDelete);
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
break;
|
||||
|
||||
if(packetType == PacketType::TYPE_XMLANSWER){ //ответы формата XML
|
||||
case PacketType::TYPE_XMLANSWER: //ответы формата XML
|
||||
{
|
||||
QByteArray array;
|
||||
stream.startTransaction();
|
||||
stream >> array;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
if(!stream.commitTransaction())
|
||||
{
|
||||
socket->waitForReadyRead(TCP_READ_TIMEOUT);
|
||||
continue;
|
||||
}
|
||||
|
||||
dataParser->xmlParser(array);
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
break;
|
||||
|
||||
if(packetType == PacketType::HASH_READY)
|
||||
case PacketType::HASH_READY:
|
||||
{
|
||||
emit sigCheckUpdate();
|
||||
}
|
||||
break;
|
||||
|
||||
if(packetType == PacketType::RECALCULATE_HASH)
|
||||
case PacketType::RECALCULATE_HASH:
|
||||
{
|
||||
emit sigdRecalculateHashOnServerState();
|
||||
}
|
||||
break;
|
||||
|
||||
if(packetType == PacketType::BUSY)
|
||||
case PacketType::BUSY:
|
||||
{
|
||||
emit sigAnimationActivated(true);
|
||||
}
|
||||
break;
|
||||
|
||||
if(packetType == PacketType::FREE)
|
||||
case PacketType::FREE:
|
||||
{
|
||||
emit sigAnimationActivated(false);
|
||||
}
|
||||
break;
|
||||
|
||||
if (packetType == PacketType::TYPE_XMLANSWER_DOCS_CHANGED) //на случай общего обновления
|
||||
case PacketType::TYPE_XMLANSWER_DOCS_CHANGED: //на случай общего обновления
|
||||
{
|
||||
if (client->getIsLoggedIn())
|
||||
{
|
||||
emit sigSendPacketType(PacketType::GET_DOCS);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
if (packetType == PacketType::UPDATE_FILE_COMPLETE)
|
||||
case PacketType::UPDATE_FILE_COMPLETE:
|
||||
{
|
||||
postProcessorSystem->calculateCommonHash();
|
||||
emit sigLoadComplete();
|
||||
emit sigSendPacketType(PacketType::GET_DOCS);
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
qCritical() << "RecognizeSystem::recognize packetType unknown!";
|
||||
}
|
||||
|
||||
//socket->waitForReadyRead(10);
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <Data\streamingversiondata.h>
|
||||
#include <Core\hashcomparer.h>
|
||||
|
||||
const int BLOCK_SIZE = 1024 * 1024; // Размер блока
|
||||
|
||||
class RecognizeSystem : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -21,8 +23,10 @@ class RecognizeSystem : public QObject
|
||||
public:
|
||||
explicit RecognizeSystem(QObject *parent = 0);
|
||||
~RecognizeSystem(){};
|
||||
|
||||
void initialize(DataParser *dataParser, VersionContainer* versionContainer,PostProcessorSystem *postProcessorSystem,Client *client);
|
||||
void recognize(QTcpSocket *socket);
|
||||
|
||||
signals:
|
||||
void sigUpdateBytesAvailable();
|
||||
void sigLoadComplete();
|
||||
@@ -40,13 +44,13 @@ private:
|
||||
VersionContainer *versionContainer;
|
||||
DataParser *dataParser;
|
||||
PostProcessorSystem *postProcessorSystem;
|
||||
PacketType packetType;
|
||||
QString filePath;
|
||||
QByteArray tmpBlock;
|
||||
Client *client;
|
||||
|
||||
qint64 sizeReceiveData;
|
||||
PacketType packetType;
|
||||
QString filePath;
|
||||
qint64 fileSize;
|
||||
qint64 sizeReceiveData;
|
||||
QByteArray tmpBlock;
|
||||
int countSend;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user