//------------------------------------------------------------- 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 KobberLan() //------------------------------------------------------------- { suggestForm = null; broadcast = null; communication = null; countBroadcast = 2; suggestedGames = new List <SuggestedGame>(); InitializeComponent(); Torrent.Get().SetGuiReference(this); Log.Get().SetGuiReference(this); }
//------------------------------------------------------------- private void button_ShareGet_Click(object sender, EventArgs e) //------------------------------------------------------------- { if (button_ShareGet.Text.Equals("Share")) { Log.Get().Write("Start sharing: " + dto_suggestion.key); button_ShareGet.Enabled = false; //button_Clear.Enabled = false; button_ShareGet.Text = "Stop"; //------------------------------------------------------------- //Run in own thread (To avoid locking gui) //------------------------------------------------------------- new Thread(() => { torrent = new DTO_Torrent() { key = dto_suggestion.key }; //------------------------------------------------------------- //Start creating torrent (hashing) //------------------------------------------------------------- torrent.torrent = Torrent.Get().CreateTorrent(path, dto_suggestion.key).Result; //------------------------------------------------------------- //Check torrent name with key (Stop if mismatch) //------------------------------------------------------------- string torrentKey = Torrent.Get().GetTorrentName(torrent.torrent); if (!torrentKey.Equals(torrent.key)) { Log.Get().Write("Torrent name not maching key, trying to delete file. torrentKey:'" + torrentKey + "' suggestkey:'" + torrent.key + "'", Log.LogType.Warning); //------------------------------------------------------------- //Delete torrent file //------------------------------------------------------------- Torrent.Get().DeleteTorrentFile(path); //------------------------------------------------------------- //ReCreate torrent file //------------------------------------------------------------- torrent.torrent = Torrent.Get().CreateTorrent(path, dto_suggestion.key).Result; if (!Torrent.Get().GetTorrentName(torrent.torrent).Equals(torrent.key)) { Log.Get().Write("Torrentfile name not maching key, aborting", Log.LogType.Error); return; } } //------------------------------------------------------------- //Insert announce ip //------------------------------------------------------------- torrent.torrent = Torrent.Get().InsertAnnounce(torrent.torrent); //------------------------------------------------------------- //Start tracker //------------------------------------------------------------- Torrent.Get().StartTracker(torrent.torrent); }).Start(); } else if (button_ShareGet.Text.Equals("Stop")) { Log.Get().Write("Stop sharing: " + dto_suggestion.key); button_ShareGet.Enabled = false; Torrent.Get().StopSharing(dto_suggestion.key); button_ShareGet.Enabled = true; button_ShareGet.Text = "Share"; //Possible to start sharing again } }
//------------------------------------------------------------- public override void UpdateProgressBar(TorrentState type, int progress) //------------------------------------------------------------- { if (type == TorrentState.Stopped) { progressBar.Visible = false; label_ProgresBar.Visible = false; } //Hide when starting to seed else if (type == TorrentState.Seeding) { //Hide progress info progressBar.Enabled = false; progressBar.Visible = false; label_ProgresBar.Visible = false; //Stop sharing enabled button_ShareGet.Enabled = true; //------------------------------------------------------------- //Allow clients to download //------------------------------------------------------------- if (torrentShared == false) { torrentShared = true; kobberLan.SendTorrent(torrent); } } else if (type == TorrentState.Metadata) { //Creating torrent file label_ProgresBar.Text = "Creating torrent data"; progressBar.Visible = true; label_ProgresBar.Visible = true; //Prevent bar totalcompleted jumping around if (metaProgress < progress) { metaProgress = progress; } progressBar.Value = metaProgress; } else if (state == type) { progressBar.Value = progress; progressBar.Visible = true; label_ProgresBar.Visible = true; label_ProgresBar.Text = type.ToString() + " " + progress.ToString("D2") + "%"; label_ProgresBar.Refresh(); } else if (type == TorrentState.Downloading) { Log.Get().Write("Game " + GetTitle() + " is downloading in OwnerControl? Maybe incomplete?", Log.LogType.Warning); /* * progressBar.Visible = false; * label_ProgresBar.Visible = true; * label_ProgresBar.Text = "Incomplete, please delete .torrent file"; * label_ProgresBar.Refresh(); * * button_ShareGet.Enabled = false; * Torrent.Get().StopSharing(dto_suggestion.key); * button_Clear.Enabled = true; */ } else if (type == TorrentState.Error) { progressBar.Visible = false; label_ProgresBar.Visible = true; label_ProgresBar.Text = "Torrent error"; label_ProgresBar.Refresh(); Log.Get().Write("Game " + GetTitle() + " could not be shared, unknown error.", Log.LogType.Error); Torrent.Get().StopSharing(dto_suggestion.key); } else { progressBar.Value = 0; state = type; } }