Exemplo n.º 1
0
        public PackedArchiveFileCollection(PackedArchive archive, PackedArchiveDirectory owner)
        {
            this.archive = archive;
            this.owner   = owner;

            internalList = new List <PackedArchiveFile>();
        }
        public PackedArchiveDirectory GetOrCreateDirectory(string key)
        {
            var directory = GetDirectory(key);

            if (directory == null)
            {
                directory = new PackedArchiveDirectory(archive, owner, key);
                internalList.Add(directory);
            }
            return(directory);
        }
Exemplo n.º 3
0
        public PackedArchiveFile(PackedArchive archive, PackedArchiveDirectory parent, string name)
        {
            Archive = archive;
            Parent  = parent;

            Name     = name;
            FullName = MakeFullName(parent, name);

            int dotIndex = name.LastIndexOf('.');

            Extension = dotIndex != -1
                                ? name.Substring(dotIndex)
                                : "";
        }
Exemplo n.º 4
0
        internal PackedArchiveDirectory(PackedArchive archive, PackedArchiveDirectory parent, string name)
        {
            Archive = archive;
            Parent  = parent;

            Directories = new PackedArchiveDirectoryCollection(archive, this);
            Files       = new PackedArchiveFileCollection(archive, this);

            if (parent != null)
            {
                Name     = name;
                FullName = MakeFullName(parent, name);
            }
        }
Exemplo n.º 5
0
            static void CopyIntoRecursive(PackedArchiveDirectory from, IArchiveDirectory to, string rename)
            {
                foreach (var file in from.Files)
                {
                    var destFile = to.Files.GetFile(file.Name);

                    using var openStream = file.OpenRead();
                    var dest = file.OpenWrite();
                    openStream.CopyTo(dest);
                }
                foreach (var directory in from.Directories.All)
                {
                    var destDirectory = to.Directories.GetDirectory(directory.Name);

                    CopyIntoRecursive(directory, destDirectory, directory.Name);
                }
            }
Exemplo n.º 6
0
        public PackedArchive(ZipArchive zipArchive)
        {
            ZipArchive    = zipArchive;
            RootDirectory = new PackedArchiveDirectory(this, null, "");

            if (zipArchive.Mode != ZipArchiveMode.Create)
            {
                foreach (var zipEntry in zipArchive.Entries)
                {
                    string[] elements = zipEntry.FullName
                                        .Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

                    var placeDirectory = RootDirectory;
                    for (int i = 0; i < elements.Length - 1; i++)
                    {
                        string element = elements[i];

                        placeDirectory = placeDirectory.Directories.GetOrCreateDirectory(element);
                    }

                    placeDirectory.Files.internalList.Add(new PackedArchiveFile(this, placeDirectory, zipEntry.Name));
                }
            }
        }