Changeset 2097
- Timestamp:
- Jun 16, 2007, 7:55:40 PM (15 years ago)
- Location:
- branches/file_selection
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/file_selection/cli/transmissioncli.c
r2082 r2097 134 134 135 135 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 } 141 142 142 143 /* Open and parse torrent file */ -
branches/file_selection/gtk/actions.c
r2064 r2097 84 84 { "remove-torrent", GTK_STOCK_REMOVE, 85 85 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) }, 86 88 { "close", GTK_STOCK_CLOSE, 87 89 N_("_Close"), "<control>C", NULL, G_CALLBACK(action_cb) }, -
branches/file_selection/gtk/hig.c
r2005 r2097 103 103 { 104 104 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); 106 106 if (GTK_IS_LABEL(l)) 107 107 gtk_label_set_use_markup (GTK_LABEL(l), TRUE); -
branches/file_selection/gtk/main.c
r2064 r2097 41 41 #include "dialogs.h" 42 42 #include "ipc.h" 43 #include "make-meta-ui.h" 43 44 #include "msgwin.h" 44 45 #include "torrent-inspector.h" … … 992 993 gtk_tree_selection_selected_foreach( s, showInfoForeach, data->wind ); 993 994 } 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 } 994 1000 else if (!strcmp (action_name, "remove-torrent")) 995 1001 { -
branches/file_selection/gtk/ui.h
r2064 r2097 8 8 " <menuitem action='recheck-torrent'/>\n" 9 9 " <menuitem action='remove-torrent'/>\n" 10 " <separator/>\n" 11 " <menuitem action='create-torrent'/>\n" 10 12 " <separator/>\n" 11 13 " <menuitem action='close'/>\n" -
branches/file_selection/libtransmission/makemeta.c
r2096 r2097 79 79 } 80 80 81 static int82 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 90 81 static void 91 82 freeFileList( struct FileList * list ) … … 184 175 ret->pieceSize = bestPieceSize( ret->totalSize ); 185 176 ret->pieceCount = MAX( 1, ret->totalSize / ret->pieceSize ); 177 if( ret->totalSize % ret->pieceSize ) 178 ++ret->pieceCount; 179 186 180 return ret; 187 181 } … … 203 197 204 198 static uint8_t* 205 getHashInfo ( const char * topFile, 206 const struct FileList * files, 207 int pieceSize, 208 int * setmeCount ) 209 { 210 int i; 199 getHashInfo ( const meta_info_builder_t * builder, 200 int * setmeCount ) 201 { 202 size_t i; 211 203 tr_torrent_t t; 212 204 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 '/' */ 215 206 216 207 /* build a mock tr_torrent_t that we can feed to tr_ioRecalculateHash() */ 217 208 memset( &t, 0, sizeof( tr_torrent_t ) ); 218 209 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; 221 212 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 ) { 224 217 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 } 233 221 t.info.pieces = calloc( t.info.pieceCount, sizeof( tr_piece_t ) ); 234 222 tr_torrentInitFilePieces( &t ); 235 236 223 ret = (uint8_t*) malloc ( SHA_DIGEST_LENGTH * t.info.pieceCount ); 237 224 walk = ret; 238 for( i=0; i< t.info.pieceCount; ++i ) {225 for( i=0; i<(size_t)t.info.pieceCount; ++i ) { 239 226 tr_ioRecalculateHash( &t, i, walk ); 240 227 walk += SHA_DIGEST_LENGTH; … … 291 278 292 279 static 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 ) 280 makeFilesList( 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 ) 302 288 { 303 289 benc_val_t * dict = tr_bencListAdd( list ); … … 308 294 length = tr_bencDictAdd( dict, "length" ); 309 295 pathVal = tr_bencDictAdd( dict, "path" ); 310 getFileInfo( topFile, walk->filename, length, pathVal );296 getFileInfo( builder->top, builder->files[i], length, pathVal ); 311 297 } 312 298 } 313 299 314 300 static 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; 301 makeInfoDict ( benc_val_t * dict, 302 const meta_info_builder_t * builder, 303 int isPrivate ) 304 { 322 305 uint8_t * pch; 323 306 int pieceCount = 0; … … 328 311 329 312 val = tr_bencDictAdd( dict, "name" ); 330 strlcpy( base, topFile, sizeof( base ) );313 strlcpy( base, builder->top, sizeof( base ) ); 331 314 tr_bencInitStrDup ( val, basename( base ) ); 332 315 333 316 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 ); 337 320 val = tr_bencDictAdd( dict, "pieces" ); 338 321 tr_bencInitStr( val, pch, SHA_DIGEST_LENGTH * pieceCount, 0 ); 339 322 340 if ( single )323 if ( builder->isSingleFile ) 341 324 { 342 325 val = tr_bencDictAdd( dict, "length" ); 343 tr_bencInitInt( val, getFileSize(files->filename));326 tr_bencInitInt( val, builder->fileLengths[0] ); 344 327 } 345 328 else … … 347 330 val = tr_bencDictAdd( dict, "files" ); 348 331 tr_bencInit( val, TYPE_LIST ); 349 makeFilesList( val, topFile, files);332 makeFilesList( val, builder ); 350 333 } 351 334 … … 354 337 } 355 338 339 /* if outputFile is NULL, builder->top + ".torrent" is used */ 356 340 int 357 tr_makeMetaInfo( const char * outputFile,358 const char * announce,359 const char * comment,360 const char * topFile,361 int isPrivate )341 tr_makeMetaInfo( const meta_info_builder_t * builder, 342 const char * outputFile, 343 const char * announce, 344 const char * comment, 345 int isPrivate ) 362 346 { 363 347 int n = 5; 364 348 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 }380 349 381 350 tr_bencInit ( &top, TYPE_DICT ); … … 403 372 tr_bencInit( val, TYPE_DICT ); 404 373 tr_bencDictReserve( val, 666 ); 405 makeInfoDict( val, topFile, files, isPrivate );374 makeInfoDict( val, builder, isPrivate ); 406 375 407 376 /* debugging... */ … … 410 379 /* save the file */ 411 380 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 ); 414 390 fwrite( pch, n, 1, fp ); 415 391 free( pch ); … … 418 394 419 395 /* cleanup */ 420 freeFileList( files );421 396 tr_bencFree( & top ); 422 397 return 0; -
branches/file_selection/libtransmission/makemeta.h
r2095 r2097 42 42 tr_metaInfoBuilderCreate( const char * topFile ); 43 43 44 int 45 tr_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 44 51 void 45 52 tr_metaInfoBuilderFree( meta_info_builder_t* ); 46 53 47 48 int49 tr_makeMetaInfo( const char * outputFile,50 const char * announce,51 const char * comment,52 const char * topFile,53 int isPrivate );54 55 54 #endif -
branches/file_selection/mk/gtk.mk
r2063 r2097 5 5 6 6 SRCS = 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.c7 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 9 9 OBJS = $(SRCS:%.c=%.o) 10 10
Note: See TracChangeset
for help on using the changeset viewer.