/// <summary> /// Logs a downloaded file pack and send a new FPR message if is necessary. /// </summary> /// <param name="Download">The download object.</param> /// <param name="StartPoint">The star point of the file pack.</param> /// <param name="SenderPeer">The sender peer object.</param> /// <param name="Status">If the file-pack has been written or not ( other ).</param> public static void LogFilePack(Objects.Download Download, int StartPoint, Objects.Peer SenderPeer, Status_FilePack Status) { // indicate the downloading of a file pack SenderPeer.FilePackDownloaded = true; if (Status == Status_FilePack.Written) { #region ... int filePackNum = StartPoint / 16384; int filePartNum = StartPoint / 2097152; // control if the file pack is already been downloaded if (Download.ListFilePacks[filePackNum] == false) { // update the list of file packs Download.ListFilePacks[filePackNum] = true; // update the number of remaining file packs Download.RemainingFilePacks--; // update the list of file parts Download.ListFileParts[filePartNum]--; // control if the file part is completed if (Download.ListFileParts[filePartNum] == 0) { // update the number of remaining file parts Download.RemainingFileParts--; // control if the download is finished if (Download.RemainingFilePacks == 0) { // move the completed download from temp-directory to shared-directory File.Move(Global.TempDirectory + Download.Name, Global.SharedDirectory + Download.Name); // update download's informations Download.Progress = 100; Download.Active = false; } else { // send a new FPR to the peer for the next not downloaded file pack of a new file part StartDownloadNextFilePart(Download, SenderPeer); } } else { // send a new FPR to the peer for the next not downloaded file pack of a this file part if (DownloadNextFilePackOfAFilePart(filePackNum, filePartNum, Download, SenderPeer) == false) { StartDownloadNextFilePart(Download, SenderPeer); } } // log the file pack Download.LogFilePack(SenderPeer.IP, filePackNum); NewOrUpdatedDownload = true; } #endregion } // if the FilePack is damaged, will send a new FPR-mess to the peer; else if (Status == Status_FilePack.Damaged) { #region ... string[] Params = new string[3]; Params[0] = Download.Name; Params[1] = Download.SHA1; Params[2] = StartPoint.ToString(); Messages.IMessage FprMess = Messages.MessagesFactory.Instance.CreateMessage(Messages.Commands.FPR, Params); SenderPeer.Send(FprMess); #endregion } }