public void CheckFile(FileInformation old) { FileInformation info = GetFileInformation(Settings.P_Client + old.FileName); _currentCount++; if (info == null || old.Length != info.Length || old.Creation != info.Creation) { if (old.FileName == System.AppDomain.CurrentDomain.FriendlyName) { File.Move(Settings.P_Client + System.AppDomain.CurrentDomain.FriendlyName, Settings.P_Client + oldClientName); Restart = true; } DownloadList.Enqueue(old); _totalBytes += old.Compressed; } }
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.P_Client + Path.GetDirectoryName(info.FileName))) Directory.CreateDirectory(Settings.P_Client + Path.GetDirectoryName(info.FileName)); File.WriteAllBytes(Settings.P_Client + info.FileName, Decompress(e.Result)); File.SetLastWriteTime(Settings.P_Client + info.FileName, info.Creation); } BeginDownload(); }; if (Settings.P_NeedLogin) client.Credentials = new NetworkCredential(Settings.AccountID, Settings.Password); _stopwatch = Stopwatch.StartNew(); client.DownloadDataAsync(new Uri(Settings.P_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" && (info.Compressed != info.Length || info.Compressed == 0)) { fileName += ".gz"; } 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(); byte[] raw = e.Result; if (info.Compressed > 0 && info.Compressed != info.Length) { raw = Decompress(e.Result); } if (!Directory.Exists(Settings.P_Client + Path.GetDirectoryName(info.FileName))) { Directory.CreateDirectory(Settings.P_Client + Path.GetDirectoryName(info.FileName)); } File.WriteAllBytes(Settings.P_Client + info.FileName, raw); File.SetLastWriteTime(Settings.P_Client + info.FileName, info.Creation); } BeginDownload(); }; if (Settings.P_NeedLogin) { client.Credentials = new NetworkCredential(Settings.P_Login, Settings.P_Password); } _stopwatch = Stopwatch.StartNew(); client.DownloadDataAsync(new Uri(Settings.P_Host + fileName)); } } catch { MessageBox.Show(string.Format("Failed to download file: {0}", fileName)); } }