[Automatic update for 2018-04-08]
[metze/wireshark/wip.git] / ui / software_update.c
1 /* software_update.h
2  * Wrappers and routines to check for software updates.
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later*/
9
10 #include "config.h"
11
12 #include "software_update.h"
13 #include "language.h"
14 #include "../epan/prefs.h"
15
16 /*
17  * Version 0 of the update URI path has the following elements:
18  * - The update path prefix (fixed, "update")
19  * - The schema version (fixed, 0)
20  * - The application name (fixed, "Wireshark")
21  * - The application version ("<major>.<minor>.<micro>")
22  * - The operating system (varable, one of "windows" or "osx")
23  * - The architecture name (variable, one of "x86", "x86-64")
24  * - The locale (fixed, "en-US)
25  * - The update channel (variable, one of "development" or "stable") + .xml
26  *
27  * Based on https://wiki.mozilla.org/Software_Update:Checking_For_Updates
28  */
29
30 #ifdef HAVE_SOFTWARE_UPDATE
31 #define SU_SCHEMA_PREFIX "update"
32 #define SU_SCHEMA_VERSION 0
33 #define SU_APPLICATION "Wireshark"
34 #define SU_LOCALE "en-US"
35 #endif /* HAVE_SOFTWARE_UPDATE */
36
37 #if defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32)
38
39 #include "glib.h"
40
41 #include <winsparkle.h>
42
43 #define SU_OSNAME "Windows"
44
45 static GString *update_url_str = NULL;
46
47 static const char *get_appcast_update_url(software_update_channel_e chan) {
48     const char *chan_name;
49     const char *arch = "x86";
50
51     if (!update_url_str) {
52         update_url_str = g_string_new("");
53     }
54
55     /* XXX Add WOW64 checks similar to version_info.c? */
56     if (sizeof(arch) != 4) {
57         arch = "x86-64";
58     }
59
60     switch (chan) {
61         case UPDATE_CHANNEL_DEVELOPMENT:
62             chan_name = "development";
63             break;
64         default:
65             chan_name = "stable";
66             break;
67     }
68     g_string_printf(update_url_str, "https://www.wireshark.org/%s/%u/%s/%s/%s/%s/en-US/%s.xml",
69                     SU_SCHEMA_PREFIX,
70                     SU_SCHEMA_VERSION,
71                     SU_APPLICATION,
72                     VERSION,
73                     SU_OSNAME,
74                     arch,
75                     chan_name);
76     return update_url_str->str;
77 }
78
79 /** Initialize software updates.
80  */
81 void
82 software_update_init(void) {
83     const char *update_url = get_appcast_update_url(prefs.gui_update_channel);
84
85     /*
86      * According to the WinSparkle 0.5 documentation these must be called
87      * once, before win_sparkle_init. We can't update them dynamically when
88      * our preferences change.
89      */
90     win_sparkle_set_registry_path("Software\\Wireshark\\WinSparkle Settings");
91     win_sparkle_set_appcast_url(update_url);
92     win_sparkle_set_automatic_check_for_updates(prefs.gui_update_enabled ? 1 : 0);
93     win_sparkle_set_update_check_interval(prefs.gui_update_interval);
94     win_sparkle_set_can_shutdown_callback(software_update_can_shutdown_callback);
95     win_sparkle_set_shutdown_request_callback(software_update_shutdown_request_callback);
96     if ((language != NULL) && (strcmp(language, "system") != 0)) {
97         win_sparkle_set_lang(language);
98     }
99     win_sparkle_init();
100 }
101
102 /** Force a software update check.
103  */
104 void
105 software_update_check(void) {
106     win_sparkle_check_update_with_ui();
107 }
108
109 /** Clean up software update checking.
110  *
111  * Does nothing on platforms that don't support software updates.
112  */
113 extern void software_update_cleanup(void) {
114     win_sparkle_cleanup();
115 }
116
117 #else /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */
118
119 /** Initialize software updates.
120  */
121 void
122 software_update_init(void) {
123 }
124
125 /** Force a software update check.
126  */
127 void
128 software_update_check(void) {
129 }
130
131 /** Clean up software update checking.
132  */
133 void software_update_cleanup(void) {
134 }
135
136 /** Check to see if Wireshark can shut down safely (e.g. offer to save the
137  *  current capture).
138  */
139 int software_update_can_shutdown_callback(void) {
140     return FALSE;
141 }
142
143 /** Shut down Wireshark in preparation for an upgrade.
144  */
145 void software_update_shutdown_request_callback(void) {
146 }
147
148 #endif /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */
149
150 /*
151  * Editor modelines
152  *
153  * Local Variables:
154  * c-basic-offset: 4
155  * tab-width: 8
156  * indent-tabs-mode: nil
157  * End:
158  *
159  * ex: set shiftwidth=4 tabstop=8 expandtab:
160  * :indentSize=4:tabSize=8:noTabs=true:
161  */
162