/// <summary> /// Opens an UCOMIStream and returns the associated file object /// </summary> /// <param name="parentStorage">storage used to open the stream</param> /// <param name="fileName">filename of the stream</param> /// <returns>A <see cref="FileObject">FileObject</see> instance if the file was found, otherwise null.</returns> public FileObject OpenUCOMStream(Interop.IStorage parentStorage, string fileName) { if (parentStorage == null) { parentStorage = storage; } FileObject retObject = null; STATSTG sTATSTG; sTATSTG.pwcsName = fileName; sTATSTG.type = 2; try { retObject = new FileObject(); UCOMIStream uCOMIStream = parentStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0); if (uCOMIStream != null) { retObject.FileType = sTATSTG.type; retObject.FilePath = ""; retObject.FileName = sTATSTG.pwcsName.ToString(); retObject.FileStream = uCOMIStream; } else { retObject = null; } } catch (Exception ex) { retObject = null; Debug.WriteLine("ITStorageWrapper.OpenUCOMStream() - Failed for file '" + fileName + "'"); Debug.Indent(); Debug.WriteLine("Exception: " + ex.Message); Debug.Unindent(); } return(retObject); }
private void LoadCatalog() { IStorageWrapper wrapper = new IStorageWrapper(_thumbDBFile, false); FileObject fileObject = wrapper.OpenUCOMStream(null, "Catalog"); String textData = String.Empty; if (fileObject != null) { Byte[] fileData = new Byte[fileObject.Length]; fileObject.Read(fileData, 0, (int)fileObject.Length); MemoryStream ms = new MemoryStream(fileData); BinaryReader br = new BinaryReader(ms); CatalogHeader ch = new CatalogHeader(); ch.num1 = br.ReadInt16(); ch.num2 = br.ReadInt16(); ch.thumbCount = br.ReadInt32(); ch.thumbWidth = br.ReadInt32(); ch.thumbHeight = br.ReadInt32(); for (int index = 0; index < ch.thumbCount; index++) { CatalogItem item = new CatalogItem(); item.num1 = br.ReadInt32(); item.itemID = br.ReadInt32(); item.num3 = br.ReadInt16(); item.num4 = br.ReadInt16(); item.num5 = br.ReadInt16(); item.num6 = br.ReadInt16(); ushort usChar; while ((usChar = br.ReadUInt16()) != 0x0000) { byte[] aChar = new byte[2]; aChar[0] = (byte)(usChar & 0x00FF); aChar[1] = (byte)((usChar & 0xFF00) >> 8); item.filename += Encoding.Unicode.GetString(aChar); } item.num7 = br.ReadInt16(); _catalogItems.Add(item); } } }
/// <summary> /// Opens an UCOMIStream and returns the associated file object /// </summary> /// <param name="parentStorage">storage used to open the stream</param> /// <param name="fileName">filename of the stream</param> /// <returns>A <see cref="FileObject">FileObject</see> instance if the file was found, otherwise null.</returns> public FileObject OpenUCOMStream(Interop.IStorage parentStorage, string fileName) { if(parentStorage == null) parentStorage = storage; FileObject retObject = null; STATSTG sTATSTG; sTATSTG.pwcsName = fileName; sTATSTG.type = 2; try { retObject = new FileObject(); UCOMIStream uCOMIStream = parentStorage.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0); if(uCOMIStream != null) { retObject.FileType = sTATSTG.type; retObject.FilePath = ""; retObject.FileName = sTATSTG.pwcsName.ToString(); retObject.FileStream = uCOMIStream; } else { retObject = null; } } catch(Exception ex) { retObject = null; Debug.WriteLine("ITStorageWrapper.OpenUCOMStream() - Failed for file '" + fileName + "'"); Debug.Indent(); Debug.WriteLine("Exception: " + ex.Message); Debug.Unindent(); } return retObject; }
/// <summary> /// Enumerates an Interop.IStorage object and creates the internal file object collection /// </summary> /// <param name="stgEnum">Interop.IStorage to enumerate</param> /// <param name="BasePath">Sets the base url for the storage files</param> protected void EnumIStorageObject(Interop.IStorage stgEnum, string BasePath) { Interop.IEnumSTATSTG iEnumSTATSTG; STATSTG sTATSTG; int i; stgEnum.EnumElements(0, IntPtr.Zero, 0, out iEnumSTATSTG); iEnumSTATSTG.Reset(); while (iEnumSTATSTG.Next(1, out sTATSTG, out i) == (int)Interop.S_OK) { if(i==0) break; FileObject newFileObj = new FileObject(); newFileObj.FileType = sTATSTG.type; switch (sTATSTG.type) { case 1: Interop.IStorage iStorage = stgEnum.OpenStorage(sTATSTG.pwcsName, IntPtr.Zero, 16, IntPtr.Zero, 0); if (iStorage != null) { string str = String.Concat(BasePath, sTATSTG.pwcsName.ToString()); newFileObj.FileStorage = iStorage; newFileObj.FilePath = BasePath; newFileObj.FileName = sTATSTG.pwcsName.ToString(); foCollection.Add(newFileObj); EnumIStorageObject(iStorage, str); } break; case 2: UCOMIStream uCOMIStream = stgEnum.OpenStream(sTATSTG.pwcsName, IntPtr.Zero, 16, 0); newFileObj.FilePath = BasePath; newFileObj.FileName = sTATSTG.pwcsName.ToString(); newFileObj.FileStream = uCOMIStream; foCollection.Add(newFileObj); break; case 4: Debug.WriteLine("Ignoring IProperty type ..."); break; case 3: Debug.WriteLine("Ignoring ILockBytes type ..."); break; default: Debug.WriteLine("Unknown object type ..."); break; } } }
/// <summary> /// Adds a new file object to the collection /// </summary> /// <param name="fo">file object instance to add</param> public void Add(FileObject fo) { base.List.Add(fo); }