FileTreeNode[] GetServer(string startpath = "", bool showdownload = false) { Log = "Идет загрузка..."; if (showdownload) { new Thread(() => ld.ShowDialog()).Start(); } var web = (Downloading.GetHTML(DownloadingPaths.ToPath(setting.URLToHTTPPort) + DownloadingPaths.SD + startpath, setting.Name, setting.Password)); var list = new List <FileTreeNode>(); HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument(); html.LoadHtml(web); var table = html.DocumentNode.SelectSingleNode("/html/body/pre/table"); var tabletr = table.ChildNodes.Where(x => x.Name == "tr").ToList(); tabletr.RemoveRange(0, 3); foreach (var item in tabletr) { if (item.ChildNodes.Count > 2) { var path = item.ChildNodes[0].ChildNodes[0].InnerHtml.Replace(" ", ""); var date = item.ChildNodes[1].ChildNodes[0].InnerHtml.Replace(" ", ""); var size = item.ChildNodes[2].ChildNodes[0].InnerHtml.Replace(" ", ""); //Console.WriteLine(path); //Console.WriteLine(date); //Console.WriteLine(type); //Console.WriteLine("----------"); FileTreeNode tr; if (size == "[DIRECTORY]") { tr = new FileTreeNode(path, /*GetServer(startpath + "" + path),*/ FileTreeNode.TypeNode.Directory, startpath + "" + path); tr.SelectedImageKey = "f"; tr.ImageKey = "f"; tr.Nodes.Add(""); } else { tr = new FileTreeNode(path, FileTreeNode.TypeNode.File, startpath + "" + path); tr.SelectedImageKey = "v"; tr.ImageKey = "v"; } tr.ContextMenuStrip = contextMenuStrip1; tr.ToolTipText = date + " (" + (size) + ")"; list.Add(tr); } } if (showdownload) { ld.Invoke(new Action(() => ld.Close())); Log = "Загрузка завершена"; } return(list.ToArray()); }
void UpdateServer(string startpath = "") { Log = "Идет загрузка..."; treeView1.Nodes.Clear(); new Thread(() => ld.ShowDialog()).Start(); var DeviceInfo = Downloading.GetDeviceParams(setting.URLToHTTPPort, setting.Name, setting.Password); label1.Text = "Свободно места на SD (" + formatFileSize(int.Parse(DeviceInfo["sdfreespace"])) + ") из " + formatFileSize(int.Parse(DeviceInfo["sdtotalspace"])); progressBar2.Maximum = int.Parse(DeviceInfo["sdtotalspace"]); progressBar2.Value = int.Parse(DeviceInfo["sdtotalspace"]) - int.Parse(DeviceInfo["sdfreespace"]); label2.Text = (DeviceInfo["sdstatus"].Contains("Ready")) ? "SD карта работает исправно" : "Ошибка SD карты"; label3.Text = "Камера запущенна: " + DeviceInfo["startdate"]; label6.Text = "Камера работает: " + (DateTime.Now - DateTime.Parse(DeviceInfo["startdate"])).ToString().Split('.')[0]; checkBox1.Checked = DeviceInfo["planrec_enable"].Contains("1"); numericUpDown1.Value = int.Parse(DeviceInfo["planrec_time"]); comboBox1.SelectedIndex = DeviceInfo["planrec_chn"] == "11" ? 1 : 0; var web = (Downloading.GetHTML(DownloadingPaths.ToPath(setting.URLToHTTPPort) + DownloadingPaths.SD + startpath, setting.Name, setting.Password)); HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument(); html.LoadHtml(web); var table = html.DocumentNode.SelectSingleNode("/html/body/pre/table"); var tabletr = table.ChildNodes.Where(x => x.Name == "tr").ToList(); tabletr.RemoveRange(0, 3); foreach (var item in tabletr) { if (item.ChildNodes.Count > 2) { var path = item.ChildNodes[0].ChildNodes[0].InnerHtml.Replace(" ", ""); var date = item.ChildNodes[1].ChildNodes[0].InnerHtml.Replace(" ", ""); var size = item.ChildNodes[2].ChildNodes[0].InnerHtml.Replace(" ", ""); //Console.WriteLine(path); //Console.WriteLine(date); //Console.WriteLine(type); //Console.WriteLine("----------"); FileTreeNode tr = new FileTreeNode(path, GetServer(startpath + "" + path), FileTreeNode.TypeNode.Directory, startpath + "" + path); tr.ToolTipText = date + " (" + size + ")"; tr.ContextMenuStrip = contextMenuStrip1; treeView1.Nodes.Add(tr); } } if (backgroundWorker1.IsBusy) { backgroundWorker1.CancelAsync(); } if (!backgroundWorker1.IsBusy) { backgroundWorker1.RunWorkerAsync(DateTime.Now - DateTime.Parse(DeviceInfo["startdate"])); } ld.Invoke(new Action(() => ld.Close())); Log = "Загрузка завершена"; }
/// <summary> /// Получить версию с сервера /// </summary> /// <returns></returns> public static VersionInfo GetVersionServer() { var serverinf = Downloading.GetHTML(URLServer + URLConfig); if (serverinf == null) { return(CurrentVersion.CurrentVersions); } return(new VersionInfo(serverinf)); }
private void button1_Click(object sender, EventArgs e) { panel2.Visible = true; using (WebDownload wc = new WebDownload()) { wc.DownloadProgressChanged += wc_DownloadProgressChanged; wc.DownloadFileCompleted += (object senders, AsyncCompletedEventArgs es) => { MessageBox.Show("Успешно загружено. Сейчас начнется установка"); Process.Start("UpdateDownloading.exe"); Application.Exit(); }; wc.DownloadFileAsync( // Param1 = Link of file new System.Uri(NetworkUpdate.URLServer + ver.URLDownload), // Param2 = Path to save "UpdateDownloading.exe" ); Console.WriteLine(Downloading.GetHTML(NetworkUpdate.URLServer + NetworkUpdate.URLConfirm)); } }