public void libFeatures() { LibraryFeature featuresExtract = SevenZipBase.CurrentLibraryFeatures; string featStringExtract = ((uint)featuresExtract).ToString("X6"); Console.WriteLine("Extractor Features: " + featStringExtract); Assert.IsTrue(featuresExtract.HasFlag(SevenZip.LibraryFeature.Extract7zAll)); }
private static bool TryLoad7ZipLibrary(string dll) { try { if (File.Exists(dll)) { SevenZipBase.SetLibraryPath(dll); LibraryFeature features = SevenZipBase.CurrentLibraryFeatures; return(features.HasFlag(LibraryFeature.Compress7z) && features.HasFlag(LibraryFeature.Extract7z)); } else { //MessageBox.Show("7zip library not found:\r\n" + dll, "Load error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } } catch // (Exception x) { //MessageBox.Show("Couldn't load 7zip library Exception:\r\n" + x.Message+"\r\n"+dll, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } }
private void CompressForm_Shown(object sender, EventArgs e) { switch (task) { case ZipTaskType.doZip: Text = "Add to archive"; break; case ZipTaskType.doUnZip: Text = "Extract from archive"; break; default: Text = "Unknown command"; DialogResult = DialogResult.Abort; return; } // Start here // Toggle between the x86 and x64 bit dll if ((SevenZipDLLPath == null) || (SevenZipDLLPath == string.Empty)) { SevenZipDLLPath = TryGet7ZipLibrary(); } if (SevenZipDLLPath == string.Empty) { DialogResult = DialogResult.Abort; return; } LibraryFeature features = SevenZipBase.CurrentLibraryFeatures; lZipFile.Text = ArchiveFileName; switch (task) { case ZipTaskType.doZip: if (!features.HasFlag(LibraryFeature.Compress7z)) { MessageBox.Show("Currently loaded 7-zip library doesn't support 7z compression, cannot continue !\r\n" + SevenZipDLLPath, "Method not supported", MessageBoxButtons.OK, MessageBoxIcon.Stop); DialogResult = DialogResult.Abort; return; } if (File.Exists(ArchiveFileName)) { if (MessageBox.Show("Target 7z file already exists, do you want to overwrite it ?\r\n" + ArchiveFileName, "Overwrite File", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { DialogResult = DialogResult.Cancel; return; } } try { zipper = new SevenZipCompressor(); zipper.CompressionLevel = SevenZip.CompressionLevel.Ultra; zipper.CompressionMethod = CompressionMethod.Lzma; zipper.CompressionMode = CompressionMode.Create; zipper.TempFolderPath = Path.GetTempPath(); zipper.ArchiveFormat = OutArchiveFormat.SevenZip; bgwZipper.RunWorkerAsync(); } catch (Exception x) { MessageBox.Show("Exception:\r\n" + x.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Abort; } break; case ZipTaskType.doUnZip: if (!File.Exists(ArchiveFileName)) { MessageBox.Show("Source 7z file not found ?\r\n" + ArchiveFileName, "File Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning); DialogResult = DialogResult.Cancel; return; } if ((Path.GetExtension(ArchiveFileName).ToLower() == ".7z") && (!features.HasFlag(LibraryFeature.Extract7z))) { MessageBox.Show("Currently loaded 7-zip library doesn't support .7z extraction, cannot continue !\r\n" + SevenZipDLLPath, "Method not supported", MessageBoxButtons.OK, MessageBoxIcon.Stop); DialogResult = DialogResult.Abort; return; } if ((Path.GetExtension(ArchiveFileName).ToLower() == ".zip") && (!features.HasFlag(LibraryFeature.ExtractZip))) { MessageBox.Show("Currently loaded 7-zip library doesn't support .zip extraction, cannot continue !\r\n" + SevenZipDLLPath, "Method not supported", MessageBoxButtons.OK, MessageBoxIcon.Stop); DialogResult = DialogResult.Abort; return; } if ((Path.GetExtension(ArchiveFileName).ToLower() == ".rar") && (!features.HasFlag(LibraryFeature.ExtractRar))) { MessageBox.Show("Currently loaded 7-zip library doesn't support .rar extraction, cannot continue !\r\n" + SevenZipDLLPath, "Method not supported", MessageBoxButtons.OK, MessageBoxIcon.Stop); DialogResult = DialogResult.Abort; return; } try { if (overrideZipFormat) { unzipper = new SevenZipExtractor(ArchiveFileName, InArchiveFormat.SevenZip); } else { unzipper = new SevenZipExtractor(ArchiveFileName); } if (unzipper.FilesCount <= 0) { MessageBox.Show("Nothing to extract", "No files", MessageBoxButtons.OK, MessageBoxIcon.Warning); DialogResult = DialogResult.Cancel; } else { pb.Minimum = 0; pb.Maximum = (int)unzipper.FilesCount + 1; pb.Step = 1; pb.Value = 0; // unzipper.FileExtractionStarted += new EventHandler<FileInfoEventArgs>(FileExtractStarted); unzipper.FileExtractionFinished += new EventHandler <FileInfoEventArgs>(FileExtractFinished); unzipper.FileExists += new EventHandler <FileOverwriteEventArgs>(FileExtractFileExists); bgwUnZipper.RunWorkerAsync(); } } catch (Exception x) { MessageBox.Show("Exception:\r\n" + x.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Abort; } break; default: DialogResult = DialogResult.Abort; return; } }