diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index f49b4e4..2e8a16f 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -2,11 +2,13 @@ #include #include #include +#include #include #include #include #include +#include "updater/updaterconst.h" #include "common/global.h" #include "common/player.h" #include "common/problem.h" @@ -66,6 +68,7 @@ MainWindow::MainWindow(QWidget* parent) : CreateActions(); UpdateRecentContest(true); + CheckUpdates(true); this->activateWindow(); } @@ -90,6 +93,15 @@ void MainWindow::UnlockTable() detail_table->Unlock(); } +void MainWindow::CheckUpdates(bool dontShowError) +{ + QString dir = QCoreApplication::applicationDirPath(); + QStringList arguments = { "-c", "-p" }; + arguments.append(QString("%1").arg(QCoreApplication::applicationPid())); + if (dontShowError) arguments.append("-n"); + QProcess::startDetached(dir + "/" + Updater::UPDATER_NAME, arguments, dir); +} + // Last contest path static QString lastContest; @@ -773,6 +785,11 @@ void MainWindow::on_action_help_triggered() } +void MainWindow::on_action_update_triggered() +{ + CheckUpdates(false); +} + void MainWindow::on_action_about_triggered() { QMessageBox msgBox(this); diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index c267037..627c20c 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -46,6 +46,9 @@ class MainWindow : public QMainWindow void LockTable(); void UnlockTable(); + /// 检查更新,是否只当有更新时才显示对话框 + void CheckUpdates(bool dontShowError); + /// 更新最近打开的竞赛列表,是否更新 listWidget_recent void UpdateRecentContest(bool); @@ -107,6 +110,7 @@ private slots: // Help menu actions void on_action_help_triggered(); + void on_action_update_triggered(); void on_action_about_triggered(); protected: diff --git a/src/mainwindow/mainwindow.ui b/src/mainwindow/mainwindow.ui index 015f86c..0febaa4 100644 --- a/src/mainwindow/mainwindow.ui +++ b/src/mainwindow/mainwindow.ui @@ -200,6 +200,7 @@ QMainWindow 帮助(&H) + @@ -338,6 +339,11 @@ QMainWindow F1 + + + 检查更新(&U)... + +