feat: before threading

This commit is contained in:
semenov
2024-08-19 11:57:33 +03:00
parent 883ac44e6b
commit c79faae730
48 changed files with 722 additions and 562 deletions

View File

@@ -10,11 +10,8 @@ TCPClient::TCPClient(QObject *parent) :
}
void TCPClient::Initialize(UpdateController *updateController,
RecognizeSystem *recognize,
ExternalExecuter *externalExecuter)
void TCPClient::Initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter)
{
this->updateController = updateController;
this->recognizeSystem = recognize;
this->externalExecuter = externalExecuter;
@@ -27,11 +24,11 @@ void TCPClient::SetConnect(ServerSettings *serverSettings)
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::onReadyRead);
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::SetDisconnect);
connect(this,&TCPClient::Recognize,recognizeSystem,&RecognizeSystem::Recognize);
socket->connectToHost(serverSettings->Address,serverSettings->Port.toShort());
emit onSendDebugLog("Try connect...");
recognizeSystem->SetSocket(socket);
socket->waitForReadyRead();
if(socket->state() != QTcpSocket::ConnectedState){
@@ -56,6 +53,37 @@ void TCPClient::SendClientAutorization()
socket->waitForBytesWritten();
}
void TCPClient::SendFile()
{
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
quint64 fileSize = 0;
int countSend = 0;
QFile file(hashFilename); //Открываем файл для чтения
stream << PacketType::TYPE_FILE; //Отправляем тип блока
QFileInfo fileInfo(file);
fileSize = fileInfo.size();
stream << fileSize;
if(file.open(QFile::ReadOnly | QFile::Text)){
while(!file.atEnd()){
QByteArray data = file.readAll();//file.read(1025*250);
stream << data;
countSend++;
}
qDebug() << Tools::GetTime() << "count end Final: " << countSend;
}
file.close();
qDebug() << "Transaction after send file: " << socket->isTransactionStarted();
countSend = 0;
}
void TCPClient::SetDisconnect()
{
socket->disconnect();
@@ -67,6 +95,11 @@ void TCPClient::WaitWrites()
socket->waitForBytesWritten();
}
void TCPClient::WaitRead(int time)
{
socket->waitForReadyRead(time);
}
QTcpSocket *TCPClient::GetSocket()
{
return socket;
@@ -80,18 +113,16 @@ void TCPClient::MessageEntered(QString message)
if(!message.isEmpty() && socket->state() == QTcpSocket::ConnectedState){
socket->waitForBytesWritten();
if(message == "check")
{
stream << PacketType::TYPE_COMMAND;
stream << message;
socket->waitForBytesWritten();
updateController->SendFile(stream);
SendFile();
emit onSendDebugLog(Tools::GetTime() + " Local checkFile sended");
WaitWrites();
socket->readyRead();
socket->waitForReadyRead(1000);
}
else if(message == "update"){
emit onSendDebugLog("Update started");
@@ -113,8 +144,11 @@ void TCPClient::onReadyRead()
emit onSendDebugLog("WRONG SOCKET");
return;
}
// qDebug() << "Transaction before recognize: " << socket->isTransactionStarted();
recognizeSystem->Recognize();
// if(socket->isTransactionStarted()) return;
emit Recognize(socket);
}
TCPClient::~TCPClient()