aboutsummaryrefslogtreecommitdiff
path: root/backends/updates
diff options
context:
space:
mode:
authorWillem Jan Palenstijn2016-07-21 13:30:47 +0200
committerWillem Jan Palenstijn2016-07-21 13:30:47 +0200
commit6f001d831623a46f643379554d20e94463d8c2f1 (patch)
tree901caa296592814b48a98ac2e3d381331c5a7821 /backends/updates
parent75fdd1504de98c7c6937344877685bfef6514344 (diff)
parent5f301b24002fffb3e8e05061a92ae2e0ee3a92ec (diff)
downloadscummvm-rg350-6f001d831623a46f643379554d20e94463d8c2f1.tar.gz
scummvm-rg350-6f001d831623a46f643379554d20e94463d8c2f1.tar.bz2
scummvm-rg350-6f001d831623a46f643379554d20e94463d8c2f1.zip
Merge branch 'master' into titanic
Diffstat (limited to 'backends/updates')
-rw-r--r--backends/updates/macosx/macosx-updates.h6
-rw-r--r--backends/updates/macosx/macosx-updates.mm75
2 files changed, 70 insertions, 11 deletions
diff --git a/backends/updates/macosx/macosx-updates.h b/backends/updates/macosx/macosx-updates.h
index fd2d1f46f5..6fb9af7712 100644
--- a/backends/updates/macosx/macosx-updates.h
+++ b/backends/updates/macosx/macosx-updates.h
@@ -39,8 +39,10 @@ public:
virtual void setAutomaticallyChecksForUpdates(UpdateState state);
virtual UpdateState getAutomaticallyChecksForUpdates();
- virtual void setUpdateCheckInterval(UpdateInterval interval);
- virtual UpdateInterval getUpdateCheckInterval();
+ virtual void setUpdateCheckInterval(int interval);
+ virtual int getUpdateCheckInterval();
+
+ virtual bool getLastUpdateCheckTimeAndDate(TimeDate &t);
};
#endif
diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm
index a94f1c21fd..db9362a459 100644
--- a/backends/updates/macosx/macosx-updates.mm
+++ b/backends/updates/macosx/macosx-updates.mm
@@ -23,14 +23,18 @@
// Disable symbol overrides so that we can use system headers.
#define FORBIDDEN_SYMBOL_ALLOW_ALL
+#include "common/system.h"
#include "backends/updates/macosx/macosx-updates.h"
#ifdef USE_SPARKLE
#include "common/translation.h"
+#include "common/config-manager.h"
#include <Cocoa/Cocoa.h>
#include <Sparkle/Sparkle.h>
+#include <AvailabilityMacros.h>
+
SUUpdater *sparkleUpdater;
/**
@@ -45,14 +49,22 @@ SUUpdater *sparkleUpdater;
*
*/
MacOSXUpdateManager::MacOSXUpdateManager() {
+ NSBundle* mainBundle = [NSBundle mainBundle];
+
+ NSString *version = [mainBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
+ if (!version || [version isEqualToString:@""]) {
+ warning("Running not in bundle, skipping Sparkle initialization");
+
+ sparkleUpdater = nullptr;
+ return;
+ }
+
NSMenuItem *menuItem = [[NSApp mainMenu] itemAtIndex:0];
NSMenu *applicationMenu = [menuItem submenu];
// Init Sparkle
sparkleUpdater = [SUUpdater sharedUpdater];
- NSBundle* mainBundle = [NSBundle mainBundle];
-
NSString* feedbackURL = [mainBundle objectForInfoDictionaryKey:@"SUFeedURL"];
// Set appcast URL
@@ -74,11 +86,13 @@ MacOSXUpdateManager::MacOSXUpdateManager() {
// Finally give up our references to the objects
[menuItem release];
- // Enable automatic update checking once a day (alternatively use
- // checkForUpdates() here to check for updates on every startup)
- // TODO: Should be removed when an update settings gui is implemented
- setAutomaticallyChecksForUpdates(kUpdateStateEnabled);
- setUpdateCheckInterval(kUpdateIntervalOneDay);
+ if (!ConfMan.hasKey("updates_check")
+ || ConfMan.getInt("updates_check") == Common::UpdateManager::kUpdateIntervalNotSupported) {
+ setAutomaticallyChecksForUpdates(kUpdateStateDisabled);
+ } else {
+ setAutomaticallyChecksForUpdates(kUpdateStateEnabled);
+ setUpdateCheckInterval(normalizeInterval(ConfMan.getInt("updates_check")));
+ }
}
MacOSXUpdateManager::~MacOSXUpdateManager() {
@@ -86,6 +100,9 @@ MacOSXUpdateManager::~MacOSXUpdateManager() {
}
void MacOSXUpdateManager::checkForUpdates() {
+ if (sparkleUpdater == nullptr)
+ return;
+
[sparkleUpdater checkForUpdatesInBackground];
}
@@ -93,24 +110,38 @@ void MacOSXUpdateManager::setAutomaticallyChecksForUpdates(UpdateManager::Update
if (state == kUpdateStateNotSupported)
return;
+ if (sparkleUpdater == nullptr)
+ return;
+
[sparkleUpdater setAutomaticallyChecksForUpdates:(state == kUpdateStateEnabled ? YES : NO)];
}
Common::UpdateManager::UpdateState MacOSXUpdateManager::getAutomaticallyChecksForUpdates() {
+ if (sparkleUpdater == nullptr)
+ return kUpdateStateDisabled;
+
if ([sparkleUpdater automaticallyChecksForUpdates])
return kUpdateStateEnabled;
else
return kUpdateStateDisabled;
}
-void MacOSXUpdateManager::setUpdateCheckInterval(UpdateInterval interval) {
+void MacOSXUpdateManager::setUpdateCheckInterval(int interval) {
+ if (sparkleUpdater == nullptr)
+ return;
+
if (interval == kUpdateIntervalNotSupported)
return;
+ interval = normalizeInterval(interval);
+
[sparkleUpdater setUpdateCheckInterval:(NSTimeInterval)interval];
}
-Common::UpdateManager::UpdateInterval MacOSXUpdateManager::getUpdateCheckInterval() {
+int MacOSXUpdateManager::getUpdateCheckInterval() {
+ if (sparkleUpdater == nullptr)
+ return kUpdateIntervalOneDay;
+
// This is kind of a hack but necessary, as the value stored by Sparkle
// might have been changed outside of ScummVM (in which case we return the
// default interval of one day)
@@ -128,4 +159,30 @@ Common::UpdateManager::UpdateInterval MacOSXUpdateManager::getUpdateCheckInterva
}
}
+bool MacOSXUpdateManager::getLastUpdateCheckTimeAndDate(TimeDate &t) {
+ if (sparkleUpdater == nullptr)
+ return false;
+
+ NSDate *date = [sparkleUpdater lastUpdateCheckDate];
+#ifdef MAC_OS_X_VERSION_10_10
+ NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
+ NSDateComponents *components = [gregorian components:(NSCalendarUnitDay | NSCalendarUnitWeekday) fromDate:date];
+#else
+ NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
+ NSDateComponents *components = [gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:date];
+#endif
+
+ t.tm_wday = [components weekday];
+ t.tm_year = [components year];
+ t.tm_mon = [components month];
+ t.tm_mday = [components day];
+ t.tm_hour = [components hour];
+ t.tm_min = [components minute];
+ t.tm_sec = [components second];
+
+ [gregorian release];
+
+ return true;
+}
+
#endif