qt: add missing initializers (CID 1325722)
[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 "../epan/prefs.h"
27
28 /*
29  * Version 0 of the update URI path has the following elements:
30  * - The update path prefix (fixed, "update")
31  * - The schema version (fixed, 0)
32  * - The application name (fixed, "Wireshark")
33  * - The application version ("<major>.<minor>.<micro>")
34  * - The operating system (varable, one of "windows" or "osx")
35  * - The architecture name (variable, one of "x86", "x86-64")
36  * - The locale (fixed, "en-US)
37  * - The update channel (variable, one of "development" or "stable") + .xml
38  *
39  * Based on https://wiki.mozilla.org/Software_Update:Checking_For_Updates
40  */
41
42 #ifdef HAVE_SOFTWARE_UPDATE
43 #define SU_SCHEMA_PREFIX "update"
44 #define SU_SCHEMA_VERSION 0
45 #define SU_APPLICATION "Wireshark"
46 #define SU_LOCALE "en-US"
47 #endif /* HAVE_SOFTWARE_UPDATE */
48
49 #if defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32)
50
51 #include "glib.h"
52
53 #include <winsparkle.h>
54
55 #define SU_OSNAME "Windows"
56
57 static GString *update_url_str = NULL;
58
59 static const char *get_appcast_update_url(software_update_channel_e chan) {
60     const char *chan_name;
61     const char *arch = "x86";
62
63     if (!update_url_str) {
64         update_url_str = g_string_new("");
65     }
66
67     /* XXX Add WOW64 checks similar to version_info.c? */
68     if (sizeof(arch) != 4) {
69         arch = "x86-64";
70     }
71
72     switch (chan) {
73         case UPDATE_CHANNEL_DEVELOPMENT:
74             chan_name = "development";
75             break;
76         default:
77             chan_name = "stable";
78             break;
79     }
80     g_string_printf(update_url_str, "https://www.wireshark.org/%s/%u/%s/%s/%s/%s/en-US/%s.xml",
81                     SU_SCHEMA_PREFIX,
82                     SU_SCHEMA_VERSION,
83                     SU_APPLICATION,
84                     VERSION,
85                     SU_OSNAME,
86                     arch,
87                     chan_name);
88     return update_url_str->str;
89 }
90
91 /** Initialize software updates.
92  */
93 void
94 software_update_init(void) {
95     const char *update_url = get_appcast_update_url(prefs.gui_update_channel);
96
97     win_sparkle_set_registry_path("Software\\Wireshark\\WinSparkle Settings");
98     win_sparkle_set_appcast_url(update_url);
99     win_sparkle_set_automatic_check_for_updates(prefs.gui_update_enabled ? 1 : 0);
100     win_sparkle_set_update_check_interval(prefs.gui_update_interval);
101     win_sparkle_init();
102 }
103
104 /** Force a software update check.
105  */
106 void
107 software_update_check(void) {
108     win_sparkle_check_update_with_ui();
109 }
110
111 /** Clean up software update checking.
112  *
113  * Does nothing on platforms that don't support software updates.
114  */
115 extern void software_update_cleanup(void) {
116     win_sparkle_cleanup();
117 }
118
119 #else /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */
120
121 /** Initialize software updates.
122  */
123 void
124 software_update_init(void) {
125 }
126
127 /** Force a software update check.
128  */
129 void
130 software_update_check(void) {
131 }
132
133 /** Clean up software update checking.
134  *
135  * Does nothing on platforms that don't support software updates.
136  */
137 extern void software_update_cleanup(void) {
138 }
139
140 #endif /* defined(HAVE_SOFTWARE_UPDATE) && defined (_WIN32) */
141
142 /*
143  * Editor modelines
144  *
145  * Local Variables:
146  * c-basic-offset: 4
147  * tab-width: 8
148  * indent-tabs-mode: nil
149  * End:
150  *
151  * ex: set shiftwidth=4 tabstop=8 expandtab:
152  * :indentSize=4:tabSize=8:noTabs=true:
153  */
154