Creating Torrents

Version 2 (Alan McGovern, 07/30/2009 12:13 AM) → Version 3/13 (Alan McGovern, 07/30/2009 12:14 AM)

h1. Creating Torrents

h1. Creating Torrents

<pre><code class="java">
// 'path' is the location of the file/folder which is going to be converted
// to a torrent. 'savePath' is where the .torrent file will be saved.
void CreateTorrent(string path, string savePath)
// The class used for creating the torrent
TorrentCreator c = new TorrentCreator();

// Add one tier which contains two trackers
List<string> tier = new List<string>();

c.Comment = "This is the comment";
c.CreatedBy = "Alan using " + VersionInfo.ClientVersion;
c.Publisher = "";

// Set the torrent as private so it will not use DHT or peer exchange
c.Private = true;

// Path can be either a directory *or* a file.
c.Path = path;

// Every time a piece has been hashed, this event will fire. It is an
// asynchronous event, so you have to handle threading yourself.
c.Hashed += delegate (object o, TorrentCreatorEventArgs e) {
Console.WriteLine("Current File is {0}% hashed", e.FileCompletion);
Console.WriteLine("Overall {0}% hashed", e.OverallCompletion);
Console.WriteLine("Total data to hash: {0}", e.OverallSize);

// Create the torrent file and save it to the specified path
</code class="java"></pre>