Ejemplo n.º 1
0
 internal DiscFileSystemInfo(DiscFileSystem fileSystem, string path)
 {
     if (path == null)
     {
         throw new ArgumentNullException("path");
     }
     _fileSystem = fileSystem;
     _path = path.Trim('\\');
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new virtual disk, possibly within an existing disk.
        /// </summary>
        /// <param name="fileSystem">The file system to create the disk on.</param>
        /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>).</param>
        /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>).</param>
        /// <param name="path">The path (or URI) for the disk to create.</param>
        /// <param name="capacity">The capacity of the new disk.</param>
        /// <param name="geometry">The geometry of the new disk (or null).</param>
        /// <param name="parameters">Untyped parameters controlling the creation process (TBD).</param>
        /// <returns>The newly created disk.</returns>
        public static VirtualDisk CreateDisk(DiscFileSystem fileSystem, string type, string variant, string path, long capacity, Geometry geometry, Dictionary<string, string> parameters)
        {
            VirtualDiskFactory factory = TypeMap[type];

            VirtualDiskParameters diskParams = new VirtualDiskParameters()
            {
                AdapterType = GenericDiskAdapterType.Scsi,
                Capacity = capacity,
                Geometry = geometry,
            };

            if (parameters != null)
            {
                foreach (var key in parameters.Keys)
                {
                    diskParams.ExtendedParameters[key] = parameters[key];
                }
            }

            return factory.CreateDisk(new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)), variant.ToLowerInvariant(), Utilities.GetFileFromPath(path), diskParams);
        }
        public void Equals(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            Assert.AreEqual(fs.GetFileInfo("foo.txt"), fs.GetFileInfo("foo.txt"));
        }
        public void Delete_NoFile(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            fs.GetFileInfo("foo.txt").Delete();
        }
        public void DeleteRoot(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            fs.Root.Delete();
        }
