private Sims3PackFile.PackagedFile.MetaTag ReadMetaTagsXml(XmlTextReader xtr)
        {
            Sims3PackFile.PackagedFile.MetaTag metatag = new Sims3PackFile.PackagedFile.MetaTag();
            string curName = "";

            while (xtr.Read())
            {
                if (xtr.NodeType == XmlNodeType.Element)
                {
                    curName = xtr.Name;
                    if (curName.ToLower() == "lotthumbs")
                    {
                        if (!xtr.IsEmptyElement)
                        {
                            // Read the lotThumbs structure
                            while (xtr.Read())
                            {
                                if (xtr.NodeType == XmlNodeType.Element)
                                {
                                    switch (xtr.Name.ToLower())
                                    {
                                    case "lotthumb":
                                        xtr.Read();
                                        if (xtr.NodeType == XmlNodeType.Whitespace)
                                        {
                                            xtr.Read();
                                        }
                                        metatag.lotThumb.Add(xtr.Value);
                                        break;
                                    }
                                }
                                if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name.ToLower() == "lotthumbs")
                                {
                                    break;
                                }
                            }
                        }
                    }
                    if (curName.ToLower() == "traits")
                    {
                        if (!xtr.IsEmptyElement)
                        {
                            // Read the traits structure
                            while (xtr.Read())
                            {
                                if (xtr.NodeType == XmlNodeType.Element)
                                {
                                    switch (xtr.Name.ToLower())
                                    {
                                    case "trait":
                                        xtr.Read();
                                        if (xtr.NodeType == XmlNodeType.Whitespace)
                                        {
                                            xtr.Read();
                                        }
                                        metatag.traits.Add(xtr.Value);
                                        break;
                                    }
                                }
                                if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name.ToLower() == "traits")
                                {
                                    break;
                                }
                            }
                        }
                    }
                    if (curName.ToLower() == "outfits")
                    {
                        if (!xtr.IsEmptyElement)
                        {
                            // Read the outfits structure
                            while (xtr.Read())
                            {
                                if (xtr.NodeType == XmlNodeType.Element)
                                {
                                    switch (xtr.Name)
                                    {
                                    case "outfitAthletic":
                                        xtr.Read();
                                        if (xtr.NodeType == XmlNodeType.Whitespace)
                                        {
                                            xtr.Read();
                                        }
                                        xtr.Read();
                                        metatag.outfits.athletic = xtr.Value;
                                        metatag.outfits.numOutfits++;
                                        break;

                                    case "outfitEveryday":
                                        xtr.Read();
                                        if (xtr.NodeType == XmlNodeType.Whitespace)
                                        {
                                            xtr.Read();
                                        }
                                        xtr.Read();
                                        metatag.outfits.everyday = xtr.Value;
                                        metatag.outfits.numOutfits++;
                                        break;

                                    case "outfitFormalwear":
                                        xtr.Read();
                                        if (xtr.NodeType == XmlNodeType.Whitespace)
                                        {
                                            xtr.Read();
                                        }
                                        xtr.Read();
                                        metatag.outfits.formalwear = xtr.Value;
                                        metatag.outfits.numOutfits++;
                                        break;

                                    case "outfitNaked":
                                        xtr.Read();
                                        if (xtr.NodeType == XmlNodeType.Whitespace)
                                        {
                                            xtr.Read();
                                        }
                                        xtr.Read();
                                        metatag.outfits.naked = xtr.Value;
                                        metatag.outfits.numOutfits++;
                                        break;

                                    case "outfitSleepwear":
                                        xtr.Read();
                                        if (xtr.NodeType == XmlNodeType.Whitespace)
                                        {
                                            xtr.Read();
                                        }
                                        xtr.Read();
                                        metatag.outfits.sleepwear = xtr.Value;
                                        metatag.outfits.numOutfits++;
                                        break;

                                    case "outfitSwimwear":
                                        xtr.Read();
                                        if (xtr.NodeType == XmlNodeType.Whitespace)
                                        {
                                            xtr.Read();
                                        }
                                        xtr.Read();
                                        metatag.outfits.swimwear = xtr.Value;
                                        metatag.outfits.numOutfits++;
                                        break;
                                    }
                                }
                                if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name.ToLower() == "outfits")
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                if (xtr.NodeType == XmlNodeType.Text)
                {
                    switch (curName.ToLower())
                    {
                    case "name":
                        metatag.name = xtr.Value;
                        break;

                    case "description":
                        metatag.description = xtr.Value;
                        break;

                    case "bio":
                        metatag.bio = xtr.Value;
                        break;

                    case "numofthumbs":
                        metatag.numLotThumbs = Convert.ToInt32(xtr.Value);
                        break;

                    case "maxlevel":
                        metatag.maxLevel = Convert.ToInt32(xtr.Value);
                        break;

                    case "minlevel":
                        metatag.minLevel = Convert.ToInt32(xtr.Value);
                        break;

                    case "dimx":
                        metatag.dimX = Convert.ToInt32(xtr.Value);
                        break;

                    case "dimz":
                        metatag.dimZ = Convert.ToInt32(xtr.Value);
                        break;

                    case "lottype":
                        metatag.lottype = Convert.ToInt32(xtr.Value);
                        break;

                    case "numlotthumbs":
                        metatag.numLotThumbs = Convert.ToInt32(xtr.Value);
                        break;

                    case "lotname":
                        metatag.lotName = xtr.Value;
                        break;

                    case "lotressubtype":
                        metatag.lotResSubType = Convert.ToInt32(xtr.Value);
                        break;

                    case "lotcomsubtype":
                        metatag.lotComSubType = Convert.ToInt32(xtr.Value);
                        break;

                    // Sims:
                    case "age":
                        metatag.age = xtr.Value;
                        break;

                    case "species":
                        metatag.species = xtr.Value;
                        break;

                    case "gender":
                        metatag.gender = xtr.Value;
                        break;

                    case "fitness":
                        metatag.fitness = xtr.Value;
                        break;

                    case "weight":
                        metatag.weight = xtr.Value;
                        break;

                    case "favcolor":
                        metatag.favcolor = xtr.Value;
                        break;

                    case "favmusic":
                        metatag.favmusic = Convert.ToInt32(xtr.Value);
                        break;

                    case "favfood":
                        metatag.favfood = Convert.ToInt32(xtr.Value);
                        break;

                    case "skintoneindex":
                        metatag.skintoneindex = xtr.Value;
                        break;

                    case "handedness":
                        metatag.handedness = xtr.Value;
                        break;
                    }
                }
                if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name.ToLower() == "metatags")
                {
                    break;
                }
            }
            return(metatag);
        }
        private string WriteMetaTagsXml(Sims3PackFile.PackagedFile.MetaTag metatag, string indent)
        {
            StringBuilder sb = new StringBuilder();

            if (String.IsNullOrEmpty(metatag.name))
            {
                return("<metatags />");
            }

            sb.AppendLine(indent + "<metatags>");

            sb.AppendLine(indent + "  <name>" + metatag.name + "</name>");
            if (!String.IsNullOrEmpty(metatag.description))
            {
                sb.AppendLine(indent + "  <description>" + System.Web.HttpUtility.HtmlEncode(metatag.description) + "</description>");
            }
            if (!String.IsNullOrEmpty(metatag.bio))
            {
                sb.AppendLine(indent + "  <bio>" + System.Web.HttpUtility.HtmlEncode(metatag.bio) + "</bio>");
            }
            if (metatag.numOfThumbs > -999999)
            {
                sb.AppendLine(indent + "  <numOfThumbs>" + metatag.numOfThumbs.ToString() + "</numOfThumbs>");
            }

            // Lot information
            if (metatag.maxLevel > -999999)
            {
                sb.AppendLine(indent + "  <maxlevel>" + metatag.maxLevel.ToString() + "</maxlevel>");
            }
            if (metatag.minLevel > -999999)
            {
                sb.AppendLine(indent + "  <minlevel>" + metatag.minLevel.ToString() + "</minlevel>");
            }
            if (metatag.dimX > -999999)
            {
                sb.AppendLine(indent + "  <dimX>" + metatag.dimX.ToString() + "</dimX>");
            }
            if (metatag.dimZ > -999999)
            {
                sb.AppendLine(indent + "  <dimZ>" + metatag.dimZ.ToString() + "</dimZ>");
            }
            if (metatag.lottype > -999999)
            {
                sb.AppendLine(indent + "  <lottype>" + metatag.lottype.ToString() + "</lottype>");
            }
            if (metatag.lotThumb.Count > 0)
            {
                sb.AppendLine(indent + "  <numLotThumbs>" + metatag.lotThumb.Count.ToString() + "</numLotThumbs>");
                sb.AppendLine(indent + "  <lotThumbs>");
                for (int i = 0; i < metatag.lotThumb.Count; i++)
                {
                    sb.AppendLine(indent + "    <lotThumb>" + metatag.lotThumb[i] + "</lotThumb>");
                }
                sb.AppendLine(indent + "  </lotThumbs>");
            }
            if (!String.IsNullOrEmpty(metatag.lotName))
            {
                sb.AppendLine(indent + "  <lotName>" + metatag.lotName + "</lotName>");
            }
            if (metatag.lotResSubType > -999999)
            {
                sb.AppendLine(indent + "  <lotResSubType>" + metatag.lotResSubType.ToString() + "</lotResSubType>");
            }
            if (metatag.lotComSubType > -999999)
            {
                sb.AppendLine(indent + "  <lotComSubType>" + metatag.lotComSubType.ToString() + "</lotComSubType>");
            }

            if (!String.IsNullOrEmpty(metatag.age))
            {
                sb.AppendLine(indent + "  <age>" + metatag.age + "</age>");
            }
            if (!String.IsNullOrEmpty(metatag.species))
            {
                sb.AppendLine(indent + "  <species>" + metatag.species + "</species>");
            }
            if (!String.IsNullOrEmpty(metatag.gender))
            {
                sb.AppendLine(indent + "  <gender>" + metatag.gender + "</gender>");
            }
            if (metatag.traits.Count > 0)
            {
                sb.AppendLine(indent + "  <traits>");
                for (int i = 0; i < metatag.traits.Count; i++)
                {
                    sb.AppendLine(indent + "    <trait>" + metatag.traits[i] + "</trait>");
                }
                sb.AppendLine(indent + "  </traits>");
            }
            if (!String.IsNullOrEmpty(metatag.fitness))
            {
                sb.AppendLine(indent + "  <fitness>" + metatag.fitness + "</fitness>");
            }
            if (!String.IsNullOrEmpty(metatag.weight))
            {
                sb.AppendLine(indent + "  <weight>" + metatag.weight + "</weight>");
            }
            if (!String.IsNullOrEmpty(metatag.favcolor))
            {
                sb.AppendLine(indent + "  <favcolor>" + metatag.age + "</favcolor>");
            }
            if (metatag.favmusic > -999999)
            {
                sb.AppendLine(indent + "  <favmusic>" + metatag.favmusic.ToString() + "</favmusic>");
            }
            if (metatag.favfood > -999999)
            {
                sb.AppendLine(indent + "  <favfood>" + metatag.favfood.ToString() + "</favfood>");
            }
            if (!String.IsNullOrEmpty(metatag.skintoneindex))
            {
                sb.AppendLine(indent + "  <skintoneindex>" + metatag.skintoneindex + "</skintoneindex>");
            }
            if (!String.IsNullOrEmpty(metatag.handedness))
            {
                sb.AppendLine(indent + "  <handedness>" + metatag.handedness + "</handedness>");
            }

            if (metatag.outfits.numOutfits > 0)
            {
                sb.AppendLine(indent + "  <outfits>");
                if (!String.IsNullOrEmpty(metatag.outfits.athletic))
                {
                    sb.AppendLine(indent + "    <outfitAthletic>");
                    sb.AppendLine(indent + "      <outfitId>" + metatag.outfits.athletic + "</outfitId>");
                    sb.AppendLine(indent + "    </outfitAthletic>");
                }
                if (!String.IsNullOrEmpty(metatag.outfits.everyday))
                {
                    sb.AppendLine(indent + "    <outfitEveryday>");
                    sb.AppendLine(indent + "      <outfitId>" + metatag.outfits.everyday + "</outfitId>");
                    sb.AppendLine(indent + "    </outfitEveryday>");
                }
                if (!String.IsNullOrEmpty(metatag.outfits.formalwear))
                {
                    sb.AppendLine(indent + "    <outfitFormalwear>");
                    sb.AppendLine(indent + "      <outfitId>" + metatag.outfits.formalwear + "</outfitId>");
                    sb.AppendLine(indent + "    </outfitFormalwear>");
                }
                if (!String.IsNullOrEmpty(metatag.outfits.naked))
                {
                    sb.AppendLine(indent + "    <outfitNaked>");
                    sb.AppendLine(indent + "      <outfitId>" + metatag.outfits.naked + "</outfitId>");
                    sb.AppendLine(indent + "    </outfitNaked>");
                }
                if (!String.IsNullOrEmpty(metatag.outfits.sleepwear))
                {
                    sb.AppendLine(indent + "    <outfitSleepwear>");
                    sb.AppendLine(indent + "      <outfitId>" + metatag.outfits.sleepwear + "</outfitId>");
                    sb.AppendLine(indent + "    </outfitSleepwear>");
                }
                if (!String.IsNullOrEmpty(metatag.outfits.swimwear))
                {
                    sb.AppendLine(indent + "    <outfitSwimwear>");
                    sb.AppendLine(indent + "      <outfitId>" + metatag.outfits.swimwear + "</outfitId>");
                    sb.AppendLine(indent + "    </outfitSwimwear>");
                }
            }

            sb.AppendLine(indent + "</metatags>");

            return(sb.ToString());
        }
        private Sims3PackFile.PackagedFile.MetaTag ReadMetaTagsXml(XmlTextReader xtr)
        {
            Sims3PackFile.PackagedFile.MetaTag metatag = new Sims3PackFile.PackagedFile.MetaTag();
            string curName = "";
            while (xtr.Read())
            {
                if (xtr.NodeType == XmlNodeType.Element)
                {
                    curName = xtr.Name;
                    if (curName.ToLower() == "lotthumbs")
                    {
                        if (!xtr.IsEmptyElement)
                        {
                            // Read the lotThumbs structure
                            while (xtr.Read())
                            {
                                if (xtr.NodeType == XmlNodeType.Element)
                                {
                                    switch (xtr.Name.ToLower())
                                    {
                                        case "lotthumb":
                                            xtr.Read();
                                            if (xtr.NodeType == XmlNodeType.Whitespace) xtr.Read();
                                            metatag.lotThumb.Add(xtr.Value);
                                            break;
                                    }
                                }
                                if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name.ToLower() == "lotthumbs")
                                {
                                    break;
                                }
                            }
                        }
                    }
                    if (curName.ToLower() == "traits")
                    {
                        if (!xtr.IsEmptyElement)
                        {
                            // Read the traits structure
                            while (xtr.Read())
                            {
                                if (xtr.NodeType == XmlNodeType.Element)
                                {
                                    switch (xtr.Name.ToLower())
                                    {
                                        case "trait":
                                            xtr.Read();
                                            if (xtr.NodeType == XmlNodeType.Whitespace) xtr.Read();
                                            metatag.traits.Add(xtr.Value);
                                            break;
                                    }
                                }
                                if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name.ToLower() == "traits")
                                {
                                    break;
                                }
                            }
                        }
                    }
                    if (curName.ToLower() == "outfits")
                    {
                        if (!xtr.IsEmptyElement)
                        {
                            // Read the outfits structure
                            while (xtr.Read())
                            {
                                if (xtr.NodeType == XmlNodeType.Element)
                                {
                                    switch (xtr.Name)
                                    {
                                        case "outfitAthletic":
                                            xtr.Read();
                                            if (xtr.NodeType == XmlNodeType.Whitespace) xtr.Read();
                                            xtr.Read();
                                            metatag.outfits.athletic = xtr.Value;
                                            metatag.outfits.numOutfits++;
                                            break;
                                        case "outfitEveryday":
                                            xtr.Read();
                                            if (xtr.NodeType == XmlNodeType.Whitespace) xtr.Read();
                                            xtr.Read();
                                            metatag.outfits.everyday = xtr.Value;
                                            metatag.outfits.numOutfits++;
                                            break;
                                        case "outfitFormalwear":
                                            xtr.Read();
                                            if (xtr.NodeType == XmlNodeType.Whitespace) xtr.Read();
                                            xtr.Read();
                                            metatag.outfits.formalwear = xtr.Value;
                                            metatag.outfits.numOutfits++;
                                            break;
                                        case "outfitNaked":
                                            xtr.Read();
                                            if (xtr.NodeType == XmlNodeType.Whitespace) xtr.Read();
                                            xtr.Read();
                                            metatag.outfits.naked = xtr.Value;
                                            metatag.outfits.numOutfits++;
                                            break;
                                        case "outfitSleepwear":
                                            xtr.Read();
                                            if (xtr.NodeType == XmlNodeType.Whitespace) xtr.Read();
                                            xtr.Read();
                                            metatag.outfits.sleepwear = xtr.Value;
                                            metatag.outfits.numOutfits++;
                                            break;
                                        case "outfitSwimwear":
                                            xtr.Read();
                                            if (xtr.NodeType == XmlNodeType.Whitespace) xtr.Read();
                                            xtr.Read();
                                            metatag.outfits.swimwear = xtr.Value;
                                            metatag.outfits.numOutfits++;
                                            break;

                                    }
                                }
                                if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name.ToLower() == "outfits")
                                {
                                    break;
                                }
                            }
                        }
                    }

                }
                if (xtr.NodeType == XmlNodeType.Text)
                {
                    switch (curName.ToLower())
                    {
                        case "name":
                            metatag.name = xtr.Value;
                            break;
                        case "description":
                            metatag.description = xtr.Value;
                            break;
                        case "bio":
                            metatag.bio = xtr.Value;
                            break;
                        case "numofthumbs":
                            metatag.numLotThumbs = Convert.ToInt32(xtr.Value);
                            break;
                        case "maxlevel":
                            metatag.maxLevel = Convert.ToInt32(xtr.Value);
                            break;
                        case "minlevel":
                            metatag.minLevel = Convert.ToInt32(xtr.Value);
                            break;
                        case "dimx":
                            metatag.dimX = Convert.ToInt32(xtr.Value);
                            break;
                        case "dimz":
                            metatag.dimZ = Convert.ToInt32(xtr.Value);
                            break;
                        case "lottype":
                            metatag.lottype = Convert.ToInt32(xtr.Value);
                            break;
                        case "numlotthumbs":
                            metatag.numLotThumbs = Convert.ToInt32(xtr.Value);
                            break;
                        case "lotname":
                            metatag.lotName = xtr.Value;
                            break;
                        case "lotressubtype":
                            metatag.lotResSubType = Convert.ToInt32(xtr.Value);
                            break;
                        case "lotcomsubtype":
                            metatag.lotComSubType = Convert.ToInt32(xtr.Value);
                            break;
                        // Sims:
                        case "age":
                            metatag.age = xtr.Value;
                            break;
                        case "species":
                            metatag.species = xtr.Value;
                            break;
                        case "gender":
                            metatag.gender = xtr.Value;
                            break;
                        case "fitness":
                            metatag.fitness = xtr.Value;
                            break;
                        case "weight":
                            metatag.weight = xtr.Value;
                            break;
                        case "favcolor":
                            metatag.favcolor = xtr.Value;
                            break;
                        case "favmusic":
                            metatag.favmusic = Convert.ToInt32(xtr.Value);
                            break;
                        case "favfood":
                            metatag.favfood = Convert.ToInt32(xtr.Value);
                            break;
                        case "skintoneindex":
                            metatag.skintoneindex = xtr.Value;
                            break;
                        case "handedness":
                            metatag.handedness = xtr.Value;
                            break;
                    }
                }
                if (xtr.NodeType == XmlNodeType.EndElement && xtr.Name.ToLower() == "metatags") break;
            }
            return metatag;
        }