Exemplo n.º 1
0
        internal ArchiveFileModel(ArchiveMetadata metadata, ArchivedFolder rootFolder, ImmutableArray <int> sections, ImmutableList <ArchivedFile> files)
        {
            if (metadata == null)
            {
                throw new ArgumentNullException(nameof(metadata));
            }

            if (rootFolder == null)
            {
                throw new ArgumentNullException(nameof(rootFolder));
            }

            if (files == null)
            {
                throw new ArgumentNullException(nameof(files));
            }

            if (sections.IsDefault)
            {
                throw new ArgumentNullException(nameof(sections));
            }

            if (sections.Length != metadata.DecoderSections.Length + 1)
            {
                throw new InternalFailureException();
            }

            this.Metadata      = metadata;
            this.RootFolder    = rootFolder;
            this.mSectionFiles = files;
            this.mSections     = sections;
        }
Exemplo n.º 2
0
        private static void UnpackArchiveStructure(ManagedLzma.SevenZip.FileModel.ArchivedFolder folder, string targetDirectory)
        {
            if (folder.Items.IsEmpty)
            {
                // Empty folders need to be created manually since the unpacking code doesn't try to write into it.
                Directory.CreateDirectory(targetDirectory);
            }
            else
            {
                foreach (var item in folder.Items)
                {
                    var file = item as ManagedLzma.SevenZip.FileModel.ArchivedFile;
                    if (file != null)
                    {
                        // Files without content are not iterated during normal unpacking so we need to create them manually.
                        if (file.Stream.IsUndefined)
                        {
                            System.Diagnostics.Debug.Assert(file.Length == 0); // If the file has no content then its length should be zero, otherwise something is wrong.

                            var filename = Path.Combine(targetDirectory, file.Name);
                            using (var stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Delete))
                            {
                                // Nothing to do, FileMode.Create already truncates the file on opening.
                            }

                            SetFileAttributes(filename, file);
                        }
                    }

                    var subfolder = item as ManagedLzma.SevenZip.FileModel.ArchivedFolder;
                    if (subfolder != null)
                    {
                        UnpackArchiveStructure(subfolder, Path.Combine(targetDirectory, subfolder.Name));
                    }
                }
            }
        }
Exemplo n.º 3
0
 public Builder(ArchivedFolder original)
     : base(original)
 {
     this.mOriginal = original;
 }