Changeset 2097


Ignore:
Timestamp:
Jun 16, 2007, 7:55:40 PM (15 years ago)
Author:
charles
Message:

more rough work on makemeta. not stable yet.

Location:
branches/file_selection
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • branches/file_selection/cli/transmissioncli.c

    r2082 r2097  
    134134
    135135    if( sourceFile && *sourceFile ) /* creating a torrent */
    136         return tr_makeMetaInfo( torrentPath,
    137                                 announce,
    138                                 comment,
    139                                 sourceFile,
    140                                 isPrivate );
     136    {
     137        meta_info_builder_t* builder = tr_metaInfoBuilderCreate( sourceFile );
     138        int ret = tr_makeMetaInfo( builder, NULL, announce, comment, isPrivate );
     139        tr_metaInfoBuilderFree( builder );
     140        return ret;
     141    }
    141142
    142143    /* Open and parse torrent file */
  • branches/file_selection/gtk/actions.c

    r2064 r2097  
    8484  { "remove-torrent", GTK_STOCK_REMOVE,
    8585    N_("_Remove"), "<control>R", NULL, G_CALLBACK(action_cb) },
     86  { "create-torrent", GTK_STOCK_NEW,
     87    N_("_Create New Torrent"), NULL, NULL, G_CALLBACK(action_cb) },
    8688  { "close", GTK_STOCK_CLOSE,
    8789    N_("_Close"), "<control>C", NULL, G_CALLBACK(action_cb) },
  • branches/file_selection/gtk/hig.c

    r2005 r2097  
    103103{
    104104  if (GTK_IS_MISC(l))
    105     gtk_misc_set_alignment (GTK_MISC(l), 0.0f, 0.0f);
     105    gtk_misc_set_alignment (GTK_MISC(l), 0.0f, 0.5f);
    106106  if (GTK_IS_LABEL(l))
    107107    gtk_label_set_use_markup (GTK_LABEL(l), TRUE);
  • branches/file_selection/gtk/main.c

    r2064 r2097  
    4141#include "dialogs.h"
    4242#include "ipc.h"
     43#include "make-meta-ui.h"
    4344#include "msgwin.h"
    4445#include "torrent-inspector.h"
     
    992993        gtk_tree_selection_selected_foreach( s, showInfoForeach, data->wind );
    993994    }
     995    else if (!strcmp (action_name, "create-torrent"))
     996    {
     997        GtkWidget * w = make_meta_ui( GTK_WINDOW( data->wind ) );
     998        gtk_widget_show_all( w );
     999    }
    9941000    else if (!strcmp (action_name, "remove-torrent"))
    9951001    {
  • branches/file_selection/gtk/ui.h

    r2064 r2097  
    88"      <menuitem action='recheck-torrent'/>\n"
    99"      <menuitem action='remove-torrent'/>\n"
     10"      <separator/>\n"
     11"      <menuitem action='create-torrent'/>\n"
    1012"      <separator/>\n"
    1113"      <menuitem action='close'/>\n"
  • branches/file_selection/libtransmission/makemeta.c

    r2096 r2097  
    7979}
    8080
    81 static int
    82 getListSize( const struct FileList * list )
    83 {
    84     int i;
    85     for( i=0; list!=NULL; list=list->next )
    86         ++i;
    87     return i;
    88 }
    89 
    9081static void
    9182freeFileList( struct FileList * list )
     
    184175    ret->pieceSize = bestPieceSize( ret->totalSize );
    185176    ret->pieceCount = MAX( 1, ret->totalSize / ret->pieceSize );
     177    if( ret->totalSize % ret->pieceSize )
     178        ++ret->pieceCount;
     179
    186180    return ret;
    187181}
     
    203197
    204198static uint8_t*
    205 getHashInfo ( const char              * topFile,
    206               const struct FileList   * files,
    207               int                       pieceSize,
    208               int                     * setmeCount )
    209 {
    210     int i;
     199getHashInfo ( const meta_info_builder_t  * builder,
     200              int                        * setmeCount )
     201{
     202    size_t i;
    211203    tr_torrent_t t;
    212204    uint8_t *ret, *walk;
    213     const struct FileList * fwalk;
    214     const size_t topLen = strlen(topFile) + 1; /* +1 for '/' */
     205    const size_t topLen = strlen(builder->top) + 1; /* +1 for '/' */
    215206
    216207    /* build a mock tr_torrent_t that we can feed to tr_ioRecalculateHash() */ 
    217208    memset( &t, 0, sizeof( tr_torrent_t ) );
    218209    tr_lockInit ( &t.lock );
    219     t.destination = (char*) topFile;
    220     t.info.fileCount = getListSize( files );
     210    t.destination = (char*) builder->top;
     211    t.info.fileCount = builder->fileCount;
    221212    t.info.files = calloc( t.info.fileCount, sizeof( tr_file_t ) );
    222    
    223     for( fwalk=files, i=0; fwalk!=NULL; fwalk=fwalk->next, ++i ) {
     213    t.info.totalSize = builder->totalSize;
     214    t.info.pieceSize = builder->pieceSize;
     215    t.info.pieceCount = builder->pieceCount;
     216    for( i=0; i<builder->fileCount; ++i ) {
    224217        tr_file_t * file = &t.info.files[i];
    225         file->length = getFileSize( fwalk->filename );
    226         strlcpy( file->name, fwalk->filename + topLen, sizeof( file->name ) );
    227         t.info.totalSize += file->length;
    228     }
    229     t.info.pieceSize = pieceSize;
    230     t.info.pieceCount = t.info.totalSize / pieceSize;
    231     if ( t.info.totalSize % pieceSize )
    232         ++t.info.pieceCount;
     218        file->length = builder->fileLengths[i];
     219        strlcpy( file->name, builder->files[i]+topLen, sizeof(file->name) );
     220    }
    233221    t.info.pieces = calloc( t.info.pieceCount, sizeof( tr_piece_t ) );
    234222    tr_torrentInitFilePieces( &t );
    235 
    236223    ret = (uint8_t*) malloc ( SHA_DIGEST_LENGTH * t.info.pieceCount );
    237224    walk = ret;
    238     for( i=0; i<t.info.pieceCount; ++i ) {
     225    for( i=0; i<(size_t)t.info.pieceCount; ++i ) {
    239226        tr_ioRecalculateHash( &t, i, walk );
    240227        walk += SHA_DIGEST_LENGTH;
     
    291278
    292279static void
    293 makeFilesList( benc_val_t            * list,
    294                const char            * topFile,
    295                const struct FileList * files )
    296 {
    297     const struct FileList * walk;
    298 
    299     tr_bencListReserve( list, getListSize(files) );
    300 
    301     for( walk=files; walk!=NULL; walk=walk->next )
     280makeFilesList( benc_val_t                 * list,
     281               const meta_info_builder_t  * builder )
     282{
     283    size_t i = 0;
     284
     285    tr_bencListReserve( list, builder->fileCount );
     286
     287    for( i=0; i<builder->fileCount; ++i )
    302288    {
    303289        benc_val_t * dict = tr_bencListAdd( list );
     
    308294        length = tr_bencDictAdd( dict, "length" );
    309295        pathVal = tr_bencDictAdd( dict, "path" );
    310         getFileInfo( topFile, walk->filename, length, pathVal );
     296        getFileInfo( builder->top, builder->files[i], length, pathVal );
    311297    }
    312298}
    313299
    314300static void
    315 makeInfoDict ( benc_val_t              * dict,
    316                const char              * topFile,
    317                const struct FileList   * files,
    318                int                       isPrivate )
    319 {
    320     static const int pieceSize = 262144; /* 256 KiB. TODO: let user choose? */
    321     const int single = files->next == NULL;
     301makeInfoDict ( benc_val_t                 * dict,
     302               const meta_info_builder_t  * builder,
     303               int                          isPrivate )
     304{
    322305    uint8_t * pch;
    323306    int pieceCount = 0;
     
    328311
    329312    val = tr_bencDictAdd( dict, "name" );
    330     strlcpy( base, topFile, sizeof( base ) );
     313    strlcpy( base, builder->top, sizeof( base ) );
    331314    tr_bencInitStrDup ( val, basename( base ) );
    332315
    333316    val = tr_bencDictAdd( dict, "piece length" );
    334     tr_bencInitInt( val, pieceSize );
    335 
    336     pch = getHashInfo( topFile, files, pieceSize, &pieceCount );
     317    tr_bencInitInt( val, builder->pieceSize );
     318
     319    pch = getHashInfo( builder, &pieceCount );
    337320    val = tr_bencDictAdd( dict, "pieces" );
    338321    tr_bencInitStr( val, pch, SHA_DIGEST_LENGTH * pieceCount, 0 );
    339322
    340     if ( single )
     323    if ( builder->isSingleFile )
    341324    {
    342325        val = tr_bencDictAdd( dict, "length" );
    343         tr_bencInitInt( val, getFileSize(files->filename) );
     326        tr_bencInitInt( val, builder->fileLengths[0] );
    344327    }
    345328    else
     
    347330        val = tr_bencDictAdd( dict, "files" );
    348331        tr_bencInit( val, TYPE_LIST );
    349         makeFilesList( val, topFile, files );
     332        makeFilesList( val, builder );
    350333    }
    351334
     
    354337}
    355338
     339/* if outputFile is NULL, builder->top + ".torrent" is used */
    356340int
    357 tr_makeMetaInfo( const char   * outputFile,
    358                  const char   * announce,
    359                  const char   * comment,
    360                  const char   * topFile,
    361                  int            isPrivate )
     341tr_makeMetaInfo( const meta_info_builder_t  * builder,
     342                 const char                 * outputFile,
     343                 const char                 * announce,
     344                 const char                 * comment,
     345                 int                          isPrivate )
    362346{
    363347    int n = 5;
    364348    benc_val_t top, *val;
    365     struct FileList *files;
    366 
    367     /* build a list of files containing topFile and,
    368        if it's a directory, all of its children */
    369     if (1) {
    370         char *dir, *base;
    371         char dirbuf[MAX_PATH_LENGTH];
    372         char basebuf[MAX_PATH_LENGTH];
    373         strlcpy( dirbuf, topFile, sizeof( dirbuf ) );
    374         strlcpy( basebuf, topFile, sizeof( basebuf ) );
    375         dir = dirname( dirbuf );
    376         base = basename( basebuf );
    377         files = getFiles( dir, base, NULL );
    378         assert( files != NULL  );
    379     }
    380349
    381350    tr_bencInit ( &top, TYPE_DICT );
     
    403372        tr_bencInit( val, TYPE_DICT );
    404373        tr_bencDictReserve( val, 666 );
    405         makeInfoDict( val, topFile, files, isPrivate );
     374        makeInfoDict( val, builder, isPrivate );
    406375
    407376    /* debugging... */
     
    410379    /* save the file */
    411380    if (1) {
    412         FILE * fp = fopen( outputFile, "wb+" );
    413         char * pch = tr_bencSaveMalloc( &top, &n );
     381        char out[MAX_PATH_LENGTH];
     382        FILE * fp;
     383        char * pch;
     384        if ( !outputFile || !*outputFile ) {
     385            snprintf( out, sizeof(out), "%s.torrent", builder->top);
     386            outputFile = out;
     387        }
     388        fp = fopen( outputFile, "wb+" );
     389        pch = tr_bencSaveMalloc( &top, &n );
    414390        fwrite( pch, n, 1, fp );
    415391        free( pch );
     
    418394
    419395    /* cleanup */
    420     freeFileList( files );
    421396    tr_bencFree( & top );
    422397    return 0;
  • branches/file_selection/libtransmission/makemeta.h

    r2095 r2097  
    4242tr_metaInfoBuilderCreate( const char * topFile );
    4343
     44int
     45tr_makeMetaInfo( const meta_info_builder_t * builder,
     46                 const char                * outputFile, /* NULL for builder->top + ".torrent" */
     47                 const char                * announce,
     48                 const char                * comment,
     49                 int                         isPrivate );
     50
    4451void
    4552tr_metaInfoBuilderFree( meta_info_builder_t* );
    4653
    47 
    48 int
    49 tr_makeMetaInfo( const char   * outputFile,
    50                  const char   * announce,
    51                  const char   * comment,
    52                  const char   * topFile,
    53                  int            isPrivate );
    54 
    5554#endif
  • branches/file_selection/mk/gtk.mk

    r2063 r2097  
    55
    66SRCS = actions.c conf.c dialogs.c hig.c io.c ipc.c main.c msgwin.c \
    7        torrent-inspector.c tr_cell_renderer_progress.c tr_core.c \
    8        tr_icon.c tr_prefs.c tr_torrent.c tr_window.c util.c
     7       make-meta-ui.c torrent-inspector.c tr_cell_renderer_progress.c \
     8       tr_core.c tr_icon.c tr_prefs.c tr_torrent.c tr_window.c util.c
    99OBJS = $(SRCS:%.c=%.o)
    1010
Note: See TracChangeset for help on using the changeset viewer.