1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 08:43:27 +00:00

rework the makemeta error messages so that they can be i18nized on the client end.

This commit is contained in:
Charles Kerr 2008-03-24 17:18:08 +00:00
parent b3663db916
commit 919eefe456
3 changed files with 70 additions and 41 deletions

View file

@ -65,7 +65,7 @@ setIsBuilding( MakeMetaUI * ui, gboolean isBuilding )
ui->isBuilding = isBuilding;
if( ui->builder != NULL )
ui->builder->failed = FALSE;
ui->builder->result = TR_MAKEMETA_OK;
if( !isBuilding )
gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR( ui->progressbar ), 0 );
@ -90,21 +90,41 @@ refresh_cb ( gpointer user_data )
if( ui->builder->isDone )
{
if( ui->builder->failed )
char * txt = NULL;
switch( ui->builder->result )
{
char * reason = ui->builder->abortFlag
? g_strdup( _( "Torrent creation cancelled" ) )
: g_strdup_printf( _( "Torrent creation failed: %s" ), ui->builder->error );
gtk_progress_bar_set_text( p, reason );
gtk_progress_bar_set_fraction( p, 0 );
g_free( reason );
}
else
{
gtk_progress_bar_set_text( p, _("Torrent created") );
case TR_MAKEMETA_OK:
txt = g_strdup( _( "Torrent created" ) );
break;
case TR_MAKEMETA_URL:
txt = g_strdup_printf( _( "Torrent creation failed: %s" ), _( "Invalid URL" ) );
break;
case TR_MAKEMETA_CANCELLED:
txt = g_strdup_printf( _( "Torrent creation cancelled" ) );
break;
case TR_MAKEMETA_IO_READ: {
char * tmp = g_strdup_printf( _( "Couldn't read \"%s\": %s" ), ui->builder->errfile, g_strerror( ui->builder->my_errno ) );
txt = g_strdup_printf( _( "Torrent creation failed: %s" ), tmp );
g_free( tmp );
break;
}
case TR_MAKEMETA_IO_WRITE: {
char * tmp = g_strdup_printf( _( "Couldn't write \"%s\": %s" ), ui->builder->errfile, g_strerror( ui->builder->my_errno ) );
txt = g_strdup_printf( _( "Torrent creation failed: %s" ), tmp );
g_free( tmp );
break;
}
}
gtk_progress_bar_set_fraction( p, ui->builder->result==TR_MAKEMETA_OK ? 1.0 : 0.0 );
gtk_progress_bar_set_text( p, txt );
setIsBuilding( ui, FALSE );
g_free( txt );
}
return !ui->builder->isDone;

View file

@ -205,10 +205,10 @@ getHashInfo ( tr_metainfo_builder * b )
totalRemain = b->totalSize;
fp = fopen( b->files[fileIndex].filename, "rb" );
if( !fp ) {
snprintf( b->error, sizeof( b->error ), _( "Couldn't open \"%s\": %s" ), b->files[fileIndex].filename, tr_strerror( errno ) );
tr_err( "%s", b->error );
b->my_errno = errno;
snprintf( b->errfile, sizeof( b->errfile ), b->files[fileIndex].filename );
b->result = TR_MAKEMETA_IO_READ;
tr_free( ret );
b->failed = 1;
return NULL;
}
while ( totalRemain )
@ -235,12 +235,10 @@ getHashInfo ( tr_metainfo_builder * b )
if( ++fileIndex < b->fileCount ) {
fp = fopen( b->files[fileIndex].filename, "rb" );
if( !fp ) {
snprintf( b->error, sizeof( b->error ),
_( "Couldn't open \"%s\": %s" ),
b->files[fileIndex].filename, tr_strerror( errno ) );
tr_err( "%s", b->error );
b->my_errno = errno;
snprintf( b->errfile, sizeof( b->errfile ), b->files[fileIndex].filename );
b->result = TR_MAKEMETA_IO_READ;
tr_free( ret );
b->failed = 1;
return NULL;
}
}
@ -253,8 +251,7 @@ getHashInfo ( tr_metainfo_builder * b )
walk += SHA_DIGEST_LENGTH;
if( b->abortFlag ) {
snprintf( b->error, sizeof( b->error ), _( "Torrent creation cancelled" ) );
b->failed = 1;
b->result = TR_MAKEMETA_CANCELLED;
break;
}
@ -385,12 +382,10 @@ tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
tr_bencInitStrDup( val, builder->announce );
if( tr_httpParseUrl( builder->announce, -1, NULL, NULL, NULL ) )
{
snprintf( builder->error, sizeof( builder->error ), _( "Invalid announce URL" ) );
tr_err( "%s", builder->error );
builder->failed = 1;
builder->result = TR_MAKEMETA_URL;
}
if( !builder->failed && !builder->abortFlag )
if( !builder->result && !builder->abortFlag )
{
if( builder->comment && *builder->comment ) {
val = tr_bencDictAdd( &top, "comment" );
@ -413,27 +408,24 @@ tr_realMakeMetaInfo ( tr_metainfo_builder * builder )
}
/* save the file */
if ( !builder->failed && !builder->abortFlag ) {
size_t nmemb;
if ( !builder->result && !builder->abortFlag ) {
char * pch = tr_bencSave( &top, &n );
FILE * fp = fopen( builder->outputFile, "wb+" );
nmemb = n;
if( fp == NULL ) {
snprintf( builder->error, sizeof( builder->error ), _( "Couldn't open \"%s\": %s" ), builder->outputFile, tr_strerror( errno ) );
tr_err( "%s", builder->error );
builder->failed = 1;
} else if( fwrite( pch, 1, nmemb, fp ) != nmemb ) {
snprintf( builder->error, sizeof( builder->error ), _( "Couldn't save file \"%s\": %s" ), builder->outputFile, tr_strerror( errno ) );
tr_err( "%s", builder->error );
builder->failed = 1;
fclose( fp );
size_t nmemb = n;
if( !fp || ( fwrite( pch, 1, nmemb, fp ) != nmemb ) ) {
builder->my_errno = errno;
strlcpy( builder->errfile, builder->outputFile, sizeof( builder->errfile ) );
builder->result = TR_MAKEMETA_IO_WRITE;
}
if( fp )
fclose( fp );
tr_free( pch );
}
/* cleanup */
tr_bencFree( & top );
builder->failed |= builder->abortFlag;
if( builder->abortFlag )
builder->result = TR_MAKEMETA_CANCELLED;
builder->isDone = 1;
}

View file

@ -20,6 +20,18 @@ typedef struct tr_metainfo_builder_file
}
tr_metainfo_builder_file;
typedef enum
{
TR_MAKEMETA_OK,
TR_MAKEMETA_URL,
TR_MAKEMETA_CANCELLED,
TR_MAKEMETA_IO_READ, /* see builder.errfile, builder.errno */
TR_MAKEMETA_IO_WRITE /* see builder.errfile, builder.errno */
}
tr_metainfo_builder_err;
typedef struct tr_metainfo_builder
{
/**
@ -57,8 +69,13 @@ typedef struct tr_metainfo_builder
uint32_t pieceIndex;
int abortFlag;
int isDone;
int failed; /* only meaningful if isDone is set */
char error[1024]; /* only meaningful if failed is set */
tr_metainfo_builder_err result;
/* file in use when result was set to _IO_READ or _IO_WRITE */
char errfile[2048];
/* errno encountered when result was set to _IO_READ or _IO_WRITE */
int my_errno;
/**
*** This is an implementation detail.