예제 #1
0
        /// <summary>
        /// Метод, работающий в отдельном потоке при запуске механизма распаковки.
        /// </summary>
        private void AR_Wrk_DoWork(object sender, DoWorkEventArgs e)
        {
            // Начинаем процесс распаковки с выводом индикатора прогресса...
            if (File.Exists(ArchName))
            {
                using (ZipFile Zip = ZipFile.Read(ArchName))
                {
                    // Формируем счётчики...
                    int TotalFiles = Zip.Count;
                    int i = 1, j = 0;

                    // Начинаем распаковку архива...
                    foreach (ZipEntry ZFile in Zip)
                    {
                        try { ZFile.Extract(DestDir, ExtractExistingFileAction.OverwriteSilently); j = (int)Math.Round(((double)i / (double)TotalFiles * (double)100.00), 0); i++; if ((j >= 0) && (j <= 100))
                              {
                                  AR_Wrk.ReportProgress(j);
                              }
                        } catch (Exception Ex) { CoreLib.WriteStringToLog(Ex.Message); }
                    }
                }
            }
            else
            {
                throw new FileNotFoundException("Archive not found.", ArchName);
            }
        }
예제 #2
0
        /// <summary>
        /// Extracts archive to specified destination directory.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">Additional arguments.</param>
        private void AR_Wrk_DoWork(object sender, DoWorkEventArgs e)
        {
            // Parsing arguments list...
            List <String> Arguments = e.Argument as List <String>;

            // Checking if archive file exists...
            if (File.Exists(Arguments[0]))
            {
                // Opening archive...
                using (ZipFile Zip = ZipFile.Read(Arguments[0]))
                {
                    // Creating some counters...
                    int TotalFiles = Zip.Count;
                    int CurrentFile = 1, CurrentPercent = 0;

                    // Unpacking archive contents...
                    foreach (ZipEntry ZFile in Zip)
                    {
                        try
                        {
                            // Extracting file, then counting and reporting progress...
                            ZFile.Extract(Arguments[1], ExtractExistingFileAction.OverwriteSilently);
                            CurrentPercent = (int)Math.Round(CurrentFile / (double)TotalFiles * 100.00d, 0); CurrentFile++;
                            if ((CurrentPercent >= 0) && (CurrentPercent <= 100))
                            {
                                AR_Wrk.ReportProgress(CurrentPercent);
                            }
                        }
                        catch (Exception Ex)
                        {
                            Logger.Warn(Ex);
                        }
                    }
                }
            }
            else
            {
                throw new FileNotFoundException(AppStrings.AR_BkgWrkExText, Arguments[0]);
            }
        }