mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
feat: before threading
This commit is contained in:
@@ -5,33 +5,8 @@ UpdateController::UpdateController(DataParser *parser, QObject *parent) :
|
||||
{
|
||||
this->dataParser = parser;
|
||||
localPath = QDir::currentPath() + "/Application";
|
||||
countSend = 0;
|
||||
}
|
||||
|
||||
void UpdateController::SendFile(QDataStream &stream)
|
||||
{
|
||||
/* Открываем файл для Чтения*/
|
||||
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();
|
||||
countSend = 0;
|
||||
}
|
||||
|
||||
void UpdateController::CalculateHash()
|
||||
{
|
||||
|
||||
@@ -24,7 +24,6 @@ class UpdateController : public QObject
|
||||
|
||||
public:
|
||||
explicit UpdateController(DataParser *parser,QObject *parent = 0);
|
||||
void SendFile(QDataStream &stream);
|
||||
void CalculateHash();
|
||||
~UpdateController();
|
||||
|
||||
@@ -32,9 +31,6 @@ private:
|
||||
DataParser *dataParser;
|
||||
QString localPath;
|
||||
QList<FileData> fileDataList;
|
||||
quint64 fileSize;
|
||||
int countSend;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
#include "Core/dataparser.h"
|
||||
|
||||
#include "FileData.h"
|
||||
#include "dataparser.h"
|
||||
#include "tools.h"
|
||||
|
||||
DataParser::DataParser(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DataParser::DataParser()
|
||||
DataParser::~DataParser()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -38,6 +43,8 @@ void DataParser::CreateXML(QList<FileData> fileDataList)
|
||||
|
||||
void DataParser::CreateAuthMessage(ClientAutorization *auth)
|
||||
{
|
||||
authPassCache = auth; //кэширование даных авторизации, для сохранения при успешном заходе
|
||||
|
||||
QFile file(tempName);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
@@ -68,9 +75,10 @@ void DataParser::CreateServerSettings(QString address, QString port)
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("ServerSettingsContainer");
|
||||
|
||||
xmlWriter.writeStartElement("ServerSettingsContainer");
|
||||
xmlWriter.writeStartElement("ServerSettings");
|
||||
|
||||
xmlWriter.writeAttribute("Address",address);
|
||||
xmlWriter.writeAttribute("Port",port);
|
||||
|
||||
@@ -83,6 +91,27 @@ void DataParser::CreateServerSettings(QString address, QString port)
|
||||
|
||||
}
|
||||
|
||||
void DataParser::CreateAuthData(ServerAuthorization *serverAuth)
|
||||
{
|
||||
QFile file(authTempName);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
xmlWriter.setAutoFormatting(true);
|
||||
xmlWriter.writeStartDocument();
|
||||
xmlWriter.writeStartElement("AuthData");
|
||||
xmlWriter.writeAttribute("Login",authPassCache->Login);
|
||||
xmlWriter.writeAttribute("Password",authPassCache->Password);
|
||||
xmlWriter.writeAttribute("InstructorName",serverAuth->InstructorName);
|
||||
xmlWriter.writeAttribute("ClientName",serverAuth->ClientName);
|
||||
xmlWriter.writeAttribute("AccessType",serverAuth->AccessType);
|
||||
|
||||
xmlWriter.writeEndElement();
|
||||
file.close();
|
||||
|
||||
}
|
||||
|
||||
ServerSettings *DataParser::GetServerSettings()
|
||||
{
|
||||
ServerSettings *settings = new ServerSettings;
|
||||
@@ -102,10 +131,6 @@ ServerSettings *DataParser::GetServerSettings()
|
||||
|
||||
if(name == "Address"){
|
||||
settings->Address = value;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(name == "Port"){
|
||||
|
||||
@@ -3,20 +3,29 @@
|
||||
|
||||
#include "FileData.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <Datas.h>
|
||||
#include <QFile>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
|
||||
class DataParser
|
||||
class DataParser : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DataParser();
|
||||
explicit DataParser(QObject *parent = 0);
|
||||
~DataParser();
|
||||
ServerSettings* GetServerSettings();
|
||||
void CreateServerSettings(QString server,QString port);
|
||||
void CreateXML(QList<FileData> fileDataList);
|
||||
void CreateAuthMessage(ClientAutorization *auth);
|
||||
void CreateAuthData(ServerAuthorization *serverAuth);
|
||||
|
||||
private:
|
||||
ClientAutorization *authPassCache;
|
||||
|
||||
};
|
||||
|
||||
#endif // DATAPARSER_H
|
||||
|
||||
@@ -21,7 +21,7 @@ void ExternalExecuter::CallApp()
|
||||
myProcess.waitForFinished(-1);
|
||||
}
|
||||
|
||||
void ExternalExecuter::FindApp()
|
||||
bool ExternalExecuter::FindApp()
|
||||
{
|
||||
QString localPath = QDir::currentPath() + "/Application";
|
||||
QDirIterator iterator(localPath,QDirIterator::Subdirectories);
|
||||
@@ -31,7 +31,9 @@ void ExternalExecuter::FindApp()
|
||||
|
||||
if(iterator.fileInfo().fileName() == "RRJ.exe"){
|
||||
programPath = iterator.fileInfo().absoluteFilePath();
|
||||
qDebug() << "Bin found: " << programPath;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class ExternalExecuter : public QObject
|
||||
public:
|
||||
ExternalExecuter();
|
||||
void CallApp();
|
||||
void FindApp();
|
||||
bool FindApp();
|
||||
~ExternalExecuter();
|
||||
|
||||
private:
|
||||
|
||||
@@ -21,20 +21,21 @@ void RecognizeSystem::Initialize(UpdateController *updateController,DataParser *
|
||||
{
|
||||
this->updateController = updateController;
|
||||
this->dataParser = dataParser;
|
||||
connect(this,&RecognizeSystem::SaveLoginData,dataParser,&DataParser::CreateAuthData);
|
||||
}
|
||||
|
||||
void RecognizeSystem::SetSocket(QTcpSocket *socket)
|
||||
{
|
||||
this->socket = socket;
|
||||
}
|
||||
|
||||
void RecognizeSystem::Recognize()
|
||||
void RecognizeSystem::Recognize(QTcpSocket *socket)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
while(socket->bytesAvailable())
|
||||
{
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
qDebug() << "BUSY, WAIT";
|
||||
}
|
||||
|
||||
if(packetType == PacketType::TYPE_NONE){ //определение первичного пакета
|
||||
|
||||
stream.startTransaction();
|
||||
@@ -109,19 +110,19 @@ void RecognizeSystem::Recognize()
|
||||
emit onSendDebugLog(Tools::GetTime() + "CLIENT: filePath, fileSize - FAIL commitTransaction");
|
||||
|
||||
if (!socket->waitForReadyRead(TCP_READ_TIMEOUT)) {
|
||||
emit onSendDebugLog(Tools::GetTime() + "CLIENT: ERROR! readyRead timeout - filePath, fileSize!!!");
|
||||
return;
|
||||
}
|
||||
emit onSendDebugLog(Tools::GetTime() + "CLIENT: ERROR! readyRead timeout - filePath, fileSize!!!");
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
filePath = Tools::CreateFullPath(filePath);
|
||||
|
||||
emit onSendDebugLog("CLIENT: filesize: " + QString::number(fileSize));
|
||||
emit onSendDebugLog("CLIENT: filePath: " + filePath);
|
||||
emit onSendDebugLog("CLIENT: filesize: " + QString::number(fileSize));
|
||||
emit onSendDebugLog("CLIENT: filePath: " + filePath);
|
||||
|
||||
socket->waitForReadyRead(100);
|
||||
emit SocketWaitForReadyRead(100);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -247,6 +248,10 @@ void RecognizeSystem::Recognize()
|
||||
stream.startTransaction();
|
||||
stream >> array;
|
||||
|
||||
if(!stream.commitTransaction()){
|
||||
continue;
|
||||
}
|
||||
|
||||
XMLParser(array);
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
@@ -260,33 +265,62 @@ void RecognizeSystem::XMLParser(QByteArray array)
|
||||
{
|
||||
QXmlStreamReader xmlReader(array);
|
||||
|
||||
xmlReader.readNext();
|
||||
xmlReader.readNext();
|
||||
|
||||
while(!xmlReader.atEnd())
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
if(!xmlReader.isStartElement()) {
|
||||
xmlReader.readNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ServerNotify")
|
||||
{
|
||||
if(!xmlReader.isStartElement()) {
|
||||
xmlReader.readNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ServerNotify")
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Code"){
|
||||
if (value == "END"){
|
||||
if(name == "Code"){
|
||||
if (value == "END"){
|
||||
|
||||
emit SockedDisabled();
|
||||
emit SockedDisabled();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ServerAuthorization"){
|
||||
|
||||
ServerAuthorization *serverAuth = new ServerAuthorization;
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if (name == "Result"){
|
||||
serverAuth->Result = value == "true" ? true : false;
|
||||
}
|
||||
|
||||
if (name == "InstructorName"){
|
||||
serverAuth->InstructorName = value;
|
||||
}
|
||||
|
||||
if (name == "ClientName"){
|
||||
serverAuth->ClientName = value;
|
||||
}
|
||||
|
||||
if (name == "AccessType"){
|
||||
serverAuth->AccessType = value;
|
||||
}
|
||||
}
|
||||
|
||||
emit SaveLoginData(serverAuth);
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,7 @@ public:
|
||||
explicit RecognizeSystem(QObject *parent = 0);
|
||||
~RecognizeSystem();
|
||||
void Initialize(UpdateController* updateController,DataParser *dataParser);
|
||||
void SetSocket(QTcpSocket *socket);
|
||||
void Recognize();
|
||||
void Recognize(QTcpSocket *socket);
|
||||
|
||||
signals:
|
||||
void UpdateBytesAvailable(qint64 size,quint64 sended);
|
||||
@@ -28,11 +27,12 @@ signals:
|
||||
void onNeedUpdate(bool flag);
|
||||
void onSendDebugLog(QString message);
|
||||
void SockedDisabled();
|
||||
void SaveLoginData(ServerAuthorization *serverAuth);
|
||||
void SocketWaitForReadyRead(int waitTime);
|
||||
|
||||
private:
|
||||
UpdateController *updateController;
|
||||
DataParser *dataParser;
|
||||
QTcpSocket *socket;
|
||||
PacketType packetType;
|
||||
QString message;
|
||||
QString filePath;
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -19,19 +19,24 @@ class RecognizeSystem;
|
||||
class TCPClient : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
||||
public:
|
||||
explicit TCPClient(QObject *parent = 0);
|
||||
void Initialize(UpdateController *updateController,RecognizeSystem *recognize,ExternalExecuter *externalExecuter);
|
||||
void Initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter);
|
||||
void SetConnect(ServerSettings *serverSettings);
|
||||
void SendClientAutorization();
|
||||
void SendFile();
|
||||
void SetDisconnect();
|
||||
void WaitWrites();
|
||||
void WaitRead(int time);
|
||||
QTcpSocket* GetSocket();
|
||||
~TCPClient();
|
||||
|
||||
signals:
|
||||
void onSendDebugLog(QString message);
|
||||
|
||||
void Recognize(QTcpSocket *socket);
|
||||
|
||||
public slots:
|
||||
void MessageEntered(QString message);
|
||||
|
||||
@@ -40,7 +45,6 @@ private slots:
|
||||
|
||||
private:
|
||||
QTcpSocket *socket;
|
||||
UpdateController *updateController;
|
||||
RecognizeSystem *recognizeSystem;
|
||||
ExternalExecuter * externalExecuter;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
static QString hashFilename = "hash.xml";
|
||||
static QString settingsName = "settings.xml";
|
||||
static QString tempName = "temp.xml";
|
||||
static QString authTempName = "authData.xml";
|
||||
|
||||
enum PacketType{
|
||||
TYPE_NONE = 0,
|
||||
|
||||
Reference in New Issue
Block a user