Esempio n. 1
0
        /// <summary>
        /// Opens a Sim2Pack File
        /// </summary>
        /// <param name="reader">The Stream containing the File</param>
        /// <returns>List of all Package descriptors</returns>
        /// <remarks>The GUIDs/Names included in the S2CPDescriptor are the ones found in the Xml Description,
        /// you need to check them with the GUIDs stored in the packges itself to
        /// <see cref="SimPe.Packages.S2CPDescriptorBase.Valid"/>
        /// <seealso cref="SimPe.Packages.S2CPDescriptorBase.Valid"/> the Content</remarks>
        public static S2CPDescriptor[] Open(BinaryReader reader)
        {
            //BinaryReader reader = new BinaryReader(s2cp);
            byte[] header = reader.ReadBytes(18);
            int    offset = reader.ReadInt32();
            string xml    = Helper.ToString(reader.ReadBytes((int)(offset - reader.BaseStream.Position)));

            System.Xml.XmlDocument xmlfile = new XmlDocument();
            xmlfile.LoadXml(xml);

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

            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);
                foreach (XmlNode pfile in node)
                {
                    //a New FileItem
                    if (pfile.LocalName == "PackagedFile")
                    {
                        list.Add(ParesPackedFile(reader, pfile, offset));
                    }
                }         //foreach pfile
            }             // for i

            S2CPDescriptor[] res = new S2CPDescriptor[list.Count];
            list.CopyTo(res);
            return(res);
        }
