|
|
|
@ -5,6 +5,8 @@
|
|
|
|
|
#include <QFileInfoList>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QIODevice>
|
|
|
|
|
#include <QTextStream>
|
|
|
|
|
#include <QProcess>
|
|
|
|
|
#include <string>
|
|
|
|
|
//#include <ftpManager.h>
|
|
|
|
@ -48,6 +50,8 @@ ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
|
|
|
|
|
qDebug() << "First connect FTP failed because " << GetLastError();
|
|
|
|
|
*/
|
|
|
|
|
readyToSendZip = false;
|
|
|
|
|
listToZip.clear();
|
|
|
|
|
tmpListToZip.clear();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -103,8 +107,8 @@ void ExportDataThread::stop()
|
|
|
|
|
b_quit = true;
|
|
|
|
|
_XMLExportDataInfo data;
|
|
|
|
|
export_XMLData_Info_queue->put(data);
|
|
|
|
|
InternetCloseHandle(hftp);
|
|
|
|
|
InternetCloseHandle(hint);
|
|
|
|
|
//InternetCloseHandle(hftp);
|
|
|
|
|
//InternetCloseHandle(hint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ExportDataThread::ConnectFtp(string *ip_, int *port_, string *username_, string *userpwd_) {
|
|
|
|
@ -117,12 +121,20 @@ bool ExportDataThread::ConnectFtp(string *ip_, int *port_, string *username_, st
|
|
|
|
|
//string userName = "FTP2";
|
|
|
|
|
///* 密码 */
|
|
|
|
|
//string pwd = "123";
|
|
|
|
|
cout << "222ftp ip =" << ip_ << "| prot =" << *port_ << endl;
|
|
|
|
|
cout << "222username =" << username_ << "| pwd =" << userpwd_ << endl;
|
|
|
|
|
cout << "222ftp ip =" << *ip_ << "| prot =" << *port_ << endl;
|
|
|
|
|
cout << "222username =" << *username_ << "| pwd =" << *userpwd_ << endl;
|
|
|
|
|
if (hftp != NULL) {
|
|
|
|
|
InternetCloseHandle(hftp);
|
|
|
|
|
hftp = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hint == NULL) {
|
|
|
|
|
hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
|
|
|
|
|
if (hint == NULL) {
|
|
|
|
|
qDebug() << "Faile to open internet";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 创建ftp连接
|
|
|
|
|
// hftp = InternetConnectA(hint, ftpServer.c_str(), port, userName.c_str(), pwd.c_str(), INTERNET_SERVICE_FTP, 0, 0);
|
|
|
|
|
hftp = InternetConnectA(hint, ip_->c_str(), *port_, username_->c_str(), userpwd_->c_str(), INTERNET_SERVICE_FTP, 0, 0);
|
|
|
|
@ -285,9 +297,9 @@ int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& dat
|
|
|
|
|
|
|
|
|
|
void ExportDataThread::run()
|
|
|
|
|
{
|
|
|
|
|
while (!b_quit) {
|
|
|
|
|
|
|
|
|
|
while (!b_quit || (b_quit && (!export_XMLData_Info_queue->isEmpty() || readyToSendZip || !tmpListToZip.isEmpty()))) {
|
|
|
|
|
_XMLExportDataInfo element;
|
|
|
|
|
if (!export_XMLData_Info_queue->isEmpty()) {
|
|
|
|
|
export_XMLData_Info_queue->take(element);
|
|
|
|
|
|
|
|
|
|
if (element.cameraId != -1 && flag) {
|
|
|
|
@ -300,21 +312,38 @@ void ExportDataThread::run()
|
|
|
|
|
QString remotePath = "/tmp/" + xmlPath;
|
|
|
|
|
ConnectServer(filePath, remotePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b_quit && (!tmpListToZip.isEmpty())) {
|
|
|
|
|
listToZip += tmpListToZip;
|
|
|
|
|
tmpListToZip.clear();
|
|
|
|
|
readyToSendZip = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (readyToSendZip) {
|
|
|
|
|
QString remotePath;
|
|
|
|
|
QStringList zipFilePaths;
|
|
|
|
|
QString zipFilePath;
|
|
|
|
|
QString okStr = "ok";
|
|
|
|
|
QStringList fileList;
|
|
|
|
|
QString okStr = "OK";
|
|
|
|
|
QProcess process(0);
|
|
|
|
|
QDateTime now_ts = QDateTime::currentDateTime();
|
|
|
|
|
|
|
|
|
|
zipFilePaths.append(g_conf_path.save_pics_path + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "ng.zip");
|
|
|
|
|
zipFilePaths.append(g_conf_path.save_pics_path + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "ok.zip");
|
|
|
|
|
remotePath = listToZip[0].mid(listToZip[0].indexOf("image") - 1);
|
|
|
|
|
QStringList argsNg;
|
|
|
|
|
QStringList argsOk;
|
|
|
|
|
|
|
|
|
|
zipFilePaths.append(g_conf_path.save_pics_path + "/" + now_ts.toString("yyyy-MM-dd_HH-mm-ss_") + "ng.zip");
|
|
|
|
|
zipFilePaths.append(g_conf_path.save_pics_path + "/" + now_ts.toString("yyyy-MM-dd_HH-mm-ss_") + "ok.zip");
|
|
|
|
|
fileList.append(g_conf_path.save_pics_path + "/" + now_ts.toString("yyyy-MM-dd_HH-mm-ss_") + "ng.txt");
|
|
|
|
|
fileList.append(g_conf_path.save_pics_path + "/" + now_ts.toString("yyyy-MM-dd_HH-mm-ss_") + "ok.txt");
|
|
|
|
|
|
|
|
|
|
QFile fileNg(fileList[0]);
|
|
|
|
|
QFile fileOk(fileList[1]);
|
|
|
|
|
|
|
|
|
|
fileNg.open(QIODevice::WriteOnly);
|
|
|
|
|
fileOk.open(QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
|
|
QTextStream ngStream(&fileNg);
|
|
|
|
|
QTextStream okStream(&fileOk);
|
|
|
|
|
|
|
|
|
|
argsNg.append("a");
|
|
|
|
|
argsNg.append(zipFilePaths[0]);
|
|
|
|
|
|
|
|
|
@ -326,11 +355,11 @@ void ExportDataThread::run()
|
|
|
|
|
strList = strList[strList.size() - 1].split(".");
|
|
|
|
|
int index = listToZip[i].lastIndexOf("/\\", 0);
|
|
|
|
|
if (strList[0] == okStr) {
|
|
|
|
|
argsOk.append(listToZip[i]);
|
|
|
|
|
okStream << listToZip[i] << endl;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
argsNg.append(listToZip[i]);
|
|
|
|
|
ngStream << listToZip[i] << endl;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
QDir dir;
|
|
|
|
@ -340,16 +369,29 @@ void ExportDataThread::run()
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
argsNg.append("-i@" + fileList[0]);
|
|
|
|
|
argsNg.append("-mx=3");
|
|
|
|
|
|
|
|
|
|
argsOk.append("-i@" + fileList[1]);
|
|
|
|
|
argsOk.append("-mx=3");
|
|
|
|
|
|
|
|
|
|
fileNg.close();
|
|
|
|
|
fileOk.close();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < zipFilePaths.size(); i++) {
|
|
|
|
|
process.start(QApplication::applicationDirPath() + "/7z.exe", i == 0 ? argsNg : argsOk);
|
|
|
|
|
process.waitForStarted();
|
|
|
|
|
process.waitForFinished();
|
|
|
|
|
//QString out = QString::fromLocal8Bit(process.readAllStandardOutput());
|
|
|
|
|
//qDebug() << out;
|
|
|
|
|
remotePath = zipFilePaths[i].mid(zipFilePaths[i].indexOf("image") - 1);
|
|
|
|
|
qDebug() << remotePath;
|
|
|
|
|
ConnectServer(zipFilePaths[i], remotePath);
|
|
|
|
|
QFile file(zipFilePaths[i]);
|
|
|
|
|
file.remove();
|
|
|
|
|
}
|
|
|
|
|
fileNg.remove();
|
|
|
|
|
fileOk.remove();
|
|
|
|
|
readyToSendZip = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -358,6 +400,11 @@ void ExportDataThread::run()
|
|
|
|
|
for (int index = 0; index < NumberOfSupportedCameras; index++) {
|
|
|
|
|
pDocument[index]->~XMLDocument();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InternetCloseHandle(hftp);
|
|
|
|
|
InternetCloseHandle(hint);
|
|
|
|
|
hftp = NULL;
|
|
|
|
|
hint = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//*****************************************已经调试好,没有理清逻辑前不要动**********************
|
|
|
|
@ -434,18 +481,72 @@ void ExportDataThread::ConnectServer(QString srcPath, QString destPath) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
bool compression_zip_file(const QString& selectFile2DirPath, const QString& savePath)
|
|
|
|
|
{
|
|
|
|
|
if (selectFile2DirPath.isEmpty() || savePath.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!QFile::exists(selectFile2DirPath) || !QFileInfo(savePath).isDir())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (QFileInfo(selectFile2DirPath).isFile())///压缩的是一个文件
|
|
|
|
|
{
|
|
|
|
|
QString fileName = QFileInfo(selectFile2DirPath).baseName();
|
|
|
|
|
QString writerFilePath = savePath + "/" + fileName + ".zip";
|
|
|
|
|
|
|
|
|
|
QFile selectFile(selectFile2DirPath);
|
|
|
|
|
qint64 size = selectFile.size() / 1024 / 1024;
|
|
|
|
|
if (!selectFile.open(QIODevice::ReadOnly) || size > FILE_MAX_SIZE)
|
|
|
|
|
{
|
|
|
|
|
///打开文件失败,或者大于1GB导致无法压缩的文件
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
QString addFileName = QFileInfo(selectFile2DirPath).fileName();
|
|
|
|
|
QZipWriter writer(writerFilePath);
|
|
|
|
|
writer.addFile(addFileName, selectFile.readAll());
|
|
|
|
|
selectFile.close();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
else///压缩的是一个文件夹
|
|
|
|
|
{
|
|
|
|
|
QString zipRootFolder = selectFile2DirPath.mid(selectFile2DirPath.lastIndexOf("/") + 1);
|
|
|
|
|
QString selectDirUpDir = selectFile2DirPath.left(selectFile2DirPath.lastIndexOf("/"));
|
|
|
|
|
QString saveFilePath = savePath + "/" + zipRootFolder + ".zip";
|
|
|
|
|
|
|
|
|
|
QZipWriter writer(saveFilePath);
|
|
|
|
|
writer.addDirectory(zipRootFolder);
|
|
|
|
|
QFileInfoList fileList = ergodic_compression_file(&writer, selectDirUpDir, selectFile2DirPath);
|
|
|
|
|
writer.close();
|
|
|
|
|
if (0 == fileList.size())
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ExportDataThread::GetDataFromSaveThread(QString filePath) {
|
|
|
|
|
QString remotePath;
|
|
|
|
|
|
|
|
|
|
if (timer->isActive()) {
|
|
|
|
|
if ((filePath.indexOf("ng_result") != -1) || (filePath.indexOf("ng") == -1)) {
|
|
|
|
|
tmpListToZip.append(filePath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
listToZip = tmpListToZip;
|
|
|
|
|
tmpListToZip.clear();
|
|
|
|
|
if ((filePath.indexOf("ng_result") != -1) || (filePath.indexOf("ng") == -1)) {
|
|
|
|
|
tmpListToZip.append(filePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!listToZip.isEmpty()) {
|
|
|
|
|
readyToSendZip = true;
|
|
|
|
|
}
|
|
|
|
|
//remotePath = filePath.mid(filePath.indexOf("image") - 1);
|
|
|
|
|
//ConnectServer(filePath, remotePath);
|
|
|
|
|
timer->start(1000 * 60 * 5); // 5min
|
|
|
|
|