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