private void OpenStream(IStorage parentStorage, ref FileAccess access) { ShellAPI.STGM grfmode = ShellAPI.STGM.SHARE_DENY_WRITE; switch (access) { case FileAccess.ReadWrite: grfmode |= ShellAPI.STGM.READWRITE; break; case FileAccess.Write: grfmode |= ShellAPI.STGM.WRITE; break; } if (parentStorage != null) { if (parentStorage.OpenStream( shellItem.Text + (shellItem.IsLink ? ".lnk" : string.Empty), IntPtr.Zero, grfmode, 0, out streamPtr) == ShellAPI.S_OK) { stream = (IStream)Marshal.GetTypedObjectForIUnknown(streamPtr, typeof(IStream)); } else if (access != FileAccess.Read) { if (parentStorage.OpenStream( shellItem.Text + (shellItem.IsLink ? ".lnk" : string.Empty), IntPtr.Zero, ShellAPI.STGM.SHARE_DENY_WRITE, 0, out streamPtr) == ShellAPI.S_OK) { access = FileAccess.Read; stream = (IStream)Marshal.GetTypedObjectForIUnknown(streamPtr, typeof(IStream)); } else { throw new IOException(String.Format("Can't open stream: {0}", shellItem)); } } else { throw new IOException(String.Format("Can't open stream: {0}", shellItem)); } } else { access = FileAccess.Read; if (!ShellHelper.GetIStream(shellItem, out streamPtr, out stream)) { throw new IOException(String.Format("Can't open stream: {0}", shellItem)); } } }
public int OpenStorage(string pwcsName, IStorage pstgPriority, ShellAPI.STGM grfMode, IntPtr snbExclude, int reserved, out IntPtr ppstg) { return(_iStorage.OpenStorage(pwcsName, pstgPriority, grfMode, snbExclude, reserved, out ppstg)); }
public int CreateStorage(string pwcsName, ShellAPI.STGM grfMode, int reserved1, int reserved2, out IntPtr ppstg) { return(_iStorage.CreateStorage(pwcsName, grfMode, reserved1, reserved2, out ppstg)); }
public int OpenStream(string pwcsName, IntPtr reserved1, ShellAPI.STGM grfMode, int reserved2, out IntPtr ppstm) { return(_iStorage.OpenStream(pwcsName, reserved1, grfMode, reserved2, out ppstm)); }
/// <summary> /// Open a file stream, used by FileStreamEx /// </summary> internal static void openStream(IStorage parentStorage, string filename, ref FileMode mode, ref FileAccess access, out IntPtr streamPtr, out IStream stream) { ShellAPI.STGM grfmode = ShellAPI.STGM.SHARE_DENY_WRITE; switch (access) { case FileAccess.ReadWrite: grfmode |= ShellAPI.STGM.READWRITE; break; case FileAccess.Write: grfmode |= ShellAPI.STGM.WRITE; break; } switch (mode) { case FileMode.Create: if (FileEx.Exists(filename)) { grfmode |= ShellAPI.STGM.CREATE; } break; case FileMode.CreateNew: grfmode |= ShellAPI.STGM.CREATE; break; } if (parentStorage != null) { if (parentStorage.OpenStream( filename, IntPtr.Zero, grfmode, 0, out streamPtr) == ShellAPI.S_OK) { stream = (IStream)Marshal.GetTypedObjectForIUnknown(streamPtr, typeof(IStream)); } else if (access != FileAccess.Read) { //Create file if not exists if (parentStorage.CreateStream( filename, ShellAPI.STGM.WRITE, 0, 0, out streamPtr) == ShellAPI.S_OK) { stream = (IStream)Marshal.GetTypedObjectForIUnknown(streamPtr, typeof(IStream)); } else { throw new IOException(String.Format("Can't open stream: {0}", filename)); } } else { throw new IOException(String.Format("Can't open stream: {0}", filename)); } } else { throw new IOException(String.Format("Can't open stream: {0}", filename)); } }