mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJClient.git
synced 2026-03-28 05:25:39 +03:00
Init commit
This commit is contained in:
112
Core/UpdateController.cpp
Normal file
112
Core/UpdateController.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
#include "UpdateController.h"
|
||||
|
||||
UpdateController::UpdateController(DataParser *parser, QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
this->dataParser = parser;
|
||||
localPath = QDir::currentPath() + "/Application";
|
||||
countSend = 0;
|
||||
CalculateHash();
|
||||
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
QDirIterator iterator(localPath,QDirIterator::Subdirectories);
|
||||
fileDataList.clear();
|
||||
QList<FileData> *files = new QList<FileData>;
|
||||
QList<FileData> * folders = new QList<FileData>;
|
||||
|
||||
if(!QDir("Application").exists()){ //проверка на наличие папки
|
||||
QDir().mkdir("Application");
|
||||
}
|
||||
|
||||
QDir dir(localPath);
|
||||
QString hashString;
|
||||
|
||||
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))
|
||||
{
|
||||
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);
|
||||
}
|
||||
else if (fileInfo.isDir() && !fileInfo.isRoot() && fileInfo.fileName() != "..")
|
||||
{
|
||||
currentFile.path = Tools::CreateLocalPath(fileInfo.path());
|
||||
currentFile.hash = "FOLDER";
|
||||
|
||||
if(!folders->contains(currentFile)){
|
||||
folders->push_back(currentFile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileDataList.append(*folders);
|
||||
fileDataList.append(*files);
|
||||
|
||||
dataParser->CreateXML(fileDataList);
|
||||
|
||||
delete folders;
|
||||
delete files;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
UpdateController::~UpdateController()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user