public static async Task Loader(string link, Label message) { if (!string.IsNullOrWhiteSpace(link)) { string filename = FileManager.GetFileName(link); // Получаем имя файла из ссылки string fullpath = FileManager.CombinePath(GlobalPath.CurrDir, filename); // Соединяем путь и имя файла if (!FileManager.ExistsFile(fullpath)) { try { var url = new Uri(link, UriKind.Absolute); using var client = new WebClient(); if (!client.IsBusy) { // Установка сертификата для успешной загрузки файл(а)ов ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12; client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36 OPR/49.0.2725.64"); client.Proxy = null; try { await client?.DownloadFileTaskAsync(url, fullpath); var file = new FileInfo(fullpath); if (file.Length > 0) { message.Location = new Point(505, 371); ControlActive.CheckMessage(message, "Файл загружен успешно!", Color.YellowGreen, 4000); } else { message.Location = new Point(505, 371); ControlActive.CheckMessage(message, "Файл повреждён, имеет 0 байтов!", Color.YellowGreen, 4000); } } catch (WebException) { FileManager.DeleteFile(fullpath); message.Location = new Point(505, 371); ControlActive.CheckMessage(message, "Ошибка загрузки файла!", Color.YellowGreen, 4000); } } } catch (Exception ex) { throw new Exception("WebClient error: ", ex); } } else { message.Location = new Point(505, 371); ControlActive.CheckMessage(message, "Файл уже существует!", Color.YellowGreen, 4000); } } }
private void SelectIcon_Click(object sender, EventArgs e) { NativeMethods.SetFocus(Hwnd.Zero); this.LogoText.Focus(); try { using var Open = new OpenFileDialog { Title = "Выберите иконку для загрузчика", Filter = "Icon (*.ico)|*.ico", Multiselect = false, AutoUpgradeEnabled = true, CheckFileExists = true, RestoreDirectory = true }; if (Open.ShowDialog() == DialogResult.OK) { this.IcoPath.Text = Open.FileName; if (FileManager.ExistsFile(this.IcoPath.Text)) { this.StatusMessage.Location = new Point(524, 371); this.IcoViewer.ImageLocation = this.IcoPath.Text; this.IcoViewer.BorderStyle = BorderStyle.None; this.LsizeIco.Text = $"Размер иконки: {GetFileSize.Inizialize(new FileInfo(this.IcoPath.Text).Length)}"; } else { this.IcoViewer.BorderStyle = BorderStyle.FixedSingle; this.StatusMessage.Location = new Point(524, 371); // 524 371 this.LsizeIco.Text = $"Размер иконки: 0"; ControlActive.CheckMessage(this.StatusMessage, "Иконка повреждена!", Color.YellowGreen, 5000); } } else { this.IcoPath.Clear(); this.IcoViewer.Image = null; this.IcoViewer.BorderStyle = BorderStyle.FixedSingle; this.StatusMessage.Location = new Point(524, 371); this.LsizeIco.Text = $"Размер иконки: 0"; ControlActive.CheckMessage(this.StatusMessage, "Иконка не выбрана", Color.YellowGreen, 5000); } } catch (Exception ex) { throw new Exception("Error OpenFile", ex); } }
private void IcoViewer_DragDrop(object sender, DragEventArgs e) { foreach (string text in (string[])e.Data.GetData(DataFormats.FileDrop)) { this.IcoPath.Text = text; this.IcoViewer.Image = Image.FromFile(text); if (FileManager.ExistsFile(this.IcoPath.Text)) { this.StatusMessage.Location = new Point(12, 418); this.LsizeIco.Text = $"Размер иконки: {GetFileSize.Inizialize(new FileInfo(this.IcoPath.Text).Length)}"; } else { this.StatusMessage.Location = new Point(12, 418); this.LsizeIco.Text = $"Размер иконки: 0"; ControlActive.CheckMessage(this.StatusMessage, "Иконка повреждена!", Color.YellowGreen, 5000); } } }