Changeset 13800 for trunk/utils/create.c


Ignore:
Timestamp:
Jan 17, 2013, 6:55:51 PM (8 years ago)
Author:
jordan
Message:

(utils) #4137 'support user-defined piece sizes in transmission-create' -- done. Initial patch by lav.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/utils/create.c

    r13625 r13800  
    1212
    1313#include <errno.h>
    14 #include <stdio.h> /* fprintf () */
    15 #include <stdlib.h> /* EXIT_FAILURE */
    16 #include <unistd.h> /* getcwd () */
     14#include <stdio.h> /* fprintf() */
     15#include <stdlib.h> /* strtoul(), EXIT_FAILURE */
     16#include <unistd.h> /* getcwd() */
    1717
    1818#include <libtransmission/transmission.h>
     
    2525
    2626#define MAX_TRACKERS 128
     27static const uint32_t KiB = 1024;
    2728static tr_tracker_info trackers[MAX_TRACKERS];
    2829static int trackerCount = 0;
    2930static bool isPrivate = false;
    3031static bool showVersion = false;
    31 const char * comment = NULL;
    32 const char * outfile = NULL;
    33 const char * infile = NULL;
     32static const char * comment = NULL;
     33static const char * outfile = NULL;
     34static const char * infile = NULL;
     35static uint32_t piecesize_kib = 0;
    3436
    3537static tr_option options[] =
     
    3739  { 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", 0, NULL },
    3840  { 'o', "outfile", "Save the generated .torrent to this filename", "o", 1, "<file>" },
     41  { 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", 1, "<size in KiB>" },
    3942  { 'c', "comment", "Add a comment", "c", 1, "<comment>" },
    4043  { 't', "tracker", "Add a tracker's announce URL", "t", 1, "<url>" },
     
    8184                trackers[trackerCount].announce = (char*) optarg;
    8285                  ++trackerCount;
     86              }
     87            break;
     88
     89          case 's':
     90            if (optarg)
     91              {
     92                char * endptr = NULL;
     93                piecesize_kib = strtoul (optarg, &endptr, 10);
     94                if (endptr && *endptr=='M')
     95                  piecesize_kib *= KiB;
    8396              }
    8497            break;
     
    170183
    171184  b = tr_metaInfoBuilderCreate (infile);
     185
     186  if (piecesize_kib != 0)
     187    tr_metaInfoBuilderSetPieceSize (b, piecesize_kib * KiB);
     188
    172189  tr_makeMetaInfo (b, outfile, trackers, trackerCount, comment, isPrivate);
    173190  while (!b->isDone)
Note: See TracChangeset for help on using the changeset viewer.