Skip to content

Commit

Permalink
让失败弹窗输出最后十条日志
Browse files Browse the repository at this point in the history
Signed-off-by: SSSSSSSan <sanmeber@163.com>
  • Loading branch information
SSSSSSSan committed Mar 3, 2023
1 parent 416a797 commit 4df7859
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 91 deletions.
62 changes: 31 additions & 31 deletions HTTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@
static QString crtPath;
class HTTP : public QObject, public QRunnable
{
Q_OBJECT


public:
HTTP(QString URL,QString Path,QObject *parent);
~HTTP();

int httpDownLoad(QString URL,QString Path);
static size_t write_data(void *ptr,
size_t size,
size_t nmemb,
void *stream
);
static int progress_callback(void *clientp,
curl_off_t dltotal,
curl_off_t dlnow, curl_off_t ultotal,
curl_off_t ulnow
);
protected:
void run();
private:
QString turl;
QString tdlpath;
void *tid;
FILE *pagefile;
CURL *handle;
private slots:

signals:
void tworkMessageBox(int tag,QString title,QString txt);
void dldone();
Q_OBJECT


public:
HTTP(QString URL,QString Path,QObject *parent);
~HTTP();

int httpDownLoad(QString URL,QString Path);
static size_t write_data(void *ptr,
size_t size,
size_t nmemb,
void *stream
);
static int progress_callback(void *clientp,
curl_off_t dltotal,
curl_off_t dlnow, curl_off_t ultotal,
curl_off_t ulnow
);
protected:
void run();
private:
QString turl;
QString tdlpath;
void *tid;
FILE *pagefile;
CURL *handle;
private slots:

signals:
void tworkMessageBox(int tag,QString title,QString txt);
void dldone();
};
void httpcrt();

Expand Down
53 changes: 51 additions & 2 deletions Start.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Start::Start(QString dir, QObject *parent)
workProcess->start();
this->dir = dir;


}

Start::~Start()
Expand Down Expand Up @@ -95,7 +96,20 @@ void Start::dlworking(LONG64 dlnow,LONG64 dltotal,void *tid,QString path)
}
void Start::stlog(int module,QString str,int mod=NULL)
{
if(tp) emit tp->log(module,str,mod);
if(tp)
{
emit tp->log(module,str,mod);
tp->newLog(module,str);
}

}
void Start::newLog(int module,QString log)
{
qDebug()<<"llog"<<module<<log;
llog * l = new llog;
l->module = module;
l->log = log;
logList.push_back(l);
}
void Start::dldone()
{
Expand Down Expand Up @@ -151,13 +165,47 @@ QString Start::tNowWork()
void Start::updaterErr()
{
tp->stlog(moduleStart,"自动更新失败",NULL);
QString str = "";
int j = 0;
qDebug()<<logList.size();
for(int i = logList.size()-1;i>=0 && j++<10;i--)
{
str += "\n";
switch(logList.at(i)->module)
{
case modulemainWindows:
str += "modulemainWindows";
break;
case moduleStart:
str += "moduleStart";
break;
case moduleHTTP:
str += "moduleHTTP";
break;
case modulefile:
str += "modulefile";
break;
case moduleMD5:
str += "moduleMD5";
break;
case moduleJson:
str += "moduleJson";
break;
}
str += " | ";
str += logList.at(i)->log;
}
emit tworkProcess(0,1);
emit this->changePBText("自动更新失败,请单击重试");
emit tworkFinished(false);
emit this->changeMainPage(1,false);
emit tworkMessageBox(1,
"自动更新失败",
uperr_new);
QString(uperr_new)
+"\n"
"最后十条日志"+
str
);
}
void Start::stopWork()
{
Expand Down Expand Up @@ -411,6 +459,7 @@ void Start::work()
emit this->changeMainPage(1,true);
emit tworkFinished(true);
tp->stlog(moduleStart,"更新流程结束",NULL);
//Start::updaterErr();
}


Expand Down
116 changes: 61 additions & 55 deletions Start.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,69 +18,75 @@
using namespace std;
static QString threadWorking;

struct llog
{
int module;
QString log;
};
struct stnetspeed
{
bool isdling=false;
LONG64 hisDl;
qint64 hisDlt;
LONG64 dl;
qint64 dlt;
LONG64 total;
void *tid;
QString path;
bool isdling=false;
LONG64 hisDl;
qint64 hisDlt;
LONG64 dl;
qint64 dlt;
LONG64 total;
void *tid;
QString path;
};
static stnetspeed netspeed[maxDlThreah];
static int totalFile;
static int doneFile;
class Start : public QObject
{
Q_OBJECT


public:
Start(QString dir, QObject *parent);
~Start();
void updaterErr();
void relaytworkMessageBox(int tag,QString title,QString txt);
void stopWork();
QString tNowWork();
bool isdling;
public:

static void dlworking(LONG64 dlnow,LONG64 dltotal,void *tid,QString path);
static void stlog(int module,QString str,int mod);

private:

QThread *workProcess = nullptr;
QThreadPool *tpoolhttp = nullptr;
QString dir;
HTTP *http=nullptr;
HTTP *thttp=nullptr;



private slots:
void work();
void dldone();
public slots:

signals:
void tstart();
void log(int module,QString str,int mod);
signals:
//void tworkError(int errorCode);
void tworkProcess(int a,int b);
void tworkFinished(bool done);
void tworkMessageBox(int tag,QString title,QString txt);
signals:
/*窗口控制托管信号*/
void changeMainPage(int page,bool done=false);/*修改MainPage,0:进度条 1:选择目录按钮*/
void changeMainPage0label_Text(QString str);/*修改MainPage->Label_Text文本*/
void changeProgressBarValue(int a,int b);/*修改进度条进度*/
void changeProgressBarColor(QString rgba,QString rgbb);
void changePBText(QString str);//修改按钮文本
void updataDlingmag();//强制刷新进度文本
Q_OBJECT


public:
Start(QString dir, QObject *parent);
~Start();
void updaterErr();
void relaytworkMessageBox(int tag,QString title,QString txt);
void stopWork();
QString tNowWork();
bool isdling;
vector<llog*> logList;
void newLog(int module,QString log);
public:

static void dlworking(LONG64 dlnow,LONG64 dltotal,void *tid,QString path);
static void stlog(int module,QString str,int mod);

private:

QThread *workProcess = nullptr;
QThreadPool *tpoolhttp = nullptr;
QString dir;
HTTP *http=nullptr;
HTTP *thttp=nullptr;


private slots:
void work();
void dldone();
public slots:

signals:
void tstart();
void log(int module,QString str,int mod);
signals:
//void tworkError(int errorCode);
void tworkProcess(int a,int b);
void tworkFinished(bool done);
void tworkMessageBox(int tag,QString title,QString txt);
signals:
/*窗口控制托管信号*/
void changeMainPage(int page,bool done=false);/*修改MainPage,0:进度条 1:选择目录按钮*/
void changeMainPage0label_Text(QString str);/*修改MainPage->Label_Text文本*/
void changeProgressBarValue(int a,int b);/*修改进度条进度*/
void changeProgressBarColor(QString rgba,QString rgbb);
void changePBText(QString str);//修改按钮文本
void updataDlingmag();//强制刷新进度文本
};


Expand Down
3 changes: 0 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@

#include <qt_windows.h>



void MessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{

qDebug().noquote()<<msg;//调试窗输出
QJsonObject joc;
QJsonArray jay;
switch(type)
{
case QtDebugMsg:
Expand Down

0 comments on commit 4df7859

Please sign in to comment.