1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 // Disable symbol overrides so that we can use system headers.
24 #define FORBIDDEN_SYMBOL_ALLOW_ALL
25
26 #include "common/system.h"
27 #include "backends/updates/win32/win32-updates.h"
28
29 #ifdef USE_SPARKLE
30 #include "common/translation.h"
31 #include "common/config-manager.h"
32
33 #include <time.h>
34 #include <winsparkle.h>
35
36 /**
37 * Sparkle is a software update framework for Mac OS X which uses appcasts for
38 * release information. Appcasts are RSS-like XML feeds which contain information
39 * about the most current version at the time. If a new version is available, the
40 * user is presented the release-notes/changes/fixes and is asked if he wants to
41 * update, and if yes the Sparkle framework downloads a signed update package
42 * from the server and automatically installs and restarts the software.
43 * More detailed information is available at the following address:
44 * http://sparkle.andymatuschak.org/
45 *
46 * WinSparkle is a heavily (to the point of being its almost-port) inspired by the
47 * Sparkle framework originally by Andy Matuschak that became the de facto standard
48 * for software updates on OS X.
49 * More detailed information is available at the following address:
50 * https://winsparkle.org/
51 *
52 */
Win32UpdateManager()53 Win32UpdateManager::Win32UpdateManager() {
54 const char *appcastUrl = "https://www.residualvm.org/appcasts/macosx/release.xml";
55
56 win_sparkle_set_appcast_url(appcastUrl);
57 win_sparkle_init();
58
59 if (!ConfMan.hasKey("updates_check")
60 || ConfMan.getInt("updates_check") == Common::UpdateManager::kUpdateIntervalNotSupported) {
61 setAutomaticallyChecksForUpdates(kUpdateStateDisabled);
62 } else {
63 setAutomaticallyChecksForUpdates(kUpdateStateEnabled);
64 setUpdateCheckInterval(normalizeInterval(ConfMan.getInt("updates_check")));
65 }
66 }
67
~Win32UpdateManager()68 Win32UpdateManager::~Win32UpdateManager() {
69 win_sparkle_cleanup();
70 }
71
checkForUpdates()72 void Win32UpdateManager::checkForUpdates() {
73 win_sparkle_check_update_with_ui();
74 }
75
setAutomaticallyChecksForUpdates(UpdateManager::UpdateState state)76 void Win32UpdateManager::setAutomaticallyChecksForUpdates(UpdateManager::UpdateState state) {
77 if (state == kUpdateStateNotSupported)
78 return;
79
80 win_sparkle_set_automatic_check_for_updates(state == kUpdateStateEnabled ? 1 : 0);
81 }
82
getAutomaticallyChecksForUpdates()83 Common::UpdateManager::UpdateState Win32UpdateManager::getAutomaticallyChecksForUpdates() {
84 if (win_sparkle_get_automatic_check_for_updates() == 1)
85 return kUpdateStateEnabled;
86 else
87 return kUpdateStateDisabled;
88 }
89
setUpdateCheckInterval(int interval)90 void Win32UpdateManager::setUpdateCheckInterval(int interval) {
91 if (interval == kUpdateIntervalNotSupported)
92 return;
93
94 interval = normalizeInterval(interval);
95
96 win_sparkle_set_update_check_interval(interval);
97 }
98
getUpdateCheckInterval()99 int Win32UpdateManager::getUpdateCheckInterval() {
100 // This is kind of a hack but necessary, as the value stored by Sparkle
101 // might have been changed outside of ScummVM (in which case we return the
102 // default interval of one day)
103
104 int updateInterval = win_sparkle_get_update_check_interval();
105 switch (updateInterval) {
106 case kUpdateIntervalOneDay:
107 case kUpdateIntervalOneWeek:
108 case kUpdateIntervalOneMonth:
109 return updateInterval;
110
111 default:
112 // Return the default value (one day)
113 return kUpdateIntervalOneDay;
114 }
115 }
116
getLastUpdateCheckTimeAndDate(TimeDate & t)117 bool Win32UpdateManager::getLastUpdateCheckTimeAndDate(TimeDate &t) {
118 time_t updateTime = win_sparkle_get_last_check_time();
119 tm *ut = localtime(&updateTime);
120
121 t.tm_wday = ut->tm_wday;
122 t.tm_year = ut->tm_year;
123 t.tm_mon = ut->tm_mon;
124 t.tm_mday = ut->tm_mday;
125 t.tm_hour = ut->tm_hour;
126 t.tm_min = ut->tm_min;
127 t.tm_sec = ut->tm_sec;
128
129 return true;
130 }
131
132 #endif
133