//------------------------------------------------------------- public void GotTorrentStatus(DTO_TorrentStatus torrentStatus) //------------------------------------------------------------- { SuggestedGame suggestedGameControl = suggestedGames.Where(L => L.GetKey().Equals(torrentStatus.key)).FirstOrDefault(); if (suggestedGameControl == null) { Log.Get().Write("KobberLan DTO_TorrentStatus unknown title: " + torrentStatus.key, Log.LogType.Error); } else { //Remove game if (torrentStatus.status == TorrentStatusType.Remove) { Torrent.Get().StopSharing(torrentStatus.key); suggestedGameControl.Remove(); suggestedGameControl.Dispose(); suggestedGames.Remove(suggestedGameControl); flowLayoutPanel_SuggestedGames.Controls.Remove(suggestedGameControl); } else //Update controller status { suggestedGameControl.UpdateStats(torrentStatus); } } }
//------------------------------------------------------------- public override void UpdateStats(DTO_TorrentStatus torrentStatus) //------------------------------------------------------------- { if (torrentStatus.status == TorrentStatusType.Finished) { if (!torrentDownloadCompleted.Contains(torrentStatus.address.ToString())) { torrentDownloadCompleted.Add(torrentStatus.address.ToString()); } if (!torrentPeers.Contains(torrentStatus.address.ToString())) { torrentPeers.Add(torrentStatus.address.ToString()); } } if (torrentStatus.status == TorrentStatusType.Starting) { if (!torrentDownloadStarted.Contains(torrentStatus.address.ToString())) { torrentDownloadStarted.Add(torrentStatus.address.ToString()); } } label_Downloading.Text = torrentDownloadCompleted.Count.ToString("D2") + " / " + torrentDownloadStarted.Count.ToString("D2"); label_Peers.Text = torrentPeers.Count.ToString("D2"); }
//------------------------------------------------------------- private void button_Clear_Click(object sender, EventArgs e) //------------------------------------------------------------- { DTO_TorrentStatus torrentStatus = new DTO_TorrentStatus() { key = dto_suggestion.key, address = Helper.GetHostIP(), status = TorrentStatusType.Remove }; kobberLan.SendTorrentStatus(torrentStatus, ""); //Empty IP, broadcast to all connected clients }
//------------------------------------------------------------- public void SendTorrentStatus(DTO_TorrentStatus torrentStatus, string IP) //------------------------------------------------------------- { Log.Get().Write("KobberLan DTO_TorrentStatus sending to host"); //Send packet to LAN communication.ClientSend(torrentStatus, IP); //Update own GUI GotTorrentStatus(torrentStatus); }
//------------------------------------------------------------- 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 UpdateStats(DTO_TorrentStatus torrentStatus) { }
//------------------------------------------------------------- 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(); } }
//------------------------------------------------------------- public abstract void UpdateStats(DTO_TorrentStatus torrentStatus);