]> git.sesse.net Git - vlc/blobdiff - src/misc/update.c
Interaction: remove (buggy and useless) dialog IDs
[vlc] / src / misc / update.c
index 93c820c9a14990f6312f2c3885f7fb472c3a76b6..320b7274c0fffe4527bc2f26005117006d762989 100644 (file)
@@ -35,6 +35,9 @@
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
+#ifdef HAVE_SYS_STAT_H
+#   include <sys/stat.h>
+#endif
 
 #include <vlc_common.h>
 #include <vlc_update.h>
@@ -845,6 +848,16 @@ static uint8_t *hash_sha1_from_file( const char *psz_file,
         gcry_md_write( hd, p_sig->specific.v4.hashed_data_len, 2 );
         size_t i_len = scalar_number( p_sig->specific.v4.hashed_data_len, 2 );
         gcry_md_write( hd, p_sig->specific.v4.hashed_data, i_len );
+
+        gcry_md_putc( hd, 0x04 );
+        gcry_md_putc( hd, 0xFF );
+
+        i_len += 6; /* hashed data + 6 bytes header */
+
+        gcry_md_putc( hd, (i_len >> 24) & 0xff );
+        gcry_md_putc( hd, (i_len >> 16) & 0xff );
+        gcry_md_putc( hd, (i_len >> 8) & 0xff );
+        gcry_md_putc( hd, (i_len) & 0xff );
     }
     else
     {   /* RFC 4880 only tells about versions 3 and 4 */
@@ -978,9 +991,9 @@ static uint8_t *key_sign_hash( public_key_t *p_pkey )
 
     size_t i_len = strlen((char*)p_pkey->psz_username);
 
-    gcry_md_putc( hd, (i_len << 24) & 0xff );
-    gcry_md_putc( hd, (i_len << 16) & 0xff );
-    gcry_md_putc( hd, (i_len << 8) & 0xff );
+    gcry_md_putc( hd, (i_len >> 24) & 0xff );
+    gcry_md_putc( hd, (i_len >> 16) & 0xff );
+    gcry_md_putc( hd, (i_len >> 8) & 0xff );
     gcry_md_putc( hd, (i_len) & 0xff );
 
     gcry_md_write( hd, p_pkey->psz_username, i_len );
@@ -1000,14 +1013,14 @@ static uint8_t *key_sign_hash( public_key_t *p_pkey )
 
     i_hashed_data_len += 6; /* hashed data + 6 bytes header */
 
-    gcry_md_putc( hd, (i_hashed_data_len << 24) & 0xff);
-    gcry_md_putc( hd, (i_hashed_data_len << 16) &0xff );
-    gcry_md_putc( hd, (i_hashed_data_len << 8) & 0xff );
+    gcry_md_putc( hd, (i_hashed_data_len >> 24) & 0xff );
+    gcry_md_putc( hd, (i_hashed_data_len >> 16) & 0xff );
+    gcry_md_putc( hd, (i_hashed_data_len >> 8) & 0xff );
     gcry_md_putc( hd, (i_hashed_data_len) & 0xff );
 
     gcry_md_final( hd );
 
-    uint8_t *p_tmp = gcry_md_read( hd, GCRY_MD_SHA1);
+    uint8_t *p_tmp = gcry_md_read( hd, GCRY_MD_SHA1 );
 
     if( !p_tmp ||
         p_tmp[0] != p_pkey->sig.hash_verification[0] ||
@@ -1074,6 +1087,7 @@ void update_Delete( update_t *p_update )
         assert( !p_update->p_download );
         vlc_object_kill( p_update->p_check );
         vlc_thread_join( p_update->p_check );
+        vlc_object_release( p_update->p_check );
     }
     else if( p_update->p_download )
     {
@@ -1308,9 +1322,9 @@ static bool GetUpdateFile( update_t *p_update )
 
         i_len += 6; /* hashed data + 6 bytes header */
 
-        gcry_md_putc( hd, (i_len << 24) & 0xff);
-        gcry_md_putc( hd, (i_len << 16) &0xff );
-        gcry_md_putc( hd, (i_len << 8) & 0xff );
+        gcry_md_putc( hd, (i_len >> 24) & 0xff );
+        gcry_md_putc( hd, (i_len >> 16) & 0xff );
+        gcry_md_putc( hd, (i_len >> 8) & 0xff );
         gcry_md_putc( hd, (i_len) & 0xff );
     }
     else
@@ -1378,7 +1392,7 @@ void update_Check( update_t *p_update, void (*pf_callback)( void*, bool ), void
     p_uct->p_data = p_data;
 
     vlc_thread_create( p_uct, "check for update", update_CheckReal,
-                       VLC_THREAD_PRIORITY_LOW, false );
+                       VLC_THREAD_PRIORITY_LOW );
 }
 
 void* update_CheckReal( vlc_object_t* p_this )
