diff --git a/Cigarette/exportData.cpp b/Cigarette/exportData.cpp index 5cd6846..2a3644a 100644 --- a/Cigarette/exportData.cpp +++ b/Cigarette/exportData.cpp @@ -1,6 +1,11 @@ #include "exportData.h" #include "QtCore\qfile.h" #include "QtCore\qtextstream.h" +#include +#include +#include +#include +#include #include //#include #include @@ -17,6 +22,7 @@ extern SysConf g_sys_conf; //系统配置参数 ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent) { + /* Move to init() //第一步执行 cg->read_conf(g_conf_path); for (int index = 0; index < NumberOfSupportedCameras; index++) @@ -40,12 +46,14 @@ ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent) } if (!ConnectFtp(&ip, &port, &username, &userpwd)) qDebug() << "First connect FTP failed because " << GetLastError(); + */ + readyToSendZip = false; } void ExportDataThread::init(string ip_, int port_, string username_, string userpwd_) { - //第三部执行 + //初始化FTP连接信息 ip = ip_; port = port_; username = username_; @@ -54,6 +62,34 @@ void ExportDataThread::init(string ip_, int port_, string username_, string user cout << "333333username =" << username << "| pwd =" << userpwd << endl; b_quit = false; flag = false; + + timer = new QTimer(this); + timer->setTimerType(Qt::PreciseTimer); + timer->setSingleShot(true); + + //第一步执行 + cg->read_conf(g_conf_path); + for (int index = 0; index < NumberOfSupportedCameras; index++) + { + XMLError error; + pDocument[index] = new tinyxml2::XMLDocument(); + QString xmlPath = QString(EXPORTDATA_FILE).arg(index); + QString filePath = g_conf_path.config_path + "/" + xmlPath; + + error = pDocument[index]->LoadFile(filePath.toLocal8Bit().constData()); + if (error != XML_SUCCESS) { + XMLDeclaration* declaration = pDocument[index]->NewDeclaration(); + pDocument[index]->InsertFirstChild(declaration); + } + } + //init(ip, port, username, userpwd); + cout << "11111111111111"; + hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0); + if (hint == NULL) { + return; + } + if (!ConnectFtp(&ip, &port, &username, &userpwd)) + qDebug() << "First connect FTP failed because " << GetLastError(); } @@ -81,16 +117,15 @@ bool ExportDataThread::ConnectFtp(string *ip_, int *port_, string *username_, st //string userName = "FTP2"; ///* 密码 */ //string pwd = "123"; - int ftpport =*port_; - 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; } // 创建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(), ftpport, username_->c_str(), userpwd_->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); if (hftp == NULL) { qDebug() << "ftp connect failed because " << GetLastError(); return false; @@ -265,6 +300,58 @@ void ExportDataThread::run() QString remotePath = "/tmp/" + xmlPath; ConnectServer(filePath, remotePath); } + + if (readyToSendZip) { + QString remotePath; + QStringList zipFilePaths; + QString zipFilePath; + 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; + + argsNg.append("a"); + argsNg.append(zipFilePaths[0]); + + argsOk.append("a"); + argsOk.append(zipFilePaths[1]); + // create zip file + for (int i = 0; i < listToZip.size(); i++) { + QStringList strList = listToZip[i].split("_"); + strList = strList[strList.size() - 1].split("."); + int index = listToZip[i].lastIndexOf("/\\", 0); + if (strList[0] == okStr) { + argsOk.append(listToZip[i]); + } + else { + + argsNg.append(listToZip[i]); + } + /* + QDir dir; + if (!dir.exists(listToZip[i].mid(index - 1))) + { + dir.mkpath(listToZip[i].mid(index - 1)); + } + */ + } + argsNg.append("-mx=3"); + + argsOk.append("-mx=3"); + + for (int i = 0; i < zipFilePaths.size(); i++) { + process.start(QApplication::applicationDirPath() + "/7z.exe", i == 0 ? argsNg : argsOk); + process.waitForStarted(); + process.waitForFinished(); + ConnectServer(zipFilePaths[i], remotePath); + } + readyToSendZip = false; + } } flag = false; @@ -349,8 +436,20 @@ void ExportDataThread::ConnectServer(QString srcPath, QString destPath) { void ExportDataThread::GetDataFromSaveThread(QString filePath) { QString remotePath; - remotePath = filePath.mid(filePath.indexOf("image") - 1); - ConnectServer(filePath, remotePath); + + if (timer->isActive()) { + tmpListToZip.append(filePath); + } + else { + listToZip = tmpListToZip; + tmpListToZip.clear(); + tmpListToZip.append(filePath); + + readyToSendZip = true; + //remotePath = filePath.mid(filePath.indexOf("image") - 1); + //ConnectServer(filePath, remotePath); + timer->start(1000 * 60 * 5); // 5min + } } //*****************************************已经调试好,没有理清逻辑前不要动********************** diff --git a/Cigarette/exportData.h b/Cigarette/exportData.h index f436e77..8143ff4 100644 --- a/Cigarette/exportData.h +++ b/Cigarette/exportData.h @@ -115,6 +115,11 @@ public: quit(); wait(); } + QTimer* timer; + QStringList listToZip; + QStringList tmpListToZip; + BOOLEAN readyToSendZip; + void init(string ip_, int port_, string username_, string userpwd_); void start_work();