From 73784c6a8488fef1ca7e6971a12868735d606de7 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 30 Mar 2016 19:27:59 +0200 Subject: UPDATES: Made interval set/get functions accept normal integers --- backends/updates/macosx/macosx-updates.h | 4 ++-- backends/updates/macosx/macosx-updates.mm | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'backends/updates') diff --git a/backends/updates/macosx/macosx-updates.h b/backends/updates/macosx/macosx-updates.h index fd2d1f46f5..9f541ad02a 100644 --- a/backends/updates/macosx/macosx-updates.h +++ b/backends/updates/macosx/macosx-updates.h @@ -39,8 +39,8 @@ 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(); }; #endif diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm index a94f1c21fd..c13f05f1c6 100644 --- a/backends/updates/macosx/macosx-updates.mm +++ b/backends/updates/macosx/macosx-updates.mm @@ -103,14 +103,14 @@ Common::UpdateManager::UpdateState MacOSXUpdateManager::getAutomaticallyChecksFo return kUpdateStateDisabled; } -void MacOSXUpdateManager::setUpdateCheckInterval(UpdateInterval interval) { +void MacOSXUpdateManager::setUpdateCheckInterval(int interval) { if (interval == kUpdateIntervalNotSupported) return; [sparkleUpdater setUpdateCheckInterval:(NSTimeInterval)interval]; } -Common::UpdateManager::UpdateInterval MacOSXUpdateManager::getUpdateCheckInterval() { +int MacOSXUpdateManager::getUpdateCheckInterval() { // 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) -- cgit v1.2.3 From 82963f7446f336fe71e71f35fa39768aed059541 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 31 Mar 2016 09:38:28 +0200 Subject: UPDATES: Read values from config file in MacOS X update manager --- backends/updates/macosx/macosx-updates.mm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'backends/updates') diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm index c13f05f1c6..6f99e71ccf 100644 --- a/backends/updates/macosx/macosx-updates.mm +++ b/backends/updates/macosx/macosx-updates.mm @@ -27,6 +27,7 @@ #ifdef USE_SPARKLE #include "common/translation.h" +#include "common/config-manager.h" #include #include @@ -74,11 +75,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(ConfMan.getInt("updates_check")); + } } MacOSXUpdateManager::~MacOSXUpdateManager() { -- cgit v1.2.3 From 33dc840d2f580ac9bd9d4634279294621692bafd Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 31 Mar 2016 15:34:50 +0200 Subject: UPDATES: Normalize update intervals at setting --- backends/updates/macosx/macosx-updates.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'backends/updates') diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm index 6f99e71ccf..6c7ed03b52 100644 --- a/backends/updates/macosx/macosx-updates.mm +++ b/backends/updates/macosx/macosx-updates.mm @@ -110,6 +110,17 @@ void MacOSXUpdateManager::setUpdateCheckInterval(int interval) { if (interval == kUpdateIntervalNotSupported) return; + const int *vals = getUpdateIntervals(); + + while (*vals != -1) { + if (interval == *vals) + break; + vals++; + } + + if (*vals == -1) + interval = kUpdateIntervalOneDay; + [sparkleUpdater setUpdateCheckInterval:(NSTimeInterval)interval]; } -- cgit v1.2.3 From a743ec2e07ccada0286085ecec54f4d87ed49d44 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 1 Apr 2016 21:29:29 +0200 Subject: UPDATES: Implement and use method for normalizing interval value to accepted values --- backends/updates/macosx/macosx-updates.mm | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'backends/updates') diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm index 6c7ed03b52..fc967f8fec 100644 --- a/backends/updates/macosx/macosx-updates.mm +++ b/backends/updates/macosx/macosx-updates.mm @@ -80,7 +80,7 @@ MacOSXUpdateManager::MacOSXUpdateManager() { setAutomaticallyChecksForUpdates(kUpdateStateDisabled); } else { setAutomaticallyChecksForUpdates(kUpdateStateEnabled); - setUpdateCheckInterval(ConfMan.getInt("updates_check")); + setUpdateCheckInterval(normalizeInterval(ConfMan.getInt("updates_check"))); } } @@ -110,16 +110,7 @@ void MacOSXUpdateManager::setUpdateCheckInterval(int interval) { if (interval == kUpdateIntervalNotSupported) return; - const int *vals = getUpdateIntervals(); - - while (*vals != -1) { - if (interval == *vals) - break; - vals++; - } - - if (*vals == -1) - interval = kUpdateIntervalOneDay; + interval = normalizeInterval(interval); [sparkleUpdater setUpdateCheckInterval:(NSTimeInterval)interval]; } -- cgit v1.2.3 From c18a12453ed7702e3ced87d5f42acf7d10b6b41d Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 9 Apr 2016 17:00:09 +0200 Subject: UPDATES: Implemented method getLastUpdateCheckTimeAndDate() Currently it uses methods and constants deprecated in 10.10. 10.10+ -specific code will follow --- backends/updates/macosx/macosx-updates.h | 2 ++ backends/updates/macosx/macosx-updates.mm | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) (limited to 'backends/updates') diff --git a/backends/updates/macosx/macosx-updates.h b/backends/updates/macosx/macosx-updates.h index 9f541ad02a..6fb9af7712 100644 --- a/backends/updates/macosx/macosx-updates.h +++ b/backends/updates/macosx/macosx-updates.h @@ -41,6 +41,8 @@ public: 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 fc967f8fec..273d80acc5 100644 --- a/backends/updates/macosx/macosx-updates.mm +++ b/backends/updates/macosx/macosx-updates.mm @@ -23,6 +23,7 @@ // 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 @@ -133,4 +134,20 @@ int MacOSXUpdateManager::getUpdateCheckInterval() { } } +bool MacOSXUpdateManager::getLastUpdateCheckTimeAndDate(TimeDate &t) { + NSDate *date = [sparkleUpdater lastUpdateCheckDate]; + NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; + NSDateComponents *components = [gregorian components:(NSDayCalendarUnit | NSWeekdayCalendarUnit) fromDate:date]; + + 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]; + + return true; +} + #endif -- cgit v1.2.3 From 600520902eb08124716cb6a76b2bd0190444ae4c Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 10 Apr 2016 01:38:48 +0200 Subject: UPDATES: Plug memory leak --- backends/updates/macosx/macosx-updates.mm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'backends/updates') diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm index 273d80acc5..a7888a70e6 100644 --- a/backends/updates/macosx/macosx-updates.mm +++ b/backends/updates/macosx/macosx-updates.mm @@ -147,6 +147,8 @@ bool MacOSXUpdateManager::getLastUpdateCheckTimeAndDate(TimeDate &t) { t.tm_min = [components minute]; t.tm_sec = [components second]; + [gregorian release]; + return true; } -- cgit v1.2.3 From aa5432b0e9c1545c4e7f952864eb542e4a3953f8 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 10 Apr 2016 10:50:59 +0200 Subject: UPDATES: Use new constants for MacOS X 10.10 --- backends/updates/macosx/macosx-updates.mm | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'backends/updates') diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm index a7888a70e6..64d1028734 100644 --- a/backends/updates/macosx/macosx-updates.mm +++ b/backends/updates/macosx/macosx-updates.mm @@ -33,6 +33,8 @@ #include #include +#include + SUUpdater *sparkleUpdater; /** @@ -136,8 +138,13 @@ int MacOSXUpdateManager::getUpdateCheckInterval() { bool MacOSXUpdateManager::getLastUpdateCheckTimeAndDate(TimeDate &t) { 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]; -- cgit v1.2.3 From 3d256150e1c660c54591a7a1c6d6891d2b1d060c Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 10 Apr 2016 11:02:54 +0200 Subject: UPDATES: Check that we're running in a bundle, and skip Sparkle initialization otherwise This was leading to an unhandled exception within Sparkle code which was hanging the application. This feature is good only for development purposes, as convenient users are supposed to run ScummVM from the supplied bundle. --- backends/updates/macosx/macosx-updates.mm | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'backends/updates') diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm index 64d1028734..db9362a459 100644 --- a/backends/updates/macosx/macosx-updates.mm +++ b/backends/updates/macosx/macosx-updates.mm @@ -49,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 @@ -92,6 +100,9 @@ MacOSXUpdateManager::~MacOSXUpdateManager() { } void MacOSXUpdateManager::checkForUpdates() { + if (sparkleUpdater == nullptr) + return; + [sparkleUpdater checkForUpdatesInBackground]; } @@ -99,10 +110,16 @@ 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 @@ -110,6 +127,9 @@ Common::UpdateManager::UpdateState MacOSXUpdateManager::getAutomaticallyChecksFo } void MacOSXUpdateManager::setUpdateCheckInterval(int interval) { + if (sparkleUpdater == nullptr) + return; + if (interval == kUpdateIntervalNotSupported) return; @@ -119,6 +139,9 @@ void MacOSXUpdateManager::setUpdateCheckInterval(int interval) { } 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) @@ -137,6 +160,9 @@ int MacOSXUpdateManager::getUpdateCheckInterval() { } 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]; -- cgit v1.2.3