-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwinsparkle.h
484 lines (345 loc) · 15.6 KB
/
winsparkle.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
/*
* This file is part of WinSparkle (https://winsparkle.org)
*
* Copyright (C) 2009-2018 Vaclav Slavik
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
#ifndef _winsparkle_h_
#define _winsparkle_h_
#include <stddef.h>
#include "winsparkle-version.h"
#if !defined(BUILDING_WIN_SPARKLE) && defined(_MSC_VER) && defined(_M_IX86_FP)
#pragma comment(lib, "..\\32\\WinSparkle.lib")
#endif
#if !defined(BUILDING_WIN_SPARKLE) && defined(_MSC_VER) && defined(_M_X64)
#pragma comment(lib, "..\\64\\WinSparkle.lib")
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BUILDING_WIN_SPARKLE
#define WIN_SPARKLE_API __declspec(dllexport)
#else
#define WIN_SPARKLE_API __declspec(dllimport)
#endif
/*--------------------------------------------------------------------------*
Initialization and shutdown
*--------------------------------------------------------------------------*/
/**
@name Initialization functions
*/
//@{
/**
Starts WinSparkle.
If WinSparkle is configured to check for updates on startup, proceeds
to perform the check. You should only call this function when your app
is initialized and shows its main window.
@note This call doesn't block and returns almost immediately. If an
update is available, the respective UI is shown later from a separate
thread.
@see win_sparkle_cleanup()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_init();
/**
Cleans up after WinSparkle.
Should be called by the app when it's shutting down. Cancels any
pending Sparkle operations and shuts down its helper threads.
*/
WIN_SPARKLE_API void __cdecl win_sparkle_cleanup();
//@}
/*--------------------------------------------------------------------------*
Language settings
*--------------------------------------------------------------------------*/
/**
@name Language settings
These functions set user interface language. They must be called before
win_sparkle_init() to have any effect. If none of them is called, WinSparkle
detects the UI language automatically.
*/
//@{
/**
Sets UI language from its ISO code.
This function must be called before win_sparkle_init().
@param lang ISO 639 language code with an optional ISO 3116 country
code, e.g. "fr", "pt-PT", "pt-BR" or "pt_BR", as used
e.g. by ::GetThreadPreferredUILanguages() too.
@since 0.5
@see win_sparkle_set_langid()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_lang(const char *lang);
/**
Sets UI language from its Win32 LANGID code.
This function must be called before win_sparkle_init().
@param lang Language code (LANGID) as created by the MAKELANGID macro
or returned by e.g. ::GetThreadUILanguage()
@since 0.5
@see win_sparkle_set_lang()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_langid(unsigned short lang);
//@}
/*--------------------------------------------------------------------------*
Configuration
*--------------------------------------------------------------------------*/
/**
@name Configuration functions
Functions for setting up WinSparkle.
All functions in this category can only be called @em before the first
call to win_sparkle_init()!
Typically, the application would configure WinSparkle on startup and then
call win_sparkle_init(), all from its main thread.
*/
//@{
/**
Sets URL for the app's appcast.
Only http and https schemes are supported.
If this function isn't called by the app, the URL is obtained from
Windows resource named "FeedURL" of type "APPCAST".
@param url URL of the appcast.
@note Always use HTTPS feeds, do not use unencrypted HTTP! This is
necessary to prevent both leaking user information and preventing
various MITM attacks.
@note See https://github.com/vslavik/winsparkle/wiki/Appcast-Feeds for
more information about appcast feeds.
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_appcast_url(const char *url);
/**
Sets DSA public key.
Only PEM format is supported.
Public key will be used to verify DSA signature of the update file.
PEM data will be set only if it contains valid DSA public key.
If this function isn't called by the app, public key is obtained from
Windows resource named "DSAPub" of type "DSAPEM".
@param dsa_pub_pem DSA public key in PEM format.
@return 1 if valid DSA public key provided, 0 otherwise.
@since 0.6.0
*/
WIN_SPARKLE_API int __cdecl win_sparkle_set_dsa_pub_pem(const char *dsa_pub_pem);
/**
Sets application metadata.
Normally, these are taken from VERSIONINFO/StringFileInfo resources,
but if your application doesn't use them for some reason, using this
function is an alternative.
@param company_name Company name of the vendor.
@param app_name Application name. This is both shown to the user
and used in HTTP User-Agent header.
@param app_version Version of the app, as string (e.g. "1.2" or "1.2rc1").
@note @a company_name and @a app_name are used to determine the location
of WinSparkle settings in registry.
(HKCU\Software\<company_name>\<app_name>\WinSparkle is used.)
@since 0.3
@see win_sparkle_set_app_build_version();
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_app_details(const wchar_t *company_name,
const wchar_t *app_name,
const wchar_t *app_version);
/**
Sets application build version number.
This is the internal version number that is not normally shown to the user.
It can be used for finer granularity that official release versions, e.g. for
interim builds.
If this function is called, then the provided *build* number is used for comparing
versions; it is compared to the "version" attribute in the appcast and corresponds
to OS X Sparkle's CFBundleVersion handling. If used, then the appcast must
also contain the "shortVersionString" attribute with human-readable display
version string. The version passed to win_sparkle_set_app_details()
corresponds to this and is used for display.
@since 0.4
@see win_sparkle_set_app_details()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_app_build_version(const wchar_t *build);
/**
Set the registry path where settings will be stored.
Normally, these are stored in
"HKCU\Software\<company_name>\<app_name>\WinSparkle"
but if your application needs to store the data elsewhere for
some reason, using this function is an alternative.
Note that @a path is relative to HKCU/HKLM root and the root is not part
of it. For example:
@code
win_sparkle_set_registry_path("Software\\My App\\Updates");
@endcode
@param path Registry path where settings will be stored.
@since 0.3
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_registry_path(const char *path);
/**
Sets whether updates are checked automatically or only through a manual call.
If disabled, win_sparkle_check_update_with_ui() must be used explicitly.
@param state 1 to have updates checked automatically, 0 otherwise
@since 0.4
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_automatic_check_for_updates(int state);
/**
Gets the automatic update checking state
@return 1 if updates are set to be checked automatically, 0 otherwise
@note Defaults to 0 when not yet configured (as happens on first start).
@since 0.4
*/
WIN_SPARKLE_API int __cdecl win_sparkle_get_automatic_check_for_updates();
/**
Sets the automatic update interval.
@param interval The interval in seconds between checks for updates.
The minimum update interval is 3600 seconds (1 hour).
@since 0.4
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_update_check_interval(int interval);
/**
Gets the automatic update interval in seconds.
Default value is one day.
@since 0.4
*/
WIN_SPARKLE_API int __cdecl win_sparkle_get_update_check_interval();
/**
Gets the time for the last update check.
Default value is -1, indicating that the update check has never run.
@since 0.4
*/
WIN_SPARKLE_API time_t __cdecl win_sparkle_get_last_check_time();
/// Callback type for win_sparkle_error_callback()
typedef void (__cdecl *win_sparkle_error_callback_t)();
/**
Set callback to be called when the updater encounters an error.
@since 0.5
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_error_callback(win_sparkle_error_callback_t callback);
/// Callback type for win_sparkle_can_shutdown_callback()
typedef int (__cdecl *win_sparkle_can_shutdown_callback_t)();
/**
Set callback for querying the application if it can be closed.
This callback will be called to ask the host if it's ready to shut down,
before attempting to launch the installer. The callback returns TRUE if
the host application can be safely shut down or FALSE if not (e.g. because
the user has unsaved documents).
@note There's no guarantee about the thread from which the callback is called,
except that it certainly *won't* be called from the app's main thread.
Make sure the callback is thread-safe.
@since 0.4
@see win_sparkle_set_shutdown_request_callback()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_can_shutdown_callback(win_sparkle_can_shutdown_callback_t callback);
/// Callback type for win_sparkle_shutdown_request_callback()
typedef void (__cdecl *win_sparkle_shutdown_request_callback_t)();
/**
Set callback for shutting down the application.
This callback will be called to ask the host to shut down immediately after
launching the installer. Its implementation should gracefully terminate the
application.
It will only be called if the call to the callback set with
win_sparkle_set_can_shutdown_callback() returns TRUE.
@note There's no guarantee about the thread from which the callback is called,
except that it certainly *won't* be called from the app's main thread.
Make sure the callback is thread-safe.
@since 0.4
@see win_sparkle_set_can_shutdown_callback()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_shutdown_request_callback(win_sparkle_shutdown_request_callback_t);
/// Callback type for win_sparkle_did_find_update_callback()
typedef void(__cdecl *win_sparkle_did_find_update_callback_t)();
/**
Set callback to be called when the updater did find an update.
This is useful in combination with
win_sparkle_check_update_with_ui_and_install() as it allows you to perform
some action after WinSparkle checks for updates.
@since 0.5
@see win_sparkle_did_not_find_update_callback()
@see win_sparkle_check_update_with_ui_and_install()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_did_find_update_callback(win_sparkle_did_find_update_callback_t callback);
/// Callback type for win_sparkle_did_not_find_update_callback()
typedef void (__cdecl *win_sparkle_did_not_find_update_callback_t)();
/**
Set callback to be called when the updater did not find an update.
This is useful in combination with
win_sparkle_check_update_with_ui_and_install() as it allows you to perform
some action after WinSparkle checks for updates.
@since 0.5
@see win_sparkle_did_find_update_callback()
@see win_sparkle_check_update_with_ui_and_install()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_did_not_find_update_callback(win_sparkle_did_not_find_update_callback_t callback);
/// Callback type for win_sparkle_update_cancelled_callback()
typedef void (__cdecl *win_sparkle_update_cancelled_callback_t)();
/**
Set callback to be called when the user cancels a download.
This is useful in combination with
win_sparkle_check_update_with_ui_and_install() as it allows you to perform
some action when the installation is interrupted.
@since 0.5
@see win_sparkle_check_update_with_ui_and_install()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_set_update_cancelled_callback(win_sparkle_update_cancelled_callback_t callback);
//@}
/*--------------------------------------------------------------------------*
Manual usage
*--------------------------------------------------------------------------*/
/**
@name Manually using WinSparkle
*/
//@{
/**
Checks if an update is available, showing progress UI to the user.
Normally, WinSparkle checks for updates on startup and only shows its UI
when it finds an update. If the application disables this behavior, it
can hook this function to "Check for updates..." menu item.
When called, background thread is started to check for updates. A small
window is shown to let the user know the progress. If no update is found,
the user is told so. If there is an update, the usual "update available"
window is shown.
This function returns immediately.
@note Because this function is intended for manual, user-initiated checks
for updates, it ignores "Skip this version" even if the user checked
it previously.
@see win_sparkle_check_update_without_ui()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_check_update_with_ui();
/**
Checks if an update is available, showing progress UI to the user and
immediately installing the update if one is available.
This is useful for the case when users should almost always use the
newest version of your software. When called, WinSparkle will check for
updates showing a progress UI to the user. If an update is found the update
prompt will be skipped and the update will be installed immediately.
If your application expects to do something after checking for updates you
may wish to use win_sparkle_set_did_not_find_update_callback() and
win_sparkle_set_update_cancelled_callback().
@since 0.5
@see win_sparkle_set_did_find_update_callback()
@see win_sparkle_set_update_cancelled_callback()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_check_update_with_ui_and_install();
/**
Checks if an update is available.
No progress UI is shown to the user when checking. If an update is
available, the usual "update available" window is shown; this function
is *not* completely UI-less.
Use with caution, it usually makes more sense to use the automatic update
checks on interval option or manual check with visible UI.
This function returns immediately.
@note This function respects "Skip this version" choice by the user.
@since 0.4
@see win_sparkle_check_update_with_ui()
*/
WIN_SPARKLE_API void __cdecl win_sparkle_check_update_without_ui();
//@}
#ifdef __cplusplus
}
#endif
#endif // _winsparkle_h_