Ejemplo n.º 6
0
        //        private static WellKnownPartitionType GetPartitionType(PartitionInfo Partition)
        //        {
        //            switch (Partition.BiosType)
        //            {
        //                case BiosPartitionTypes.Fat16:
        //                case BiosPartitionTypes.Fat32:
        //                case BiosPartitionTypes.Fat32Lba:
        //                    return WellKnownPartitionType.WindowsFat;
        //                case BiosPartitionTypes.Ntfs:
        //                    return WellKnownPartitionType.WindowsNtfs;
        //                case BiosPartitionTypes.LinuxNative:
        //                    return WellKnownPartitionType.Linux;
        //                case BiosPartitionTypes.LinuxSwap:
        //                    return WellKnownPartitionType.LinuxSwap;
        //                case BiosPartitionTypes.LinuxLvm:
        //                    return WellKnownPartitionType.LinuxLvm;
        //                default:
        //                    throw new ArgumentException(
        //                        String.Format("Unsupported partition type: '{0}'", BiosPartitionTypes.ToString(Partition.BiosType)), "Partition");
        //            }
        //        }
        //
        //        private static DiscFileSystem DetectFileSystem(PartitionInfo Partition)
        //        {
        //            using (var stream = Partition.Open())
        //            {
        //                if (NtfsFileSystem.Detect(stream))
        //                    return new NtfsFileSystem(Partition.Open());
        //                stream.Seek(0, SeekOrigin.Begin);
        //                if (FatFileSystem.Detect(stream))
        //                    return new FatFileSystem(Partition.Open());
        //
        //                /* Ext2/3/4 file system - when Ext becomes fully writable
        //                
        //                stream.Seek(0, SeekOrigin.Begin);
        //                if (ExtFileSystem.Detect(stream))
        //                    return new ExtFileSystem(Partition.Open());
        //                */
        //
        //                return null;
        //            }
        //        }
        private static void DiffPart(DiscFileSystem PartA, DiscFileSystem PartB, DiscFileSystem Output, ComparisonStyle Style = ComparisonStyle.DateTimeOnly, CopyQueue WriteQueue = null)
        {
            if (PartA == null) throw new ArgumentNullException("PartA");
            if (PartB == null) throw new ArgumentNullException("PartB");
            if (Output == null) throw new ArgumentNullException("Output");

            if (PartA is NtfsFileSystem)
            {
                ((NtfsFileSystem) PartA).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem) PartA).NtfsOptions.HideSystemFiles = false;
            }
            if (PartB is NtfsFileSystem)
            {
                ((NtfsFileSystem) PartB).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem) PartB).NtfsOptions.HideSystemFiles = false;
            }
            if (Output is NtfsFileSystem)
            {
                ((NtfsFileSystem) Output).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem) Output).NtfsOptions.HideSystemFiles = false;
            }

            if (WriteQueue == null) WriteQueue = new CopyQueue();

            var RootA = PartA.Root;
            var RootB = PartB.Root;
            var OutRoot = Output.Root;
            var OutFileRoot = Output.GetDirectoryInfo(RootFiles);
            if (!OutFileRoot.Exists) OutFileRoot.Create();

            CompareTree(RootA, RootB, OutFileRoot, WriteQueue, Style);

            WriteQueue.Go();

            // Now handle registry files (if any)
            ParallelQuery<DiscFileInfo> Ofiles;
            lock(OutFileRoot.FileSystem)
                Ofiles = OutFileRoot.GetFiles("*.*", SearchOption.AllDirectories).AsParallel();
            Ofiles = Ofiles.Where(dfi =>
                                    SystemRegistryFiles.Contains(dfi.FullName, StringComparer.CurrentCultureIgnoreCase));

            foreach (var file in Ofiles)
            {
                var A = PartA.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1));
                if (!A.Exists)
                {
                    file.FileSystem.MoveFile(file.FullName, String.Concat(RootSystemRegistry, A.FullName));
                    continue;
                }
                //else
                MemoryStream SideA = new MemoryStream();
                using (var tmp = A.OpenRead()) tmp.CopyTo(SideA);
                MemoryStream SideB = new MemoryStream();
                using (var tmp = file.OpenRead()) tmp.CopyTo(SideB);
                var comp = new RegistryComparison(SideA, SideB, RegistryComparison.Side.B);
                comp.DoCompare();
                var diff = new RegDiff(comp, RegistryComparison.Side.B);
                var outFile = Output.GetFileInfo(Path.Combine(RootSystemRegistry, file.FullName));
                if (!outFile.Directory.Exists)
                {
                    outFile.Directory.Create();
                }
                using (var OUT = outFile.Open(outFile.Exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.ReadWrite))
                    diff.WriteToStream(OUT);
                file.Delete(); // remove this file from the set of file to copy and overwrite
            }

            lock (OutFileRoot.FileSystem)
                Ofiles = OutFileRoot.GetFiles("*.*", SearchOption.AllDirectories).AsParallel();
            Ofiles = Ofiles.Where(dfi => UserRegisrtyFiles.IsMatch(dfi.FullName));

            foreach (var file in Ofiles)
            {
                var match = UserRegisrtyFiles.Match(file.FullName);
                var A = PartA.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1));
                if (!A.Exists)
                {
                    file.FileSystem.MoveFile(file.FullName,
                                                Path.Combine(RootUserRegistry, match.Groups["user"].Value, A.Name));
                    continue;
                }
                //else
                MemoryStream SideA = new MemoryStream();
                using (var tmp = A.OpenRead()) tmp.CopyTo(SideA);
                MemoryStream SideB = new MemoryStream();
                using (var tmp = file.OpenRead()) tmp.CopyTo(SideB);
                var comp = new RegistryComparison(SideA, SideB, RegistryComparison.Side.B);
                comp.DoCompare();
                var diff = new RegDiff(comp, RegistryComparison.Side.B);
                var outFile =
                    Output.GetFileInfo(Path.Combine(RootUserRegistry, match.Groups["user"].Value, file.FullName));
                if (!outFile.Directory.Exists)
                {
                    outFile.Directory.Create();
                }
                using (var OUT = outFile.Open(outFile.Exists ? FileMode.Truncate : FileMode.CreateNew, FileAccess.ReadWrite))
                    diff.WriteToStream(OUT);
                file.Delete(); // remove this file from the set of file to copy and overwrite
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Create a new differencing disk, possibly within an existing disk.
 /// </summary>
 /// <param name="fileSystem">The file system to create the disk on.</param>
 /// <param name="path">The path (or URI) for the disk to create.</param>
 /// <returns>The newly created disk.</returns>
 public abstract VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path);
Ejemplo n.º 8
0
 public DiscFileLocator(DiscFileSystem fileSystem, string basePath)
 {
     _fileSystem = fileSystem;
     _basePath   = basePath;
 }
