Example #1
0
        }         // func GetFileItems

        private void CompareDirectoryRoot()
        {
            try
            {
                var source = new DirectoryInfo(Stuff.GetCleanPath(Source));
                var target = new DirectoryInfo(Stuff.GetCleanPath(Target));

                sourceOffset = source.FullName.Length + 1;
                targetOffset = target.FullName.Length + 1;

                // build filter
                rules = new FileFilterRules(Excludes);

                CompareDirectory(source, target);
            }
            finally
            {
                EnqueueAction(null);
            }
        }         // func CompareDirectoryRoot
Example #2
0
        }         // proc UpdateMetaData

        protected override void ProcessRecord()
        {
            var notify     = new CmdletNotify(this);
            var totalBytes = 0L;

            // Lese den Index ein
            var index = new FileIndex();

            index.ReadIndex(notify, Path.Combine(Source, "index.txt.gz"));

            // Suche alle aktiven Archive
            var archives = new Dictionary <string, List <FileIndexItem> >(StringComparer.OrdinalIgnoreCase);

            using (var bar = notify.CreateStatus("Wiederherstellen eines Verzeichnisses", $"Wiederherstellen von {Source}..."))
            {
                var filter = new FileFilterRules(Filter);                 // Erzeuge Filter und entferne alle Dateien aus dem Index die dem nicht entsprechen
                if (filter.IsEmpty)
                {
                    foreach (var c in index)
                    {
                        AddArchive(archives, c, ref totalBytes);
                    }
                }
                else
                {
                    var remove = new List <FileIndexItem>();
                    foreach (var c in index)
                    {
                        if (filter.IsFiltered(c.RelativePath))
                        {
                            AddArchive(archives, c, ref totalBytes);
                        }
                        else
                        {
                            remove.Add(c);
                        }
                    }

                    foreach (var c in remove)
                    {
                        index.RemoveEntry(c);
                    }
                }

                // Entpacke die Archvie
                bar.StartRemaining();
                bar.Maximum = totalBytes;

                foreach (var c in archives)
                {
                    if (Stuff.IsGZipFile(c.Key) || Stuff.IsNoPackFile(c.Key))                     // GZip-Datei
                    {
                        using (var src = Stuff.OpenRead(new FileInfo(Path.Combine(Source, c.Key)), notify, CompressMode.Auto))
                        {
                            var srcFile = c.Value[0];
                            var dstFile = new FileInfo(Path.Combine(Target, srcFile.RelativePath));
                            using (var dst = Override ? Stuff.OpenWrite(dstFile, notify) : Stuff.OpenCreate(dstFile, notify))
                            {
                                dst.SetLength(srcFile.Length);
                                Stuff.CopyRawBytes(bar, srcFile.RelativePath, srcFile.Length, src, dst);
                            }

                            // Aktualisiere die Attribute
                            UpdateMetaData(notify, srcFile, dstFile);
                        }
                    }
                    else                     // zip-Datei
                    {
                        using (var zipStream = Stuff.OpenRead(new FileInfo(Path.Combine(Source, c.Key)), notify, CompressMode.Stored))
                            using (var zip = new ZipInputStream(zipStream))
                            {
                                var srcEntry = zip.GetNextEntry();
                                while (srcEntry != null)
                                {
                                    // Suche den passenden Index
                                    var srcIndex = c.Value.Find(c2 => String.Compare(srcEntry.Name, ZipEntry.CleanName(c2.RelativePath), StringComparison.OrdinalIgnoreCase) == 0);
                                    if (srcIndex != null)
                                    {
                                        var dstFile = new FileInfo(Path.Combine(Target, srcIndex.RelativePath));
                                        using (var dst = Override ? Stuff.OpenWrite(dstFile, notify) : Stuff.OpenCreate(dstFile, notify))
                                        {
                                            dst.SetLength(srcIndex.Length);
                                            Stuff.CopyRawBytes(bar, srcIndex.RelativePath, srcIndex.Length, zip, dst);
                                        }

                                        // Aktualisiere die Attribute
                                        UpdateMetaData(notify, srcIndex, dstFile);
                                    }
                                    else
                                    {
                                        zip.CloseEntry();
                                    }

                                    // Schließe den Eintrag ab
                                    srcEntry = zip.GetNextEntry();
                                }
                            }
                    }
                }
            }
        }         // proc ProcessRecord