private void createTorrent() { creator = new TorrentCreator(); progressDialog = new CreateTorrentProgressDialog(); // TODO: Read the multi-tracker spec -- learn the proper way to add multiple trackers creator.Announces.Add(new RawTrackerTier()); foreach (string s in GetTrackers()) { creator.Announces[0].Add(s); } creator.Comment = Comment; creator.CreatedBy = Defines.ApplicationName; creator.Hashed += delegate(object o, TorrentCreatorEventArgs e) { GLib.Idle.Add(delegate { OnHashed(o, e); return(false); }); }; var result = creator.BeginCreate(new TorrentFileSource(SavePath), delegate(IAsyncResult r) { GLib.Idle.Add(delegate { BeginCreateCb(r); return(false); }); }, null); ResponseType cancelResult = (ResponseType)progressDialog.Run(); if (cancelResult == ResponseType.Cancel) { creator.AbortCreation(); try{ creator.EndCreate(result); progressDialog.Destroy(); } catch (Exception e) { logger.ErrorException("Unable to end creation" + e.Message, e); } } }
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()); } }
private void createTorrent() { creator = new TorrentCreator(); progressDialog = new CreateTorrentProgressDialog(); // TODO: Read the multi-tracker spec -- learn the proper way to add multiple trackers creator.Announces.Add(new RawTrackerTier ()); foreach(string s in GetTrackers()) creator.Announces[0].Add(s); creator.Comment = Comment; creator.CreatedBy = Defines.ApplicationName; creator.Hashed += delegate(object o, TorrentCreatorEventArgs e) { GLib.Idle.Add(delegate { OnHashed(o, e); return false; }); }; var result = creator.BeginCreate(new TorrentFileSource (SavePath), delegate (IAsyncResult r) { GLib.Idle.Add (delegate { BeginCreateCb (r); return false; }); }, null); ResponseType cancelResult = (ResponseType) progressDialog.Run(); if(cancelResult == ResponseType.Cancel){ creator.AbortCreation (); try{ creator.EndCreate(result); progressDialog.Destroy(); } catch (Exception e) { logger.ErrorException("Unable to end creation" + e.Message, e); } } }