mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
ref: refactoring treads, check local update instructor
This commit is contained in:
@@ -9,6 +9,11 @@ UpdateController::UpdateController(DataParser *parser,SendSystem *sendSystem, QO
|
||||
applicationFolderPath = QDir::currentPath() + applicationFolderName;
|
||||
}
|
||||
|
||||
void UpdateController::initialize(MainWindow *mainWindow)
|
||||
{
|
||||
connect(this,&UpdateController::sigUpdateComplete,mainWindow,&MainWindow::showCompleteDialogBox);
|
||||
}
|
||||
|
||||
void UpdateController::calculateCommonHash()
|
||||
{
|
||||
appDataList.clear();
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
#include <QObject>
|
||||
|
||||
class SendSystem;
|
||||
class MainWindow;
|
||||
class DataParser;
|
||||
|
||||
class UpdateController : public QObject
|
||||
{
|
||||
@@ -27,7 +29,7 @@ class UpdateController : public QObject
|
||||
|
||||
public:
|
||||
explicit UpdateController(DataParser *parser,SendSystem *sendSystem,QObject *parent = 0);
|
||||
|
||||
void initialize(MainWindow *mainWindow);
|
||||
void calculateCommonHash();
|
||||
void calculateStreamingHash();
|
||||
void setServerVersion(StreamingVersionData *version);
|
||||
|
||||
@@ -13,6 +13,11 @@ DataParser::DataParser(QObject *parent) :
|
||||
}
|
||||
}
|
||||
|
||||
void DataParser::initialize(RecognizeSystem *recognizeSystem)
|
||||
{
|
||||
this->recognizeSystem = recognizeSystem;
|
||||
}
|
||||
|
||||
void DataParser::createFileDataList(QList<FileData> fileDataList,QString filename)
|
||||
{
|
||||
|
||||
@@ -62,8 +67,6 @@ void DataParser::createAuthMessage(ClientAutorization *auth)
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DataParser::createServerSettings(ServerSettings* serverSettings)
|
||||
{
|
||||
QFile file(settingsName);
|
||||
@@ -164,7 +167,7 @@ void DataParser::addRunData(QList<int> displays)
|
||||
ServerSettings *DataParser::getServerSettings()
|
||||
{
|
||||
ServerSettings *settings = new ServerSettings;
|
||||
QFile file(settingsName);
|
||||
QFile file(QDir::currentPath() + settingsName);
|
||||
file.open(QIODevice::ReadOnly);
|
||||
QXmlStreamReader xmlReader(&file);
|
||||
|
||||
@@ -326,6 +329,101 @@ QByteArray DataParser::xmlAnswer(QList<SXmlAnswerTag> listTag, QString elemUp1,
|
||||
return array;
|
||||
}
|
||||
|
||||
void DataParser::xmlParser(QByteArray array)
|
||||
{
|
||||
QXmlStreamReader xmlReader(array);
|
||||
|
||||
xmlReader.readNext();
|
||||
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
if(!xmlReader.isStartElement()) {
|
||||
xmlReader.readNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ServerNotify")
|
||||
{
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Code")
|
||||
{
|
||||
if (value == "END")
|
||||
{
|
||||
emit recognizeSystem->sigSocketDisabled();
|
||||
}
|
||||
|
||||
if(value == "BLOCKED")
|
||||
{
|
||||
emit recognizeSystem->sigServerBlocked();
|
||||
}
|
||||
|
||||
if(value == "HASHSENDCOMPLETE")
|
||||
{
|
||||
emit recognizeSystem->sigStartCompare();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
recognizeSystem->checkAccessType(value);
|
||||
}
|
||||
}
|
||||
|
||||
emit recognizeSystem->sigSaveLoginData(serverAuth);
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "VersionData")
|
||||
{
|
||||
StreamingVersionData *serverVersion = new StreamingVersionData;
|
||||
foreach(const QXmlStreamAttribute &attr,xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Version")
|
||||
{
|
||||
serverVersion->setName(value);
|
||||
}
|
||||
|
||||
if(name == "Created")
|
||||
{
|
||||
serverVersion->setCreateData(QDateTime::fromString(value));
|
||||
}
|
||||
|
||||
}
|
||||
recognizeSystem->setServerVersion(serverVersion);
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
}
|
||||
|
||||
DataParser::~DataParser()
|
||||
{
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
#define DATAPARSER_H
|
||||
|
||||
#include "FileData.h"
|
||||
#include "recognizesystem.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <Datas.h>
|
||||
#include <QFile>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
class RecognizeSystem;
|
||||
|
||||
class DataParser : public QObject
|
||||
{
|
||||
|
||||
@@ -15,6 +18,7 @@ class DataParser : public QObject
|
||||
|
||||
public:
|
||||
explicit DataParser(QObject *parent = 0);
|
||||
void initialize(RecognizeSystem *recognizeSystem);
|
||||
~DataParser();
|
||||
ServerSettings* getServerSettings();
|
||||
void createServerSettings(ServerSettings* serverSettings);
|
||||
@@ -27,6 +31,7 @@ public:
|
||||
QByteArray xmlAnswer(QList<SXmlAnswerTag> listTag, QString elemUp1 = "", QString elemUp2 = "");
|
||||
QList<FileData>* xmlFileDataParse(QByteArray array,QString filter);
|
||||
|
||||
void xmlParser(QByteArray array);
|
||||
public slots:
|
||||
QByteArray xmlAnswer_notify(QString code);
|
||||
|
||||
@@ -35,6 +40,7 @@ private:
|
||||
const QString XMLLanguageProperty = "Language=\"";
|
||||
const QString XMLAutoStartProperty = "AutoStart=\"";
|
||||
ClientAutorization *authPassCache;
|
||||
RecognizeSystem *recognizeSystem;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -9,19 +9,25 @@ HashComparer::HashComparer(DataParser *dataParser,QObject *)
|
||||
this->dataParser = dataParser;
|
||||
}
|
||||
|
||||
void HashComparer::initialize(MainWindow* mainWindow)
|
||||
{
|
||||
connect(this,&HashComparer::sigCallCheck,mainWindow,&MainWindow::checkUpdate);
|
||||
connect(this,&HashComparer::sigHaveDelta,mainWindow,&MainWindow::showUpdateInfo);
|
||||
}
|
||||
|
||||
void HashComparer::CompareDeltas()
|
||||
{
|
||||
QList<FileData> *serverStreamingHash = new QList<FileData>;
|
||||
QList<FileData> *localStreamingHash = new QList<FileData>;
|
||||
QList<FileData> *files = new QList<FileData>;
|
||||
|
||||
QFile file(serverHash);
|
||||
QFile file(QDir::currentPath() + serverHash);
|
||||
file.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
|
||||
serverStreamingHash = dataParser->xmlFileDataParse(file.readAll(),"StreamingAssets");
|
||||
file.close();
|
||||
|
||||
QFile file2(streamingHashFilename);
|
||||
QFile file2(QDir::currentPath() + streamingHashFilename);
|
||||
file2.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
|
||||
localStreamingHash = dataParser->xmlFileDataParse(file2.readAll(),"StreamingAssets");
|
||||
|
||||
@@ -15,6 +15,7 @@ class HashComparer :public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit HashComparer(DataParser *dataParser,QObject *parent = nullptr);
|
||||
void initialize(MainWindow* mainWindow);
|
||||
void CompareDeltas();
|
||||
~HashComparer();
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
continue;
|
||||
}
|
||||
|
||||
xmlParser(array);
|
||||
dataParser->xmlParser(array);
|
||||
|
||||
packetType = PacketType::TYPE_NONE;
|
||||
}
|
||||
@@ -269,102 +269,6 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
|
||||
}
|
||||
}
|
||||
|
||||
void RecognizeSystem::xmlParser(QByteArray array)
|
||||
{
|
||||
QXmlStreamReader xmlReader(array);
|
||||
|
||||
xmlReader.readNext();
|
||||
|
||||
while(!xmlReader.atEnd())
|
||||
{
|
||||
if(!xmlReader.isStartElement()) {
|
||||
xmlReader.readNext();
|
||||
continue;
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "ServerNotify")
|
||||
{
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Code")
|
||||
{
|
||||
if (value == "END")
|
||||
{
|
||||
emit sigSocketDisabled();
|
||||
}
|
||||
|
||||
if(value == "BLOCKED")
|
||||
{
|
||||
emit sigServerBlocked();
|
||||
}
|
||||
|
||||
if(value == "HASHSENDCOMPLETE")
|
||||
{
|
||||
emit sigStartCompare();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
checkAccessType(value);
|
||||
}
|
||||
}
|
||||
|
||||
emit sigSaveLoginData(serverAuth);
|
||||
}
|
||||
|
||||
if(xmlReader.name() == "VersionData")
|
||||
{
|
||||
StreamingVersionData *serverVersion = new StreamingVersionData;
|
||||
foreach(const QXmlStreamAttribute &attr,xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Version")
|
||||
{
|
||||
serverVersion->setName(value);
|
||||
}
|
||||
|
||||
if(name == "Created")
|
||||
{
|
||||
serverVersion->setCreateData(QDateTime::fromString(value));
|
||||
}
|
||||
|
||||
}
|
||||
updateController->setServerVersion(serverVersion);
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
}
|
||||
|
||||
void RecognizeSystem::checkAccessType(QString type)
|
||||
{
|
||||
if(type == "instructor")
|
||||
@@ -372,3 +276,8 @@ void RecognizeSystem::checkAccessType(QString type)
|
||||
mainWindow->callUpdateList();
|
||||
}
|
||||
}
|
||||
|
||||
void RecognizeSystem::setServerVersion(StreamingVersionData *serverVersion)
|
||||
{
|
||||
updateController->setServerVersion(serverVersion);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class UpdateController;
|
||||
class MainWindow;
|
||||
class HashComparer;
|
||||
class TCPClient;
|
||||
class ServerAuthorization;
|
||||
|
||||
class RecognizeSystem : public QObject
|
||||
{
|
||||
@@ -26,7 +27,10 @@ public:
|
||||
MainWindow *mainWindow,
|
||||
HashComparer *hashComparer,
|
||||
TCPClient *client);
|
||||
|
||||
void recognize(QTcpSocket *socket);
|
||||
void checkAccessType(QString type);
|
||||
void setServerVersion(StreamingVersionData *serverVersion);
|
||||
|
||||
signals:
|
||||
void sigUpdateBytesAvailable();
|
||||
@@ -52,10 +56,6 @@ private:
|
||||
qint64 sizeReceiveData;
|
||||
qint64 fileSize;
|
||||
int countSend;
|
||||
|
||||
void xmlParser(QByteArray array);
|
||||
|
||||
void checkAccessType(QString type);
|
||||
};
|
||||
|
||||
#endif // RECOGNIZESYSTEM_H
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <QToolButton>
|
||||
#include <QLabel>
|
||||
|
||||
class DataParser;
|
||||
class ScreenChecker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -9,13 +9,16 @@ TCPClient::TCPClient(QObject *parent) :
|
||||
{
|
||||
}
|
||||
|
||||
void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter,SendSystem *sendSystem)
|
||||
void TCPClient::initialize(MainWindow *mainWindow,RecognizeSystem *recognize,ExternalExecuter *externalExecuter,SendSystem *sendSystem)
|
||||
{
|
||||
this->recognizeSystem = recognize;
|
||||
this->externalExecuter = externalExecuter;
|
||||
this->sendSystem = sendSystem;
|
||||
isConnected = false;
|
||||
|
||||
connect(this,&TCPClient::sigConnectionState,mainWindow,&MainWindow::slotConnectionState,Qt::AutoConnection);
|
||||
connect(this,&TCPClient::sigServerDisconnect,mainWindow,&MainWindow::slotServerDisconnect);
|
||||
|
||||
emit sigSendDebugLog(Tools::getTime() + " Client started");
|
||||
}
|
||||
|
||||
@@ -36,14 +39,10 @@ void TCPClient::setConnect(ServerSettings *serverSettings)
|
||||
|
||||
if (socket->waitForConnected(2000))
|
||||
{
|
||||
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::slotReadyRead,Qt::DirectConnection);
|
||||
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::slotReadyRead,Qt::AutoConnection);
|
||||
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::setDisconnect);
|
||||
//connect(socket,&QTcpSocket::connected,this,&TCPClient::slotConnectNotify);
|
||||
|
||||
connect(this,&TCPClient::sigRecognize,recognizeSystem,&RecognizeSystem::recognize,Qt::DirectConnection);
|
||||
connect(this,&TCPClient::sigSetSocket,sendSystem,&SendSystem::setSocket);
|
||||
|
||||
emit sigSetSocket(socket);
|
||||
sendSystem->setSocket(socket);
|
||||
slotConnectNotify();
|
||||
}
|
||||
else
|
||||
@@ -131,7 +130,7 @@ void TCPClient::slotReadyRead()
|
||||
return;
|
||||
}
|
||||
|
||||
emit sigRecognize(socket);
|
||||
recognizeSystem->recognize(socket);
|
||||
}
|
||||
|
||||
bool TCPClient::getIsConnected() const
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
class UpdateController;
|
||||
class RecognizeSystem;
|
||||
class SendSystem;
|
||||
class MainWindow;
|
||||
class ServerSettings;
|
||||
|
||||
class TCPClient : public QObject
|
||||
{
|
||||
@@ -24,7 +26,7 @@ class TCPClient : public QObject
|
||||
|
||||
public:
|
||||
explicit TCPClient(QObject *parent = 0);
|
||||
void initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter,SendSystem *sendSystem);
|
||||
void initialize(MainWindow *mainWindow,RecognizeSystem *recognize,ExternalExecuter *externalExecuter,SendSystem *sendSystem);
|
||||
void setConnect(ServerSettings *serverSettings);
|
||||
|
||||
void waitRead(int time);
|
||||
@@ -35,10 +37,8 @@ public:
|
||||
|
||||
signals:
|
||||
void sigSendDebugLog(QString message);
|
||||
void sigRecognize(QTcpSocket *socket);
|
||||
void sigServerDisconnect();
|
||||
void sigConnectionState(bool flag);
|
||||
void sigSetSocket(QTcpSocket *socket);
|
||||
|
||||
public slots:
|
||||
void slotSendCommand(QString message);
|
||||
|
||||
@@ -33,15 +33,26 @@ QString Tools::createReceiveFullPath(QString path, StreamingVersionData *version
|
||||
if(pos == -1)
|
||||
{
|
||||
pos = path.indexOf(version->getViewName());
|
||||
localPath = path.remove(0,pos + version->getViewName().length());
|
||||
localPath.prepend(streamingAssetsPath);
|
||||
|
||||
if(pos == -1)
|
||||
{
|
||||
fullPath = QDir::currentPath() + path;
|
||||
}
|
||||
else
|
||||
{
|
||||
//StreamingAssets section
|
||||
localPath = path.remove(0,pos + version->getViewName().length());
|
||||
localPath.prepend(streamingAssetsPath);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//build section
|
||||
localPath = path.remove(0,--pos);
|
||||
fullPath = QDir::currentPath() + localPath;
|
||||
}
|
||||
|
||||
fullPath = QDir::currentPath() + localPath;
|
||||
|
||||
qDebug() << "CLIENT: localPath" << localPath;
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
static QString applicationEXEName = "RRJ.exe";
|
||||
static QString applicationFolderName = "/Application";
|
||||
static QString staticDataFolderName = "StaticData";
|
||||
static QString staticDataFolderName = "/StaticData";
|
||||
static QString streamingAssetsPath = "/Application/RRJLoader/RRJ_Data/StreamingAssets";
|
||||
static QString hashFilename = staticDataFolderName + "/clientHash.xml";
|
||||
static QString settingsName = staticDataFolderName + "/settings.xml";
|
||||
|
||||
Reference in New Issue
Block a user