]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/update.m
macosx: Use fork+exec instead of posix_spawn.
[vlc] / modules / gui / macosx / update.m
index 52abfdd2c262b8ac2885499c75f802f17789681e..f8c71ae66c60f8d37eeb52a6a39445ece361fc36 100644 (file)
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-#ifdef HAVE_CONFIG_H
-#   include "config.h"
-#endif
+#import "update.h"
 
 #ifdef UPDATE_CHECK
 
+#include <assert.h>
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#import "update.h"
-#import "intf.h"
 
 static NSString * kPrefUpdateOnStartup = @"UpdateOnStartup";
 static NSString * kPrefUpdateLastTimeChecked = @"UpdateLastTimeChecked";
@@ -56,7 +54,7 @@ static VLCUpdate *_o_sharedInstance = nil;
         [self dealloc];
     } else {
         _o_sharedInstance = [super init];
-        b_checked = VLC_FALSE;
+        b_checked = false;
 
         /* clean the interface */
         [o_fld_releaseNote setString: @""];
@@ -71,6 +69,11 @@ static VLCUpdate *_o_sharedInstance = nil;
     return _o_sharedInstance;
 }
 
+- (void)end
+{
+    if( p_u ) update_Delete( p_u );
+}
+
 - (void)awakeFromNib
 {
     /* we don't use - (BOOL)shouldCheckUpdateOnStartup because we don't want
@@ -122,7 +125,7 @@ static VLCUpdate *_o_sharedInstance = nil;
     {
         [o_bar_checking startAnimation: self];
         [self checkForUpdate];
-        b_checked = VLC_TRUE;
+        b_checked = true;
         [o_bar_checking stopAnimation: self];
     }
 }
@@ -136,8 +139,10 @@ static VLCUpdate *_o_sharedInstance = nil;
     [saveFilePanel setRequiredFileType: @"dmg"];
     [saveFilePanel setCanSelectHiddenExtension: YES];
     [saveFilePanel setCanCreateDirectories: YES];
+    update_release_t *p_release = update_GetRelease( p_u );
+    assert( p_release );
     [saveFilePanel beginSheetForDirectory:nil file:
-        [[[NSString stringWithUTF8String: p_u->release.psz_url] componentsSeparatedByString:@"/"] lastObject]
+        [[[NSString stringWithUTF8String: p_release->psz_url] componentsSeparatedByString:@"/"] lastObject]
                            modalForWindow: o_update_window 
                             modalDelegate:self
                            didEndSelector:sel
@@ -151,7 +156,7 @@ static VLCUpdate *_o_sharedInstance = nil;
     if( returnCode == NSOKButton )
     {
         /* perform download and pass the selected path */
-        [self performDownload: [sheet filename]];
+        [NSThread detachNewThreadSelector:@selector(performDownload:) toTarget:self withObject:[sheet filename]];
     }
     [sheet release];
 }
@@ -167,36 +172,38 @@ static VLCUpdate *_o_sharedInstance = nil;
     [self setShouldCheckUpdate: [sender state]];
 }
 
-- (void)updateManagement:(vlc_bool_t)b_success
+- (void)setUpToDate:(NSNumber *)uptodate
 {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-    if( !b_success ||
-        update_CompareReleaseToCurrent( p_u ) != UpdateReleaseStatusNewer )
+    if( [uptodate boolValue] )
     {
+        [o_fld_releaseNote setString: @""];
+        [o_fld_currentVersion setStringValue: @""];
         [o_fld_status setStringValue: _NS("This version of VLC is the latest available.")];
         [o_btn_DownloadNow setEnabled: NO];
     }
     else
     {
-        [o_fld_releaseNote setString: [NSString stringWithUTF8String: (p_u->release.psz_desc)]];
+        update_release_t *p_release = update_GetRelease( p_u );
+        [o_fld_releaseNote setString: [NSString stringWithUTF8String: (p_release->psz_desc ? p_release->psz_desc : "" )]];
         [o_fld_status setStringValue: _NS("This version of VLC is outdated.")];
         [o_fld_currentVersion setStringValue: [NSString stringWithFormat:
-            _NS("The current release is %d.%d.%d%c."), p_u->release.i_major,
-            p_u->release.i_minor, p_u->release.i_revision, p_u->release.extra]];
+            _NS("The current release is %d.%d.%d%c."), p_release->i_major,
+            p_release->i_minor, p_release->i_revision, p_release->extra]];
         [o_btn_DownloadNow setEnabled: YES];
         /* Make sure the update window is showed in case we have something */
         [o_update_window center];
         [o_update_window displayIfNeeded];
         [o_update_window makeKeyAndOrderFront: self];
     }
-
-    [pool release];
 }
 
-static void updateCallback( void * p_data, vlc_bool_t b_success )
+static void updateCallback( void * p_data, bool b_success )
 {
-    [(id)p_data updateManagement: b_success];
+    VLCUpdate * update = p_data;
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+    NSNumber * state = [NSNumber numberWithBool:!b_success || !update_NeedUpgrade( update->p_u )];
+    [update performSelectorOnMainThread:@selector(setUpToDate:) withObject:state waitUntilDone:YES];
+    [pool release];
 }
 
 - (void)checkForUpdate
@@ -206,15 +213,21 @@ static void updateCallback( void * p_data, vlc_bool_t b_success )
         return;
     update_Check( p_u, updateCallback, self );
 
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
     [[NSUserDefaults standardUserDefaults] setObject: [NSDate date] forKey: kPrefUpdateLastTimeChecked];
+    [pool release];
 }
 
 - (void)performDownload:(NSString *)path
 {
-    update_Download( p_u, (char*)[path UTF8String] );
+    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+    update_Download( p_u, [path UTF8String] );
     [o_btn_DownloadNow setEnabled: NO];
     [o_update_window orderOut: self];
+    update_WaitDownload( p_u );
     update_Delete( p_u );
+    p_u = nil;
+    [pool release];
 }
 
 @end