//------------------------------------------------------------- private void button_ShareGet_Click(object sender, EventArgs e) //------------------------------------------------------------- { if (dto_suggestion.torrent == null) { Log.Get().Write("Torrent is null, aborting Get operation.", Log.LogType.Error); return; } if (button_Get.Text.Equals("Stop")) { //------------------------------------------------------------- //Stop seeding //------------------------------------------------------------- Torrent.Get().StopSharing(dto_suggestion.key); } else { //------------------------------------------------------------- //Note host about starting to download //------------------------------------------------------------- DTO_TorrentStatus torrentStatus = new DTO_TorrentStatus() { key = dto_suggestion.key, address = Helper.GetHostIP(), status = TorrentStatusType.Starting }; kobberLan.SendTorrentStatus(torrentStatus, dto_suggestion.author); //------------------------------------------------------------- //Download torrent //------------------------------------------------------------- Torrent.Get().DownloadTorrent(dto_suggestion.torrent); } //------------------------------------------------------------- //Disable get/stop button //------------------------------------------------------------- button_Get.Enabled = false; }
//------------------------------------------------------------- public override void UpdateProgressBar(TorrentState type, int progress) //------------------------------------------------------------- { if (type == TorrentState.Stopped || type == TorrentState.Stopping) { progressBar.Visible = false; label_ProgressBar.Visible = false; button_Play.Enabled = true; Log.Get().Write("Torrent: " + dto_suggestion.key + " state: " + type.ToString()); } else if (type == TorrentState.Seeding) { progressBar.Visible = false; label_ProgressBar.Visible = false; //------------------------------------------------------------- //Note host about finished download //------------------------------------------------------------- if (finishedDownloaded == false) { finishedDownloaded = true; DTO_TorrentStatus torrentStatus = new DTO_TorrentStatus() { key = dto_suggestion.key, address = Helper.GetHostIP(), status = TorrentStatusType.Finished }; kobberLan.SendTorrentStatus(torrentStatus, dto_suggestion.author); } //------------------------------------------------------------- //Enable stop button //------------------------------------------------------------- if (button_Play.Enabled == false) //Ignore seeding message, when stop has been called { button_Get.Enabled = true; button_Get.Text = "Stop"; } } else if (type == TorrentState.Error) { progressBar.Visible = false; label_ProgressBar.Visible = true; label_ProgressBar.Text = "Torrent error"; label_ProgressBar.Refresh(); Log.Get().Write("Game " + GetTitle() + " got unknown error.", Log.LogType.Error); Torrent.Get().StopSharing(dto_suggestion.key); } else //Download { progressBar.Enabled = true; progressBar.Visible = true; label_ProgressBar.Visible = true; if (type == TorrentState.Hashing && state == TorrentState.Downloading) //Ignore hash check for every files progress (Make progress bar jump strangely) { return; } else if (type == TorrentState.Hashing) { state = TorrentState.Hashing; label_ProgressBar.Text = "Hashing: " + progress.ToString("D2") + "%"; } else if (type == TorrentState.Downloading && progress > 0) { state = TorrentState.Downloading; label_ProgressBar.Text = "Downloading: " + progress.ToString("D2") + "%"; } else { label_ProgressBar.Text = type.ToString(); } progressBar.Value = progress; label_ProgressBar.Refresh(); } }