Exemplo n.º 1
0
        private static Task CompTree(DiscDirectoryInfo A, DiscDirectoryInfo B, DiscDirectoryInfo Out,
                                     CopyQueue WriteQueue, ComparisonStyle Style = ComparisonStyle.DateTimeOnly)

        {
            if (WriteQueue == null)
            {
                throw new ArgumentNullException("WriteQueue");
            }
            List <Task> tasks = new List <Task>();

            DiscFileSystem Alock = A.FileSystem;
            DiscFileSystem Block = B.FileSystem;
            DiscFileSystem Olock = Out.FileSystem;

            ParallelQuery <DiscFileInfo> BFiles;

            lock (Block)
                BFiles = B.GetFiles("*.*", SearchOption.AllDirectories).ToArray().AsParallel();
            BFiles = BFiles.Where(file =>
                                  !ExcludeFiles.Contains(file.FullName.ToUpperInvariant())
                                  ).AsParallel();
            BFiles = ExclusionRules.Aggregate(BFiles, (current, rule) => current.Where(file => !rule.IsMatch(file.FullName)));

            BFiles = BFiles.Where(file =>
            {
                DiscFileInfo Atmp;
                lock (Alock)
                    Atmp = Alock.GetFileInfo(file.FullName);
                return(!CompareFile(Atmp, file, Style));
            }).ToArray().AsParallel();

            foreach (var file in BFiles)
            {
                DiscFileInfo outFile;
                lock (Olock)
                    outFile = Out.FileSystem.GetFileInfo(Path.Combine(Out.FullName, file.FullName));
                WriteQueue.Add(file, outFile);
            }

            return(Task.Factory.StartNew(() => Task.WaitAll(tasks.ToArray()), TaskCreationOptions.AttachedToParent));
        }
Exemplo n.º 2
0
        private static void ApplyPartDiff(PartitionInfo Base, PartitionInfo Diff)
        {
            CopyQueue queue = new CopyQueue();

            var BFS = DetectFileSystem(Base);
            var DFS = DetectFileSystem(Diff);

            if (BFS is NtfsFileSystem)
            {
                ((NtfsFileSystem)BFS).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem)BFS).NtfsOptions.HideSystemFiles = false;
            }
            if (DFS is NtfsFileSystem)
            {
                ((NtfsFileSystem)DFS).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem)DFS).NtfsOptions.HideSystemFiles = false;
            }

            var DRoot = DFS.Root;

            var DFRoots = DRoot.GetDirectories(RootFiles);

            if (DFRoots.Any())
            {
                var DFileRoot = DFRoots.Single();

                foreach (var file in DFileRoot.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    var BFile = BFS.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1));
                    queue.Add(file, BFile);

                    /*
                     * Stream OutStream;
                     * if (BFile.Exists) OutStream = BFile.Open(FileMode.Truncate, FileAccess.ReadWrite);
                     * else
                     * {
                     *  if (!BFile.Directory.Exists)
                     *      BFile.Directory.Create();
                     *  OutStream = BFile.Create();
                     * }
                     * using (var InStream = file.OpenRead())
                     * using (OutStream)
                     *  InStream.CopyTo(OutStream);
                     */
                }
                queue.Go();
            }

            var DsysRegs = DRoot.GetDirectories(RootSystemRegistry);

            if (DsysRegs.Any())
            {
                var DsysReg = DsysRegs.Single();

                foreach (var file in DsysReg.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    var BReg = BFS.GetFileInfo(file.FullName.Substring(RootSystemRegistry.Length + 1));
                    if (!BReg.Exists)
                    {
                        queue.Add(file, BReg);
                    }
                    else
                    {
                        var BHive = new RegistryHive(BReg.Open(FileMode.Open, FileAccess.ReadWrite));
                        RegDiff.ReadFromStream(file.OpenRead()).ApplyTo(BHive.Root);
                    }
                }
                queue.Go();
            }

            var DuserRegs = DRoot.GetDirectories(RootUserRegistry);

            if (DuserRegs.Any())
            {
                var DuserReg = DuserRegs.Single();
                var Bfiles   =
                    BFS.GetFiles(String.Empty, "*.*", SearchOption.AllDirectories)
                    .Where(str => UserRegisrtyFiles.IsMatch(str))
                    .ToArray();
                foreach (var file in DuserReg.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    var username = DiffUserRegistry.Match(file.FullName).Groups["user"].Value;
                    var userFile = Bfiles.Where(str => GetUserRegex(username).IsMatch(str)).ToArray();
                    if (!userFile.Any())
                    {
                        continue;
                    }
                    var BReg = BFS.GetFileInfo(userFile.Single());
                    if (!BReg.Exists)
                    {
                        continue;
                    }
                    var BHive = new RegistryHive(BReg.Open(FileMode.Open, FileAccess.ReadWrite));
                    RegDiff.ReadFromStream(file.OpenRead()).ApplyTo(BHive.Root);
                }
            }
        }
