Qt: More byte view and proto tree fixes.
[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  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include "software_update.h"
26 #include "language.h"
27 #include "../epan/prefs.h"
28
29 /*
30  * Version 0 of the update URI path has the following elements:
31  * - The update path prefix (fixed, "update")
32  * - The schema version (fixed, 0)
33  * - The application name (fixed, "Wireshark")
34  * - The application version ("<major>.<minor>.<micro>")
35  * - The operating system (varable, one of "windows" or "osx")
36  * - The architecture name (variable, one of "x86", "x86-64")
37  * - The locale (fixed, "en-US)
38  * - The update channel (variable, one of "development" or "stable") + .xml
39  *
40  * Based on https://wiki.mozilla.org/Software_Update:Checking_For_Updates
41  */
42
43 #ifdef HAVE_SOFTWARE_UPDATE
44 #define SU_SCHEMA_PREFIX "update"
45 #define SU_SCHEMA_VERSION 0
46 #define SU_APPLICATION "Wireshark"
47 #define SU_LOCALE "en-US"
48 #endif /* HAVE_SOFTWARE_UPDATE */
49
50 #if defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32)
51
52 #include "glib.h"
53
54 #include <winsparkle.h>
55
56 #define SU_OSNAME "Windows"
57
58 static GString *update_url_str = NULL;
59
60 static const char *get_appcast_update_url(software_update_channel_e chan) {
61     const char *chan_name;
62     const char *arch = "x86";
63
64     if (!update_url_str) {
65         update_url_str = g_string_new("");
66     }
67
68     /* XXX Add WOW64 checks similar to version_info.c? */
69     if (sizeof(arch) != 4) {
70         arch = "x86-64";
71     }
72
73     switch (chan) {
74         case UPDATE_CHANNEL_DEVELOPMENT:
75             chan_name = "development";
76             break;
77         default:
78             chan_name = "stable";
79             break;
80     }
81     g_string_printf(update_url_str, "https://www.wireshark.org/%s/%u/%s/%s/%s/%s/en-US/%s.xml",
82                     SU_SCHEMA_PREFIX,
83                     SU_SCHEMA_VERSION,
84                     SU_APPLICATION,
85                     VERSION,
86                     SU_OSNAME,
87                     arch,
88                     chan_name);
89     return update_url_str->str;
90 }
91
92 /** Initialize software updates.
93  */
94 void
95 software_update_init(void) {
96     const char *update_url = get_appcast_update_url(prefs.gui_update_channel);
97
98     /*
99      * According to the WinSparkle 0.5 documentation these must be called
100      * once, before win_sparkle_init. We can't update them dynamically when
101      * our preferences change.
102      */
103     win_sparkle_set_registry_path("Software\\Wireshark\\WinSparkle Settings");
104     win_sparkle_set_appcast_url(update_url);
105     win_sparkle_set_automatic_check_for_updates(prefs.gui_update_enabled ? 1 : 0);
106     win_sparkle_set_update_check_interval(prefs.gui_update_interval);
107     win_sparkle_set_can_shutdown_callback(software_update_can_shutdown_callback);
108     win_sparkle_set_shutdown_request_callback(software_update_shutdown_request_callback);
109     if ((language != NULL) && (strcmp(language, "system") != 0)) {
110         win_sparkle_set_lang(language);
111     }
112     win_sparkle_init();
113 }
114
115 /** Force a software update check.
116  */
117 void
118 software_update_check(void) {
119     win_sparkle_check_update_with_ui();
120 }
121
122 /** Clean up software update checking.
123  *
124  * Does nothing on platforms that don't support software updates.
125  */
126 extern void software_update_cleanup(void) {
127     win_sparkle_cleanup();
128 }
129
130 #else /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */
131
132 /** Initialize software updates.
133  */
134 void
135 software_update_init(void) {
136 }
137
138 /** Force a software update check.
139  */
140 void
141 software_update_check(void) {
142 }
143
144 /** Clean up software update checking.
145  */
146 void software_update_cleanup(void) {
147 }
148
149 /** Check to see if Wireshark can shut down safely (e.g. offer to save the
150  *  current capture).
151  */
152 int software_update_can_shutdown_callback(void) {
153     return FALSE;
154 }
155
156 /** Shut down Wireshark in preparation for an upgrade.
157  */
158 void software_update_shutdown_request_callback(void) {
159 }
160
161 #endif /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */
162
163 /*
164  * Editor modelines
165  *
166  * Local Variables:
167  * c-basic-offset: 4
168  * tab-width: 8
169  * indent-tabs-mode: nil
170  * End:
171  *
172  * ex: set shiftwidth=4 tabstop=8 expandtab:
173  * :indentSize=4:tabSize=8:noTabs=true:
174  */
175