]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/update.m
macosx: experimental 64bit support
[vlc] / modules / gui / macosx / update.m
index e201cb26fce40a539d911571b98a106a480677d0..12f162b56c904891572be1e18bad2c0d8260f6e8 100644 (file)
@@ -26,6 +26,8 @@
 
 #ifdef UPDATE_CHECK
 
+#include <assert.h>
+
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
@@ -34,7 +36,7 @@ static NSString * kPrefUpdateOnStartup = @"UpdateOnStartup";
 static NSString * kPrefUpdateLastTimeChecked = @"UpdateLastTimeChecked";
 
 /*****************************************************************************
- * VLCExtended implementation
+ * VLCUpdate implementation
  *****************************************************************************/
 
 @implementation VLCUpdate
@@ -67,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
@@ -78,6 +85,9 @@ static VLCUpdate *_o_sharedInstance = nil;
 {
     [[NSUserDefaults standardUserDefaults] setBool: check forKey: kPrefUpdateOnStartup];
     [o_chk_updateOnStartup setState: check];
+
+    /* make sure we got this set, even if we crash later on */
+    [[NSUserDefaults standardUserDefaults] synchronize];
 }
 
 - (BOOL)shouldCheckForUpdate
@@ -88,7 +98,7 @@ static VLCUpdate *_o_sharedInstance = nil;
     if( ![[NSUserDefaults standardUserDefaults] objectForKey: kPrefUpdateOnStartup] )
     {
         /* We don't have any preferences stored, ask the user. */
-        int res = NSRunInformationalAlertPanel( _NS("Do you want VLC to check for updates automatically?"),
+        NSInteger res = NSRunInformationalAlertPanel( _NS("Do you want VLC to check for updates automatically?"),
               _NS("You can change this option in VLC's update window later on."), _NS("Yes"), _NS("No"), nil );
         [self setShouldCheckUpdate: res];
     }
@@ -100,7 +110,7 @@ static VLCUpdate *_o_sharedInstance = nil;
     if( !o_last_update )
         return YES;
 
-    o_next_update = [[[NSDate alloc] initWithTimeInterval: 60*60*24*2 /* every two days */ sinceDate: o_last_update] autorelease];
+    o_next_update = [[[NSDate alloc] initWithTimeInterval: 60*60*24*7 /* every seven days */ sinceDate: o_last_update] autorelease];
     if( !o_next_update )
         return YES;
 
@@ -132,22 +142,24 @@ static VLCUpdate *_o_sharedInstance = nil;
     [saveFilePanel setRequiredFileType: @"dmg"];
     [saveFilePanel setCanSelectHiddenExtension: YES];
     [saveFilePanel setCanCreateDirectories: YES];
-    [saveFilePanel beginSheetForDirectory:nil file:
-        [[[NSString stringWithUTF8String: p_u->release.psz_url] componentsSeparatedByString:@"/"] lastObject]
+    update_release_t *p_release = update_GetRelease( p_u );
+    assert( p_release );
+    [saveFilePanel beginSheetForDirectory:@"~/Downloads" file:
+        [[[NSString stringWithUTF8String: p_release->psz_url] componentsSeparatedByString:@"/"] lastObject]
                            modalForWindow: o_update_window 
                             modalDelegate:self
                            didEndSelector:sel
                               contextInfo:nil];
 }
 
-- (void)getLocationForSaving: (NSSavePanel *)sheet 
+- (void)getLocationForSaving: (NSSavePanel *)sheet
                   returnCode: (int)returnCode 
                  contextInfo: (void *)contextInfo
 {
     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];
 }
@@ -163,11 +175,9 @@ static VLCUpdate *_o_sharedInstance = nil;
     [self setShouldCheckUpdate: [sender state]];
 }
 
-- (void)setUpToDate:(BOOL)uptodate
+- (void)setUpToDate:(NSNumber *)uptodate
 {
-    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
-    if( uptodate )
+    if( [uptodate boolValue] )
     {
         [o_fld_releaseNote setString: @""];
         [o_fld_currentVersion setStringValue: @""];
@@ -176,24 +186,27 @@ static VLCUpdate *_o_sharedInstance = nil;
     }
     else
     {
-        [o_fld_releaseNote setString: [NSString stringWithUTF8String: (p_u->release.psz_desc ? 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, bool b_success )
 {
-    [(id)p_data setUpToDate: !b_success || !update_NeedUpgrade( ((VLCUpdate*)p_data)->p_u )];
+    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
@@ -203,15 +216,21 @@ static void updateCallback( void * p_data, bool 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
 {
+    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