/// <summary> /// 保存文件 /// </summary> /// <param name="downloader"></param> /// <param name="total">需要保存的文件总数</param> /// <param name="from"></param> /// <param name="to"></param> /// <returns></returns> private bool SaveFile(Downloader downloader, int total, int from, int to) { string filepath = Path.Combine(tbxFolder.Text.Trim(), GetFileName(from, to)); try { using (StreamWriter writer = new StreamWriter(filepath, false, Encoding.Default)) { writer.Write(downloader.DownloadData(from, to)); writer.Flush(); writer.Close(); } AddCurrentCount(to - from + 1); Func<bool> report = () => { ReportProcess(); return true; }; this.Invoke(report); return true; } catch (IOException) { return false; } }
public bool DownloadFile(Downloader downloader, Item item) { string filepath = Path.Combine(tbxFolder.Text.Trim(), GetFileName(item)); try { using (StreamWriter writer = new StreamWriter(filepath, false, Encoding.Default)) { downloader.PostContent = outbountserviceString; writer.Write(downloader.DownloadData(item.From, item.To)); writer.Flush(); writer.Close(); System.Threading.Thread.Sleep(ThreadSleepTime); } return true; } catch (IOException) { return false; } catch (WebException) { return false; } }