« Previous -
Version 4/13
(diff) -
Next » -
Current version
Alan McGovern, 07/30/2009 12:14 AM
Creating Torrents¶
1 // 'path' is the location of the file/folder which is going to be converted
2 // to a torrent. 'savePath' is where the .torrent file will be saved.
3 void CreateTorrent(string path, string savePath)
4 {
5 // The class used for creating the torrent
6 TorrentCreator c = new TorrentCreator();
7
8 // Add one tier which contains two trackers
9 List<string> tier = new List<string>();
10 tier.Add("http://www.example.com/announce");
11 tier.Add("http://backup.example.com/announce");
12
13 c.Announces.Add(tier);
14 c.Comment = "This is the comment";
15 c.CreatedBy = "Alan using " + VersionInfo.ClientVersion;
16 c.Publisher = "www.homepage.com";
17
18 // Set the torrent as private so it will not use DHT or peer exchange
19 // Generally you will not want to set this.
20 c.Private = true;
21
22 // Path can be either a directory *or* a file.
23 c.Path = path;
24
25 // Every time a piece has been hashed, this event will fire. It is an
26 // asynchronous event, so you have to handle threading yourself.
27 c.Hashed += delegate (object o, TorrentCreatorEventArgs e) {
28 Console.WriteLine("Current File is {0}% hashed", e.FileCompletion);
29 Console.WriteLine("Overall {0}% hashed", e.OverallCompletion);
30 Console.WriteLine("Total data to hash: {0}", e.OverallSize);
31 };
32
33 // Create the torrent file and save it to the specified path
34 c.Create(save_path);
35 }