private void UnzipThreadRoutine()
        {
            try
            {
                if (File.Exists(_downloadSetup.BinsZipLocation))
                {
                    Helpers.ConsolePrint(TAG, _downloadSetup.BinsZipLocation + " already downloaded");
                    Helpers.ConsolePrint(TAG, "unzipping");

                    // if using other formats as zip are returning 0
                    FileInfo fileArchive = new FileInfo(_downloadSetup.BinsZipLocation);
                    var      archive     = ArchiveFactory.Open(_downloadSetup.BinsZipLocation);
                    _minerUpdateIndicator.SetMaxProgressValue(100);
                    long SizeCount = 0;
                    foreach (var entry in archive.Entries)
                    {
                        if (!entry.IsDirectory)
                        {
                            SizeCount += entry.CompressedSize;
                            Helpers.ConsolePrint(TAG, entry.Key);
                            entry.WriteToDirectory("", ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite);

                            double prog = ((double)(SizeCount) / (double)(fileArchive.Length) * 100);
                            _minerUpdateIndicator.SetProgressValueAndMsg((int)prog, String.Format(International.GetText("MinersDownloadManager_Title_Settup_Unzipping"), prog.ToString("F2")));
                        }
                    }
                    archive.Dispose();
                    archive = null;
                    // after unzip stuff
                    _minerUpdateIndicator.FinishMsg(true);
                    // remove bins zip
                    try
                    {
                        if (File.Exists(_downloadSetup.BinsZipLocation))
                        {
                            File.Delete(_downloadSetup.BinsZipLocation);
                        }
                    }
                    catch (Exception e)
                    {
                        Helpers.ConsolePrint("MinersDownloader.UnzipThreadRoutine", "Cannot delete exception: " + e.Message);
                    }
                }
                else
                {
                    Helpers.ConsolePrint(TAG, String.Format("UnzipThreadRoutine {0} file not found", _downloadSetup.BinsZipLocation));
                }
            }
            catch (Exception e)
            {
                Helpers.ConsolePrint(TAG, "UnzipThreadRoutine has encountered an error: " + e.Message);
            }
        }
Beispiel #2
0
 private void UnzipThreadRoutine()
 {
     if (File.Exists(BinsZipLocation))
     {
         Helpers.ConsolePrint(TAG, BinsZipLocation + " already downloaded");
         Helpers.ConsolePrint(TAG, "unzipping");
         using (ZipArchive archive = ZipFile.Open(BinsZipLocation, ZipArchiveMode.Read)) {
             //archive.ExtractToDirectory("bin");
             _minerUpdateIndicator.SetMaxProgressValue(archive.Entries.Count);
             int prog = 0;
             // first create dirs
             foreach (ZipArchiveEntry entry in archive.Entries)
             {
                 if (entry.Length == 0)
                 {
                     Helpers.ConsolePrint("ZipArchiveEntry", entry.FullName);
                     Helpers.ConsolePrint("ZipArchiveEntry", entry.Length.ToString());
                     Directory.CreateDirectory(entry.FullName);
                     _minerUpdateIndicator.SetProgressValueAndMsg(prog++, String.Format(International.GetText("MinersDownloadManager_Title_Settup_Unzipping"), ((double)(prog) / (double)(archive.Entries.Count) * 100).ToString("F2")));
                 }
             }
             // unzip files
             foreach (ZipArchiveEntry entry in archive.Entries)
             {
                 if (entry.Length > 0)
                 {
                     Helpers.ConsolePrint("ZipArchiveEntry", entry.FullName);
                     Helpers.ConsolePrint("ZipArchiveEntry", entry.Length.ToString());
                     entry.ExtractToFile(entry.FullName);
                     _minerUpdateIndicator.SetProgressValueAndMsg(prog++, String.Format(International.GetText("MinersDownloadManager_Title_Settup_Unzipping"), ((double)(prog) / (double)(archive.Entries.Count) * 100).ToString("F2")));
                 }
             }
         }
         // after unzip stuff
         ConfigManager.Instance.GeneralConfig.DownloadInit = true;
         ConfigManager.Instance.GeneralConfig.Commit();
         _minerUpdateIndicator.FinishMsg(IsMinersBinsInit());
         // remove bins zip
         try {
             if (File.Exists(BinsZipLocation))
             {
                 File.Delete(BinsZipLocation);
             }
         } catch { }
     }
     else
     {
         Helpers.ConsolePrint(TAG, "UnzipThreadRoutine bin.zip file not found");
     }
 }