Exemplo n.º 3
0
        private static Task CompTree(DiscDirectoryInfo A, DiscDirectoryInfo B, DiscDirectoryInfo Out,
            CopyQueue WriteQueue, ComparisonStyle Style = ComparisonStyle.DateTimeOnly)
        {
            if (WriteQueue == null) throw new ArgumentNullException("WriteQueue");
            List<Task> tasks = new List<Task>();

            DiscFileSystem Alock = A.FileSystem;
            DiscFileSystem Block = B.FileSystem;
            DiscFileSystem Olock = Out.FileSystem;

            ParallelQuery<DiscFileInfo> BFiles;
            lock(Block)
                BFiles = B.GetFiles("*.*", SearchOption.AllDirectories).ToArray().AsParallel();
            BFiles = BFiles.Where(file =>
                                  !ExcludeFiles.Contains(file.FullName.ToUpperInvariant())
                                 ).AsParallel();
            BFiles = ExclusionRules.Aggregate(BFiles, (current, rule) => current.Where(file => !rule.IsMatch(file.FullName)));

                BFiles = BFiles.Where(file =>
                    {
                        DiscFileInfo Atmp;
                        lock (Alock)
                            Atmp = Alock.GetFileInfo(file.FullName);
                        return !CompareFile(Atmp, file, Style);
                    }).ToArray().AsParallel();

            foreach (var file in BFiles)
            {
                DiscFileInfo outFile;
                lock (Olock)
                    outFile = Out.FileSystem.GetFileInfo(Path.Combine(Out.FullName, file.FullName));
                WriteQueue.Add(file, outFile);
            }

            return Task.Factory.StartNew(() => Task.WaitAll(tasks.ToArray()), TaskCreationOptions.AttachedToParent);
        }
Exemplo n.º 4
0
        private static void ApplyPartDiff(PartitionInfo Base, PartitionInfo Diff)
        {
            CopyQueue queue = new CopyQueue();

            var BFS = DetectFileSystem(Base);
            var DFS = DetectFileSystem(Diff);

            if (BFS is NtfsFileSystem)
            {
                ((NtfsFileSystem)BFS).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem)BFS).NtfsOptions.HideSystemFiles = false;
            }
            if (DFS is NtfsFileSystem)
            {
                ((NtfsFileSystem)DFS).NtfsOptions.HideHiddenFiles = false;
                ((NtfsFileSystem)DFS).NtfsOptions.HideSystemFiles = false;
            }

            var DRoot = DFS.Root;

            var DFRoots = DRoot.GetDirectories(RootFiles);
            if (DFRoots.Any())
            {
                var DFileRoot = DFRoots.Single();

                foreach (var file in DFileRoot.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    var BFile = BFS.GetFileInfo(file.FullName.Substring(RootFiles.Length + 1));
                    queue.Add(file, BFile);
                    /*
                    Stream OutStream;
                    if (BFile.Exists) OutStream = BFile.Open(FileMode.Truncate, FileAccess.ReadWrite);
                    else
                    {
                        if (!BFile.Directory.Exists)
                            BFile.Directory.Create();
                        OutStream = BFile.Create();
                    }
                    using (var InStream = file.OpenRead())
                    using (OutStream)
                        InStream.CopyTo(OutStream);
                    */
                }
                queue.Go();
            }

            var DsysRegs = DRoot.GetDirectories(RootSystemRegistry);
            if (DsysRegs.Any())
            {
                var DsysReg = DsysRegs.Single();

                foreach (var file in DsysReg.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    var BReg = BFS.GetFileInfo(file.FullName.Substring(RootSystemRegistry.Length + 1));
                    if (!BReg.Exists) queue.Add(file, BReg);
                    else
                    {
                        var BHive = new RegistryHive(BReg.Open(FileMode.Open, FileAccess.ReadWrite));
                        RegDiff.ReadFromStream(file.OpenRead()).ApplyTo(BHive.Root);
                    }
                }
                queue.Go();
            }

            var DuserRegs = DRoot.GetDirectories(RootUserRegistry);
            if (DuserRegs.Any())
            {
                var DuserReg = DuserRegs.Single();
                var Bfiles =
                    BFS.GetFiles(String.Empty, "*.*", SearchOption.AllDirectories)
                       .Where(str => UserRegisrtyFiles.IsMatch(str))
                       .ToArray();
                foreach (var file in DuserReg.GetFiles("*.*", SearchOption.AllDirectories))
                {
                    var username = DiffUserRegistry.Match(file.FullName).Groups["user"].Value;
                    var userFile = Bfiles.Where(str => GetUserRegex(username).IsMatch(str)).ToArray();
                    if (!userFile.Any()) continue;
                    var BReg = BFS.GetFileInfo(userFile.Single());
                    if (!BReg.Exists) continue;
                    var BHive = new RegistryHive(BReg.Open(FileMode.Open, FileAccess.ReadWrite));
                    RegDiff.ReadFromStream(file.OpenRead()).ApplyTo(BHive.Root);
                }
            }
        }