OSDN Git Service

Measure time for update check (for debugging).
[x264-launcher/x264-launcher.git] / src / win_updater.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #pragma once
23
24 #include <QDialog>
25 #include <QMap>
26
27 class QMovie;
28 class QElapsedTimer;
29 class SysinfoModel;
30
31 namespace Ui
32 {
33         class UpdaterDialog;
34 }
35
36 namespace MUtils
37 {
38         class UpdateChecker;
39 }
40
41 class UpdaterDialog : public QDialog
42 {
43         Q_OBJECT
44
45 public:
46         UpdaterDialog(QWidget *parent, const SysinfoModel *sysinfo, const char *const updateUrl);
47         ~UpdaterDialog(void);
48
49         typedef struct
50         {
51                 const char* name;
52                 const char* hash;
53                 const bool  exec;
54         }
55         binary_t;
56
57         static const int READY_TO_INSTALL_UPDATE = 42;
58         static const binary_t BINARIES[];
59
60         inline bool getSuccess(void) { return m_success; }
61
62 protected:
63         virtual bool event(QEvent *e);
64         virtual void showEvent(QShowEvent *event);
65         virtual void closeEvent(QCloseEvent *e);
66         virtual void keyPressEvent(QKeyEvent *event);
67
68 private slots:
69         void initUpdate(void);
70         void checkForUpdates(void);
71         void threadStatusChanged(int status);
72         void threadMessageLogged(const QString &message);
73         void threadFinished(void);
74         void updateFinished(void);
75         void openUrl(const QString &url);
76         void installUpdate(void);
77
78 private:
79         Ui::UpdaterDialog *const ui;
80
81         bool checkBinaries();
82         bool checkFileHash(const QString &filePath, const char *expectedHash);
83         void cleanFiles(void);
84
85         const SysinfoModel *const m_sysinfo;
86         const char *const m_updateUrl;
87
88         bool m_firstShow;
89         bool m_success;
90
91         QScopedPointer<QMovie> m_animator;
92         QScopedPointer<MUtils::UpdateChecker> m_thread;
93         QScopedPointer<QElapsedTimer> m_elapsed;
94
95         unsigned long m_updaterProcess;
96         QStringList m_logFile;
97         QMap<QString,QString> m_binaries;
98         int m_status;
99 };