Пример #1
0
 public void DownloadFile(string url, bool openAfterDownload)
 {
     if (webClient.IsBusy)
     {
         throw new Exception("Данный клиент для скачивания занят");
     }
     try
     {
         var startDownloading = DateTime.UtcNow;
         webClient.Proxy = null;
         if (!SelectFolder(Path.GetFileName(url), out var filePath))
         {
             throw DownloadingError();
         }
         webClient.DownloadProgressChanged += (o, args) =>
         {
             ProgressPercentageChanged?.Invoke(args.ProgressPercentage);
             FileSizeChanged?.Invoke(args.TotalBytesToReceive);
             DownloadBytesChanged?.Invoke(args.BytesReceived, DateTime.UtcNow - startDownloading);
             if (args.ProgressPercentage >= 100 && openAfterDownload)
             {
                 Process.Start(filePath);
             }
         };
         webClient.DownloadFileCompleted += (o, args) => DownloadComplete?.Invoke();
         stopWatch.Start();
         webClient.DownloadFileAsync(new Uri(url), filePath);
     }
     catch (Exception e)
     {
         throw DownloadingError();
     }
 }
Пример #2
0
 private static void AddonsBackup_ExtractProgress(object sender, ExtractProgressEventArgs e)
 {
     if (e.EntriesTotal != 0)
     {
         var procent = e.EntriesExtracted * 100 / e.EntriesTotal;
         if (procent != _prevProcent && procent >= 0 && procent <= 100)
         {
             _prevProcent = procent;
             ProgressPercentageChanged?.Invoke(procent);
         }
     }
 }