mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
hotfix: updateController
This commit is contained in:
@@ -90,13 +90,23 @@ void RecognizeSystem::recognize()
|
|||||||
if (command == commandUpdateFilesClient) //запускает процесс оновления
|
if (command == commandUpdateFilesClient) //запускает процесс оновления
|
||||||
{
|
{
|
||||||
sendSystem->updateFiles(updateController->getFileSendList(),
|
sendSystem->updateFiles(updateController->getFileSendList(),
|
||||||
updateController->getClientDataList());
|
updateController->getFileDeleteList());
|
||||||
|
|
||||||
qDebug()<< "Call update";
|
qDebug()<< "Call update";
|
||||||
packetType = PacketType::TYPE_NONE;
|
packetType = PacketType::TYPE_NONE;
|
||||||
command = "";
|
command = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(command == "check")
|
||||||
|
{
|
||||||
|
command = "";
|
||||||
|
QFile checkFile(clientHash);
|
||||||
|
checkFile.open(QIODevice::ReadOnly);
|
||||||
|
updateController->compareFiles(clientHandler,checkFile.readAll());
|
||||||
|
checkFile.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (packetType == PacketType::TYPE_XMLANSWER)
|
if (packetType == PacketType::TYPE_XMLANSWER)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -280,14 +290,6 @@ void RecognizeSystem::recognize()
|
|||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
if(command == "check")
|
|
||||||
{
|
|
||||||
QFile checkFile(filePath);
|
|
||||||
checkFile.open(QIODevice::ReadOnly);
|
|
||||||
updateController->compareFiles(clientHandler,checkFile.readAll());
|
|
||||||
checkFile.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
filePath.clear();
|
filePath.clear();
|
||||||
fileSize = 0;
|
fileSize = 0;
|
||||||
tmpBlock.clear();
|
tmpBlock.clear();
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ static const QString versionListFile = staticDataFolderName + "/versionList.xml"
|
|||||||
static const QString hashFileName = staticDataFolderName + "/serverHash.xml";
|
static const QString hashFileName = staticDataFolderName + "/serverHash.xml";
|
||||||
static const QString buildHashName = staticDataFolderName + "/buildHash.xml";
|
static const QString buildHashName = staticDataFolderName + "/buildHash.xml";
|
||||||
static const QString buildDataPath = "/Application/RRJLoader/RRJ_Data/";
|
static const QString buildDataPath = "/Application/RRJLoader/RRJ_Data/";
|
||||||
|
static const QString clientHash = staticDataFolderName + "/clientHash.xml";
|
||||||
|
|
||||||
static const QString baseNameVersion = "base";//может вынести комманды куда нибудь?
|
static const QString baseNameVersion = "base";//может вынести комманды куда нибудь?
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ void UpdateController::compareFiles(ClientHandler* handler, QByteArray array)
|
|||||||
loadHash();
|
loadHash();
|
||||||
clientDataList.clear();
|
clientDataList.clear();
|
||||||
xmlFileDataParse(array);
|
xmlFileDataParse(array);
|
||||||
clientDataList.append(*datas);
|
|
||||||
checkNeedUpdate(handler);
|
checkNeedUpdate(handler);
|
||||||
mutex->unlock();
|
mutex->unlock();
|
||||||
}
|
}
|
||||||
@@ -182,8 +181,6 @@ QString UpdateController::getCommands()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void UpdateController::setUpCurrentServerHash()
|
void UpdateController::setUpCurrentServerHash()
|
||||||
{
|
{
|
||||||
QList<FileData> *fileList = new QList<FileData>;
|
QList<FileData> *fileList = new QList<FileData>;
|
||||||
@@ -296,62 +293,121 @@ QList<FileData>* UpdateController::calculateHash(QString path)
|
|||||||
{
|
{
|
||||||
serverDataList.clear();
|
serverDataList.clear();
|
||||||
|
|
||||||
QDirIterator iterator(path,QDirIterator::Subdirectories);
|
|
||||||
if(!QDir(path).exists()){
|
if(!QDir(path).exists()){
|
||||||
QDir().mkdir(path);
|
QDir().mkdir(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDir dir(path);
|
|
||||||
dir.setFilter(QDir::NoDotAndDotDot);
|
|
||||||
QString hashString;
|
QString hashString;
|
||||||
|
QStringList filter;
|
||||||
|
filter << "*";
|
||||||
QList<FileData> *files = new QList<FileData>;
|
QList<FileData> *files = new QList<FileData>;
|
||||||
|
|
||||||
while (iterator.hasNext())
|
QDirIterator dirIterator(path,filter, QDir::AllEntries | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
|
||||||
|
|
||||||
|
while (dirIterator.hasNext())
|
||||||
{
|
{
|
||||||
iterator.next();
|
QFileInfo fileInfo(dirIterator.next());
|
||||||
QFileInfo fileInfo = iterator.fileInfo();
|
|
||||||
FileData currentFile;
|
FileData currentFile;
|
||||||
QFile file(fileInfo.absoluteFilePath());
|
if(fileInfo.isDir() && !fileInfo.fileName().startsWith(".") && fileInfo.fileName() != "RRJLoader")
|
||||||
|
|
||||||
quint64 fileSize = file.size();
|
|
||||||
const quint64 bufferSize = 10240;
|
|
||||||
|
|
||||||
if (fileInfo.isHidden()) continue;
|
|
||||||
|
|
||||||
if(fileInfo.isFile() && file.open(QIODevice::ReadOnly) && !fileInfo.fileName().contains(".meta"))
|
|
||||||
{
|
{
|
||||||
char buffer[bufferSize];
|
|
||||||
int bytesRead;
|
|
||||||
int readSize = qMin(fileSize,bufferSize);
|
|
||||||
|
|
||||||
QCryptographicHash hash(QCryptographicHash::Md5);
|
|
||||||
while(readSize > 0 && (bytesRead = file.read(buffer,readSize)) > 0){
|
|
||||||
fileSize -= bytesRead;
|
|
||||||
hash.addData(buffer,bytesRead);
|
|
||||||
readSize = qMin(fileSize,bufferSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
hashString = QString(hash.result().toHex());
|
|
||||||
currentFile.hash = hashString;
|
|
||||||
currentFile.path = Tools::createLocalPath(fileInfo.absoluteFilePath());
|
currentFile.path = Tools::createLocalPath(fileInfo.absoluteFilePath());
|
||||||
|
|
||||||
files->push_back(currentFile);
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(fileInfo.isDir() && fileInfo.fileName() != ".." && !fileInfo.isRoot())
|
|
||||||
{
|
|
||||||
currentFile.hash = "FOLDER";
|
currentFile.hash = "FOLDER";
|
||||||
currentFile.path = Tools::createLocalPath(fileInfo.path());
|
|
||||||
|
|
||||||
if(!files->contains(currentFile)){
|
if(!files->contains(currentFile))
|
||||||
|
{
|
||||||
files->push_back(currentFile);
|
files->push_back(currentFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::sort(files->begin(),files->end());
|
QDirIterator fileIterator(path,filter,QDir::Files | QDir::NoDotAndDotDot,QDirIterator::Subdirectories);
|
||||||
|
|
||||||
|
while (fileIterator.hasNext())
|
||||||
|
{
|
||||||
|
fileIterator.next();
|
||||||
|
QFileInfo fileInfo = fileIterator.fileInfo();
|
||||||
|
FileData currentFile;
|
||||||
|
QFile file(fileInfo.absoluteFilePath());
|
||||||
|
|
||||||
|
quint64 fileSize = file.size(); //буффер для хэширования крупных файлов
|
||||||
|
const quint64 bufferSize = 10240;
|
||||||
|
|
||||||
|
if(fileInfo.isHidden()) continue;
|
||||||
|
|
||||||
|
if(fileInfo.isFile() && file.open(QIODevice::ReadOnly) && !fileInfo.fileName().contains(".meta"))
|
||||||
|
{
|
||||||
|
char buffer[bufferSize];
|
||||||
|
int bytesRead;
|
||||||
|
int readSize = qMin(fileSize,bufferSize);
|
||||||
|
|
||||||
|
QCryptographicHash hash(QCryptographicHash::Md5);
|
||||||
|
|
||||||
|
while(readSize > 0 && (bytesRead = file.read(buffer,readSize)) > 0)
|
||||||
|
{
|
||||||
|
fileSize -= bytesRead;
|
||||||
|
hash.addData(buffer,bytesRead);
|
||||||
|
readSize = qMin(fileSize,bufferSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
hashString = QString(hash.result().toHex());
|
||||||
|
currentFile.path = Tools::createLocalPath(fileInfo.absoluteFilePath());
|
||||||
|
currentFile.hash = hashString;
|
||||||
|
files->push_back(currentFile);
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
serverDataList.append(*files);
|
serverDataList.append(*files);
|
||||||
|
|
||||||
|
// QDirIterator iterator(path,QDirIterator::Subdirectories);
|
||||||
|
// QDir dir(path);
|
||||||
|
// dir.setFilter(QDir::NoDotAndDotDot);
|
||||||
|
|
||||||
|
// while (iterator.hasNext())
|
||||||
|
// {
|
||||||
|
// iterator.next();
|
||||||
|
// QFileInfo fileInfo = iterator.fileInfo();
|
||||||
|
// FileData currentFile;
|
||||||
|
// QFile file(fileInfo.absoluteFilePath());
|
||||||
|
|
||||||
|
// quint64 fileSize = file.size();
|
||||||
|
// const quint64 bufferSize = 10240;
|
||||||
|
|
||||||
|
// if (fileInfo.isHidden()) continue;
|
||||||
|
|
||||||
|
// if(fileInfo.isFile() && file.open(QIODevice::ReadOnly) && !fileInfo.fileName().contains(".meta"))
|
||||||
|
// {
|
||||||
|
// char buffer[bufferSize];
|
||||||
|
// int bytesRead;
|
||||||
|
// int readSize = qMin(fileSize,bufferSize);
|
||||||
|
|
||||||
|
// QCryptographicHash hash(QCryptographicHash::Md5);
|
||||||
|
// while(readSize > 0 && (bytesRead = file.read(buffer,readSize)) > 0){
|
||||||
|
// fileSize -= bytesRead;
|
||||||
|
// hash.addData(buffer,bytesRead);
|
||||||
|
// readSize = qMin(fileSize,bufferSize);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// hashString = QString(hash.result().toHex());
|
||||||
|
// currentFile.hash = hashString;
|
||||||
|
// currentFile.path = Tools::createLocalPath(fileInfo.absoluteFilePath());
|
||||||
|
|
||||||
|
// files->push_back(currentFile);
|
||||||
|
// file.close();
|
||||||
|
|
||||||
|
// }
|
||||||
|
// else if(fileInfo.isDir() && fileInfo.fileName() != ".." && !fileInfo.isRoot())
|
||||||
|
// {
|
||||||
|
// currentFile.hash = "FOLDER";
|
||||||
|
// currentFile.path = Tools::createLocalPath(fileInfo.path());
|
||||||
|
|
||||||
|
// if(!files->contains(currentFile)){
|
||||||
|
// files->push_back(currentFile);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// std::sort(files->begin(),files->end());
|
||||||
|
//
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,7 +555,6 @@ bool UpdateController::checkDuplicate(QString versionName)
|
|||||||
void UpdateController::xmlFileDataParse(QByteArray array)
|
void UpdateController::xmlFileDataParse(QByteArray array)
|
||||||
{
|
{
|
||||||
QXmlStreamReader xmlReader(array);
|
QXmlStreamReader xmlReader(array);
|
||||||
datas = new QList<FileData>;
|
|
||||||
xmlReader.readNext();
|
xmlReader.readNext();
|
||||||
|
|
||||||
//Крутимся в цикле до тех пор, пока не достигнем конца документа
|
//Крутимся в цикле до тех пор, пока не достигнем конца документа
|
||||||
@@ -523,7 +578,7 @@ void UpdateController::xmlFileDataParse(QByteArray array)
|
|||||||
data.hash = value;
|
data.hash = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
datas->append(data);
|
clientDataList.append(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,11 +620,6 @@ DataInfo *UpdateController::getCurrentDataInfo()
|
|||||||
return dataInfo;
|
return dataInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<FileData> *UpdateController::getDatas() const
|
|
||||||
{
|
|
||||||
return datas;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateController::clearCurrentDataInfo()
|
void UpdateController::clearCurrentDataInfo()
|
||||||
{
|
{
|
||||||
delete dataInfo;
|
delete dataInfo;
|
||||||
|
|||||||
@@ -51,7 +51,6 @@ public:
|
|||||||
|
|
||||||
DataInfo *getCurrentDataInfo();
|
DataInfo *getCurrentDataInfo();
|
||||||
void clearCurrentDataInfo();
|
void clearCurrentDataInfo();
|
||||||
QList<FileData> *getDatas() const;
|
|
||||||
void createVersionListXmlAnswer(QList<StreamingVersionData *> version);
|
void createVersionListXmlAnswer(QList<StreamingVersionData *> version);
|
||||||
void saveVersionToFile(StreamingVersionData *streamingVersion);
|
void saveVersionToFile(StreamingVersionData *streamingVersion);
|
||||||
void xmlFileDataParse(QByteArray array);
|
void xmlFileDataParse(QByteArray array);
|
||||||
@@ -71,7 +70,6 @@ private:
|
|||||||
QList<FileData> fileSendList;
|
QList<FileData> fileSendList;
|
||||||
QList<FileData> fileDeleteList;
|
QList<FileData> fileDeleteList;
|
||||||
|
|
||||||
QList<FileData> *datas;
|
|
||||||
DataInfo *dataInfo;
|
DataInfo *dataInfo;
|
||||||
|
|
||||||
QString buildPath;
|
QString buildPath;
|
||||||
|
|||||||
Reference in New Issue
Block a user