Ejemplo n.º 9
0
 internal DiscFileSystemInfo(DiscFileSystem fileSystem, ReaderDirEntry entry)
     : this(fileSystem, entry.Path)
 {
     _entries = entry;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Construction limited to sub classes.
 /// </summary>
 internal DiscDirectoryInfo(DiscFileSystem fileSystem, string path)
     : base(fileSystem, path)
 {
 }
Ejemplo n.º 11
0
 internal DiscFileInfo(DiscFileSystem fileSystem, ReaderDirEntry entry)
     : base(fileSystem, entry)
 {
 }
        public void Parent_Root(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            Assert.IsNull(fs.Root.Parent);
        }
        public void GetDirectories_BadPath(NewFileSystemDelegate fsFactory)
        {
            DiscFileSystem fs = fsFactory();

            fs.GetDirectories(@"\baddir");
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Opens an existing virtual disk, possibly from within an existing disk.
        /// </summary>
        /// <param name="fs">The file system to open the disk on.</param>
        /// <param name="path">The path of the virtual disk to open.</param>
        /// <param name="access">The desired access to the disk.</param>
        /// <returns>The Virtual Disk, or <c>null</c> if an unknown disk format.</returns>
        public static VirtualDisk OpenDisk(DiscFileSystem fs, string path, FileAccess access)
        {
            if (fs == null)
            {
                return OpenDisk(path, access);
            }

            string extension = Path.GetExtension(path).ToUpperInvariant();
            if (extension.StartsWith(".", StringComparison.Ordinal))
            {
                extension = extension.Substring(1);
            }

            VirtualDiskFactory factory;
            if (ExtensionMap.TryGetValue(extension, out factory))
            {
                return factory.OpenDisk(fs, path, access);
            }

            return null;
        }
Ejemplo n.º 15
0
 public VirtualDisk OpenDisk(DiscFileSystem fileSystem, string path, FileAccess access)
 {
     return OpenDisk(new DiscFileLocator(fileSystem, @"\"), path, access);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Create a new differencing disk, possibly within an existing disk.
 /// </summary>
 /// <param name="fileSystem">The file system to create the disk on.</param>
 /// <param name="path">The path (or URI) for the disk to create.</param>
 /// <returns>The newly created disk.</returns>
 public abstract VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path);
Ejemplo n.º 17
0
        /// <summary>
        /// Create a new virtual disk, possibly within an existing disk.
        /// </summary>
        /// <param name="fileSystem">The file system to create the disk on</param>
        /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>)</param>
        /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>)</param>
        /// <param name="path">The path (or URI) for the disk to create</param>
        /// <param name="capacity">The capacity of the new disk</param>
        /// <param name="geometry">The geometry of the new disk (or null).</param>
        /// <param name="parameters">Untyped parameters controlling the creation process (TBD)</param>
        /// <returns>The newly created disk</returns>
        public static VirtualDisk CreateDisk(DiscFileSystem fileSystem, string type, string variant, string path, long capacity, Geometry geometry, Dictionary <string, string> parameters)
        {
            VirtualDiskFactory factory = TypeMap[type];

            return(factory.CreateDisk(new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)), variant.ToLowerInvariant(), Utilities.GetFileFromPath(path), capacity, geometry, parameters ?? new Dictionary <string, string>()));
        }
Ejemplo n.º 18
0
 public override VirtualDisk CreateDifferencingDisk(DiscFileSystem fileSystem, string path)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 19
0
 public VirtualDisk OpenDisk(DiscFileSystem fileSystem, string path, FileAccess access)
 {
     return(OpenDisk(new DiscFileLocator(fileSystem, @"\"), path, access));
 }
Ejemplo n.º 20
0
 public DiscFileLocator(DiscFileSystem fileSystem, string basePath)
 {
     _fileSystem = fileSystem;
     _basePath = basePath;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Indicates if <paramref name="obj"/> is equivalent to this object.
        /// </summary>
        /// <param name="obj">The object to compare</param>
        /// <returns><c>true</c> if <paramref name="obj"/> is equivalent, else <c>false</c></returns>
        public override bool Equals(object obj)
        {
            DiscFileSystemInfo asInfo = obj as DiscFileSystemInfo;

            if (obj == null)
            {
                return(false);
            }

            return(string.Compare(Path, asInfo.Path, StringComparison.Ordinal) == 0 && DiscFileSystem.Equals(FileSystem, asInfo.FileSystem));
        }
 /// <summary>
 /// Initializes a new instance of the DiscDirectoryInfo class.
 /// </summary>
 /// <param name="fileSystem">The file system the directory info relates to</param>
 /// <param name="path">The path within the file system of the directory</param>
 internal DiscDirectoryInfo(DiscFileSystem fileSystem, string path)
     : base(fileSystem, path)
 {
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Create a new virtual disk, possibly within an existing disk.
 /// </summary>
 /// <param name="fileSystem">The file system to create the disk on</param>
 /// <param name="type">The type of disk to create (see <see cref="SupportedDiskTypes"/>)</param>
 /// <param name="variant">The variant of the type to create (see <see cref="GetSupportedDiskVariants"/>)</param>
 /// <param name="path">The path (or URI) for the disk to create</param>
 /// <param name="capacity">The capacity of the new disk</param>
 /// <param name="geometry">The geometry of the new disk (or null).</param>
 /// <param name="parameters">Untyped parameters controlling the creation process (TBD)</param>
 /// <returns>The newly created disk</returns>
 public static VirtualDisk CreateDisk(DiscFileSystem fileSystem, string type, string variant, string path, long capacity, Geometry geometry, Dictionary<string, string> parameters)
 {
     VirtualDiskFactory factory = TypeMap[type];
     return factory.CreateDisk(new DiscFileLocator(fileSystem, Utilities.GetDirectoryFromPath(path)), variant.ToLowerInvariant(), Utilities.GetFileFromPath(path), capacity, geometry, parameters ?? new Dictionary<string, string>());
 }