public void CheckFile(FileInformation old) { FileInformation info = GetFileInformation(Settings.Client + (old.FileName == "AutoPatcher.gz" ? "AutoPatcher.exe" : old.FileName)); _currentCount++; if (info == null || old.Length != info.Length || old.Creation != info.Creation) { DownloadList.Enqueue(old); _totalBytes += old.Compressed; } }
public void Download(FileInformation info) { string fileName = info.FileName.Replace(@"\", "/"); if (fileName != "AutoPatcher.gz" && fileName != "PList.gz") fileName += Path.GetExtension(fileName); try { using (WebClient client = new WebClient()) { client.DownloadProgressChanged += (o, e) => { _currentBytes = e.BytesReceived; }; client.DownloadDataCompleted += (o, e) => { if (e.Error != null) throw e.Error; _currentCount++; _completedBytes += _currentBytes; _currentBytes = 0; _stopwatch.Stop(); if (!Directory.Exists(Settings.Client + Path.GetDirectoryName(info.FileName))) Directory.CreateDirectory(Settings.Client + Path.GetDirectoryName(info.FileName)); File.WriteAllBytes(Settings.Client + info.FileName, Decompress(e.Result)); File.SetLastWriteTime(Settings.Client + info.FileName, info.Creation); BeginDownload(); }; if (Settings.NeedLogin) client.Credentials = new NetworkCredential(Settings.Login, Settings.Password); _stopwatch = Stopwatch.StartNew(); client.DownloadDataAsync(new Uri(Settings.Host + Path.ChangeExtension("/" + fileName, ".gz"))); } } catch { MessageBox.Show(string.Format("Failed to download file: {0}", fileName)); } }
private void BeginDownload() { if (DownloadList == null) return; if (DownloadList.Count == 0) { DownloadList = null; _currentFile = null; Completed = true; CleanUp(); return; } _currentFile = DownloadList.Dequeue(); Download(_currentFile); }
public void Download(FileInformation info) { string fileName = info.FileName.Replace(@"\", "/"); if (fileName != "PList.gz") fileName += Path.GetExtension(fileName); try { using (WebClient client = new WebClient()) { client.DownloadProgressChanged += (o, e) => { _currentBytes = e.BytesReceived; }; client.DownloadDataCompleted += (o, e) => { if (e.Error != null) { File.AppendAllText(@".\Error.txt", string.Format("[{0}] {1}{2}", DateTime.Now, info.FileName + " could not be downloaded. (" + e.Error.Message + ")", Environment.NewLine)); ErrorFound = true; } else { _currentCount++; _completedBytes += _currentBytes; _currentBytes = 0; _stopwatch.Stop(); if (!Directory.Exists(Settings.Client + Path.GetDirectoryName(info.FileName))) Directory.CreateDirectory(Settings.Client + Path.GetDirectoryName(info.FileName)); File.WriteAllBytes(Settings.Client + info.FileName, Decompress(e.Result)); File.SetLastWriteTime(Settings.Client + info.FileName, info.Creation); } BeginDownload(); }; if (Settings.NeedLogin) client.Credentials = new NetworkCredential(Settings.Login, Settings.Password); _stopwatch = Stopwatch.StartNew(); client.DownloadDataAsync(new Uri(Settings.Host + Path.ChangeExtension("/" + fileName, ".gz"))); } } catch { MessageBox.Show(string.Format("Failed to download file: {0}", fileName)); } }