@@ -1446,13 +1460,13 @@ static char *size_str( long int l_size )
     char *psz_tmp = NULL;
     int i_retval = 0;
     if( l_size >> 30 )
-        i_retval = asprintf( &psz_tmp, "%.1f GB", (float)l_size/(1<<30) );
+        i_retval = asprintf( &psz_tmp, _("%.1f GB"), (float)l_size/(1<<30) );
     else if( l_size >> 20 )
-        i_retval = asprintf( &psz_tmp, "%.1f MB", (float)l_size/(1<<20) );
+        i_retval = asprintf( &psz_tmp, _("%.1f MB"), (float)l_size/(1<<20) );
     else if( l_size >> 10 )
-        i_retval = asprintf( &psz_tmp, "%.1f kB", (float)l_size/(1<<10) );
+        i_retval = asprintf( &psz_tmp, _("%.1f kB"), (float)l_size/(1<<10) );
     else
-        i_retval = asprintf( &psz_tmp, "%ld B", l_size );
+        i_retval = asprintf( &psz_tmp, _("%ld B"), l_size );
 
     return i_retval == -1 ? NULL : psz_tmp;
 }
@@ -1471,10 +1485,12 @@ static void* update_DownloadReal( vlc_object_t *p_this );
  * Download the file given in the update_t
  *
  * \param p_update structure
- * \param dir to store the download file
+ * \param destination to store the download file
+ *        This can be an existing dir, a (non)existing target fullpath filename or
+ *        NULL for the current working dir.
  * \return nothing
  */
-void update_Download( update_t *p_update, const char *psz_destdir )
+void update_Download( update_t *p_update, const char *destination )
 {
     assert( p_update );
 
@@ -1486,16 +1502,16 @@ void update_Download( update_t *p_update, const char *psz_destdir )
 
     p_udt->p_update = p_update;
     p_update->p_download = p_udt;
-    p_udt->psz_destdir = psz_destdir ? strdup( psz_destdir ) : NULL;
+    p_udt->psz_destination = destination ? strdup( destination ) : NULL;
 
     vlc_thread_create( p_udt, "download update", update_DownloadReal,
-                       VLC_THREAD_PRIORITY_LOW, false );
+                       VLC_THREAD_PRIORITY_LOW );
 }
 
 static void* update_DownloadReal( vlc_object_t *p_this )
 {
     update_download_thread_t *p_udt = (update_download_thread_t *)p_this;
-    int i_progress = 0;
+    interaction_dialog_t *p_progress = 0;
     long int l_size;
     long int l_downloaded = 0;
     float f_progress;
@@ -1506,13 +1522,14 @@ static void* update_DownloadReal( vlc_object_t *p_this )
     char *psz_tmpdestfile = NULL;
 
     FILE *p_file = NULL;
+    struct stat p_stat;
     stream_t *p_stream = NULL;
     void* p_buffer = NULL;
     int i_read;
     int canc;
 
     update_t *p_update = p_udt->p_update;
-    char *psz_destdir = p_udt->psz_destdir;
+    char *psz_destination = p_udt->psz_destination;
 
     msg_Dbg( p_udt, "Opening Stream '%s'", p_update->release.psz_url );
     canc = vlc_savecancel ();
@@ -1532,17 +1549,29 @@ static void* update_DownloadReal( vlc_object_t *p_this )
     psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' );
     if( !psz_tmpdestfile )
     {
-        msg_Err( p_udt, "The URL %s is false formated", p_update->release.psz_url );
+        msg_Err( p_udt, "The URL %s is badly formated",
+                 p_update->release.psz_url );
         goto end;
     }
     psz_tmpdestfile++;
-    if( asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ) == -1 )
-        goto end;
+
+    if( utf8_stat( psz_destination, &p_stat) == 0 && (p_stat.st_mode & S_IFDIR) )
+    {
+        if( asprintf( &psz_destfile, "%s%c%s", psz_destination, DIR_SEP_CHAR, psz_tmpdestfile ) == -1 )
+            goto end;
+    }
+    else if( psz_destination )
+        psz_destfile = strdup( psz_destination );
+    else
+        psz_destfile = strdup( psz_tmpdestfile );
 
     p_file = utf8_fopen( psz_destfile, "w" );
     if( !p_file )
     {
         msg_Err( p_udt, "Failed to open %s for writing", psz_destfile );
+        intf_UserFatal( p_udt, true, _("Saving file failed"),
+            _("Failed to open \"%s\" for writing"),
+             psz_destfile );
         goto end;
     }
 
