protected void initParent() { if (!_parentInited) { if (Exists) { if (FullName.Equals(IOTools.IID_Desktop)) { return; } this.RequestPIDL((pidl) => { //PIDL relPIDL; _parent = new DirectoryInfoEx(getParentPIDL(pidl)); _parentInited = true; }); } else { _parent = new DirectoryInfoEx(PathEx.GetDirectoryName(FullName)); _parentInited = true; } } }
/// <summary> /// Copy directory or file, take full path of source and dest as parameter. /// </summary> public static void Copy(string source, string dest) { DirectoryInfoEx fromDir, toDir; fromDir = new DirectoryInfoEx(PathEx.GetDirectoryName(source)); toDir = new DirectoryInfoEx(PathEx.GetDirectoryName(dest)); if (fromDir.Storage == null) { throw new IOException("Source directory does not support IStorage"); } if (toDir.Storage == null) { throw new IOException("Destination directory does not support IStorage"); } int hr = fromDir.Storage.MoveElementTo(PathEx.GetFileName(source), toDir.Storage, Path.GetFileName(dest), ShellAPI.STGMOVE.COPY); if (hr != ShellAPI.S_OK) { Marshal.ThrowExceptionForHR(hr); } }
protected void initParent() { if (!_parentInited) { if (Exists) { if (FullName.Equals(IOTools.IID_Desktop)) { return; } PIDL relPIDL; _parent = new DirectoryInfoEx(getParentPIDL(PIDL, out relPIDL)); _parentInited = true; relPIDL.Free(); } else { _parent = new DirectoryInfoEx(PathEx.GetDirectoryName(FullName)); _parentInited = true; } } }
protected virtual void init(string file, FileMode mode, FileAccess access) { _fileName = file; string dirPath = PathEx.GetDirectoryName(file); DirectoryInfoEx dir = new DirectoryInfoEx(dirPath); if (dir == null) { throw new IOException(String.Format("Directory not exists: {0}", dirPath)); } if (!IOTools.getIStorage(dir, out tempParentStoragePtr, out tempParentStorage)) { throw new IOException(String.Format("Failed to obtaiin IStorage: {0}", dirPath)); } IOTools.openStream(tempParentStorage, file, ref mode, ref access, out streamPtr, out stream); this._canRead = (access == FileAccess.Read || access == FileAccess.ReadWrite); this._canWrite = (access == FileAccess.Write || access == FileAccess.ReadWrite); currentPos = 0; if (_canRead) { stream.Stat(out streamInfo, ShellAPI.STATFLAG.NONAME); } switch (mode) { case FileMode.Append: Seek(0, SeekOrigin.End); break; case FileMode.CreateNew: break; } }