private void ThreadDoWork() { if (Info.TaskSettings.Media.DiscType != SourceType.Bluray) { ReportProgress("Reading " + Path.GetFileName(Info.TaskSettings.Media.Location) + " using MediaInfo..."); Info.TaskSettings.Media.ReadMedia(); OnMediaLoaded(); } if (Info.TaskSettings.MediaOptions.UploadScreenshots) { TakeScreenshots(); UploadScreenshots(); } else if (Info.TaskSettings.MediaOptions.CreateScreenshots) { TakeScreenshots(); } string PublishString = CreatePublishInitial(Info.TaskSettings); OnTorrentInfoCreated(); // create textFiles of MediaInfo if (App.Settings.ProfileActive.WritePublish) { string txtPath = Path.Combine(Info.TaskSettings.TorrentFolder, Info.TaskSettings.Media.Overall.FileName) + ".txt"; Helpers.CreateDirectoryFromDirectoryPath(Info.TaskSettings.TorrentFolder); using (StreamWriter sw = new StreamWriter(txtPath)) { sw.WriteLine(PublishString); } } // create torrent if (Info.TaskSettings.MediaOptions.CreateTorrent) { CreateTorrent(); } // create xml info if (App.Settings.ProfileActive.XMLTorrentUploadCreate) { string fp = Path.Combine(Info.TaskSettings.TorrentFolder, MediaHelper.GetMediaName(Info.TaskSettings.Media.Location)) + ".xml"; FileSystem.GetXMLTorrentUpload(Info.TaskSettings).Write2(fp); } }
public void CreateTorrent() { string p = Info.TaskSettings.Media.Location; if (Info.TaskSettings.Profile != null && Info.TaskSettings.Profile.Trackers != null && (File.Exists(p) || Directory.Exists(p))) { foreach (string tracker in Info.TaskSettings.Profile.Trackers) { TorrentCreator tc = new TorrentCreator(); tc.CreatedBy = Application.ProductName; tc.Private = true; tc.Comment = MediaHelper.GetMediaName(p); tc.Path = p; tc.PublisherUrl = "https://github.com/McoreD/TDMaker"; tc.Publisher = Application.ProductName; tc.StoreMD5 = false; // delays torrent creation List <string> temp = new List <string>(); temp.Add(tracker); tc.Announces.Add(temp); var uri = new Uri(tracker); string torrentFileName = string.Format("{0}.torrent", (File.Exists(p) ? Path.GetFileNameWithoutExtension(p) : MediaHelper.GetMediaName(p))); Info.TaskSettings.TorrentFilePath = Path.Combine(Path.Combine(Info.TaskSettings.TorrentFolder, uri.Host), torrentFileName); ReportProgress(string.Format("Creating {0}", Info.TaskSettings.TorrentFilePath)); tc.Hashed += delegate(object o, TorrentCreatorEventArgs e) { Info.TorrentProgress = e.OverallCompletion; OnTorrentProgressChanged(); }; Helpers.CreateDirectoryFromFilePath(Info.TaskSettings.TorrentFilePath); tc.Create(Info.TaskSettings.TorrentFilePath); ReportProgress(string.Format("Created {0}", Info.TaskSettings.TorrentFilePath)); Success = true; } } else { DebugHelper.WriteLine("There were no active trackers configured to create a torrent."); } }
/// <summary> /// Create torrent with progress /// </summary> /// <param name="workerMy"></param> public void CreateTorrent(BackgroundWorker workerMy) { string p = this.MediaLocation; if (this.TrackerGroupActive != null) { if (File.Exists(p) || Directory.Exists(p)) { foreach (Tracker myTracker in this.TrackerGroupActive.Trackers) { MonoTorrent.Common.TorrentCreator tc = new MonoTorrent.Common.TorrentCreator(); tc.CreatedBy = Application.ProductName; tc.Private = true; tc.Comment = MediaHelper.GetMediaName(p); tc.Path = p; tc.PublisherUrl = "https://github.com/McoreD/TDMaker"; tc.Publisher = Application.ProductName; tc.StoreMD5 = false; // delays torrent creation List <string> temp = new List <string>(); temp.Add(myTracker.AnnounceURL); tc.Announces.Add(temp); string torrentFileName = string.Format("{0} - {1}.torrent", (File.Exists(p) ? Path.GetFileName(p) : MediaHelper.GetMediaName(p)), myTracker.Name); this.SetTorrentFilePath(torrentFileName); ReportProgress(workerMy, ProgressType.UPDATE_STATUSBAR_DEBUG, string.Format("Creating {0}", this.TorrentFilePath)); tc.Hashed += delegate(object o, TorrentCreatorEventArgs e) { ReportProgress(workerMy, ProgressType.UPDATE_PROGRESSBAR_CUMULATIVE, e.OverallCompletion); }; HelpersLib.Helpers.CreateDirectoryIfNotExist(this.TorrentFilePath); tc.Create(this.TorrentFilePath); ReportProgress(workerMy, ProgressType.UPDATE_STATUSBAR_DEBUG, string.Format("Created {0}", this.TorrentFilePath)); } } } else { Console.WriteLine("There were no active trackers configured to create a torrent."); } }