@@ -1557,17 +1586,18 @@ static void* update_DownloadReal( vlc_object_t *p_this )
     msg_Dbg( p_udt, "Downloading Stream '%s'", p_update->release.psz_url );
 
     psz_size = size_str( l_size );
-    if( asprintf( &psz_status, "%s\nDownloading... O.O/%s %.1f%% done",
-        p_update->release.psz_url, psz_size, 0.0 ) != -1 )
+    if( asprintf( &psz_status, _("%s\nDownloading... %s/%s %.1f%% done"),
+        p_update->release.psz_url, "0.0", psz_size, 0.0 ) != -1 )
     {
-        i_progress = intf_UserProgress( p_udt, "Downloading ...", psz_status, 0.0, 0 );
+        p_progress = intf_UserProgress( p_udt, _( "Downloading ..."),
+                                        psz_status, 0.0, 0 );
         free( psz_status );
     }
 
     vlc_object_lock( p_udt );
     while( vlc_object_alive( p_udt ) &&
            ( i_read = stream_Read( p_stream, p_buffer, 1 << 10 ) ) &&
-           !intf_ProgressIsCancelled( p_udt, i_progress ) )
+           !intf_ProgressIsCancelled( p_udt, p_progress ) )
     {
         vlc_object_unlock( p_udt );
         if( fwrite( p_buffer, i_read, 1, p_file ) < 1 )
@@ -1580,11 +1610,11 @@ static void* update_DownloadReal( vlc_object_t *p_this )
         psz_downloaded = size_str( l_downloaded );
         f_progress = 100.0*(float)l_downloaded/(float)l_size;
 
-        if( asprintf( &psz_status, "%s\nDonwloading... %s/%s %.1f%% done",
+        if( asprintf( &psz_status, _( "%s\nDownloading... %s/%s %.1f%% done" ),
                       p_update->release.psz_url, psz_downloaded, psz_size,
                       f_progress ) != -1 )
         {
-            intf_ProgressUpdate( p_udt, i_progress, psz_status, f_progress, 0 );
+            intf_ProgressUpdate( p_udt, p_progress, psz_status, f_progress, 0 );
             free( psz_status );
         }
         free( psz_downloaded );
@@ -1596,14 +1626,14 @@ static void* update_DownloadReal( vlc_object_t *p_this )
     p_file = NULL;
 
     if( vlc_object_alive( p_udt ) &&
-        !intf_ProgressIsCancelled( p_udt, i_progress ) )
+        !intf_ProgressIsCancelled( p_udt, p_progress ) )
     {
         vlc_object_unlock( p_udt );
-        if( asprintf( &psz_status, "%s\nDone %s (100.0%%)",
+        if( asprintf( &psz_status, _("%s\nDone %s (100.0%%)"),
             p_update->release.psz_url, psz_size ) != -1 )
         {
-            intf_ProgressUpdate( p_udt, i_progress, psz_status, 100.0, 0 );
-            i_progress = 0;
+            intf_ProgressUpdate( p_udt, p_progress, psz_status, 100.0, 0 );
+            p_progress = NULL
             free( psz_status );
         }
     }
@@ -1693,23 +1723,23 @@ static void* update_DownloadReal( vlc_object_t *p_this )
     free( p_hash );
 
 end:
-    if( i_progress )
+    if( p_progress )
     {
-        intf_ProgressUpdate( p_udt, i_progress, "Cancelled", 100.0, 0 );
+        intf_ProgressUpdate( p_udt, p_progress, _("Cancelled"), 100.0, 0 );
     }
     if( p_stream )
         stream_Delete( p_stream );
     if( p_file )
         fclose( p_file );
-    free( psz_destdir );
     free( psz_destfile );
     free( p_buffer );
     free( psz_size );
 
+    free( p_udt->psz_destination );
     p_udt->p_update->p_download = NULL;
 
     vlc_object_release( p_udt );
-    vlc_restorecancel (canc);
+    vlc_restorecancel( canc );
     return NULL;
 }