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

            files = new List <PackedArchiveFile>();
        }
        public PackedArchiveDirectoryCollection(PackedArchive archive, PackedArchiveDirectory owner)
        {
            this.archive = archive;
            this.owner   = owner;

            directories = new List <PackedArchiveDirectory>();
        }
Exemplo n.º 3
0
        internal PackedArchiveDirectory(PackedArchive archive, PackedArchiveDirectory parent, string name)
        {
            Archive  = archive;
            Parent   = parent;
            Name     = name;
            FullName = MakeFullName(parent, name);

            Directories = new PackedArchiveDirectoryCollection(archive, this);
            Files       = new PackedArchiveFileCollection(archive, this);
        }
Exemplo n.º 4
0
 private static string MakeFullName(PackedArchiveDirectory parent, string key)
 {
     if (parent == null || parent.FullName == "")
     {
         return(key);
     }
     else
     {
         return($"{parent.FullName}/{key}");
     }
 }
Exemplo n.º 5
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)
                                : "";
        }
        public PackedArchiveDirectory GetOrCreateDirectory(string key)
        {
            foreach (var directory in directories)
            {
                if (directory.Name == key)
                {
                    return(directory);
                }
            }

            var newDirectory = new PackedArchiveDirectory(archive, owner, key);

            directories.Add(newDirectory);
            return(newDirectory);
        }
Exemplo n.º 7
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)
                {
                    var destDirectory = to.Directories.GetDirectory(directory.Name);

                    CopyIntoRecursive(directory, destDirectory, directory.Name);
                }
            }
Exemplo n.º 8
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[] { '/' }, System.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.files.Add(new PackedArchiveFile(this, placeDirectory, zipEntry.Name));
                }
            }
        }