Example #1
0
        public void FileSystemInfo()
        {
            FatFileSystem      fs = FatFileSystem.FormatFloppy(new MemoryStream(), FloppyDiskType.HighDensity, "FLOPPY_IMG ");
            DiscFileSystemInfo fi = fs.GetFileSystemInfo(@"SOMEDIR\SOMEFILE");

            Assert.IsNotNull(fi);
        }
Example #2
0
        protected override void RenameItem(string path, string newName)
        {
            object obj = FindItemByPath(Utilities.NormalizePath(path), true, false);

            DiscFileSystemInfo fsiObj = obj as DiscFileSystemInfo;

            if (fsiObj == null)
            {
                WriteError(new ErrorRecord(
                               new InvalidOperationException("Cannot move items to this location"),
                               "BadParentForNewItem",
                               ErrorCategory.InvalidArgument,
                               newName));
                return;
            }

            string newFullName = Path.Combine(Path.GetDirectoryName(fsiObj.FullName.TrimEnd('\\')), newName);

            if (obj is DiscDirectoryInfo)
            {
                DiscDirectoryInfo dirObj = (DiscDirectoryInfo)obj;
                dirObj.MoveTo(newFullName);
            }
            else
            {
                DiscFileInfo fileObj = (DiscFileInfo)obj;
                fileObj.MoveTo(newFullName);
            }
        }
Example #3
0
        public void FileSystemInfo()
        {
            CDBuilder          builder = new CDBuilder();
            CDReader           fs      = new CDReader(builder.Build(), false);
            DiscFileSystemInfo fi      = fs.GetFileSystemInfo(@"SOMEDIR\SOMEFILE");

            Assert.NotNull(fi);
        }
Example #4
0
        public static string Mode(PSObject instance)
        {
            if (instance == null)
            {
                return("");
            }

            DiscFileSystemInfo fsi = instance.BaseObject as DiscFileSystemInfo;

            if (fsi == null)
            {
                return("");
            }

            StringBuilder result = new StringBuilder(5);

            result.Append(((fsi.Attributes & FileAttributes.Directory) != 0) ? "d" : "-");
            result.Append(((fsi.Attributes & FileAttributes.Archive) != 0) ? "a" : "-");
            result.Append(((fsi.Attributes & FileAttributes.ReadOnly) != 0) ? "r" : "-");
            result.Append(((fsi.Attributes & FileAttributes.Hidden) != 0) ? "h" : "-");
            result.Append(((fsi.Attributes & FileAttributes.System) != 0) ? "s" : "-");
            return(result.ToString());
        }
Example #5
0
        protected override void NewItem(string path, string itemTypeName, object newItemValue)
        {
            string parentPath = GetParentPath(path, null);

            if (string.IsNullOrEmpty(itemTypeName))
            {
                WriteError(new ErrorRecord(
                               new InvalidOperationException("No type specified.  Specify \"file\" or \"directory\" as the type."),
                               "NoTypeForNewItem",
                               ErrorCategory.InvalidArgument,
                               itemTypeName));
                return;
            }
            string itemTypeUpper = itemTypeName.ToUpperInvariant();


            object obj = FindItemByPath(Utilities.NormalizePath(parentPath), true, false);

            if (obj is DiscDirectoryInfo)
            {
                DiscDirectoryInfo dirInfo = (DiscDirectoryInfo)obj;
                if (itemTypeUpper == "FILE")
                {
                    using (dirInfo.FileSystem.OpenFile(Path.Combine(dirInfo.FullName, GetChildName(path)), FileMode.Create)) { }
                }
                else if (itemTypeUpper == "DIRECTORY")
                {
                    dirInfo.FileSystem.CreateDirectory(Path.Combine(dirInfo.FullName, GetChildName(path)));
                }
                else if (itemTypeUpper == "HARDLINK")
                {
                    NtfsFileSystem ntfs = dirInfo.FileSystem as NtfsFileSystem;

                    if (ntfs != null)
                    {
                        NewHardLinkDynamicParameters hlParams = (NewHardLinkDynamicParameters)DynamicParameters;

                        var srcItems = SessionState.InvokeProvider.Item.Get(hlParams.SourcePath);
                        if (srcItems.Count != 1)
                        {
                            WriteError(new ErrorRecord(
                                           new InvalidOperationException("The type is unknown for this provider.  Only \"file\" and \"directory\" can be specified."),
                                           "UnknownTypeForNewItem",
                                           ErrorCategory.InvalidArgument,
                                           itemTypeName));
                            return;
                        }

                        DiscFileSystemInfo srcFsi = srcItems[0].BaseObject as DiscFileSystemInfo;

                        ntfs.CreateHardLink(srcFsi.FullName, Path.Combine(dirInfo.FullName, GetChildName(path)));
                    }
                }
                else
                {
                    WriteError(new ErrorRecord(
                                   new InvalidOperationException("The type is unknown for this provider.  Only \"file\" and \"directory\" can be specified."),
                                   "UnknownTypeForNewItem",
                                   ErrorCategory.InvalidArgument,
                                   itemTypeName));
                    return;
                }
            }
            else
            {
                WriteError(new ErrorRecord(
                               new InvalidOperationException("Cannot create items in an object of this type: " + (obj != null ? obj.GetType() : null)),
                               "UnknownObjectTypeForNewItemParent",
                               ErrorCategory.InvalidOperation,
                               obj));
                return;
            }
        }