Exemplo n.º 1
0
        public void AllEntries_List()
        {
            using (Stream stream = File.OpenRead("TestAssets/hfsp.cdr"))
                using (HfsPlusFileSystem hfs = new HfsPlusFileSystem(stream))
                {
                    var dir = hfs.GetDirectoryInfo("\\");

                    Assert.Collection(
                        dir.GetFileSystemInfos(),
                        e =>
                    {
                        var dir = Assert.IsType <DiscFileSystemInfo>(e);
                        Assert.Equal(".HFS+ Private Directory Data\r", dir.Name);
                    },
                        e =>
                    {
                        var file = Assert.IsType <DiscFileSystemInfo>(e);
                        Assert.Equal("hello.txt", file.Name);
                    },
                        e =>
                    {
                        var file = Assert.IsType <DiscFileSystemInfo>(e);
                        Assert.Equal("System", file.Name);
                    },
                        e =>
                    {
                        var dir = Assert.IsType <DiscFileSystemInfo>(e);
                        Assert.Equal("\0\0\0\0HFS+ Private Data", dir.Name);
                    });
                }
        }
Exemplo n.º 2
0
        protected override void DoRun()
        {
            using (var disk = VirtualDisk.OpenDisk(_dmg.Value, FileAccess.Read))
            {
                // Find the first (and supposedly, only, HFS partition)

                foreach (var volume in VolumeManager.GetPhysicalVolumes(disk))
                {
                    foreach (var fileSystem in FileSystemManager.DetectFileSystems(volume))
                    {
                        if (fileSystem.Name == "HFS+")
                        {
                            using (HfsPlusFileSystem hfs = (HfsPlusFileSystem)fileSystem.Open(volume))
                            {
                                var source = hfs.GetDirectoryInfo(_folder.Value);
                                var target = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, source.Name));

                                if (target.Exists)
                                {
                                    target.Delete(true);
                                }

                                target.Create();

                                CopyDirectory(source, target, _recursive.IsPresent);
                            }
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
 public void GetUnixFileInfo_MissingFile_Throws()
 {
     using (var stream = File.OpenRead("TestAssets/hfsp.cdr"))
         using (var hfs = new HfsPlusFileSystem(stream))
         {
             Assert.Throws <FileNotFoundException>(() => hfs.GetUnixFileInfo(@"\test\invalid"));
         }
 }
Exemplo n.º 4
0
 public void GetEntryByName_ReturnsEntry()
 {
     using (Stream stream = File.OpenRead("TestAssets/hfsp.cdr"))
         using (HfsPlusFileSystem hfs = new HfsPlusFileSystem(stream))
         {
             var file = hfs.GetFileInfo("\\hello.txt");
             Assert.Equal(14, file.Length);
         }
 }
Exemplo n.º 5
0
        public void CommonProperties_Work()
        {
            using (var stream = File.OpenRead("TestAssets/hfsp.cdr"))
                using (var hfs = new HfsPlusFileSystem(stream))
                {
                    Assert.Equal("Apple HFS+", hfs.FriendlyName);
                    Assert.Equal("Volume Name", hfs.VolumeLabel);
                    Assert.False(hfs.CanWrite);

                    Assert.Throws <NotSupportedException>(() => hfs.Size);
                    Assert.Throws <NotSupportedException>(() => hfs.UsedSpace);
                    Assert.Throws <NotSupportedException>(() => hfs.AvailableSpace);
                }
        }
Exemplo n.º 6
0
        public void ReadHfsPlusFilesystemTest()
        {
            using (Stream stream = File.OpenRead("TestAssets/hfsp.cdr"))
                using (HfsPlusFileSystem hfs = new HfsPlusFileSystem(stream))
                {
                    Assert.True(hfs.FileExists("hello.txt"));

                    using (Stream helloStream = hfs.OpenFile("hello.txt", FileMode.Open, FileAccess.Read))
                        using (MemoryStream copyStream = new MemoryStream())
                        {
                            Assert.NotEqual(0, helloStream.Length);
                            helloStream.CopyTo(copyStream);
                            Assert.Equal(helloStream.Length, copyStream.Length);

                            Assert.Equal("Hello, World!\n", Encoding.UTF8.GetString(copyStream.ToArray()));
                        }
                }
        }
Exemplo n.º 7
0
        protected override void DoRun()
        {
            using (var disk = VirtualDisk.OpenDisk(_dmg.Value, FileAccess.Read))
                using (HfsPlusFileSystem hfs = new HfsPlusFileSystem(disk.Partitions[3].Open()))
                {
                    var source = hfs.GetDirectoryInfo(_folder.Value);
                    var target = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, source.Name));

                    if (target.Exists)
                    {
                        target.Delete(true);
                    }

                    target.Create();

                    CopyDirectory(source, target, _recursive.IsPresent);
                }
        }
Exemplo n.º 8
0
        public void GetUnixFileInfo_ReturnsInfo()
        {
            using (var stream = File.OpenRead("TestAssets/hfsp.cdr"))
                using (var hfs = new HfsPlusFileSystem(stream))
                {
                    var fileInfo = hfs.GetFileInfo("hello.txt");

                    Assert.Equal((FileAttributes)0, fileInfo.Attributes);
                    Assert.True(fileInfo.CreationTimeUtc > new DateTime(2021, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));
                    Assert.Equal("\\", fileInfo.DirectoryName);
                    Assert.True(fileInfo.Exists);
                    Assert.Equal("txt", fileInfo.Extension);
                    Assert.Same(hfs, fileInfo.FileSystem);
                    Assert.Equal("hello.txt", fileInfo.FullName);
                    Assert.False(fileInfo.IsReadOnly);
                    Assert.True(fileInfo.LastAccessTimeUtc > new DateTime(2021, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));
                    Assert.True(fileInfo.LastWriteTimeUtc > new DateTime(2021, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc));
                    Assert.Equal(0xe, fileInfo.Length);
                    Assert.Equal("hello.txt", fileInfo.Name);
                    Assert.NotNull(fileInfo.Parent);
                }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Gets a <see cref="SystemVersion"/> object with additional information about the developer
        /// disk image.
        /// </summary>
        /// <param name="developerDiskImageStream">
        /// A <see cref="Stream"/> which represents the developer disk image.
        /// </param>
        /// <returns>
        /// A <see cref="SystemVersion"/> object with additional information about the developer
        /// disk image.
        /// </returns>
        public static (SystemVersion, DateTimeOffset) GetVersionInformation(Stream developerDiskImageStream)
        {
            using (var disk = new Disk(developerDiskImageStream, Ownership.None))
            {
                // Find the first (and supposedly, only, HFS partition)
                var volumes = VolumeManager.GetPhysicalVolumes(disk);

                if (volumes.Length != 1)
                {
                    throw new InvalidDataException($"The developer disk should contain exactly one volume");
                }

                using (var volumeStream = volumes[0].Open())
                    using (var hfs = new HfsPlusFileSystem(volumeStream))
                    {
                        if (hfs.FileExists(SystemVersionPath))
                        {
                            using (Stream systemVersionStream = hfs.OpenFile(SystemVersionPath, FileMode.Open, FileAccess.Read))
                            {
                                var           dict  = (NSDictionary)PropertyListParser.Parse(systemVersionStream);
                                SystemVersion plist = new SystemVersion();
                                plist.FromDictionary(dict);

                                if (plist.ProductName != "iPhone OS")
                                {
                                    throw new InvalidDataException("The developer disk does not target iOS");
                                }

                                return(plist, hfs.Root.CreationTimeUtc);
                            }
                        }
                    }

                throw new InvalidDataException($"The file does not contain any HFS+ parition. Is it a valid developer disk image?");
            }
        }