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