]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/update.m
* made the look-for-update process faster and more error tolerant
[vlc] / modules / gui / macosx / update.m
index f5654d4e6d2a1153ecd7d53bacf1fcc995bb36d4..ff08a8c40ac719084e8ecb3ef096c40e3b357d1d 100644 (file)
@@ -72,12 +72,8 @@ static VLCUpdate *_o_sharedInstance = nil;
 
 - (void)dealloc
 {
-    if( o_hashOfOurBinary )
-        [o_hashOfOurBinary release];
     if( o_urlOfBinary )
         [o_urlOfBinary release];
-    if( o_indexOfOurBinary )
-        [o_indexOfOurBinary release];
 
     [super dealloc];
 }
@@ -85,7 +81,7 @@ static VLCUpdate *_o_sharedInstance = nil;
 - (void)initStrings
 {
     /* translate strings to the user's language */
-    [o_update_window setTitle: _NS("Check for Update")];
+    [o_update_window setTitle: _NS("Check for Updates")];
     [o_btn_DownloadNow setTitle: _NS("Download now")];
     [o_btn_okay setTitle: _NS("OK")];
 }
@@ -93,7 +89,7 @@ static VLCUpdate *_o_sharedInstance = nil;
 - (void)showUpdateWindow
 {
     /* show the window and check for a potential update */
-    [o_fld_status setStringValue: _NS("Checking for Update...")];
+    [o_fld_status setStringValue: _NS("Checking for Updates...")];
     [o_fld_currentVersionAndSize setStringValue: @""];
     [o_fld_releaseNote setString: @""];
 
@@ -144,11 +140,11 @@ static VLCUpdate *_o_sharedInstance = nil;
     update_Check( p_u, VLC_FALSE );
     update_iterator_t *p_uit = update_iterator_New( p_u );
     BOOL releaseChecked = NO;
+    BOOL gettingReleaseNote = NO;
     int x = 0;
     NSString * pathToReleaseNote;
-    pathToReleaseNote = [[NSString stringWithString: \
-        @"~/Library/Caches/vlc_releasenote_temp.txt"] \
-        stringByExpandingTildeInPath];
+    pathToReleaseNote = [NSString stringWithFormat: \
+        @"/tmp/vlc_releasenote_%d.tmp", mdate()];
     
     if( p_uit )
     {
@@ -158,6 +154,7 @@ static VLCUpdate *_o_sharedInstance = nil;
         
         while( update_iterator_Action( p_uit, UPDATE_FILE) != UPDATE_FAIL )
         {
+            msg_Dbg( p_intf, "parsing available updates, run %i", x );
             /* if the announced item is of the type "binary", keep it and display
              * its details to the user. Do similar stuff on "info". Do both 
              * only if the file is announced as stable */
@@ -165,23 +162,26 @@ static VLCUpdate *_o_sharedInstance = nil;
             {
                 if( p_uit->file.i_type == UPDATE_FILE_TYPE_INFO )
                 {
+                    msg_Dbg( p_intf, "release note found, desc = %s",
+                        p_uit->file.psz_description );
                     [o_fld_releaseNote setString: \
                         [NSString stringWithUTF8String: \
                         (p_uit->file.psz_description)]];
                     /* download our release note
                      * We will read the temp file after this loop */
                     update_download( p_uit, (char *)[pathToReleaseNote UTF8String] );
+                    gettingReleaseNote = YES;
                 }
                 else if( p_uit->file.i_type == UPDATE_FILE_TYPE_BINARY )
                 {
-                    msg_Dbg( p_intf, "binary found, version = %s" \
-                        ", hash=%s, size=%i MB, position in release file list=%i",\
-                        p_uit->release.psz_version, p_uit->file.psz_md5, \
-                        (int)((p_uit->file.l_size / 1024) / 1024), \
-                        p_uit->i_f);
-                    [o_fld_currentVersionAndSize setStringValue: \
-                        [NSString stringWithFormat: \
-                        @"The current release is %s (%i MB to download).", \
+                    msg_Dbg( p_intf, "binary found, version = %s" \
+                        "url=%s, size=%i MB", p_uit->release.psz_version, \
+                        p_uit->file.psz_url, \
+                        (int)((p_uit->file.l_size / 1024) / 1024) );
+                    [o_fld_currentVersionAndSize setStringValue: [NSString \
+                        stringWithFormat: \
+                        _NS("The latest VLC media player release " \
+                            "is %s (%i MB to download)."), \
                         p_uit->release.psz_version, ((p_uit->file.l_size \
                         / 1024) / 1024)]];
                         
@@ -189,30 +189,13 @@ static VLCUpdate *_o_sharedInstance = nil;
                         [o_urlOfBinary release];
                     o_urlOfBinary = [[NSString alloc] initWithUTF8String: \
                         p_uit->file.psz_url];
-
-                    /* save the hash of our file, if available */
-                    if( p_uit->file.psz_md5 )
-                    {
-                        if( o_hashOfOurBinary )
-                            [o_hashOfOurBinary release];
-                        o_hashOfOurBinary = [[NSString alloc] \
-                            initWithUTF8String: p_uit->file.psz_md5];
-                    }
-                    
-                    if( p_uit->i_f )
-                    {
-                        if( o_indexOfOurBinary )
-                            [o_indexOfOurBinary release];
-                        o_indexOfOurBinary = [[NSNumber alloc] \
-                            initWithInt: p_uit->i_f];
-                    }
                 }
                 if( p_uit->release.i_status == UPDATE_RELEASE_STATUS_NEWER &&
                     !releaseChecked )
                 {
                     /* our version is outdated, let the user download the new
                      * release */
-                    [o_fld_status setStringValue: _NS("Your version of VLC " \
+                    [o_fld_status setStringValue: _NS("This version of VLC " \
                         "is outdated.")];
                     [o_btn_DownloadNow setEnabled: YES];
                     msg_Dbg( p_intf, "this version of VLC is outdated" );
@@ -225,8 +208,8 @@ static VLCUpdate *_o_sharedInstance = nil;
                 }
                 else if(! releaseChecked )
                 {
-                    [o_fld_status setStringValue: _NS("Your version of VLC " \
-                        "is up-to-date.")];
+                    [o_fld_status setStringValue: _NS("This version of VLC " \
+                        "is latest available.")];
                     [o_btn_DownloadNow setEnabled: NO];
                     msg_Dbg( p_intf, "current version is up-to-date" );
                     releaseChecked = YES;
@@ -237,36 +220,48 @@ static VLCUpdate *_o_sharedInstance = nil;
 
         update_iterator_Delete( p_uit );
         
-        /* wait for our download, since it is done by another thread
-         * this does usually take 300000 to 500000 ms */
-        int i = 0;
-        while( [[NSFileManager defaultManager] fileExistsAtPath: pathToReleaseNote] == NO )
+        /* wait for our release notes if necessary, since the download is done
+         * by another thread -- this does usually take 300000 to 500000 ms */
+        if( gettingReleaseNote )
         {
-            msleep( 100000 );
-            i += 1;
-            if( i == 600 )
+            int i = 0;
+            while( [[NSFileManager defaultManager] fileExistsAtPath: pathToReleaseNote] == NO )
             {
-                /* if this takes more than 1 min, exit */
-                msg_Warn( p_intf, "download took more than a minute, exiting" );
-                return;
+                msleep( 100000 );
+                i += 1;
+                if( i == 150 )
+                {
+                    /* if this takes more than 15 sec, exit */
+                    msg_Warn( p_intf, "download took more than 15 sec, exiting" );
+                    break;
+                }
             }
-        }
-        msg_Dbg( p_intf, "waited %i ms for the release notes", (i * 100000) );
-        msleep( 500000 );
-
-        /* let's open our cached release note and display it
-         * we can't use NSString stringWithContentsOfFile:encoding:error: 
-         * since it is Tiger only */
-        NSString * releaseNote = [[NSString alloc] initWithData: \
-            [NSData dataWithContentsOfFile: pathToReleaseNote] \
-            encoding: NSISOLatin1StringEncoding];
-        if( releaseNote )
-            [o_fld_releaseNote setString: releaseNote];
+            msg_Dbg( p_intf, "waited %i ms for the release notes", (i * 100000) );
+            msleep( 500000 );
 
-        /* delete the file since it isn't needed anymore */
-        BOOL myBOOL = NO;
-        myBOOL = [[NSFileManager defaultManager] removeFileAtPath: \
-            pathToReleaseNote handler: nil];
+            /* let's open our cached release note and display it
+             * we can't use NSString stringWithContentsOfFile:encoding:error: 
+             * since it is Tiger only */
+            NSString * releaseNote = [[NSString alloc] initWithData: \
+                [NSData dataWithContentsOfFile: pathToReleaseNote] \
+                encoding: NSISOLatin1StringEncoding];
+            if( releaseNote )
+                [o_fld_releaseNote setString: releaseNote];
+        
+            /* delete the file since it isn't needed anymore */
+            BOOL myBOOL = NO;
+            myBOOL = [[NSFileManager defaultManager] removeFileAtPath: \
+                pathToReleaseNote handler: nil];
+        }
+        else
+        {
+            /* don't confuse the user, but make her happy */
+            [o_fld_status setStringValue: _NS("This version of VLC " \
+                "is latest available.")];
+            [o_btn_DownloadNow setEnabled: NO];
+            msg_Dbg( p_intf, "current version is up-to-date" );
+            msg_Warn( p_intf, "retrieving current release notes failed!" );
+        }
     }
 }
 
@@ -283,6 +278,11 @@ static VLCUpdate *_o_sharedInstance = nil;
                 p_uit->release.i_status == UPDATE_RELEASE_STATUS_NEWER &&
                 p_uit->file.i_type == UPDATE_FILE_TYPE_BINARY )
             {
+                /* put the mirror information */
+                msg_Dbg( p_intf, "used mirror: %s, %s [%s]", \
+                    p_uit->mirror.psz_name, p_uit->mirror.psz_location, \
+                    p_uit->mirror.psz_type );
+
                 /* that's our binary */
                 update_download( p_uit, (char *)[path UTF8String] );
             }