Commit 9548b129 authored by ivoire's avatar ivoire
Browse files

another cleaning session

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