Exemplo n.º 1
0
        /// <summary>
        /// Creates a Package File from a previously extracted Package
        /// </summary>
        /// <param name="filename">Filename of package.xml File describing the Package</param>
        /// <param name="pb">A Progressbar indicating the progress</param>
        /// <returns>Binary Reader representing the Package File</returns>
        public static System.IO.BinaryReader OpenExtractedPackage(ProgressBar pb, string filename)
        {
            string path = System.IO.Path.GetDirectoryName(filename);

            System.Xml.XmlDocument xmlfile = new XmlDocument();
            xmlfile.Load(filename);

            //Root Node suchen
            XmlNodeList XMLData = xmlfile.GetElementsByTagName("package");

            ArrayList list = new ArrayList();

            //Alle Eintr&auml;ge im Root Node verarbeiten
            Data.MetaData.IndexTypes type = Data.MetaData.IndexTypes.ptShortFileIndex;
            for (int i = 0; i < XMLData.Count; i++)
            {
                XmlNode node = XMLData.Item(i);

                object o = node.Attributes["type"].Value; if (o == null)
                {
                    o = "1";
                }
                type = (Data.MetaData.IndexTypes) uint.Parse(o.ToString());

                if (pb != null)
                {
                    pb.Maximum = node.ChildNodes.Count;
                }
                int count = 0;
                foreach (XmlNode subnode in node)
                {
                    if (pb != null)
                    {
                        pb.Value = count++;
                        System.Windows.Forms.Application.DoEvents();
                    }
                    ///a New FileItem
                    if (subnode.LocalName == "packedfile")
                    {
                        list.Add(CreateDescriptor(path, subnode));
                    }
                }
            }

            SimPe.Packages.GeneratableFile file = SimPe.Packages.GeneratableFile.CreateNew();
            file.BeginUpdate();
            file.Header.IndexType = type;

            foreach (SimPe.Packages.PackedFileDescriptor pfd in list)
            {
                file.Add(pfd);
                if (pfd.Type == Packages.File.FILELIST_TYPE)
                {
                    file.FileList = pfd;
                }
            }

            System.IO.MemoryStream ms = file.Build();
            file.EndUpdate();
            if (pb != null)
            {
                pb.Value = pb.Maximum;
            }
            return(new System.IO.BinaryReader(ms));
        }