[vlc-devel] commit: Fix MacOSX update checking - inverted behavior ( Rafaël Carré )

git version control git at videolan.org
Tue Apr 15 21:42:37 CEST 2008


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Tue Apr 15 21:41:37 2008 +0200| [c64426b9ddac138ccad991fdf0c0f1f1f0a38333]

Fix MacOSX update checking - inverted behavior

The problem came from my misreading of the API
This commit also fix potential misunderstanding by simplifying it further

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c64426b9ddac138ccad991fdf0c0f1f1f0a38333
---

 include/vlc_update.h             |    9 +-------
 modules/gui/macosx/update.m      |    2 +-
 modules/gui/qt4/dialogs/help.cpp |    2 +-
 src/misc/update.c                |   42 +++++--------------------------------
 4 files changed, 9 insertions(+), 46 deletions(-)

diff --git a/include/vlc_update.h b/include/vlc_update.h
index d80c674..46add4c 100644
--- a/include/vlc_update.h
+++ b/include/vlc_update.h
@@ -155,13 +155,6 @@ struct public_key_t
 
 typedef struct public_key_t public_key_t;
 
-enum
-{
-    UpdateReleaseStatusOlder,
-    UpdateReleaseStatusEqual,
-    UpdateReleaseStatusNewer
-};
-
 /**
  * Describes an update VLC release number
  */
@@ -191,7 +184,7 @@ struct update_t
 VLC_EXPORT( update_t *, __update_New, ( vlc_object_t * ) );
 VLC_EXPORT( void, update_Delete, ( update_t * ) );
 VLC_EXPORT( void, update_Check, ( update_t *, void (*callback)( void*, bool ), void * ) );
-VLC_EXPORT( int, update_CompareReleaseToCurrent, ( update_t * ) );
+VLC_EXPORT( bool, update_NeedUpgrade, ( update_t * ) );
 VLC_EXPORT( void, update_Download, ( update_t *, char* ) );
 
 /**
diff --git a/modules/gui/macosx/update.m b/modules/gui/macosx/update.m
index 134b367..e201cb2 100644
--- a/modules/gui/macosx/update.m
+++ b/modules/gui/macosx/update.m
@@ -193,7 +193,7 @@ static VLCUpdate *_o_sharedInstance = nil;
 
 static void updateCallback( void * p_data, bool b_success )
 {
-    [(id)p_data setUpToDate: !b_success || update_CompareReleaseToCurrent( ((VLCUpdate*)p_data)->p_u ) == UpdateReleaseStatusNewer ];
+    [(id)p_data setUpToDate: !b_success || !update_NeedUpgrade( ((VLCUpdate*)p_data)->p_u )];
 }
 
 - (void)checkForUpdate
diff --git a/modules/gui/qt4/dialogs/help.cpp b/modules/gui/qt4/dialogs/help.cpp
index 4f33721..c6ced9b 100644
--- a/modules/gui/qt4/dialogs/help.cpp
+++ b/modules/gui/qt4/dialogs/help.cpp
@@ -284,7 +284,7 @@ void UpdateDialog::updateNotify( bool b_result )
     /* The update finish without errors */
     if( b_result )
     {
-        if( update_CompareReleaseToCurrent( p_update ) == UpdateReleaseStatusNewer )
+        if( update_NeedUpgrade( p_update ) )
         {
             b_checked = true;
             updateButton->setText( "Download" );
diff --git a/src/misc/update.c b/src/misc/update.c
index 0311938..b84de83 100644
--- a/src/misc/update.c
+++ b/src/misc/update.c
@@ -88,8 +88,6 @@
  *****************************************************************************/
 static void EmptyRelease( update_t *p_update );
 static bool GetUpdateFile( update_t *p_update );
-static int CompareReleases( const struct update_release_t *p1,
-                            const struct update_release_t *p2 );
 static char * size_str( long int l_size );
 
 
@@ -1146,47 +1144,19 @@ void update_CheckReal( update_check_thread_t *p_uct )
 }
 
 /**
- * Compare two release numbers
- *
- * \param p1 first release
- * \param p2 second release
- * \return UpdateReleaseStatus(Older|Equal|Newer)
- */
-static int CompareReleases( const struct update_release_t *p1,
-                            const struct update_release_t *p2 )
-{
-    int32_t d;
-    d = ( p1->i_major << 24 ) + ( p1->i_minor << 16 ) + ( p1->i_revision << 8 )
-      - ( p2->i_major << 24 ) - ( p2->i_minor << 16 ) - ( p2->i_revision << 8 )
-      + ( p1->extra ) - ( p2->extra );
-
-    if( d < 0 )
-        return UpdateReleaseStatusOlder;
-    else if( d == 0 )
-        return UpdateReleaseStatusEqual;
-    else
-        return UpdateReleaseStatusNewer;
-}
-
-/**
  * Compare a given release's version number to the current VLC's one
  *
  * \param p_update structure
- * \return UpdateReleaseStatus(Older|Equal|Newer)
+ * \return true if we have to upgrade to the given version to be up to date
  */
-int update_CompareReleaseToCurrent( update_t *p_update )
+bool update_NeedUpgrade( update_t *p_update )
 {
     assert( p_update );
 
-    struct update_release_t c;
-
-    /* get the current version number */
-    c.i_major = *PACKAGE_VERSION_MAJOR - '0';
-    c.i_minor = *PACKAGE_VERSION_MINOR - '0';
-    c.i_revision = *PACKAGE_VERSION_REVISION - '0';
-    c.extra = *PACKAGE_VERSION_EXTRA;
-
-    return CompareReleases( &p_update->release, &c );
+    return  p_update->release.i_major < *PACKAGE_VERSION_MAJOR - '0' ||
+            p_update->release.i_minor < *PACKAGE_VERSION_MINOR - '0' ||
+            p_update->release.i_revision < *PACKAGE_VERSION_REVISION ||
+            p_update->release.extra < *PACKAGE_VERSION_EXTRA;
 }
 
 /**




More information about the vlc-devel mailing list