public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string pathName = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: pathName = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: pathName = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { return(AfpResultCode.FPObjectNotFound); } IStorageItem deleteItem = null; if (!string.IsNullOrEmpty(pathName)) { deleteItem = container.Content(pathName); } if (deleteItem == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer deleteContainer = (deleteItem as IStorageContainer); if (deleteContainer != null && deleteContainer.Contents().Count() > 0) { return(AfpResultCode.FPDirNotEmpty); } deleteItem.Delete(); return(AfpResultCode.FPNoErr); }
public void WriteStorageContainerInfo(IAfpVolume volume, IStorageContainer container, AfpFileDirectoryBitmap bitmap) { this.WriteUInt8(1 << 7); while ((this.Stream.Length % 2) != 0) { this.WriteUInt8(0); } this.BeginMarking(); foreach (AfpFileDirectoryBitmap flag in bitmap.EnumerateFlags()) { switch (flag) { case AfpFileDirectoryBitmap.kFPAttributeBit: AfpFileDirectoryAttributes attrs = 0; if ((container.Attributes & StorageItemAttributes.Hidden) != 0) { attrs |= AfpFileDirectoryAttributes.kFPInvisibleBit; } this.WriteEnum <AfpFileDirectoryAttributes>(attrs); break; case AfpFileDirectoryBitmap.kFPParentDirIDBit: if (container.Parent == null) { this.WriteUInt32(1); } else if (container.Parent is IStorageProvider) { this.WriteUInt32(2); } else { this.WriteUInt32(volume.GetNode(container.Parent)); } break; case AfpFileDirectoryBitmap.kFPOffspringCountBit: this.WriteUInt16((ushort)container.Contents().Count()); break; case AfpFileDirectoryBitmap.kFPCreateDateBit: this.WriteMacintoshDate(container.DateCreated); break; case AfpFileDirectoryBitmap.kFPModDateBit: this.WriteMacintoshDate(container.DateModified); break; case AfpFileDirectoryBitmap.kFPBackupDateBit: this.WriteUInt32(0x80000000); break; case AfpFileDirectoryBitmap.kFPFinderInfoBit: this.WriteBytes(new byte[32]); break; case AfpFileDirectoryBitmap.kFPLongNameBit: this.WriteMark("LongName"); break; case AfpFileDirectoryBitmap.kFPShortNameBit: this.WriteMark("ShortName"); break; case AfpFileDirectoryBitmap.kFPUTF8NameBit: this.WriteMark("UTF8Name"); this.WriteBytes(new byte[4]); break; case AfpFileDirectoryBitmap.kFPNodeIDBit: if (container is IStorageProvider) { this.WriteUInt32(2); } else { this.WriteUInt32(volume.GetNode(container)); } break; case AfpFileDirectoryBitmap.kFPOwnerIDBit: this.WriteUInt32(0); break; case AfpFileDirectoryBitmap.kFPGroupIDBit: this.WriteUInt32(0); break; case AfpFileDirectoryBitmap.kFPAccessRightsBit: this.WriteEnum <AfpAccessRightsBitmap>(AfpAccessRightsBitmap.All); break; default: Console.WriteLine("Unrecog flag: {0}", flag); break; } } //this.WriteUInt32(0); // Pad foreach (AfpFileDirectoryBitmap flag in bitmap.EnumerateFlags()) { switch (flag) { case AfpFileDirectoryBitmap.kFPLongNameBit: this.BeginMark("LongName"); this.WritePascalString(container.Name, 32); break; case AfpFileDirectoryBitmap.kFPShortNameBit: this.BeginMark("ShortName"); this.WritePascalString(container.Name, 12); break; case AfpFileDirectoryBitmap.kFPUTF8NameBit: this.BeginMark("UTF8Name"); this.WriteUTF8StringWithHint(container.Name); break; } } this.EndMarking(); }
public AfpResultCode Process(IAfpSession session, DsiHeader dsiHeader, AfpStream requestStream, AfpStream responseStream) { requestStream.ReadUInt8(); // Padding ushort volumeId = requestStream.ReadUInt16(); uint directoryId = requestStream.ReadUInt32(); AfpFileDirectoryBitmap fileBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>(); AfpFileDirectoryBitmap directoryBitmap = requestStream.ReadEnum <AfpFileDirectoryBitmap>(); short reqCount = requestStream.ReadInt16(); int startIndex = requestStream.ReadInt32(); int maxReplySize = requestStream.ReadInt32(); AfpPathType pathType = requestStream.ReadEnum <AfpPathType>(); string path = null; switch (pathType) { case AfpPathType.kFPLongName: case AfpPathType.kFPShortName: path = requestStream.ReadPascalString(); break; case AfpPathType.kFPUTF8Name: path = requestStream.ReadUTF8StringWithHint(); break; } IAfpVolume volume = session.GetVolume(volumeId); if (volume == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer container = null; if (directoryId == 2) { container = volume.StorageProvider; } else { container = (volume.GetNode(directoryId) as IStorageContainer); } if (container == null) { return(AfpResultCode.FPObjectNotFound); } IStorageContainer lookAtContainer = null; if (string.IsNullOrEmpty(path)) { lookAtContainer = container; } else { lookAtContainer = (container.Content(path) as IStorageContainer); } if (lookAtContainer == null) { return(AfpResultCode.FPObjectNotFound); } var useContents = lookAtContainer.Contents(); if (fileBitmap == 0) { useContents = useContents.OfType <IStorageContainer>(); } else if (directoryBitmap == 0) { useContents = useContents.OfType <IStorageFile>(); } useContents = useContents .Skip(startIndex - 1) .Take(reqCount); var contents = useContents.ToList(); if (contents.Count == 0) { return(AfpResultCode.FPObjectNotFound); } responseStream.WriteEnum <AfpFileDirectoryBitmap>(fileBitmap); responseStream.WriteEnum <AfpFileDirectoryBitmap>(directoryBitmap); responseStream.WriteInt16((short)contents.Count); foreach (IStorageItem item in contents) { AfpStream resultRecord = new AfpStream(); resultRecord.WriteUInt16(0); // Length if (item is IStorageContainer) { resultRecord.WriteStorageContainerInfo(volume, (IStorageContainer)item, directoryBitmap); } else { resultRecord.WriteStorageFileInfo(volume, (IStorageFile)item, fileBitmap); } resultRecord.WritePadding(); resultRecord.Stream.Position = 0; resultRecord.WriteUInt16((byte)resultRecord.Stream.Length); byte[] recordData = resultRecord.ToByteArray(); responseStream.WriteBytes(recordData); } return(AfpResultCode.FPNoErr); }