private void indexWorker_DoWork(object sender, DoWorkEventArgs e) { Utils.writeLog("indexWorker_DoWork: Starting to build index"); Indexer.buildIndex(sharedFolders.Items, indexWorker, e); }
private void loadIndexWorker_DoWork(object sender, DoWorkEventArgs e) { Indexer.deserializeHashTables(); }
public static string postDownload(DownloadProgress dp, PendingResponse pr, BackgroundWorker worker) { int percentComplete = (int)(100 * dp.bytesDownloaded / pr.fileSize); if (dp.isFailed) { dp.attempts = dp.attempts + 1; if (dp.attempts > 10) { dp.status = "Failed"; dp.isFailedUnrecoverably = true; worker.ReportProgress(percentComplete, dp); return(null); } dp.status = "Retrying.. (" + dp.attempts + ")"; dp.isFailed = false; worker.ReportProgress(percentComplete, dp); System.Threading.Thread.Sleep(3000); return("FAILED"); } BackgroundWorker updateWorker = new BackgroundWorker(); updateWorker.DoWork += Downloads.updateWorker_DoWork; updateWorker.RunWorkerCompleted += Downloads.updateWorker_RunWorkerCompleted; // Set update parameters UpdateRequest updateRequest = new UpdateRequest(); updateRequest.transferID = dp.transferID; updateRequest.uploader = dp.mac; if (dp.isCanceled) { try { File.Delete(dp.downloadedFilePath); } catch (Exception e2) { } // Do nothing. We only want to try and delete the file. // Remove from pendingToDownload DownloadProgress temp = null; pendingToDownload.TryRemove(pr, out temp); updateRequest.newHash = dp.hash; updateRequest.status = "canceled"; updateWorker.RunWorkerAsync(updateRequest); return(null); } // Download neither canceled nor failed String newHash = Indexer.GenerateHash(dp.downloadedFilePath); if (dp.type == "secondleg" || dp.type == "direct") { if (newHash == dp.hash) { Utils.writeLog("download: Hash verified"); dp.isComplete = true; dp.status = "Completed"; worker.ReportProgress(100, dp); // Removing from partially-downloaded-files list Settings.Default.partiallyDownloadedFiles.Replace(dp.downloadedFilePath + "; ", ""); } else { Utils.writeLog("download: Hash verification failed"); dp.status = "Failed integrity check"; dp.isHashMismatch = true; dp.isFailed = true; dp.isFailedUnrecoverably = true; worker.ReportProgress(100, dp); try { File.Delete(dp.downloadedFilePath); } catch (Exception e2) { } // Do nothing. We only want to try and delete the file. } updateRequest.newHash = newHash; updateRequest.status = "done"; updateWorker.RunWorkerAsync(updateRequest); return(newHash); } if (dp.type == "firstleg") { // Rename the file to the new hash String newPath = dp.downloadedFilePath.Substring(0, dp.downloadedFilePath.LastIndexOf(@"\")); newPath = newPath + "\\" + newHash + ".bounced"; // Removing from partially-downloaded-files list Settings.Default.partiallyDownloadedFiles.Replace(dp.downloadedFilePath + "; ", ""); try { File.Move(dp.downloadedFilePath, newPath); } catch (Exception e) { Utils.writeLog("download: Critical. Unable to rename file to the new hash."); } dp.status = "Completed"; dp.isComplete = true; worker.ReportProgress(100, dp); } updateRequest.newHash = newHash; updateRequest.status = "done"; updateWorker.RunWorkerAsync(updateRequest); return(newHash); }