mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
fead: load without animation
This commit is contained in:
@@ -1,19 +1,37 @@
|
||||
#include "UpdateController.h"
|
||||
|
||||
UpdateController::UpdateController(DataParser *parser, QObject *parent) :
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
UpdateController::UpdateController(DataParser *parser,SendSystem *sendSystem, QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
this->dataParser = parser;
|
||||
this->sendSystem = sendSystem;
|
||||
localPath = QDir::currentPath() + applicationFolderName;
|
||||
}
|
||||
|
||||
void UpdateController::calculateCommonHash()
|
||||
{
|
||||
fileDataList.clear();
|
||||
calculateHash(localPath);
|
||||
dataParser->createFileDataList(fileDataList,hashFilename);
|
||||
qDebug() << "UpdateController threadID " << QThread::currentThreadId();
|
||||
qDebug() << " OR " << thread();
|
||||
}
|
||||
|
||||
void UpdateController::calculateHash()
|
||||
void UpdateController::calculateStreamingHash()
|
||||
{
|
||||
fileDataList.clear();
|
||||
calculateHash(QDir::currentPath() + streamingAssetsPath);
|
||||
dataParser->createFileDataList(fileDataList,streamingHashFilename);
|
||||
}
|
||||
|
||||
void UpdateController::calculateHash(QString path)
|
||||
{
|
||||
qDebug() << "Try calculate";
|
||||
|
||||
|
||||
QDirIterator iterator(localPath,QDirIterator::Subdirectories);
|
||||
QDirIterator iterator(path,QDirIterator::Subdirectories);
|
||||
fileDataList.clear();
|
||||
QList<FileData> *files = new QList<FileData>;
|
||||
QList<FileData> * folders = new QList<FileData>;
|
||||
@@ -22,7 +40,7 @@ void UpdateController::calculateHash()
|
||||
QDir().mkdir(applicationFolderName);
|
||||
}
|
||||
|
||||
QDir dir(localPath);
|
||||
QDir dir(path);
|
||||
QString hashString;
|
||||
|
||||
while (iterator.hasNext())
|
||||
@@ -50,6 +68,9 @@ void UpdateController::calculateHash()
|
||||
hash.addData(buffer,bytesRead);
|
||||
readSize = qMin(fileSize,bufferSize);
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
hashString = QString(hash.result().toHex());
|
||||
currentFile.path = Tools::createLocalPath(fileInfo.absoluteFilePath());
|
||||
currentFile.hash = hashString;
|
||||
@@ -70,13 +91,42 @@ void UpdateController::calculateHash()
|
||||
fileDataList.append(*folders);
|
||||
fileDataList.append(*files);
|
||||
|
||||
dataParser->createXML(fileDataList);
|
||||
|
||||
delete folders;
|
||||
delete files;
|
||||
|
||||
}
|
||||
|
||||
void UpdateController::updateFilesOnServer(QList<FileData> *fileSendList){
|
||||
|
||||
QListIterator<FileData> serverIterator(*fileSendList);
|
||||
try {
|
||||
|
||||
while(serverIterator.hasNext())
|
||||
{
|
||||
FileData data = serverIterator.next();
|
||||
|
||||
if (data.hash == "FOLDER")
|
||||
{
|
||||
sendSystem->sendFolderBlock(data.path);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendSystem->sendFileBlock(data.path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
calculateCommonHash();
|
||||
|
||||
sendSystem->sendFinish();
|
||||
emit sigUpdateComplete(true);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
emit sigUpdateComplete(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
UpdateController::~UpdateController()
|
||||
|
||||
@@ -17,20 +17,31 @@
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
|
||||
class SendSystem;
|
||||
|
||||
class UpdateController : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit UpdateController(DataParser *parser,QObject *parent = 0);
|
||||
void calculateHash();
|
||||
explicit UpdateController(DataParser *parser,SendSystem *sendSystem,QObject *parent = 0);
|
||||
|
||||
void calculateCommonHash();
|
||||
void calculateStreamingHash();
|
||||
~UpdateController();
|
||||
|
||||
void updateFilesOnServer(QList<FileData> *fileSendList);
|
||||
|
||||
signals:
|
||||
void sigUpdateComplete(bool flag);
|
||||
private:
|
||||
DataParser *dataParser;
|
||||
SendSystem *sendSystem;
|
||||
QString localPath;
|
||||
QList<FileData> fileDataList;
|
||||
|
||||
void calculateHash(QString path);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ QByteArray DataParser::slotGetXmlAnswer(QString answerCode)
|
||||
}
|
||||
}
|
||||
|
||||
void DataParser::createXML(QList<FileData> fileDataList)
|
||||
void DataParser::createFileDataList(QList<FileData> fileDataList,QString filename)
|
||||
{
|
||||
|
||||
QFile file(hashFilename);
|
||||
QFile file(filename);
|
||||
file.open(QIODevice::WriteOnly);
|
||||
QXmlStreamWriter xmlWriter(&file);
|
||||
|
||||
@@ -188,6 +188,7 @@ ServerSettings *DataParser::getServerSettings()
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
file.close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
@@ -213,6 +214,44 @@ void DataParser::saveClientSettrings(QString language, bool isAutoStart)
|
||||
file.close();
|
||||
}
|
||||
|
||||
QList<FileData>* DataParser::xmlFileDataParse(QByteArray array, QString filter = "")
|
||||
{
|
||||
QXmlStreamReader xmlReader(array);
|
||||
QList<FileData> *datas = new QList<FileData>;
|
||||
xmlReader.readNext(); // Переходим к первому элементу в файле
|
||||
|
||||
//Крутимся в цикле до тех пор, пока не достигнем конца документа
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
//Проверяем, является ли элемент началом тега
|
||||
if(xmlReader.isStartElement())
|
||||
{
|
||||
if(xmlReader.name() == "FileData")
|
||||
{
|
||||
FileData data;
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr,xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Path")
|
||||
data.path = value;
|
||||
else if(name == "Hash")
|
||||
data.hash = value;
|
||||
}
|
||||
|
||||
if(data.path.contains(filter))
|
||||
|
||||
datas->append(data);
|
||||
}
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
return datas;
|
||||
}
|
||||
|
||||
QByteArray DataParser::xmlAnswer(QList<SXmlAnswerTag> listTag, QString elemUp1, QString elemUp2)
|
||||
{
|
||||
|
||||
@@ -19,13 +19,14 @@ public:
|
||||
ServerSettings* getServerSettings();
|
||||
void createServerSettings(QString server,QString port);
|
||||
void saveClientSettrings(QString language,bool isAutoStart);
|
||||
void createXML(QList<FileData> fileDataList);
|
||||
void createFileDataList(QList<FileData> fileDataList,QString filename);
|
||||
void createAuthMessage(ClientAutorization *auth);
|
||||
void createAuthData(ServerAuthorization *serverAuth);
|
||||
void addRunData(QList<int> displays);
|
||||
QByteArray xmlAnswer_notify(QString code);
|
||||
QByteArray xmlAnswer(QList<SXmlAnswerTag> listTag, QString elemUp1 = "", QString elemUp2 = "");
|
||||
|
||||
QList<FileData>* xmlFileDataParse(QByteArray array,QString filter);
|
||||
public slots:
|
||||
QByteArray slotGetXmlAnswer(QString);
|
||||
|
||||
|
||||
71
Core/hashcomparer.cpp
Normal file
71
Core/hashcomparer.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "hashcomparer.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <updatenotifywidget.h>
|
||||
|
||||
|
||||
HashComparer::HashComparer(DataParser *dataParser,QObject *parent)
|
||||
{
|
||||
this->dataParser = dataParser;
|
||||
this->updateWidget = updateWidget;
|
||||
}
|
||||
|
||||
void HashComparer::CompareDeltas()
|
||||
{
|
||||
QList<FileData> *serverStreamingHash = new QList<FileData>;
|
||||
QList<FileData> *localStreamingHash = new QList<FileData>;
|
||||
|
||||
QFile file(serverHash);
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
|
||||
serverStreamingHash = dataParser->xmlFileDataParse(file.readAll(),"StreamingAssets");
|
||||
file.close();
|
||||
|
||||
QFile file2(streamingHashFilename);
|
||||
file2.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
|
||||
localStreamingHash = dataParser->xmlFileDataParse(file2.readAll(),"StreamingAssets");
|
||||
file2.close();
|
||||
|
||||
QMutableListIterator<FileData> iterator(*localStreamingHash);
|
||||
|
||||
for (auto &item:*localStreamingHash)
|
||||
{
|
||||
if(serverStreamingHash->contains(item))
|
||||
{
|
||||
serverStreamingHash->removeOne(item);
|
||||
localStreamingHash->removeOne(item);
|
||||
}
|
||||
}
|
||||
|
||||
filesForUpdate = localStreamingHash;
|
||||
showDeltas();
|
||||
}
|
||||
|
||||
void HashComparer::showDeltas()
|
||||
{
|
||||
|
||||
if (filesForUpdate->length() <= 0)
|
||||
{
|
||||
emit sigCallCheck();
|
||||
return;
|
||||
}
|
||||
for (auto &item:*filesForUpdate)
|
||||
{
|
||||
updateWidget->addToList(item);
|
||||
}
|
||||
|
||||
updateWidget->setUpdateList(filesForUpdate);
|
||||
updateWidget->show();
|
||||
updateWidget->activateWindow();
|
||||
}
|
||||
|
||||
void HashComparer::setWidget(UpdateNotifyWidget* updateWidget)
|
||||
{
|
||||
this->updateWidget = updateWidget;
|
||||
}
|
||||
|
||||
HashComparer::~HashComparer()
|
||||
{
|
||||
|
||||
}
|
||||
31
Core/hashcomparer.h
Normal file
31
Core/hashcomparer.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef HASHCOMPARER_H
|
||||
#define HASHCOMPARER_H
|
||||
|
||||
#include "FileData.h"
|
||||
#include "dataparser.h"
|
||||
#include "tools.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QFile>
|
||||
#include <updatenotifywidget.h>
|
||||
|
||||
class UpdateNotifyWidget;
|
||||
class HashComparer :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HashComparer(DataParser *dataParser,QObject *parent = nullptr);
|
||||
void CompareDeltas();
|
||||
~HashComparer();
|
||||
|
||||
void showDeltas();
|
||||
void setWidget(UpdateNotifyWidget *updateWidget);
|
||||
signals:
|
||||
void sigCallCheck();
|
||||
private:
|
||||
UpdateNotifyWidget* updateWidget;
|
||||
QList<FileData> *filesForUpdate;
|
||||
DataParser *dataParser;
|
||||
};
|
||||
|
||||
#endif // HASHCOMPARER_H
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "Core/recognizesystem.h"
|
||||
|
||||
#include <updatenotifywidget.h>
|
||||
|
||||
RecognizeSystem::RecognizeSystem(QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
@@ -17,15 +19,18 @@ RecognizeSystem::~RecognizeSystem()
|
||||
|
||||
}
|
||||
|
||||
void RecognizeSystem::initialize(UpdateController *updateController,DataParser *dataParser)
|
||||
void RecognizeSystem::initialize(UpdateController *updateController,DataParser *dataParser,MainWindow *mainWindow)
|
||||
{
|
||||
this->updateController = updateController;
|
||||
this->dataParser = dataParser;
|
||||
this->mainWindow = mainWindow;
|
||||
connect(this,&RecognizeSystem::sigSaveLoginData,dataParser,&DataParser::createAuthData);
|
||||
}
|
||||
|
||||
void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
{
|
||||
qDebug() << "RecognizeThreadId " << QThread::currentThreadId();
|
||||
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
@@ -159,6 +164,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
|
||||
file.close();
|
||||
emit sigSendDebugLog(Tools::getTime() + "File loaded");
|
||||
emit
|
||||
|
||||
//ОЧИСТКА ПОСЛЕ ПЕРЕДАЧИ
|
||||
|
||||
@@ -204,7 +210,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
}
|
||||
|
||||
if(packetType ==PacketType::TYPE_FINISH){ //для повторного создания хэша после загрузки
|
||||
updateController->calculateHash();
|
||||
updateController->calculateCommonHash();
|
||||
emit sigLoadComplete();
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
@@ -273,6 +279,11 @@ void RecognizeSystem::xmlParser(QByteArray array)
|
||||
{
|
||||
emit sigServerBlocked();
|
||||
}
|
||||
|
||||
if(value == "HASHSENDCOMPLETE")
|
||||
{
|
||||
emit sigStartCompare();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,6 +311,7 @@ void RecognizeSystem::xmlParser(QByteArray array)
|
||||
|
||||
if (name == "AccessType"){
|
||||
serverAuth->AccessType = value;
|
||||
checkAccessType(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,5 +320,13 @@ void RecognizeSystem::xmlParser(QByteArray array)
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RecognizeSystem::checkAccessType(QString type)
|
||||
{
|
||||
if(type == "instructor")
|
||||
{
|
||||
updateController->calculateStreamingHash();
|
||||
mainWindow->callUpdateList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <Core\UpdateController.h>
|
||||
|
||||
class UpdateController;
|
||||
class MainWindow;
|
||||
|
||||
class RecognizeSystem : public QObject
|
||||
{
|
||||
@@ -18,7 +19,7 @@ class RecognizeSystem : public QObject
|
||||
public:
|
||||
explicit RecognizeSystem(QObject *parent = 0);
|
||||
~RecognizeSystem();
|
||||
void initialize(UpdateController* updateController,DataParser *dataParser);
|
||||
void initialize(UpdateController* updateController,DataParser *dataParser,MainWindow *mainWindow);
|
||||
void recognize(QTcpSocket *socket);
|
||||
|
||||
signals:
|
||||
@@ -30,8 +31,10 @@ signals:
|
||||
void sigServerBlocked();
|
||||
void sigSaveLoginData(ServerAuthorization *serverAuth);
|
||||
void sigSocketWaitForReadyRead(int waitTime);
|
||||
void sigStartCompare();
|
||||
|
||||
private:
|
||||
MainWindow *mainWindow;
|
||||
UpdateController *updateController;
|
||||
DataParser *dataParser;
|
||||
PacketType packetType;
|
||||
@@ -45,6 +48,7 @@ private:
|
||||
|
||||
void xmlParser(QByteArray array);
|
||||
|
||||
void checkAccessType(QString type);
|
||||
};
|
||||
|
||||
#endif // RECOGNIZESYSTEM_H
|
||||
|
||||
131
Core/sendsystem.cpp
Normal file
131
Core/sendsystem.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
#include "sendsystem.h"
|
||||
#include "tools.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QThread>
|
||||
|
||||
|
||||
|
||||
SendSystem::SendSystem(QObject* parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SendSystem::setSocket(QTcpSocket *socket)
|
||||
{
|
||||
this->socket = socket;
|
||||
}
|
||||
|
||||
|
||||
void SendSystem::sendDisable()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QByteArray data;
|
||||
data = emit sigGetXmlAnswer("DISABLE");
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void SendSystem::sendClientAutorization()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QFile file(tempName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
QByteArray array = file.readAll();
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << array;
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
void SendSystem::sendFileBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
QString fullPath = Tools::createFullPath(path);
|
||||
quint64 fileSize = 0;
|
||||
int countSend = 0;
|
||||
|
||||
|
||||
QFile file(fullPath); //Открываем файл для чтения
|
||||
QFileInfo fileInfo(file);
|
||||
|
||||
fileSize = fileInfo.size();
|
||||
|
||||
stream << PacketType::TYPE_FILE; //Отправляем тип блока
|
||||
stream << path << fileSize;
|
||||
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
if(file.open(QFile::ReadOnly)){
|
||||
while(!file.atEnd()){
|
||||
QByteArray data = file.read(1025*250);
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
countSend++;
|
||||
}
|
||||
|
||||
qDebug() << Tools::getTime() << "count end Final: " << countSend;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
//qDebug() << "Transaction after send file: " << socket->isTransactionStarted();
|
||||
countSend = 0;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void SendSystem::sendFolderBlock(QString path)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FOLDER;
|
||||
stream << path;
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
|
||||
void SendSystem::sendQTConnect()
|
||||
{
|
||||
QString value = QString::number(PacketType::TYPE_QT);
|
||||
socket->write(value.toUtf8());
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void SendSystem::sendXMLAnswer(QByteArray array)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << array;
|
||||
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void SendSystem::sendFinish()
|
||||
{
|
||||
socket->waitForReadyRead();
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
stream << PacketType::TYPE_FINISH;
|
||||
|
||||
socket->waitForReadyRead(100);
|
||||
}
|
||||
|
||||
SendSystem::~SendSystem()
|
||||
{
|
||||
|
||||
}
|
||||
30
Core/sendsystem.h
Normal file
30
Core/sendsystem.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef SENDSYSTEM_H
|
||||
#define SENDSYSTEM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QTcpSocket>
|
||||
#include <QDataStream>
|
||||
|
||||
class SendSystem :public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SendSystem(QObject* parent = nullptr);
|
||||
void setSocket(QTcpSocket *socket);
|
||||
void sendClientAutorization();
|
||||
void sendDisable();
|
||||
void sendFileBlock(QString path);
|
||||
void sendFolderBlock(QString path);
|
||||
void sendQTConnect();
|
||||
void sendXMLAnswer(QByteArray array);
|
||||
~SendSystem();
|
||||
void sendFinish();
|
||||
signals:
|
||||
|
||||
QByteArray sigGetXmlAnswer(QString);
|
||||
|
||||
private:
|
||||
QTcpSocket *socket;
|
||||
};
|
||||
|
||||
#endif // SENDSYSTEM_H
|
||||
@@ -7,95 +7,40 @@
|
||||
TCPClient::TCPClient(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
//socket = NULL;
|
||||
socket = new QTcpSocket();
|
||||
socket->setParent(this);
|
||||
socket->moveToThread(this->thread());
|
||||
}
|
||||
|
||||
void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter)
|
||||
void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter,SendSystem *sendSystem)
|
||||
{
|
||||
this->recognizeSystem = recognize;
|
||||
this->externalExecuter = externalExecuter;
|
||||
|
||||
this->sendSystem = sendSystem;
|
||||
|
||||
emit sigSendDebugLog(Tools::getTime() + " Client started");
|
||||
}
|
||||
|
||||
void TCPClient::setConnect(ServerSettings *serverSettings)
|
||||
void TCPClient::setConnect(ServerSettings *serverSettings,QThread *th)
|
||||
{
|
||||
socket = new QTcpSocket();
|
||||
qDebug() << "TCPCLient thread: " << thread();
|
||||
if (socket != NULL && socket->state() == QTcpSocket::ConnectedState)
|
||||
{
|
||||
emit sigSendDebugLog("already connected");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
socket->connectToHost(serverSettings->Address,serverSettings->Port.toShort());
|
||||
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::slotReadyRead,Qt::DirectConnection);
|
||||
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::setDisconnect);
|
||||
connect(socket,&QTcpSocket::connected,this,&TCPClient::slotConnectNotify);
|
||||
connect(this,&TCPClient::sigRecognize,recognizeSystem,&RecognizeSystem::recognize,Qt::DirectConnection);
|
||||
|
||||
socket->connectToHost(serverSettings->Address,serverSettings->Port.toShort());
|
||||
connect(this,&TCPClient::sigRecognize,recognizeSystem,&RecognizeSystem::recognize,Qt::DirectConnection);
|
||||
connect(this,&TCPClient::sigSetSocket,sendSystem,&SendSystem::setSocket);
|
||||
|
||||
emit sigSetSocket(socket);
|
||||
emit sigSendDebugLog("Try connect...");
|
||||
}
|
||||
|
||||
void TCPClient::sendClientAutorization()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
if(socket->state() != QTcpSocket::ConnectedState){
|
||||
emit sigConnectionState(false);
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(tempName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
|
||||
QByteArray array = file.readAll();
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << array;
|
||||
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::sendQTConnect()
|
||||
{
|
||||
QString value = QString::number(PacketType::TYPE_QT);
|
||||
socket->write(value.toUtf8());
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void TCPClient::setDisconnect()
|
||||
{
|
||||
@@ -104,20 +49,8 @@ void TCPClient::setDisconnect()
|
||||
emit sigSendDebugLog("Server disabled");
|
||||
}
|
||||
|
||||
void TCPClient::sendDisable()
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
QByteArray data;
|
||||
data = emit sigGetXmlAnswer("DISABLE");
|
||||
|
||||
stream << PacketType::TYPE_XMLANSWER;
|
||||
stream << data;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
|
||||
void TCPClient::waitRead(int time)
|
||||
void TCPClient:: waitRead(int time)
|
||||
{
|
||||
socket->waitForReadyRead(time);
|
||||
}
|
||||
@@ -127,32 +60,32 @@ QTcpSocket *TCPClient::getSocket()
|
||||
return socket;
|
||||
}
|
||||
|
||||
void TCPClient::slotMessageEntered(QString message)
|
||||
void TCPClient::slotSendCommand(QString command)
|
||||
{
|
||||
QDataStream stream(socket);
|
||||
QByteArray data;
|
||||
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
|
||||
|
||||
if(!message.isEmpty() && socket->state() == QTcpSocket::ConnectedState){
|
||||
if(!command.isEmpty() && socket->state() == QTcpSocket::ConnectedState){
|
||||
|
||||
if(message == "check")
|
||||
if(command == "check")
|
||||
{
|
||||
stream << PacketType::TYPE_COMMAND;
|
||||
stream << message;
|
||||
stream << command;
|
||||
socket->waitForBytesWritten();
|
||||
|
||||
sendFile();
|
||||
sendSystem->sendFileBlock("/" + hashFilename);
|
||||
emit sigSendDebugLog(Tools::getTime() + " Local checkFile sended");
|
||||
|
||||
socket->waitForReadyRead(1000);
|
||||
}
|
||||
else if(message == "update"){
|
||||
else if(command == "update"){
|
||||
emit sigSendDebugLog("Update started");
|
||||
stream << PacketType::TYPE_COMMAND;
|
||||
stream << message;
|
||||
stream << command;
|
||||
socket->waitForBytesWritten();
|
||||
}
|
||||
else if(message == "run"){
|
||||
else if(command == "run"){
|
||||
externalExecuter->callApp();
|
||||
}
|
||||
}else{
|
||||
@@ -172,7 +105,7 @@ void TCPClient::slotConnectNotify()
|
||||
{
|
||||
emit sigSendDebugLog("Connect complete");
|
||||
emit sigConnectionState(true);
|
||||
sendQTConnect();
|
||||
sendSystem->sendQTConnect();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,10 +116,6 @@ void TCPClient::slotReadyRead()
|
||||
return;
|
||||
}
|
||||
|
||||
// qDebug() << "Transaction before recognize: " << socket->isTransactionStarted();
|
||||
|
||||
// if(socket->isTransactionStarted()) return;
|
||||
|
||||
emit sigRecognize(socket);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
class UpdateController;
|
||||
class RecognizeSystem;
|
||||
class SendSystem;
|
||||
|
||||
class TCPClient : public QObject
|
||||
{
|
||||
@@ -23,12 +24,9 @@ class TCPClient : public QObject
|
||||
|
||||
public:
|
||||
explicit TCPClient(QObject *parent = 0);
|
||||
void initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter);
|
||||
void setConnect(ServerSettings *serverSettings);
|
||||
void sendClientAutorization();
|
||||
void sendQTConnect();
|
||||
void initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter,SendSystem *sendSystem);
|
||||
void setConnect(ServerSettings *serverSettings,QThread *thread);
|
||||
|
||||
void sendDisable();
|
||||
void waitRead(int time);
|
||||
QTcpSocket* getSocket();
|
||||
~TCPClient();
|
||||
@@ -36,23 +34,23 @@ public:
|
||||
signals:
|
||||
void sigSendDebugLog(QString message);
|
||||
void sigRecognize(QTcpSocket *socket);
|
||||
void sigConnectionState(bool flag);
|
||||
void sigServerDisconnect();
|
||||
QByteArray sigGetXmlAnswer(QString);
|
||||
void sigConnectionState(bool flag);
|
||||
void sigSetSocket(QTcpSocket *socket);
|
||||
|
||||
public slots:
|
||||
void slotMessageEntered(QString message);
|
||||
void slotSendCommand(QString message);
|
||||
void slotConnectNotify();
|
||||
|
||||
private slots:
|
||||
void slotReadyRead();
|
||||
|
||||
private:
|
||||
SendSystem *sendSystem;
|
||||
QTcpSocket *socket;
|
||||
RecognizeSystem *recognizeSystem;
|
||||
ExternalExecuter * externalExecuter;
|
||||
|
||||
void sendFile();
|
||||
void setDisconnect();
|
||||
};
|
||||
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
static QString applicationEXEName = "RRJ.exe";
|
||||
static QString applicationFolderName = "/Application";
|
||||
static QString staticDataFolderName = "StaticData";
|
||||
static QString hashFilename = staticDataFolderName + "/hash.xml";
|
||||
static QString streamingAssetsPath = "/Application/RRJLoader/RRJ_Data/StreamingAssets";
|
||||
static QString hashFilename = staticDataFolderName + "/clientHash.xml";
|
||||
static QString settingsName = staticDataFolderName + "/settings.xml";
|
||||
static QString tempName = staticDataFolderName + "/temp.xml";
|
||||
static QString authTempName = staticDataFolderName + "/authData.xml";
|
||||
static QString displayTemp = staticDataFolderName + "/displayData.xml";
|
||||
static QString streamingHashFilename = staticDataFolderName + "/streamingHash.xml";
|
||||
static QString serverHash = staticDataFolderName + "/serverHash.xml";
|
||||
|
||||
enum PacketType{
|
||||
TYPE_NONE = 0,
|
||||
|
||||
Reference in New Issue
Block a user