/*****************************************************************************
* Preamble
*****************************************************************************/
+
+#include <vlc/vlc.h>
+
+#include <stdio.h>
#include <stdlib.h> /* malloc(), free() */
#include <ctype.h> /* tolower() */
-#include <vlc/vlc.h>
#include "vlc_update.h"
#include "vlc_stream.h"
#include "vlc_xml.h"
#include "vlc_interaction.h"
+#include "charset.h"
/*****************************************************************************
* Misc defines
#define UPDATE_VLC_STATUS_URL "http://update.videolan.org/vlc/status.xml"
#define UPDATE_VLC_MIRRORS_URL "http://update.videolan.org/mirrors.xml"
-#define FREE( a ) free(a);a=NULL;
#define STRDUP( a ) ( a ? strdup( a ) : NULL )
/*****************************************************************************
vlc_mutex_init( p_this, &p_update->lock );
- p_update->p_vlc = p_this->p_vlc;
+ p_update->p_libvlc = p_this->p_libvlc;
p_update->p_releases = NULL;
p_update->i_releases = 0;
free( p_update->p_mirrors[i].psz_type );
free( p_update->p_mirrors[i].psz_base_url );
}
- FREE( p_update->p_mirrors );
+ FREENULL( p_update->p_mirrors );
p_update->i_mirrors = 0;
p_update->b_mirrors = VLC_FALSE;
}
free( p_release->psz_svn_revision );
free( p_release->p_files );
}
- FREE( p_update->p_releases );
+ FREENULL( p_update->p_releases );
p_update->i_releases = 0;
p_update->b_releases = VLC_FALSE;
}
xml_t *p_xml = NULL;
xml_reader_t *p_xml_reader = NULL;
-
char *psz_eltname = NULL;
//char *psz_eltvalue = NULL;
char *psz_name = NULL;
char *psz_value = NULL;
-
- struct update_mirror_t tmp_mirror = {0};
+ struct update_mirror_t tmp_mirror;
vlc_mutex_lock( &p_update->lock );
+ memset( &tmp_mirror, 0, sizeof(struct update_mirror_t));
+
if( p_update->b_mirrors && b_force == VLC_FALSE )
{
vlc_mutex_unlock( &p_update->lock );
return;
}
- p_xml = xml_Create( p_update->p_vlc );
+ p_xml = xml_Create( p_update->p_libvlc );
if( !p_xml )
{
- msg_Err( p_update->p_vlc, "Failed to open XML parser" );
+ msg_Err( p_update->p_libvlc, "Failed to open XML parser" );
goto error;
}
- p_stream = stream_UrlNew( p_update->p_vlc, UPDATE_VLC_MIRRORS_URL );
+ p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_MIRRORS_URL );
if( !p_stream )
{
- msg_Err( p_update->p_vlc, "Failed to open %s for reading",
+ msg_Err( p_update->p_libvlc, "Failed to open %s for reading",
UPDATE_VLC_MIRRORS_URL );
goto error;
}
if( !p_xml_reader )
{
- msg_Err( p_update->p_vlc, "Failed to open %s for parsing",
+ msg_Err( p_update->p_libvlc, "Failed to open %s for parsing",
UPDATE_VLC_MIRRORS_URL );
goto error;
}
switch( xml_ReaderNodeType( p_xml_reader ) )
{
case -1:
- msg_Err( p_update->p_vlc, "Error while parsing %s",
+ msg_Err( p_update->p_libvlc, "Error while parsing %s",
UPDATE_VLC_MIRRORS_URL );
goto error;
psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
{
- msg_Err( p_update->p_vlc, "Error while parsing %s",
+ msg_Err( p_update->p_libvlc, "Error while parsing %s",
UPDATE_VLC_MIRRORS_URL );
goto error;
}
if( !psz_name || !psz_value )
{
- msg_Err( p_update->p_vlc, "Error while parsing %s",
+ msg_Err( p_update->p_libvlc, "Error while parsing %s",
UPDATE_VLC_MIRRORS_URL );
goto error;
}
else if( !strcmp( psz_name, "base" ) )
tmp_mirror.psz_base_url = STRDUP( psz_value );
}
- FREE( psz_name );
- FREE( psz_value );
+ FREENULL( psz_name );
+ FREENULL( psz_value );
}
if( !strcmp( psz_eltname, "url" ) )
{
tmp_mirror.psz_type = NULL;
tmp_mirror.psz_base_url = NULL;
}
- FREE( psz_eltname );
+ FREENULL( psz_eltname );
break;
case XML_READER_ENDELEM:
psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
{
- msg_Err( p_update->p_vlc, "Error while parsing %s",
+ msg_Err( p_update->p_libvlc, "Error while parsing %s",
UPDATE_VLC_MIRRORS_URL );
goto error;
}
if( !strcmp( psz_eltname, "mirror" ) )
{
- FREE( tmp_mirror.psz_name );
- FREE( tmp_mirror.psz_location );
+ FREENULL( tmp_mirror.psz_name );
+ FREENULL( tmp_mirror.psz_location );
}
- FREE( psz_eltname );
+ FREENULL( psz_eltname );
break;
/*case XML_READER_TEXT:
psz_eltvalue = xml_ReaderValue( p_xml_reader );
- FREE( psz_eltvalue );
+ FREENULL( psz_eltvalue );
break;*/
}
}
char *psz_value = NULL;
struct update_release_t *p_release = NULL;
- struct update_release_t tmp_release = {0};
- struct update_file_t tmp_file = {0};
- tmp_release.i_type = UPDATE_RELEASE_TYPE_STABLE;
+ struct update_release_t tmp_release;
+ struct update_file_t tmp_file;
vlc_bool_t b_os = VLC_FALSE, b_arch = VLC_FALSE;
+ memset( &tmp_release, 0, sizeof(struct update_release_t) );
+ memset( &tmp_file, 0, sizeof(struct update_file_t) );
+
+ tmp_release.i_type = UPDATE_RELEASE_TYPE_STABLE;
+
vlc_mutex_lock( &p_update->lock );
if( p_update->b_releases && b_force == VLC_FALSE )
return;
}
- p_xml = xml_Create( p_update->p_vlc );
+ p_xml = xml_Create( p_update->p_libvlc );
if( !p_xml )
{
- msg_Err( p_update->p_vlc, "Failed to open XML parser" );
+ msg_Err( p_update->p_libvlc, "Failed to open XML parser" );
goto error;
}
- p_stream = stream_UrlNew( p_update->p_vlc, UPDATE_VLC_STATUS_URL );
+ p_stream = stream_UrlNew( p_update->p_libvlc, UPDATE_VLC_STATUS_URL );
if( !p_stream )
{
- msg_Err( p_update->p_vlc, "Failed to open %s for reading",
+ msg_Err( p_update->p_libvlc, "Failed to open %s for reading",
UPDATE_VLC_STATUS_URL );
goto error;
}
if( !p_xml_reader )
{
- msg_Err( p_update->p_vlc, "Failed to open %s for parsing",
+ msg_Err( p_update->p_libvlc, "Failed to open %s for parsing",
UPDATE_VLC_STATUS_URL );
goto error;
}
switch( xml_ReaderNodeType( p_xml_reader ) )
{
case -1:
- msg_Err( p_update->p_vlc, "Error while parsing %s",
+ msg_Err( p_update->p_libvlc, "Error while parsing %s",
UPDATE_VLC_STATUS_URL );
goto error;
psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
{
- msg_Err( p_update->p_vlc, "Error while parsing %s",
+ msg_Err( p_update->p_libvlc, "Error while parsing %s",
UPDATE_VLC_STATUS_URL );
goto error;
}
if( !psz_name || !psz_value )
{
- msg_Err( p_update->p_vlc, "Error while parsing %s",
+ msg_Err( p_update->p_libvlc, "Error while parsing %s",
UPDATE_VLC_STATUS_URL );
goto error;
}
{
b_arch = VLC_TRUE;
}
- FREE( psz_name );
- FREE( psz_value );
+ FREENULL( psz_name );
+ FREENULL( psz_value );
}
if( ( b_os && b_arch && strcmp( psz_eltname, "arch" ) ) )
{
if( !strcmp( psz_eltname, "version" ) )
{
int i;
- /* look for a previous occurence of this release */
+ /* look for a previous occurrence of this release */
for( i = 0; i < p_update->i_releases; i++ )
{
p_release = p_update->p_releases + i;
}
else
{
- FREE( tmp_release.psz_major );
- FREE( tmp_release.psz_minor );
- FREE( tmp_release.psz_revision );
- FREE( tmp_release.psz_extra );
- FREE( tmp_release.psz_svn_revision );
+ FREENULL( tmp_release.psz_major );
+ FREENULL( tmp_release.psz_minor );
+ FREENULL( tmp_release.psz_revision );
+ FREENULL( tmp_release.psz_extra );
+ FREENULL( tmp_release.psz_svn_revision );
tmp_release.i_type = UPDATE_RELEASE_TYPE_STABLE;
- FREE( tmp_release.p_files );
+ FREENULL( tmp_release.p_files );
tmp_release.i_files = 0;
}
}
tmp_file.psz_description = NULL;
}
}
- FREE( psz_eltname );
+ FREENULL( psz_eltname );
break;
case XML_READER_ENDELEM:
psz_eltname = xml_ReaderName( p_xml_reader );
if( !psz_eltname )
{
- msg_Err( p_update->p_vlc, "Error while parsing %s",
+ msg_Err( p_update->p_libvlc, "Error while parsing %s",
UPDATE_VLC_STATUS_URL );
goto error;
}
b_os = VLC_FALSE;
else if( !strcmp( psz_eltname, "arch" ) )
b_arch = VLC_FALSE;
- FREE( psz_eltname );
+ FREENULL( psz_eltname );
break;
case XML_READER_TEXT:
if( p_release && p_release->i_files )
p_release->p_files[ p_release->i_files - 1 ]
.psz_description = STRDUP( psz_eltvalue );
- FREE( psz_eltvalue );
+ FREENULL( psz_eltvalue );
break;
}
}
*/
int CompareReleaseToCurrent( struct update_release_t *p )
{
- struct update_release_t c = {0};
+ struct update_release_t c;
int r;
+
+ memset( &c, 0, sizeof(struct update_release_t) );
c.psz_major = STRDUP( PACKAGE_VERSION_MAJOR );
c.psz_minor = STRDUP( PACKAGE_VERSION_MINOR );
c.psz_revision = STRDUP( PACKAGE_VERSION_REVISION );
void update_iterator_ClearData( update_iterator_t *p_uit )
{
p_uit->file.i_type = UPDATE_FILE_TYPE_NONE;
- FREE( p_uit->file.psz_md5 );
+ FREENULL( p_uit->file.psz_md5 );
p_uit->file.l_size = 0;
- FREE( p_uit->file.psz_description );
- FREE( p_uit->file.psz_url );
- FREE( p_uit->release.psz_version );
- FREE( p_uit->release.psz_svn_revision );
+ FREENULL( p_uit->file.psz_description );
+ FREENULL( p_uit->file.psz_url );
+ FREENULL( p_uit->release.psz_version );
+ FREENULL( p_uit->release.psz_svn_revision );
p_uit->release.i_type = UPDATE_RELEASE_TYPE_UNSTABLE;
p_uit->release.i_status = UPDATE_RELEASE_STATUS_NONE;
- FREE( p_uit->mirror.psz_name );
- FREE( p_uit->mirror.psz_location );
- FREE( p_uit->mirror.psz_type );
+ FREENULL( p_uit->mirror.psz_name );
+ FREENULL( p_uit->mirror.psz_location );
+ FREENULL( p_uit->mirror.psz_type );
}
/**
void update_download( update_iterator_t *p_uit, char *psz_dest )
{
download_thread_t *p_dt =
- vlc_object_create( p_uit->p_u->p_vlc, sizeof( download_thread_t ) );
+ vlc_object_create( p_uit->p_u->p_libvlc, sizeof( download_thread_t ) );
p_dt->psz_dest = strdup( psz_dest );
p_dt->psz_src = strdup( p_uit->file.psz_url );
VLC_THREAD_PRIORITY_LOW, VLC_FALSE );
}
+/**
+ * Convert a long int size in bytes to a string
+ *
+ * \param l_size the size in bytes
+ * \return the size as a string
+ */
+char *size_str( long int l_size )
+{
+ char *psz_tmp;
+ if( l_size>> 30 )
+ asprintf( &psz_tmp, "%.1f GB", (float)l_size/(1<<30) );
+ if( l_size >> 20 )
+ asprintf( &psz_tmp, "%.1f MB", (float)l_size/(1<<20) );
+ else if( l_size >> 10 )
+ asprintf( &psz_tmp, "%.1f kB", (float)l_size/(1<<10) );
+ else
+ asprintf( &psz_tmp, "%ld B", l_size );
+ return psz_tmp;
+}
+
/**
* The true download function.
*
char *psz_dest = p_this->psz_dest;
char *psz_src = p_this->psz_src;
stream_t *p_stream;
- vlc_t *p_vlc = p_this->p_vlc;
+ libvlc_int_t *p_libvlc = p_this->p_libvlc;
FILE *p_file = NULL;
void *p_buffer;
char *psz_status;
int i_progress;
- int i_size;
- int i_done = 0;
+ long int l_size, l_done = 0;
vlc_thread_ready( p_this );
- p_stream = stream_UrlNew( p_vlc, psz_src );
+ asprintf( &psz_status, "%s\nDownloading... 0.0/? %.1f%% done",
+ p_this->psz_status, 0.0 );
+ i_progress = intf_UserProgress( p_libvlc, "Downloading...",
+ psz_status, 0.0, 0 );
+
+ p_stream = stream_UrlNew( p_libvlc, psz_src );
if( !p_stream )
{
- msg_Err( p_vlc, "Failed to open %s for reading", psz_src );
+ msg_Err( p_libvlc, "Failed to open %s for reading", psz_src );
+ intf_UserFatal( p_libvlc, VLC_TRUE, "Error while Downloading...",
+ "VLC failed to open %s for reading.", psz_src );
+ intf_UserHide( p_libvlc, i_progress );
}
else
{
- p_file = fopen( psz_dest, "w" );
+ p_file = utf8_fopen( psz_dest, "w" );
if( !p_file )
{
- msg_Err( p_vlc, "Failed to open %s for writing", psz_dest );
+ msg_Err( p_libvlc, "Failed to open %s for writing", psz_dest );
+ intf_UserFatal( p_libvlc, VLC_TRUE, "Error while Downloading...",
+ "VLC failed to open %s for writing.", psz_dest );
+ intf_UserHide( p_libvlc, i_progress );
}
else
{
+ long int l_read;
+ char *psz_s1; char *psz_s2;
- i_size = (int)(stream_Size(p_stream)/(1<<10));
+ l_size = stream_Size(p_stream);
p_buffer = (void *)malloc( 1<<10 );
- asprintf( &psz_status, "%s\nDownloading... %.1f%% done",
- p_this->psz_status, 0.0 );
- i_progress = intf_UserProgress( p_vlc, "Downloading...",
- psz_status, 0.0 );
-
- while( stream_Read( p_stream, p_buffer, 1<<10 ) )
+ while( ( l_read = stream_Read( p_stream, p_buffer, 1<<10 ) ) )
{
float f_progress;
- fwrite( p_buffer, 1<<10, 1, p_file );
+ fwrite( p_buffer, l_read, 1, p_file );
- i_done++;
+ l_done += l_read;
free( psz_status );
- f_progress = 100.0*(float)i_done/(float)i_size;
- asprintf( &psz_status, "%s\nDownloading... %.1f%% done",
- p_this->psz_status, f_progress );
- intf_UserProgressUpdate( p_vlc, i_progress,
- psz_status, f_progress );
+ f_progress = 100.0*(float)l_done/(float)l_size;
+ psz_s1 = size_str( l_done );
+ psz_s2 = size_str( l_size );
+ asprintf( &psz_status, "%s\nDownloading... %s/%s (%.1f%%) done",
+ p_this->psz_status, psz_s1, psz_s2, f_progress );
+ free( psz_s1 ); free( psz_s2 );
+
+ intf_ProgressUpdate( p_libvlc, i_progress,
+ psz_status, f_progress, 0 );
}
free( p_buffer );
- free( psz_status );
fclose( p_file );
stream_Delete( p_stream );
+ free( psz_status );
+ psz_s2 = size_str( l_size );
+ asprintf( &psz_status, "%s\nDone %s (100.00%%)",
+ p_this->psz_status, psz_s2 );
+ free( psz_s2 );
+ intf_ProgressUpdate( p_libvlc, i_progress, psz_status, 100.0, 0 );
+ free( psz_status );
}
}