private void BtnStart_Click(object sender, EventArgs e) { btnStart.Enabled = false; if (Validate_Controls_Values() != true) { btnStart.Enabled = true; return; } // Initialize Download Parameters CDL.sBaseAddress = txtBaseAddress.Text; CDL.sDestPath = txtDestPath.Text; CDL.iPFrom = Convert.ToInt32(nudPFrom.Value); CDL.iPTo = Convert.ToInt32(nudPTo.Value); CDL.iFailed = 0; // Populate ListView lvMain.Items.Clear(); for (int i = CDL.iPFrom; i <= CDL.iPTo; i++) { ListViewItem lviNew = new ListViewItem(); DLItemStatus DLIS = new DLItemStatus(); DLIS.iFile = i; DLIS.iStatus = 0; lviNew.Tag = DLIS; lviNew.Text = CDL.sBaseAddress + i.ToString("D3") + ".jpg"; lviNew.SubItems.Add("Queued"); lviNew.Checked = true; lvMain.Items.Add(lviNew); } lvMain.Refresh(); // Prepare Next File Download CDL.iCurrentFile = CDL.iPFrom; CDL.uriCurrentURI = new Uri(CDL.sBaseAddress + CDL.iPFrom.ToString("D3") + ".jpg"); //System.Diagnostics.Debug.WriteLine(CDL.uriCurrentURI.ToString()); CDL.iRetry = 0; Download_File(); }
private void Wc_DFC(object sender, AsyncCompletedEventArgs e) { if (e.Error != null) { if (nudRetries.Value != 0 && CDL.iRetry < nudRetries.Value) { CDL.iRetry++; Download_File(); return; } else { int iCLVII = CDL.iCurrentFile - CDL.iPFrom; lvMain.Items[iCLVII].SubItems[1].Text = "Failed"; DLItemStatus DLIS1 = (DLItemStatus)lvMain.Items[iCLVII].Tag; DLIS1.iStatus = -1; lvMain.Items[iCLVII].Tag = DLIS1; lvMain.Items[iCLVII].Checked = true; CDL.iFailed++; // TODO: Delete failed file (it's created, but 0 size) string sLoc = Path.Combine(CDL.sDestPath, CDL.iCurrentFile.ToString("D3") + ".jpg"); if (File.Exists(sLoc)) { File.Delete(sLoc); } } } else { int iCLVII = CDL.iCurrentFile - CDL.iPFrom; lvMain.Items[iCLVII].SubItems[1].Text = "Completed"; DLItemStatus DLIS = (DLItemStatus)lvMain.Items[iCLVII].Tag; DLIS.iStatus = 1; lvMain.Items[iCLVII].Tag = DLIS; lvMain.Items[iCLVII].Checked = false; } if (CDL.iCurrentFile == CDL.iPTo) { string sMsg; if (CDL.iFailed != 0) { sMsg = "Process completed. " + CDL.iFailed.ToString() + " failed."; } else { sMsg = "Download completed."; } MessageBox.Show(sMsg, "LTG"); btnStart.Enabled = true; } else { CDL.iCurrentFile++; CDL.uriCurrentURI = new Uri(CDL.sBaseAddress + CDL.iCurrentFile.ToString("D3") + ".jpg"); CDL.iRetry = 0; Download_File(); // Scroll to current int iCLVII = CDL.iCurrentFile - CDL.iPFrom; lvMain.EnsureVisible(iCLVII); } }