slightly improve wscript
c++ code for auto-update compiles

Change-Id: Iad2aebf330f8620573db3fec615d83086c94c779
diff --git a/gui/chronosharegui.cpp b/gui/chronosharegui.cpp
index d37b985..1bd0c1c 100644
--- a/gui/chronosharegui.cpp
+++ b/gui/chronosharegui.cpp
@@ -42,7 +42,7 @@
   , m_executor (1)
 #endif
 #ifdef SPARKLE_SUPPORTED
-  , m_autoUpdate(0)
+  , m_autoUpdate(new SparkleAutoUpdate(tr("http://no-url.org")))
 #endif
 {
   setWindowTitle("Settings");
@@ -152,6 +152,7 @@
 #endif
 #ifdef SPARKLE_SUPPORTED
   delete m_autoUpdate;
+  delete m_checkForUpdates;
 #endif
   delete m_openFolder;
   delete m_viewSettings;
@@ -215,8 +216,8 @@
 #endif
 
 #ifdef SPARKLE_SUPPORTED
-  m_autoUpdate = new QAction (tr("Check For Updates"), this);
-  connect (m_autoUpdate, SIGNAL(triggered()), this, SLOT(onCheckForUpdates()));
+  m_checkForUpdates = new QAction (tr("Check For Updates"), this);
+  connect (m_checkForUpdates, SIGNAL(triggered()), this, SLOT(onCheckForUpdates()));
 #endif
 
   // create the "quit program" action
diff --git a/gui/chronosharegui.h b/gui/chronosharegui.h
index 8403a66..e0db4ba 100644
--- a/gui/chronosharegui.h
+++ b/gui/chronosharegui.h
@@ -27,7 +27,7 @@
 
 #if __APPLE__ && HAVE_SPARKLE
 #define SPARKLE_SUPPORTED 1
-#include "auto-update.h"
+#include "sparkle-auto-update.h"
 #endif
 
 #include <QtGui>
diff --git a/osx/auto-update/auto-update.h b/osx/auto-update/auto-update.h
index 4313641..86068c8 100644
--- a/osx/auto-update/auto-update.h
+++ b/osx/auto-update/auto-update.h
@@ -24,6 +24,7 @@
 class AutoUpdate
 {
 public:
+  virtual ~AutoUpdate() {};
   virtual void checkForUpdates() = 0;
 };
 #endif
diff --git a/osx/auto-update/sparkle-auto-update.h b/osx/auto-update/sparkle-auto-update.h
index dc54bb1..1a19b9c 100644
--- a/osx/auto-update/sparkle-auto-update.h
+++ b/osx/auto-update/sparkle-auto-update.h
@@ -29,7 +29,7 @@
 {
 public:
   SparkleAutoUpdate (const QString &url);
-  ~SparkleAutoUpdate ();
+  virtual ~SparkleAutoUpdate ();
   virtual void checkForUpdates();
 private:
   class Private;
diff --git a/wscript b/wscript
index 151271a..11c7b34 100644
--- a/wscript
+++ b/wscript
@@ -1,6 +1,4 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-import os
-
 VERSION='0.1'
 APPNAME='chronoshare'
 
@@ -13,39 +11,10 @@
     opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx logging support''')
 
     if Utils.unversioned_sys_platform () == "darwin":
-        opt.add_option('--autoupdate', action='store_true',default=False,dest='autoupdate',help='''(OSX) Download sparkle framework and enable autoupdate feature''')
+        opt.add_option('--auto-update', action='store_true',default=False,dest='autoupdate',help='''(OSX) Download sparkle framework and enable autoupdate feature''')
 
     opt.load('compiler_c compiler_cxx boost ccnx protoc qt4')
 
-def check_framework(conf, name, **kwargs):
-  frameworkLocations = (os.environ.get('HOME') + '/Library/Frameworks'
-                        , '/opt/local/Library/Frameworks'
-                        , '/Library/Frameworks'
-                        , '/Network/Library/Frameworks'
-                        , '/System/Library/Frameworks'
-                        )
-  uselib = name.upper()
-  frameworkName = name + ".framework"
-  found = False
-  for frameworkLocation in frameworkLocations:
-    dynamicLib = os.path.join(frameworkLocation, frameworkName, name)
-    if os.path.exists(dynamicLib):
-      conf.env.append_unique('FRAMEWORK_' + uselib, name)
-      conf.msg('Checking for %s' % name, dynamicLib, 'GREEN')
-      conf.env.append_unique('INCLUDES_' + uselib, os.path.join(frameworkLocation, frameworkName, 'Headers'))
-      found = True
-      define_name = kwargs.get('define_name', None)
-      if define_name is not None:
-        conf.define(define_name, 1)
-      break
-
-  if not found:
-    mandatory = kwargs.get('mandatory', True)
-    if mandatory:
-      conf.fatal('Cannot find ' + frameworkName)
-    else:
-      conf.msg('Checking for %s' % name, False, 'YELLOW')
-
 def configure(conf):
     conf.load("compiler_c compiler_cxx")
 
@@ -60,31 +29,38 @@
         conf.check_cxx(framework_name='CoreWLAN',   uselib_store='OSX_COREWLAN',   define_name='HAVE_COREWLAN', mandatory=False, compile_filename='test.mm')
 
         if conf.options.autoupdate:
+            def check_sparkle(**kwargs):
+              conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
+                              uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True,
+                              compile_filename='test.mm',
+                              **kwargs
+                              )
             try:
                 # Try standard paths first
-                conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
-                                uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True, compile_filename='test.mm')
+                check_sparkle()
             except:
                 try:
                     # Try local path
                     Logs.info ("Check local version of Sparkle framework")
-                    conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
-                                    uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True,
-                                    cxxflags="-F%s/build/Sparkle" % conf.path.abspath(),
-                                    linkflags="-F%s/build/Sparkle" % conf.path.abspath(), compile_filename='test.mm')
+                    check_sparkle(cxxflags="-F%s/build/Sparkle" % conf.path.abspath(),
+                              linkflags="-F%s/build/Sparkle" % conf.path.abspath())
                 except:
                     # Download to local path and retry
                     Logs.info ("Sparkle framework not found, trying to download it to 'build/'")
 
                     import urllib, subprocess, os
                     urllib.urlretrieve ("http://sparkle.andymatuschak.org/files/Sparkle%201.5b6.zip", "build/Sparkle.zip")
-                    subprocess.call ("unzip build/Sparkle.zip -d build/Sparkle", shell=True)
-                    os.remove ("build/Sparkle.zip")
+                    if os.path.exists('build/Sparkle.zip'):
+                      try:
+                        subprocess.check_call (['unzip', '-qq', 'build/Sparkle.zip', '-d', 'build/Sparkle'])
+                        os.remove ("build/Sparkle.zip")
+                        check_sparkle(cxxflags="-F%s/build/Sparkle" % conf.path.abspath(),
+                              linkflags="-F%s/build/Sparkle" % conf.path.abspath())
+                      except subprocess.CalledProcessError as e:
+                        conf.fatal("Cannot find Sparkle framework. Auto download failed: '%s' returned %s" % (' '.join(e.cmd), e.returncode))
+                      except:
+                        conf.fatal("Unknown Error happened when auto downloading Sparkle framework")
 
-                    conf.check_cxx (framework_name='Sparkle', header_name="Foundation/Foundation.h",
-                                    uselib_store='OSX_SPARKLE', define_name='HAVE_SPARKLE', mandatory=True,
-                                    cxxflags="-F%s/build/Sparkle" % conf.path.abspath(),
-                                    linkflags="-F%s/build/Sparkle" % conf.path.abspath(), compile_filename='test.mm')
             if conf.is_defined('HAVE_SPARKLE'):
                 conf.env.HAVE_SPARKLE = 1 # small cheat for wscript