| 1 | // Aseprite |
| 2 | // Copyright (C) 2001-2016 David Capello |
| 3 | // |
| 4 | // This program is distributed under the terms of |
| 5 | // the End-User License Agreement for Aseprite. |
| 6 | |
| 7 | #ifndef UPDATER_CHECK_UPDATE_H_INCLUDED |
| 8 | #define UPDATER_CHECK_UPDATE_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include "base/disable_copying.h" |
| 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | namespace updater { |
| 16 | |
| 17 | typedef std::string Uuid; |
| 18 | |
| 19 | // Data received by a "check new version" request. |
| 20 | class CheckUpdateResponse { |
| 21 | public: |
| 22 | enum Type { |
| 23 | Unknown, |
| 24 | NoUpdate, // No update available. You've the latest version. |
| 25 | Critical, // There are critical bugs fixed. |
| 26 | Major // New major version. |
| 27 | }; |
| 28 | |
| 29 | CheckUpdateResponse(); |
| 30 | CheckUpdateResponse(const CheckUpdateResponse& other); |
| 31 | CheckUpdateResponse(const std::string& responseBody); |
| 32 | |
| 33 | // Returns the type of the available update. |
| 34 | Type getUpdateType() const { return m_type; } |
| 35 | |
| 36 | // Returns the latest version available to be downloaded. |
| 37 | std::string getLatestVersion() const { return m_version; } |
| 38 | |
| 39 | // Returns the URL to download the new version. |
| 40 | std::string getUrl() const { return m_url; } |
| 41 | |
| 42 | // Returns a UUID to be assigned to this user. This parameter is |
| 43 | // returned only when the request is done without an existent |
| 44 | // UUID. |
| 45 | Uuid getUuid() const { return m_uuid; } |
| 46 | |
| 47 | // Returns the number of days that this client should wait for the |
| 48 | // next "check for updates". |
| 49 | double getWaitDays() const { return m_waitDays; } |
| 50 | |
| 51 | private: |
| 52 | Type m_type; |
| 53 | std::string m_version; |
| 54 | std::string m_url; |
| 55 | Uuid m_uuid; |
| 56 | double m_waitDays; |
| 57 | }; |
| 58 | |
| 59 | // Delegate called by CheckUpdate when the request to the server is |
| 60 | // done. It must be implemented by the client of CheckUpdate. |
| 61 | class CheckUpdateDelegate { |
| 62 | public: |
| 63 | virtual ~CheckUpdateDelegate() { } |
| 64 | |
| 65 | // Called by CheckUpdate::checkNewVersion() when the response from |
| 66 | // the "updates server" is received. |
| 67 | virtual void onResponse(CheckUpdateResponse& data) = 0; |
| 68 | }; |
| 69 | |
| 70 | // Checks for new versions. |
| 71 | class CheckUpdate { |
| 72 | public: |
| 73 | CheckUpdate(); |
| 74 | ~CheckUpdate(); |
| 75 | |
| 76 | // Cancels any operation in progress. It is called automatically in |
| 77 | // the destructor. |
| 78 | void abort(); |
| 79 | |
| 80 | // Sends a request to the "updates server" and calls the delegate |
| 81 | // when the response is received. |
| 82 | bool checkNewVersion(const Uuid& uuid, const std::string& , CheckUpdateDelegate* delegate); |
| 83 | |
| 84 | private: |
| 85 | class CheckUpdateImpl; |
| 86 | CheckUpdateImpl* m_impl; |
| 87 | |
| 88 | DISABLE_COPYING(CheckUpdate); |
| 89 | }; |
| 90 | |
| 91 | } // namespace updater |
| 92 | |
| 93 | #endif |
| 94 | |