internal bool GetFileTransferBySelection(out GuiFileTransfer gft) { gft = new GuiFileTransfer(); if (_b.GUI.lb_filesDownloads.SelectedIndex != -1) { if (GetFileTransferByListIndexDir(_b.GUI.lb_filesDownloads.SelectedIndex, Direction.DIRECTION_DOWNLOAD, out gft)) { } else { return(false); } } else if (_b.GUI.lb_filesUploads.SelectedIndex != -1) { if (GetFileTransferByListIndexDir(_b.GUI.lb_filesUploads.SelectedIndex, Direction.DIRECTION_UPLOAD, out gft)) { } else { return(false); } } else { return(false); } return(true); }
private void bt_filesCancel_Click(object sender, EventArgs e) { GuiFileTransfer gft = new GuiFileTransfer(); if (!_b.FileProcessor.GetFileTransferBySelection(out gft)) { return; } _b.RPC.FilesControllDownload(RequestControlDownload.Action.ACTION_CANCEL, gft.FileTransfer.file); }
private bool GetFileTransferByListIndexDir(int index, Direction dir, out GuiFileTransfer gft) { GuiFileTransfer[] values = new GuiFileTransfer[_fileTransfers.Values.Count]; _fileTransfers.Values.CopyTo(values, 0); foreach (GuiFileTransfer ft in values) { if (ft.Index == index && ft.FileTransfer.direction == dir) { gft = ft; return(true); } } gft = default(GuiFileTransfer); return(false); }
internal void UpdateFileTransfers(ResponseTransferList list, uint reqID) { List <string> hashes = new List <string>(); // get direction(DL/UL) of request/result Direction dir; if (_pendingRequests.TryGetValue(reqID, out dir)) { } //_pendingRequests.Remove(reqID); else if (list.transfers.Count > 0) { dir = list.transfers[0].direction; } else { // shouldn't end here return; } // add new / update old foreach (FileTransfer ft in list.transfers) { if (ft == null) { continue; } if (_fileTransfers.ContainsKey(ft.file.hash)) // update { GuiFileTransfer gft = _fileTransfers[ft.file.hash]; gft.FileTransfer = ft; _fileTransfers[ft.file.hash] = gft; System.Diagnostics.Debug.WriteLineIf(DEBUG_FILES, "FileTransfer: updating " + ft.file.hash); } else //new { GuiFileTransfer gft = new GuiFileTransfer(); gft.FileTransfer = ft; _fileTransfers.Add(gft.Hash, gft); System.Diagnostics.Debug.WriteLineIf(DEBUG_FILES, "FileTransfer: adding " + ft.file.hash); } hashes.Add(ft.file.hash); } // remove GuiFileTransfer[] fileTransfers = new GuiFileTransfer[_fileTransfers.Values.Count]; _fileTransfers.Values.CopyTo(fileTransfers, 0); foreach (GuiFileTransfer gft in fileTransfers) { if (!hashes.Contains(gft.Hash) && gft.FileTransfer.direction == dir) { _fileTransfers.Remove(gft.Hash); } } UpdateFileLists(dir); //UpdateFileListsNEW(dir); }