public void GetProperty(int index, ItemPropId propID, ref PropVariant value) { switch (propID) { case ItemPropId.kpidPath: value.VarType = VarEnum.VT_BSTR; value.pointerValue = Marshal.StringToBSTR(Path.GetFileName(filename)); break; case ItemPropId.kpidIsFolder: case ItemPropId.kpidIsAnti: value.VarType = VarEnum.VT_BOOL; value.longValue = 0; break; case ItemPropId.kpidCreationTime: value.VarType = VarEnum.VT_FILETIME; value.longValue = (documentEntry.FileDate ?? DateTime.Now).ToFileTime(); break; case ItemPropId.kpidLastAccessTime: value.VarType = VarEnum.VT_FILETIME; value.longValue = (documentEntry.FileDate ?? DateTime.Now).ToFileTime(); break; case ItemPropId.kpidLastWriteTime: value.VarType = VarEnum.VT_FILETIME; value.longValue = (documentEntry.FileDate ?? DateTime.Now).ToFileTime(); break; case ItemPropId.kpidSize: value.VarType = VarEnum.VT_UI8; value.longValue = content.Length; break; } }
public Stream GetInputStream(uint index) { using (Stream stream = GetArchiveStream()) { using (InStreamWrapper wrapper = new InStreamWrapper(stream)) { using (ArchiveOpenCallback callback = new ArchiveOpenCallback(this, ParentLayer.Parent, file)) { ulong checkPos = 128 * 1024; if (archive.Open(wrapper, ref checkPos, callback) != 0) { throw new FileSystemException(String.Format("Could not open archive file \"{0}\".", ParentLayer)); } try { PropVariant sizeProperty = new PropVariant(); archive.GetProperty(index, ItemPropId.kpidSize, ref sizeProperty); // TODO: Limit memory usage. MemoryStream ms = new MemoryStream(sizeProperty.intValue); archive.Extract(new[] {index}, 1, 0, new ArchiveExtractCallback(ms)); ms.Seek(0, SeekOrigin.Begin); return ms; } finally { closeCommunicationLink(); } } } } }
public override void init() { base.init(); try { IList strongRef = new ArrayList(100); using(Stream stream = GetArchiveStream()) { using(InStreamWrapper wrapper = new InStreamWrapper(stream)) { using (ArchiveOpenCallback callback = new ArchiveOpenCallback(this, ParentLayer.Parent, file)) { ulong checkPos = 128 * 1024; if (archive.Open(wrapper, ref checkPos, callback) != 0) { throw new FileSystemException(String.Format("Could not open Zip file \"{0}\".", ParentLayer)); } uint count = archive.GetNumberOfItems(); for (uint index = 0; index < count; index++) { PropVariant entryName = new PropVariant(); archive.GetProperty(index, ItemPropId.kpidPath, ref entryName); PropVariant hostSystem = new PropVariant(); archive.GetProperty(index, ItemPropId.kpidHostOS, ref hostSystem); string path = (string) entryName.GetObject(); if (String.Compare((string) hostSystem.GetObject(), "FAT", 0) == 0) { if (SevenZipFormat.SystemCodePage != SevenZipFormat.DefaultCodePage) { path = SevenZipFormat.DefaultEncoding.GetString(SevenZipFormat.SystemEncoding.GetBytes(path)); } } IFileName name = FileSystemManager.resolveName(RootName, VirtualFileSystem.Provider.UriParser.encode(path)); PropVariant isFolderProperty = new PropVariant(); archive.GetProperty(index, ItemPropId.kpidIsFolder, ref isFolderProperty); SevenZipFileObject fileObj; if ((bool) isFolderProperty.GetObject() && getFileFromCache(name) != null) { fileObj = (SevenZipFileObject) getFileFromCache(name); fileObj.Index = index; continue; } fileObj = createFileObject(name, index); putFileToCache(fileObj); strongRef.Add(fileObj); fileObj.holdObject(strongRef); SevenZipFileObject parent = null; for (IFileName parentName = name.Parent; parentName != null; fileObj = parent, parentName = parentName.Parent) { // Locate the parent parent = (SevenZipFileObject) getFileFromCache(parentName); if (parent == null) { parent = createFileObject(parentName, UInt32.MaxValue); putFileToCache(parent); strongRef.Add(parent); parent.holdObject(strongRef); } // Attach child to parent parent.attachChild(fileObj.Name); } } } } } } finally { closeCommunicationLink(); } }
public int GetProperty(ItemPropId propID, ref PropVariant value) { switch (propID) { case ItemPropId.kpidName: value.VarType = VarEnum.VT_BSTR; value.pointerValue = Marshal.StringToBSTR(archiveFile.FullName); break; case ItemPropId.kpidIsFolder: value.VarType = VarEnum.VT_BOOL; value.longValue = (byte)(archiveFile.Attributes & FileAttributes.Directory); break; case ItemPropId.kpidCreationTime: value.VarType = VarEnum.VT_FILETIME; value.longValue = archiveFile.CreationTime.ToFileTime(); break; case ItemPropId.kpidLastAccessTime: value.VarType = VarEnum.VT_FILETIME; value.longValue = archiveFile.LastAccessTime.ToFileTime(); break; case ItemPropId.kpidLastWriteTime: value.VarType = VarEnum.VT_FILETIME; value.longValue = archiveFile.LastWriteTime.ToFileTime(); break; case ItemPropId.kpidSize: value.VarType = VarEnum.VT_UI8; value.longValue = archiveFile.Length; break; } return 0; }
private static extern int PropVariantClear(ref PropVariant pvar);