|
@@ -1,6 +1,8 @@
|
|
|
#include "mainwindow.h"
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
|
+#include <QFile>
|
|
|
+
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
QMainWindow(parent),
|
|
|
ui(new Ui::MainWindow)
|
|
@@ -14,6 +16,12 @@ MainWindow::MainWindow(QWidget *parent) :
|
|
|
connect(socket_, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
|
|
|
connect(socket_, SIGNAL(error(QAbstractSocket::SocketError)), this,
|
|
|
SLOT(errorSlot(QAbstractSocket::SocketError)));
|
|
|
+
|
|
|
+ mpTimer = new QTimer(this);
|
|
|
+ connect(mpTimer,SIGNAL(timeout()),this,SLOT(onTimer()));
|
|
|
+ mpTimer->start(100);
|
|
|
+
|
|
|
+ setWindowTitle("Firmware Update");
|
|
|
}
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
@@ -81,6 +89,12 @@ void MainWindow::readyReadSlot()
|
|
|
strncpy(mstrdownname,strdownname,1000);
|
|
|
ui->plainTextEdit->setPlainText("Down File....");
|
|
|
|
|
|
+ int64_t nnow = std::chrono::system_clock::now().time_since_epoch().count();
|
|
|
+ snprintf(mstrfilename,256,"%lld.zip",nnow);
|
|
|
+ snprintf(mstrlogname,256,"%lld.log",nnow);
|
|
|
+
|
|
|
+ mnState = 1;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -109,3 +123,90 @@ void MainWindow::errorSlot(QAbstractSocket::SocketError)
|
|
|
ui->pushButton_Update->setEnabled(true);
|
|
|
}
|
|
|
|
|
|
+void MainWindow::threadunzip()
|
|
|
+{
|
|
|
+ char * strhome = getenv("HOME");
|
|
|
+ char strshell[1000];
|
|
|
+ snprintf(strshell,1000,"unzip -o %s -d %s; rm %s;rm %s,cd %s; unzip -o app.zip -d .;rm app.zip; rm frp.zip; ",
|
|
|
+ mstrfilename,strhome,mstrfilename,mstrlogname,strhome);
|
|
|
+ system(strshell);
|
|
|
+ std::cout<<strshell<<std::endl;
|
|
|
+ mbunzipcomplete = true;
|
|
|
+}
|
|
|
+
|
|
|
+void MainWindow::onTimer()
|
|
|
+{
|
|
|
+ if(mnState == 1)
|
|
|
+ {
|
|
|
+
|
|
|
+ char strshell[1000];
|
|
|
+ snprintf(strshell,256,"wget -b -O %s http://116.63.46.168:19000/%s -o %s",mstrfilename,mstrdownname,mstrlogname);
|
|
|
+ std::cout<<strshell<<std::endl;
|
|
|
+
|
|
|
+ system(strshell);
|
|
|
+
|
|
|
+ mnState = 2;
|
|
|
+ ui->progressBar->setValue(0);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if(mnState == 3)
|
|
|
+ {
|
|
|
+ mbunzipcomplete = false;
|
|
|
+ mpthread = new std::thread(&MainWindow::threadunzip,this);
|
|
|
+
|
|
|
+ mnState = 4;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(mnState == 4)
|
|
|
+ {
|
|
|
+ if(mbunzipcomplete)
|
|
|
+ {
|
|
|
+ QMessageBox::information(this,"Update","Update Complete",QMessageBox::YesAll);
|
|
|
+ mnState = 0;
|
|
|
+// ui->pushButton_Update->setEnabled(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(mnState == 2)
|
|
|
+ {
|
|
|
+ QFile xFile;
|
|
|
+// snprintf(mstrlogname,256,"1692931161205695836.log");
|
|
|
+// snprintf(mstrfilename,256,"1692931161205695836.zip");
|
|
|
+ xFile.setFileName(mstrlogname);
|
|
|
+ bool bProcOK = false;
|
|
|
+ int nProc = 0;
|
|
|
+ if(xFile.open(QIODevice::ReadOnly))
|
|
|
+ {
|
|
|
+ QByteArray ba;
|
|
|
+ ba = xFile.readLine(3000);
|
|
|
+ while(ba.size()>0)
|
|
|
+ {
|
|
|
+
|
|
|
+ QString strline(ba);
|
|
|
+ int index = strline.indexOf("........");
|
|
|
+ if((index > 0) &&(strline.size()>60))
|
|
|
+ {
|
|
|
+ QString strproc =strline.mid(index + 54,3);
|
|
|
+ nProc = strproc.toInt();
|
|
|
+ bProcOK = true;
|
|
|
+ }
|
|
|
+ ba = xFile.readLine(3000);
|
|
|
+ }
|
|
|
+ if(bProcOK)
|
|
|
+ {
|
|
|
+ ui->progressBar->setValue(nProc);
|
|
|
+
|
|
|
+ if(nProc == 100)
|
|
|
+ {
|
|
|
+ mnState = 3;
|
|
|
+ ui->plainTextEdit->setPlainText("Unzip File.");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ xFile.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|