Esempio n. 2
0
 private void AddPackage(object sender, System.EventArgs e)
 {
     ofd.Filter = "Sims 2 Package (*.package)|*.package|All Files (*.*)|*.*";
     if (ofd.ShowDialog() == DialogResult.OK)
     {
         SimPe.Packages.GeneratableFile package = GeneratableFile.LoadFromFile(ofd.FileName);
         S2CPDescriptor s2cp = new S2CPDescriptor(package, "", "", "", "", Sims2CommunityPack.DEFAULT_COMPRESSION_STRENGTH, new S2CPDescriptorBase[0], extension);
         lblist.Items.Add(s2cp);
         lblist.SelectedIndex = lblist.Items.Count - 1;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Shows the Save Dialog
        /// </summary>
        /// <param name="files">all packages that should be initially in the File</param>
        /// <param name="extension">true if you want to add the Community Extension, otherwise
        /// a normal Sims2Pack File will be generated</param>
        /// <returns>A list of all packages this File should contain</returns>
        public S2CPDescriptor[] Execute(SimPe.Packages.GeneratableFile[] files, ref bool extension)
        {
            this.extension = extension;
            ok             = false;

            S2CPDescriptor[] s2cps = new S2CPDescriptor[files.Length];
            for (int i = 0; i < files.Length; i++)
            {
                s2cps[i] = new S2CPDescriptor(files[i], "", "", "", "", Sims2CommunityPack.DEFAULT_COMPRESSION_STRENGTH, new S2CPDescriptorBase[0], extension);
                lblist.Items.Add(s2cps[i]);
            }

            this.tbflname.ReadOnly  = false;
            this.tbname.ReadOnly    = true;
            this.tbauthor.ReadOnly  = false;
            this.tbver.ReadOnly     = false;
            this.tbdesc.ReadOnly    = false;
            this.tbtitle.ReadOnly   = false;
            this.tbcontact.ReadOnly = false;
            this.cb2cp.Checked      = extension;
            btadd.Visible           = true;
            btdelete.Visible        = true;
            btbrowse.Enabled        = true;
            btsave.Text             = "Save";
            cbcompress.Enabled      = true;

            this.lblist.SelectionMode = SelectionMode.One;

            if (lblist.Items.Count > 0)
            {
                lblist.SelectedIndex = 0;
            }
            btdelete.Enabled = (lblist.SelectedIndex >= 0);

            this.Checks2cp(this.cb2cp, null);
            this.ShowDialog();

            extension = this.cb2cp.Checked;
            if (ok)
            {
                s2cps = new S2CPDescriptor[lblist.Items.Count];
                for (int i = 0; i < s2cps.Length; i++)
                {
                    s2cps[i] = (S2CPDescriptor)lblist.Items[i];
                    s2cps[i].Update();
                }

                return(s2cps);
            }

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Shows the Load Dialog
        /// </summary>
        /// <param name="files">All Descriptors within the S2CP File</param>
        /// <param name="selmode">Selection Mode for the Listbox</param>
        /// <returns>All the Packages the user has selected</returns>
        public S2CPDescriptor[] Execute(S2CPDescriptor[] files, SelectionMode selmode)
        {
            this.extension = false;
            ok             = false;

            for (int i = 0; i < files.Length; i++)
            {
                lblist.Items.Add(files[i]);
            }

            this.tbflname.ReadOnly  = true;
            this.tbname.ReadOnly    = true;
            this.tbauthor.ReadOnly  = true;
            this.tbver.ReadOnly     = true;
            this.tbdesc.ReadOnly    = true;
            this.tbtitle.ReadOnly   = true;
            this.tbcontact.ReadOnly = true;
            btadd.Visible           = false;
            btdelete.Visible        = false;
            btbrowse.Enabled        = false;
            btsave.Text             = "Open";
            cbcompress.Enabled      = false;

            this.lblist.SelectionMode = selmode;

            if (lblist.Items.Count > 0)
            {
                lblist.SelectedIndex = 0;
            }
            btdelete.Enabled = (lblist.SelectedIndex >= 0);

            this.Checks2cp(this.cb2cp, null);
            this.ShowDialog();

            if (ok)
            {
                S2CPDescriptor[] fls = new S2CPDescriptor[lblist.SelectedItems.Count];
                for (int i = 0; i < fls.Length; i++)
                {
                    fls[i] = (S2CPDescriptor)lblist.SelectedItems[i];
                }

                return(fls);
            }

            return(null);
        }
Esempio n. 5
0
        /// <summary>
        /// Parse the packedFile Node in an XML
        /// </summary>
        /// <param name="reader">The source Stream of the S2CP File</param>
        /// <param name="pfile">The PackedFile Node</param>
        /// <param name="offset">The Ofset for the package Data</param>
        /// <returns>The Descriptor of the PackedFile</returns>
        /// <remarks>The GUIDs and the Names of the Descriptors are the ones stored in the
        /// XML Data not the ones from the Package. So you have to <seealso cref="SimPe.Packages.S2CPDescriptorBase.Valid"/><see cref="SimPe.Packages.S2CPDescriptorBase.Valid"/> the Content with the Package.</remarks>
        protected static S2CPDescriptor ParesPackedFile(BinaryReader reader, XmlNode pfile, int offset)
        {
            S2CPDescriptor s2cp      = new S2CPDescriptor(null, "", "", "", "", Sims2CommunityPack.CompressionStrength.None, null, true);
            int            pkglen    = 0;
            int            pkgoffset = 0;

            foreach (XmlNode mainnode in pfile)
            {
                switch (mainnode.LocalName)
                {
                case "Name":
                {
                    s2cp.Name = mainnode.InnerText;
                    break;
                }

                case "Description":
                {
                    s2cp.Description = mainnode.InnerText;
                    break;
                }

                case "Crc":
                {
                    s2cp.Crc = mainnode.InnerText;
                    break;
                }

                case "Length":
                {
                    pkglen = Convert.ToInt32(mainnode.InnerText);
                    break;
                }

                case "Offset":
                {
                    pkgoffset = Convert.ToInt32(mainnode.InnerText);
                    break;
                }

                case "Sims2CommuniytExt":
                {
                    foreach (XmlNode subnode in mainnode)
                    {
                        switch (subnode.LocalName)
                        {
                        case "Author":
                        {
                            foreach (XmlNode authnode in subnode)
                            {
                                switch (authnode.LocalName)
                                {
                                case "PersonalName":
                                {
                                    s2cp.Author = authnode.InnerText;
                                    break;
                                }

                                case "Contact":
                                {
                                    s2cp.Contact = authnode.InnerText;
                                    break;
                                }
                                }                                                //switch
                            }
                            break;
                        }

                        case "Title":
                        {
                            s2cp.Title = subnode.InnerText;
                            break;
                        }

                        case "ObjectVersion":
                        {
                            s2cp.ObjectVersion = subnode.InnerText;
                            break;
                        }

                        case "GlobalGUID":
                        {
                            s2cp.Guid = subnode.InnerText;
                            break;
                        }

                        case "Compressed":
                        {
                            s2cp.Compressed = (CompressionStrength)Convert.ToInt32(subnode.InnerText);
                            break;
                        }

                        case "Dependency":
                        {
                            ArrayList al = new ArrayList();
                            foreach (XmlNode dep in subnode)
                            {
                                if (dep.LocalName == "PackagedFile")
                                {
                                    al.Add(ParesDependingPackedFile(dep));
                                }
                            }
                            S2CPDescriptorBase[] deps = new S2CPDescriptorBase[al.Count];
                            al.CopyTo(deps);
                            s2cp.Dependency = deps;
                            break;
                        }
                        }
                    }
                    break;
                }
                }         //switch
            }             //foreach

            s2cp.Package = LoadPackage(reader, offset + pkgoffset, pkglen, s2cp);
            return(s2cp);
        }
Esempio n. 6
0
 /// <summary>
 /// Create a Sims2CommunityPack File
 /// </summary>
 /// <param name="file">The Descriptors of the Package to inlcude</param>
 /// <param name="extension">true if you want to add the Community Extension, otherwise
 /// a normal Sims2Pack File will be generated</param>
 /// <returns>The MemoryStream containing the S2CP File</returns>
 public static MemoryStream Create(S2CPDescriptor file, bool extension)
 {
     S2CPDescriptor[] ms = new S2CPDescriptor[1];
     ms[0] = file;
     return(Create(ms, extension));
 }
Esempio n. 7
0
 /// <summary>
 /// Updates the Link Text for the Dependency Window
 /// </summary>
 /// <param name="s2cp"></param>
 void UpdateDepText(S2CPDescriptor s2cp)
 {
     lldep.Text     = "Show " + s2cp.Dependency.Length + " Dependencies...";
     lldep.LinkArea = new LinkArea(lldep.Text.Length - 15, 12);
 }