source: filezilla/trunk/fuentes/src/interface/updater.h @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 2.9 KB
Line 
1#ifndef FILEZILLA_UPDATER_HEADER
2#define FILEZILLA_UPDATER_HEADER
3
4#if FZ_MANUALUPDATECHECK
5
6#include <wx/timer.h>
7
8struct build
9{
10        wxString url_;
11        wxString version_;
12        wxString hash_;
13        int64_t size_{-1};
14};
15
16struct version_information
17{
18        bool empty() const {
19                return available_.version_.empty();
20        }
21
22        void update_available();
23
24        build stable_;
25        build beta_;
26        build nightly_;
27
28        build available_;
29
30        wxString changelog;
31};
32
33enum class UpdaterState
34{
35        idle,
36        failed,
37        checking,
38        newversion, // There is a new version available, user needs to manually download
39        newversion_downloading, // There is a new version available, file is being downloaded
40        newversion_ready // There is a new version available, file has been downloaded
41};
42
43class CUpdateHandler
44{
45public:
46        virtual void UpdaterStateChanged( UpdaterState s, build const& v ) = 0;
47};
48
49class CFileZillaEngineContext;
50class CUpdater : public wxEvtHandler
51{
52public:
53        CUpdater(CUpdateHandler& parent, CFileZillaEngineContext& engine_context);
54        virtual ~CUpdater();
55
56        // 2-Stage initialization
57        void Init();
58
59        void AddHandler( CUpdateHandler& handler );
60        void RemoveHandler( CUpdateHandler& handler );
61
62        UpdaterState GetState() const { return state_; }
63        build AvailableBuild() const { return version_information_.available_; }
64        wxString GetChangelog() const { return version_information_.changelog; }
65
66        wxString DownloadedFile() const;
67
68        int64_t BytesDownloaded() const; // Returns -1 on error
69
70        wxString GetLog() const { return log_; }
71
72        bool LongTimeSinceLastCheck() const;
73
74        static CUpdater* GetInstance();
75
76        bool UpdatableBuild() const;
77
78        void RunIfNeeded();
79
80protected:
81        int Download(wxString const& url, wxString const& local_file = _T(""));
82        int ContinueDownload();
83
84        void AutoRunIfNeeded();
85        bool Run();
86
87        bool CreateConnectCommand(wxString const& url);
88        bool CreateTransferCommand(wxString const& url, wxString const& local_file);
89
90        wxString GetUrl();
91        void ProcessNotification(std::unique_ptr<CNotification> && notification);
92        void ProcessOperation(COperationNotification const& operation);
93        void ProcessData(CDataNotification& dataNotification);
94        void ParseData();
95        UpdaterState ProcessFinishedDownload();
96        UpdaterState ProcessFinishedData(bool can_download);
97
98        bool VerifyChecksum(wxString const& file, int64_t size, wxString const& checksum);
99
100        wxString GetTempFile() const;
101        wxString GetFilename(wxString const& url) const;
102        wxString GetLocalFile(build const& b, bool allow_existing);
103
104        void SetState( UpdaterState s );
105
106        DECLARE_EVENT_TABLE()
107        void OnEngineEvent(wxFzEvent& event);
108        void OnTimer(wxTimerEvent& ev);
109
110        UpdaterState state_;
111        wxString local_file_;
112        CFileZillaEngine* engine_;
113        bool m_use_internal_rootcert{};
114
115        wxString raw_version_information_;
116
117        version_information version_information_;
118
119        std::list<CUpdateHandler*> handlers_;
120
121        wxString log_;
122
123        wxTimer update_timer_;
124
125        std::deque<std::unique_ptr<CCommand>> pending_commands_;
126};
127
128#endif //FZ_MANUALUPDATECHECK
129
130#endif
Note: See TracBrowser for help on using the repository browser.