Example #1
0
        private void SetupTreeView(ArchiveProject project)
        {
            treeView.Items.Clear();
            root = new TreeViewItem()
            {
                Header = project.Root
            };
            treeView.Items.Add(root);

            project.Root.Children.ForEach(child => AddTreeNode(root, child));
            project.BuildParents();
        }
Example #2
0
        private void OpenProjectCmd(object sender, ExecutedRoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Title  = Resource.open_project_dialog_title,
                Filter = "Archive Project (*.arproj)|*.arproj"
            };

            if (dialog.ShowDialog().GetValueOrDefault(false))
            {
                try
                {
                    using FileStream stream = File.OpenRead(dialog.FileName);
                    XmlSerializer serializer = new XmlSerializer(typeof(ArchiveProject));
                    archiveProject = (ArchiveProject)serializer.Deserialize(stream);
                    SetupTreeView(archiveProject);
                }
                catch (Exception error)
                {
                    MessageBox.Show(error.Message, "Open Project Error");
                }
            }
        }
Example #3
0
        public void Export(ArchiveProject project, Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);

            PAKMainHeader mainHeader    = new PAKMainHeader();
            long          startPosition = stream.Position;

            stream.Seek(PAKMainHeader.SIZE_OF, SeekOrigin.Current);

            ICollection <ArchiveProjectEntry> entries = project.GetFiles();
            List <PAKFileHeader> fileHeaders          = new List <PAKFileHeader>();

            foreach (ArchiveProjectEntry entry in entries)
            {
                byte[] contents = File.ReadAllBytes(entry.Path);

                PAKFileHeader header = new PAKFileHeader
                {
                    Name   = entry.RelativePath.ToCharArray(),
                    Offset = mainHeader.DirectoryOffset,
                    Size   = contents.Length
                };

                writer.Write(contents);

                mainHeader.DirectoryOffset += contents.Length;
                mainHeader.DirectoryLength += PAKFileHeader.SIZE_OF;

                fileHeaders.Add(header);
            }

            fileHeaders.ForEach(header => header.Write(writer));

            stream.Position = startPosition;
            mainHeader.Write(writer);
            stream.Position = startPosition + mainHeader.DirectoryOffset + mainHeader.DirectoryLength;
        }