Ejemplo n.º 1
0
        public void AddEntry(string path, ArchiveEntryBase entry)
        {
            Exceptions.CheckArgumentNullOrEmprty(path, "path");
            Exceptions.CheckArgumentNull(entry, "entry");

            if (ParentDirectory != null)
            {
                throw new Exception("Узел не является корневым.");
            }

            string[] partNames = path.ToLowerInvariant().Split(Path.DirectorySeparatorChar);
            if (partNames.Length < 2)
            {
                throw Exceptions.CreateException("Заданный путь не содержит корневого узла или имени файла: '{1}'", Name, path);
            }

            if (partNames.First() != Name)
            {
                throw Exceptions.CreateException("Узел '{0}' не явяется корневым для заданного пути: '{1}'", Name, path);
            }

            ArchiveDirectoryEntry dirNode = this;

            for (int i = 1; i < partNames.Length - 1; i++)
            {
                dirNode = dirNode.EnsureDirectoryExists(partNames[i]);
            }

            dirNode.AddEntry(entry);
        }
Ejemplo n.º 2
0
        public static void Initialize(ArchiveInformation[] infos)
        {
            ArchiveDirectoryEntry root = new ArchiveDirectoryEntry("c:");

            foreach (ArchiveInformation info in infos)
            {
                foreach (ArchiveFileEntry file in info.RootArchive.Expand())
                {
                    if (file.ParentArchive == null)
                    {
                        continue;
                    }

                    root.AddEntry(file.GetFullPath(), file);
                }
            }

            while (root.Childs.Count == 1)
            {
                ArchiveDirectoryEntry child = root.Childs.First().Value as ArchiveDirectoryEntry;
                if (child == null)
                {
                    break;
                }

                root = child;
            }

            Infos = infos;
            Root  = root;
        }
Ejemplo n.º 3
0
        private void MoveFile(ArchiveFileEntry oldFile, ArchiveArchiveEntry newParent, ArchiveDirectoryEntry newDirectory)
        {
            ArchiveFileEntry newFile = oldFile.Clone();

            {
                newFile.Compression   = Compression.None;
                newFile.ContentOffset = newParent.CurrentPosition;
                SetCapacity(newFile);
                newParent.CurrentPosition += newFile.ContentCapacity;
            }

            newParent.AddEntry(newFile);
            newDirectory.AddEntry(oldFile.GetFullPath(), newFile);
        }