sizeof (tr_metainfo_builder_file),
builderFileCompare);
- ret->pieceSize = bestPieceSize (ret->totalSize);
- ret->pieceCount = (int)(ret->totalSize / ret->pieceSize);
- if (ret->totalSize % ret->pieceSize)
- ++ret->pieceCount;
+ tr_metaInfoBuilderSetPieceSize (ret, bestPieceSize (ret->totalSize));
return ret;
}
+void
+tr_metaInfoBuilderSetPieceSize (tr_metainfo_builder * b,
+ uint32_t bytes)
+{
+ b->pieceSize = bytes;
+
+ b->pieceCount = (int)(b->totalSize / b->pieceSize);
+ if (b->totalSize % b->pieceSize)
+ ++b->pieceCount;
+}
+
+
void
tr_metaInfoBuilderFree (tr_metainfo_builder * builder)
{
*/
#include <errno.h>
-#include <stdio.h> /* fprintf () */
-#include <stdlib.h> /* EXIT_FAILURE */
-#include <unistd.h> /* getcwd () */
+#include <stdio.h> /* fprintf() */
+#include <stdlib.h> /* strtoul(), EXIT_FAILURE */
+#include <unistd.h> /* getcwd() */
#include <libtransmission/transmission.h>
#include <libtransmission/makemeta.h>
#define MY_NAME "transmission-create"
#define MAX_TRACKERS 128
+static const uint32_t KiB = 1024;
static tr_tracker_info trackers[MAX_TRACKERS];
static int trackerCount = 0;
static bool isPrivate = false;
static bool showVersion = false;
-const char * comment = NULL;
-const char * outfile = NULL;
-const char * infile = NULL;
+static const char * comment = NULL;
+static const char * outfile = NULL;
+static const char * infile = NULL;
+static uint32_t piecesize_kib = 0;
static tr_option options[] =
{
{ 'p', "private", "Allow this torrent to only be used with the specified tracker(s)", "p", 0, NULL },
{ 'o', "outfile", "Save the generated .torrent to this filename", "o", 1, "<file>" },
+ { 's', "piecesize", "Set how many KiB each piece should be, overriding the preferred default", "s", 1, "<size in KiB>" },
{ 'c', "comment", "Add a comment", "c", 1, "<comment>" },
{ 't', "tracker", "Add a tracker's announce URL", "t", 1, "<url>" },
{ 'V', "version", "Show version number and exit", "V", 0, NULL },
}
break;
+ case 's':
+ if (optarg)
+ {
+ char * endptr = NULL;
+ piecesize_kib = strtoul (optarg, &endptr, 10);
+ if (endptr && *endptr=='M')
+ piecesize_kib *= KiB;
+ }
+ break;
+
case TR_OPT_UNK:
infile = optarg;
break;
fflush (stdout);
b = tr_metaInfoBuilderCreate (infile);
+
+ if (piecesize_kib != 0)
+ tr_metaInfoBuilderSetPieceSize (b, piecesize_kib * KiB);
+
tr_makeMetaInfo (b, outfile, trackers, trackerCount, comment, isPrivate);
while (!b->isDone)
{