public ArchiveFile(string archiveFilePath, string libraryFilePath = null) { this.libraryFilePath = libraryFilePath; this.InitializeAndValidateLibrary(); if (!File.Exists(archiveFilePath)) { throw new SevenZipException("Archive file not found"); } string extension = Path.GetExtension(archiveFilePath); if (string.IsNullOrWhiteSpace(extension)) { throw new SevenZipException("Unable to guess format for file: " + archiveFilePath); } string fileExtension = extension.Trim('.').ToLowerInvariant(); if (!Formats.ExtensionFormatMapping.ContainsKey(fileExtension)) { throw new SevenZipException(fileExtension + " is not a known archive type"); } KnownSevenZipFormat format = Formats.ExtensionFormatMapping[fileExtension]; this.archive = this.sevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format]); this.archiveStream = new InStreamWrapper(File.OpenRead(archiveFilePath)); }
public static Guid GetClassIdFromKnownFormat(KnownSevenZipFormat format) { Guid Result; if (FormatClassMap.TryGetValue(format, out Result)) { return(Result); } return(Guid.Empty); }
public static Guid GetClassIdFromKnownFormat(KnownSevenZipFormat format) { Guid guid; if (SevenZipFormat.FormatClassMap.TryGetValue(format, out guid)) { return(guid); } return(Guid.Empty); }
public string Extract(string archiveName, string folderToExtract, uint fileNumber, KnownSevenZipFormat ZipFormat, out bool isDirectory) { isDirectory = false; ZipFormatG = ZipFormat; string FileName = null; try { using (SevenZipFormat Format = new SevenZipFormat(SevenZipDllPath)) { IInArchive Archive = Format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(ZipFormat)); if (Archive == null) { return(null); } try { using (InStreamWrapper ArchiveStream = new InStreamWrapper(File.OpenRead(archiveName))) { IArchiveOpenCallback OpenCallback = new ArchiveOpenCallback(); ulong CheckPos = 256 * 1024; if (Archive.Open(ArchiveStream, ref CheckPos, OpenCallback) != 0) { return(null); } PropVariant Name = new PropVariant(); Archive.GetProperty(fileNumber, ItemPropId.kpidPath, ref Name); FileName = (string)Name.GetObject(); Archive.GetProperty(fileNumber, ItemPropId.kpidIsFolder, ref Name); isDirectory = (bool)Name.GetObject(); if (!isDirectory) { Archive.Extract(new uint[] { fileNumber }, 1, 0, new ArchiveExtractCallback(fileNumber, folderToExtract + FileName)); } } } finally { Marshal.ReleaseComObject(Archive); } } } catch { } return(FileName); }
public ArchiveFile(Stream archiveStream, KnownSevenZipFormat format, string libraryFilePath = null) { this.libraryFilePath = libraryFilePath; this.InitializeAndValidateLibrary(); if (archiveStream == null) { throw new SevenZipException("archiveStream is null"); } this.archive = this.sevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format]); this.archiveStream = new InStreamWrapper(archiveStream); }
public List <string> List(string archiveName, KnownSevenZipFormat ZipFormat) { List <string> List = new List <string>(); using (SevenZipFormat Format = new SevenZipFormat(SevenZipDllPath)) { IInArchive Archive = Format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(ZipFormat)); if (Archive == null) { return(List); } try { using (InStreamWrapper ArchiveStream = new InStreamWrapper(File.OpenRead(archiveName))) { IArchiveOpenCallback OpenCallback = new ArchiveOpenCallback(); ulong CheckPos = 256 * 1024; if (Archive.Open(ArchiveStream, ref CheckPos, OpenCallback) != 0) { return(List); } uint Count = Archive.GetNumberOfItems(); for (uint I = 0; I < Count; I++) { PropVariant Name = new PropVariant(); Archive.GetProperty(I, ItemPropId.kpidPath, ref Name); string[] T = Name.GetObject().ToString().Split('\\'); List.Add(T[T.Length - 1]); } } } finally { Marshal.ReleaseComObject(Archive); } } return(List); }
public bool extract(string archiveName, uint fileNumber, string arcType, ProgressBar progress, Label status) { Program.form.waitForFreeMemory(status); attachedProgressBar = progress; attachedStatus = status; status.Text = "Extracting File " + this.extracting_file; progress.Maximum = 1; progress.Value = 0; Application.DoEvents(); bool flag = false; KnownSevenZipFormat format = this.stringToSevenZipFormat(arcType); switch (format) { case KnownSevenZipFormat.SevenZip: case KnownSevenZipFormat.Zip: break; case KnownSevenZipFormat.Rar: return(this.extractRar(archiveName, progress, status, true)); default: showError("1.0"); break; } using (SevenZipFormat format2 = new SevenZipFormat(SevenZipDllPath)) { if (this.ArchiveIn != null) { Marshal.ReleaseComObject(this.ArchiveIn); for (int i = 0; i < 5; i++) { Application.DoEvents(); } } this.ArchiveIn = format2.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(format)); if (this.ArchiveIn == null) { showError("1.1"); flag = false; } try { using (InStreamWrapper wrapper = new InStreamWrapper(System.IO.File.OpenRead(archiveName))) { IArchiveOpenCallback openArchiveCallback = new ArchiveOpenCallback(); if (this.ArchiveIn.Open(wrapper, 0x20000L, openArchiveCallback) != 0) { showError("1.2"); flag = false; } else { PropVariant variant = new PropVariant(); this.ArchiveIn.GetProperty(fileNumber, ItemPropId.kpidPath, ref variant); string fileName = (string)variant.GetObject(); this.ArchiveIn.Extract(new uint[] { fileNumber }, 1, 0, new ArchiveExtractCallback(fileNumber, fileName)); flag = true; } } } finally { Marshal.ReleaseComObject(this.ArchiveIn); } } Program.form.waitForFreeMemory(status); return(flag); }
public void Pack(string archiveName, ICollection <string> filePathList, string arcType, ProgressBar progress, Label status, bool delete) { Program.form.waitForFreeMemory(status); string outPutFolder = ""; if (archiveName.Replace('/', '+') != archiveName) { outPutFolder = archiveName.Substring(0, archiveName.LastIndexOf('/') + 1); } else { outPutFolder = archiveName.Substring(0, archiveName.LastIndexOf('\\') + 1); } creating_archive = Program.form.origFileLocToNewFileName(archiveName, false, false, outPutFolder); attachedProgressBar = progress; attachedStatus = status; KnownSevenZipFormat format = this.stringToSevenZipFormat(arcType); using (SevenZipFormat format2 = new SevenZipFormat(SevenZipDllPath)) { this.ArchiveOut = format2.CreateOutArchive(SevenZipFormat.GetClassIdFromKnownFormat(format)); if (this.ArchiveOut == null) { showError("-0100\n\n" + format); creating_archive = ""; return; } List <FileInfo> list = new List <FileInfo>(filePathList.Count); foreach (string str2 in filePathList) { list.Add(new FileInfo(str2)); } try { using (OutStreamWrapper wrapper = new OutStreamWrapper(System.IO.File.OpenWrite(archiveName))) { this.ArchiveOut.UpdateItems(wrapper, list.Count, new ArchiveUpdateCallback(list)); } } finally { Marshal.ReleaseComObject(this.ArchiveOut); } if (delete) { foreach (string str3 in filePathList) { status.Text = "Waiting for " + Program.form.origFileLocToNewFileName(str3, false, false, "") + " to be released"; Application.DoEvents(); Label_0187 :; try { System.IO.File.Delete(str3); } catch { goto Label_0187; } } } } creating_archive = ""; Program.form.waitForFreeMemory(status); }
public int findFirstExtInArchive(string ext, string archiveName, string arcType, ProgressBar progress, Label status) { status.Text = "Scanning Archive " + archiveName; progress.Maximum = 4; progress.Value = 0; Application.DoEvents(); int num = -1; using (SevenZipFormat format = new SevenZipFormat(SevenZipDllPath)) { KnownSevenZipFormat sevenZip = KnownSevenZipFormat.SevenZip; arcType = arcType.ToLower(); switch (arcType) { case "rar": sevenZip = KnownSevenZipFormat.Rar; break; case "zip": sevenZip = KnownSevenZipFormat.Zip; break; case "7z": sevenZip = KnownSevenZipFormat.SevenZip; break; default: showError("0.1"); break; } IInArchive o = format.CreateInArchive(SevenZipFormat.GetClassIdFromKnownFormat(sevenZip)); if (o == null) { showError("0.2"); num = -1; } try { using (InStreamWrapper wrapper = new InStreamWrapper(System.IO.File.OpenRead(archiveName))) { IArchiveOpenCallback openArchiveCallback = new ArchiveOpenCallback(); if (o.Open(wrapper, 0x40000L, openArchiveCallback) != 0) { showError("0.3"); num = -1; } uint numberOfItems = o.GetNumberOfItems(); fileInRar = ""; for (int i = 0; i < numberOfItems; i++) { PropVariant variant = new PropVariant(); o.GetProperty((uint)i, ItemPropId.kpidPath, ref variant); PropVariant variant2 = new PropVariant(); o.GetProperty((uint)i, ItemPropId.kpidCRC, ref variant2); if (Program.form.getFileExtension(variant.GetObject().ToString()).ToLower() == ext.ToLower()) { num = i; fileInRar = variant.GetObject().ToString(); this.crc_of_extracting_file = long.Parse(variant2.GetObject().ToString()).ToString("X8"); return(num); } } return(num); } } finally { Marshal.ReleaseComObject(o); } } return(num); }
public static Guid GetClassIdFromKnownFormat(KnownSevenZipFormat format) { Guid Result; if (FormatClassMap.TryGetValue(format, out Result)) return Result; return Guid.Empty; }
public SevenZipPropertiesBuilder(KnownSevenZipFormat format) { this.KnownFormat = format; }
private string Write163_KnownSevenZipFormat(KnownSevenZipFormat v) { switch (v) { case KnownSevenZipFormat.Unknown: return "Unknown"; case KnownSevenZipFormat.SevenZip: return "SevenZip"; case KnownSevenZipFormat.Arj: return "Arj"; case KnownSevenZipFormat.BZip2: return "BZip2"; case KnownSevenZipFormat.Cab: return "Cab"; case KnownSevenZipFormat.Chm: return "Chm"; case KnownSevenZipFormat.Compound: return "Compound"; case KnownSevenZipFormat.Cpio: return "Cpio"; case KnownSevenZipFormat.Deb: return "Deb"; case KnownSevenZipFormat.Dmg: return "Dmg"; case KnownSevenZipFormat.ELF: return "ELF"; case KnownSevenZipFormat.FAT: return "FAT"; case KnownSevenZipFormat.FLV: return "FLV"; case KnownSevenZipFormat.GZip: return "GZip"; case KnownSevenZipFormat.HFS: return "HFS"; case KnownSevenZipFormat.Iso: return "Iso"; case KnownSevenZipFormat.Lzh: return "Lzh"; case KnownSevenZipFormat.Lzma: return "Lzma"; case KnownSevenZipFormat.Lzma86: return "Lzma86"; case KnownSevenZipFormat.MachO: return "MachO"; case KnownSevenZipFormat.MBR: return "MBR"; case KnownSevenZipFormat.MsLz: return "MsLz"; case KnownSevenZipFormat.Mub: return "Mub"; case KnownSevenZipFormat.Nsis: return "Nsis"; case KnownSevenZipFormat.NTFS: return "NTFS"; case KnownSevenZipFormat.PE: return "PE"; case KnownSevenZipFormat.Rar: return "Rar"; case KnownSevenZipFormat.Rpm: return "Rpm"; case KnownSevenZipFormat.Split: return "Split"; case KnownSevenZipFormat.SWF: return "SWF"; case KnownSevenZipFormat.SWFc: return "SWFc"; case KnownSevenZipFormat.Tar: return "Tar"; case KnownSevenZipFormat.Udf: return "Udf"; case KnownSevenZipFormat.VHD: return "VHD"; case KnownSevenZipFormat.Wim: return "Wim"; case KnownSevenZipFormat.Xar: return "Xar"; case KnownSevenZipFormat.Xz: return "Xz"; case KnownSevenZipFormat.Z: return "Z"; case KnownSevenZipFormat.Zip: return "Zip"; } long num = (long) v; throw base.CreateInvalidEnumValueException(num.ToString(CultureInfo.InvariantCulture), "Nomad.FileSystem.Archive.SevenZip.KnownSevenZipFormat"); }