示例#1
0
        private void BeginCreateCb(IAsyncResult result)
        {
            logger.Debug("Torrent creation finished");
            progressDialog.Destroy();
            try{
                BEncodedDictionary dict = creator.EndCreate(result);

                string p = savePathChooser.Filename;
                if (!p.EndsWith(".torrent", StringComparison.OrdinalIgnoreCase))
                {
                    p = p + ".torrent";
                }

                System.IO.File.WriteAllBytes(p, dict.Encode());
                if (startSeedingCheckBox.Active)
                {
                    Torrent  t  = Torrent.Load(p);
                    BitField bf = new BitField(t.Pieces.Count);
                    bf.Not();
                    MonoTorrent.Client.FastResume fresume = new MonoTorrent.Client.FastResume(t.InfoHash, bf);
                    torrentController.FastResume.Add(fresume);
                    string savePath;
                    if (newTorrentLocationButton.Action == FileChooserAction.SelectFolder)
                    {
                        savePath = SavePath.Substring(0, SavePath.LastIndexOf('/'));
                    }
                    else
                    {
                        savePath = System.IO.Path.GetDirectoryName(SavePath);
                    }
                    torrentController.addTorrent(t, savePath, startSeedingCheckBox.Active);
                }
                logger.Debug("Torrent file created");
            }catch (Exception e) {
                logger.Error("Failed to create torrent - " + e.ToString());
            }
        }