aboutsummaryrefslogtreecommitdiff
path: root/backends/updates
diff options
context:
space:
mode:
authorOystein Eftevaag2011-08-02 16:09:58 -0700
committerOystein Eftevaag2011-08-02 16:09:58 -0700
commit9044e17499797ef007c9c8240d79f69382f61765 (patch)
treeb686c9fc28f0d2eae4c0db3ff98687f43556066a /backends/updates
parent8f70ee9afc877b22123269669d155e710a467c4b (diff)
parentefd9dff55662e1c0c4c794ed8f0143a87cc5fa0d (diff)
downloadscummvm-rg350-9044e17499797ef007c9c8240d79f69382f61765.tar.gz
scummvm-rg350-9044e17499797ef007c9c8240d79f69382f61765.tar.bz2
scummvm-rg350-9044e17499797ef007c9c8240d79f69382f61765.zip
Merge pull request #52 from CeRiAl/macosx-sparkle
MACOSX: Add Sparkle support
Diffstat (limited to 'backends/updates')
-rw-r--r--backends/updates/macosx/macosx-updates.h46
-rw-r--r--backends/updates/macosx/macosx-updates.mm129
-rw-r--r--backends/updates/sparkle-updates.cpp45
-rw-r--r--backends/updates/sparkle-updates.h48
4 files changed, 268 insertions, 0 deletions
diff --git a/backends/updates/macosx/macosx-updates.h b/backends/updates/macosx/macosx-updates.h
new file mode 100644
index 0000000000..1fe0e4bb75
--- /dev/null
+++ b/backends/updates/macosx/macosx-updates.h
@@ -0,0 +1,46 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BACKENDS_UPDATES_MACOSX_H
+#define BACKENDS_UPDATES_MACOSX_H
+
+#include "backends/updates/sparkle-updates.h"
+
+#if defined(MACOSX) && defined(USE_SPARKLE)
+
+class MacOSXUpdateManager : public SparkleUpdateManager {
+public:
+ MacOSXUpdateManager();
+ virtual ~MacOSXUpdateManager();
+
+ virtual void checkForUpdates();
+
+ virtual void setAutomaticallyChecksForUpdates(UpdateState state);
+ virtual UpdateState getAutomaticallyChecksForUpdates();
+
+ virtual void setUpdateCheckInterval(UpdateInterval interval);
+ virtual UpdateInterval getUpdateCheckInterval();
+};
+
+#endif
+
+#endif // BACKENDS_UPDATES_MACOSX_H
diff --git a/backends/updates/macosx/macosx-updates.mm b/backends/updates/macosx/macosx-updates.mm
new file mode 100644
index 0000000000..f3675f9bd2
--- /dev/null
+++ b/backends/updates/macosx/macosx-updates.mm
@@ -0,0 +1,129 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// Disable symbol overrides so that we can use system headers.
+#define FORBIDDEN_SYMBOL_ALLOW_ALL
+
+#include "backends/updates/sparkle-updates.h"
+
+#if defined(MACOSX) && defined(USE_SPARKLE)
+
+#include "backends/updates/macosx/macosx-updates.h"
+#include "common/translation.h"
+
+#include <Cocoa/Cocoa.h>
+#include <Sparkle/Sparkle.h>
+
+SUUpdater *sparkleUpdater;
+
+/**
+ * Sparkle is a software update framework for Mac OS X which uses appcasts for
+ * release information. Appcasts are RSS-like XML feeds which contain information
+ * about the most current version at the time. If a new version is available, the
+ * user is presented the release-notes/changes/fixes and is asked if he wants to
+ * update, and if yes the Sparkle framework downloads a signed update package
+ * from the server and automatically installs and restarts the software.
+ * More detailed information is available at the following address:
+ * http://sparkle.andymatuschak.org/
+ *
+ */
+MacOSXUpdateManager::MacOSXUpdateManager() {
+ NSMenuItem *menuItem = [[NSApp mainMenu] itemAtIndex:0];
+ NSMenu *applicationMenu = [menuItem submenu];
+
+ // Init Sparkle
+ sparkleUpdater = [SUUpdater sharedUpdater];
+
+ // Set appcast URL
+ [sparkleUpdater setFeedURL:[NSURL URLWithString:[NSString stringWithCString:getAppcastUrl().c_str()]]];
+
+ // Get current encoding
+ NSStringEncoding stringEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)[NSString stringWithCString:(TransMan.getCurrentCharset()).c_str() encoding:NSASCIIStringEncoding]));
+
+ // Add "Check for Updates..." menu item
+ NSMenuItem *updateMenuItem = [applicationMenu insertItemWithTitle:[NSString stringWithCString:_("Check for Updates...") encoding:stringEncoding] action:@selector(checkForUpdates:) keyEquivalent:@"" atIndex:1];
+
+ // Set the target of the new menu item
+ [updateMenuItem setTarget:sparkleUpdater];
+
+ // 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);
+}
+
+MacOSXUpdateManager::~MacOSXUpdateManager() {
+ [sparkleUpdater release];
+}
+
+void MacOSXUpdateManager::checkForUpdates() {
+ [sparkleUpdater checkForUpdatesInBackground];
+}
+
+void MacOSXUpdateManager::setAutomaticallyChecksForUpdates(UpdateManager::UpdateState state) {
+ if (state == kUpdateStateNotSupported)
+ return;
+
+ [sparkleUpdater setAutomaticallyChecksForUpdates:(state == kUpdateStateEnabled ? YES : NO)];
+}
+
+Common::UpdateManager::UpdateState MacOSXUpdateManager::getAutomaticallyChecksForUpdates() {
+ if ([sparkleUpdater automaticallyChecksForUpdates])
+ return kUpdateStateEnabled;
+ else
+ return kUpdateStateDisabled;
+}
+
+void MacOSXUpdateManager::setUpdateCheckInterval(UpdateInterval interval) {
+ if (interval == kUpdateIntervalNotSupported)
+ return;
+
+ [sparkleUpdater setUpdateCheckInterval:(NSTimeInterval)interval];
+}
+
+Common::UpdateManager::UpdateInterval 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)
+ switch ((UpdateInterval)[sparkleUpdater updateCheckInterval]) {
+ default:
+ break;
+
+ case kUpdateIntervalOneDay:
+ return kUpdateIntervalOneDay;
+
+ case kUpdateIntervalOneWeek:
+ return kUpdateIntervalOneWeek;
+
+ case kUpdateIntervalOneMonth:
+ return kUpdateIntervalOneMonth;
+ }
+
+ // Return the default value (one day)
+ return kUpdateIntervalOneDay;
+}
+
+#endif
diff --git a/backends/updates/sparkle-updates.cpp b/backends/updates/sparkle-updates.cpp
new file mode 100644
index 0000000000..f146237a98
--- /dev/null
+++ b/backends/updates/sparkle-updates.cpp
@@ -0,0 +1,45 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "backends/updates/sparkle-updates.h"
+
+#if defined(USE_SPARKLE)
+
+// TODO replace by proper URL
+#if defined(MACOSX)
+ #define APPCAST_BASE_URL "http://www.scummvm.org/appcasts/macosx/"
+#elif defined(WIN32)
+ #define APPCAST_BASE_URL "http://www.scummvm.org/appcasts/win32/"
+#else
+ #error "Please define APPCAST_BASE_URL for your platform!"
+#endif
+
+
+Common::String SparkleUpdateManager::getAppcastUrl() {
+#ifdef RELEASE_BUILD
+ return APPCAST_BASE_URL "release.xml";
+#else
+ return APPCAST_BASE_URL "beta.xml";
+#endif
+}
+
+#endif
diff --git a/backends/updates/sparkle-updates.h b/backends/updates/sparkle-updates.h
new file mode 100644
index 0000000000..26f170db2e
--- /dev/null
+++ b/backends/updates/sparkle-updates.h
@@ -0,0 +1,48 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef BACKENDS_UPDATES_SPARKLE_UPDATE_H
+#define BACKENDS_UPDATES_SPARKLE_UPDATE_H
+
+#include "common/scummsys.h"
+#include "common/str.h"
+#include "common/updates.h"
+
+#if defined(USE_SPARKLE)
+
+class SparkleUpdateManager : public Common::UpdateManager {
+public:
+ /**
+ * Gets the appcast url.
+ *
+ * Beta/RC versions and releases might have a different appcast url.
+ * This function takes care of checking which version of ScummVM is running
+ * and return the url to the proper appcast.
+ *
+ * @return the appcast url.
+ */
+ Common::String getAppcastUrl();
+};
+
+#endif
+
+#endif // BACKENDS_UPDATES_SPARKLE_UPDATE_H