Commit 9548b129 authored by Rémi Duraffort's avatar Rémi Duraffort

another cleaning session

parent cac92f55
...@@ -38,16 +38,13 @@ ...@@ -38,16 +38,13 @@
#ifdef UPDATE_CHECK #ifdef UPDATE_CHECK
#include <ctype.h> /* tolower() */
#include <assert.h> #include <assert.h>
#include <vlc_update.h> #include <vlc_update.h>
#include <vlc_block.h>
#include <vlc_stream.h> #include <vlc_stream.h>
#include <vlc_interface.h> #include <vlc_interface.h>
#include <vlc_charset.h>
/***************************************************************************** /*****************************************************************************
* Misc defines * Misc defines
...@@ -70,7 +67,6 @@ ...@@ -70,7 +67,6 @@
#elif defined( WIN32 ) #elif defined( WIN32 )
# define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-win-x86" # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-win-x86"
#elif defined( __APPLE__ ) #elif defined( __APPLE__ )
# define UPDATE_VLC_OS "macosx"
# if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ ) # if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
# define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-ppc" # define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status-mac-ppc"
# else # else
...@@ -1033,15 +1029,16 @@ void update_DownloadReal( update_download_thread_t *p_udt ) ...@@ -1033,15 +1029,16 @@ void update_DownloadReal( update_download_thread_t *p_udt )
int i_progress = 0; int i_progress = 0;
long int l_size; long int l_size;
long int l_downloaded = 0; long int l_downloaded = 0;
char *psz_status; float f_progress;
char *psz_downloaded; char *psz_status = NULL;
char *psz_size; char *psz_downloaded = NULL;
char *psz_destfile; char *psz_size = NULL;
char *psz_tmpdestfile; char *psz_destfile = NULL;
char *psz_tmpdestfile = NULL;
FILE *p_file = NULL; FILE *p_file = NULL;
stream_t *p_stream; stream_t *p_stream = NULL;
void* p_buffer; void* p_buffer = NULL;
int i_read; int i_read;
update_t *p_update = p_udt->p_update; update_t *p_update = p_udt->p_update;
...@@ -1049,38 +1046,38 @@ void update_DownloadReal( update_download_thread_t *p_udt ) ...@@ -1049,38 +1046,38 @@ void update_DownloadReal( update_download_thread_t *p_udt )
/* Open the stream */ /* Open the stream */
p_stream = stream_UrlNew( p_update->p_libvlc, p_update->release.psz_url ); p_stream = stream_UrlNew( p_update->p_libvlc, p_update->release.psz_url );
if( !p_stream ) if( !p_stream )
{ {
msg_Err( p_update->p_libvlc, "Failed to open %s for reading", p_update->release.psz_url ); msg_Err( p_update->p_libvlc, "Failed to open %s for reading", p_update->release.psz_url );
goto error;
} }
else
{ /* Get the stream size */
/* Get the stream size and open the output file */
l_size = stream_Size( p_stream ); l_size = stream_Size( p_stream );
/* Get the file name and open it*/
psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' ); psz_tmpdestfile = strrchr( p_update->release.psz_url, '/' );
if( !psz_tmpdestfile ) if( !psz_tmpdestfile )
{ {
msg_Err( p_update->p_libvlc, "The URL %s is false formated", p_update->release.psz_url ); msg_Err( p_update->p_libvlc, "The URL %s is false formated", p_update->release.psz_url );
return; goto error;
} }
else
{
psz_tmpdestfile++; psz_tmpdestfile++;
if( asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ) != -1 ) if( asprintf( &psz_destfile, "%s%s", psz_destdir, psz_tmpdestfile ) == -1 )
{ goto error;
p_file = utf8_fopen( psz_destfile, "w" ); p_file = utf8_fopen( psz_destfile, "w" );
if( !p_file ) if( !p_file )
{ {
msg_Err( p_update->p_libvlc, "Failed to open %s for writing", psz_destfile ); msg_Err( p_update->p_libvlc, "Failed to open %s for writing", psz_destfile );
goto error;
} }
else
{
/* Create a buffer and fill it with the downloaded file */ /* Create a buffer and fill it with the downloaded file */
p_buffer = (void *)malloc( 1 << 10 ); p_buffer = (void *)malloc( 1 << 10 );
if( p_buffer ) if( !p_buffer )
{ goto error;
psz_size = size_str( l_size ); 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... O.O/%s %.1f%% done", p_update->release.psz_url, psz_size, 0.0 ) != -1 )
{ {
...@@ -1095,17 +1092,20 @@ void update_DownloadReal( update_download_thread_t *p_udt ) ...@@ -1095,17 +1092,20 @@ void update_DownloadReal( update_download_thread_t *p_udt )
l_downloaded += i_read; l_downloaded += i_read;
psz_downloaded = size_str( l_downloaded ); 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", p_update->release.psz_url, if( asprintf( &psz_status, "%s\nDonwloading... %s/%s %.1f%% done", p_update->release.psz_url,
psz_size, psz_downloaded, 100.0*(float)l_downloaded/(float)l_size ) != -1 ) psz_size, psz_downloaded, f_progress ) != -1 )
{ {
intf_ProgressUpdate( p_update->p_libvlc, i_progress, psz_status, 10.0, 0 ); intf_ProgressUpdate( p_update->p_libvlc, i_progress, psz_status, f_progress, 0 );
free( psz_status ); free( psz_status );
} }
free( psz_downloaded ); free( psz_downloaded );
} }
free( p_buffer );
/* If the user cancelled the download */ /* Finish the progress bar or delete the file if the user had canceled */
fclose( p_file );
p_file = NULL;
if( !intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) ) if( !intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) )
{ {
if( asprintf( &psz_status, "%s\nDone %s (100.0%%)", p_update->release.psz_url, psz_size ) != -1 ) if( asprintf( &psz_status, "%s\nDone %s (100.0%%)", p_update->release.psz_url, psz_size ) != -1 )
...@@ -1114,18 +1114,18 @@ void update_DownloadReal( update_download_thread_t *p_udt ) ...@@ -1114,18 +1114,18 @@ void update_DownloadReal( update_download_thread_t *p_udt )
free( psz_status ); free( psz_status );
} }
} }
free( psz_size ); else
}
fclose( p_file );
if( intf_ProgressIsCancelled( p_update->p_libvlc, i_progress ) )
remove( psz_destfile ); remove( psz_destfile );
}
free( psz_destfile ); error:
} if( p_stream )
}
}
free( psz_destdir );
stream_Delete( p_stream ); stream_Delete( p_stream );
if( p_file )
fclose( p_file );
free( psz_destdir );
free( psz_destfile );
free( p_buffer );
free( psz_size );
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment