/// <summary>
        /// reads the icon und xml resources from a package file
        /// </summary>
        /// <param name="path">path of the package file</param>
        /// <param name="isTemp">is package a temporary file</param>
        /// <returns>pattern object filled with read informations</returns>
        public Pattern read(string path, bool isTemp)
        {
            Pattern pattern = new Pattern(path);

            IPackage                    package     = s3pi.Package.Package.OpenPackage(0, path, false);
            List<IResourceIndexEntry>   resources  = package.GetResourceList;

            foreach (IResourceIndexEntry indexEntry in resources)
            {
                //Get Icon Image from ICON Resource (different res types for small medium, large, very large)
                if (    indexEntry.ResourceType == 0x2E75C764
                     || indexEntry.ResourceType == 0x2E75C765
                     || indexEntry.ResourceType == 0x2E75C766
                     || indexEntry.ResourceType == 0x2E75C767
                    )
                {
                    IResource imageResource = WrapperDealer.GetResource(0, package, indexEntry);
                    ImageResource.ImageResource imageRes = imageResource as ImageResource.ImageResource;
                    pattern.Icon = imageRes.Value;
                }

                // Get pattern xml ressource
                else if (indexEntry.ResourceType == 0x0333406C)
                {
                    IResource   xmlResource = WrapperDealer.GetResource(0, package, indexEntry);
                    Stream      stream      = xmlResource.Stream;

                    pattern.Xml = System.Text.UTF8Encoding.UTF8.GetString(xmlResource.AsBytes);

                }
                // Get pattern xml manifest
                else if (indexEntry.ResourceType == 0x73E93EEB)
                {
                    IResource xmlResource = WrapperDealer.GetResource(0, package, indexEntry);
                    Stream stream = xmlResource.Stream;

                    pattern.Manifest = System.Text.UTF8Encoding.UTF8.GetString(xmlResource.AsBytes);

                }

            }

            s3pi.Package.Package.ClosePackage(0, package);

            if (isTemp)
            {
                File.Delete(pattern.Path);

            }

            return pattern;
        }
        private void displayPattern(Pattern pattern)
        {
            resetGui();

            if (pattern != null)
            {
                if (pattern.Colors[0] != Color.Empty)
                {
                    textBoxColor0.Text = ColorTranslator.ToHtml(pattern.Colors[0]).Remove(0,1);
                    _saveColor0Text     = textBoxColor0.Text;

                    colorBox0.BackColor = pattern.Colors[0];
                }

                if (pattern.Colors[1] != Color.Empty)
                {
                    textBoxColor1.Text = ColorTranslator.ToHtml(pattern.Colors[1]).Remove(0, 1);
                    _saveColor1Text     = textBoxColor1.Text;

                    colorBox1.BackColor = pattern.Colors[1];
                }

                if (pattern.Colors[2] != Color.Empty)
                {
                    textBoxColor2.Text = ColorTranslator.ToHtml(pattern.Colors[2]).Remove(0, 1);
                    _saveColor2Text     = textBoxColor2.Text;

                    colorBox2.BackColor = pattern.Colors[2];
                }

                if (pattern.Colors[3] != Color.Empty)
                {
                    textBoxColor3.Text = ColorTranslator.ToHtml(pattern.Colors[3]).Remove(0, 1);
                    _saveColor3Text     = textBoxColor3.Text;

                    colorBox3.BackColor = pattern.Colors[3];
                }
            }

            pictureBoxIcon.Image = pattern.Icon;
            textBoxFilePath.Text = pattern.DisplayPath;
            textBoxSurfaceMaterial.Text = pattern.SurfaceMaterial;
            textBoxCategory.Text = pattern.Category;
        }
        private void openSimsPatternFile(string filePath)
        {
            _pattern = null;

            FileInfo file = new FileInfo(filePath);

            if (file.Extension.ToLower() == ".package")
            {
                PackageReader packageReader = new PackageReader();
                _pattern = packageReader.read(filePath, false);
                _pattern.DisplayPath = filePath;

                XmlDecoder xmlDecoder = new XmlDecoder();
                xmlDecoder.decode(_pattern);
            }
            else if (file.Extension.ToLower() == ".sims3pack")
            {
                Sims3PackXmlReader sims3packReader = new Sims3PackXmlReader();
                PatternPackage patternPackage = sims3packReader.read(filePath);

                XmlDecoder xmlDecoder = new XmlDecoder();
                xmlDecoder.decode(patternPackage);

                PackageFileCreator packageFileCreator = new PackageFileCreator();
                packageFileCreator.createTmpPackageFile(patternPackage);

                PackageReader packageReader = new PackageReader();
                _pattern = packageReader.read(patternPackage.TmpPackagePath, true);
                _pattern.DisplayPath = patternPackage.Sims3PackPath;

                xmlDecoder.decode(_pattern);
            }

            displayPattern(_pattern);
        }
 /// <summary>
 /// decodes a pattern
 /// </summary>
 /// <param name="pattern"></param>
 public void decode(Pattern pattern)
 {
     decodePatternXml(pattern);
        decodeManifestXml(pattern);
 }
        /// <summary>
        /// decodes color values from pattern resource xml
        /// </summary>
        /// <param name="pattern"></param>
        private void decodePatternXml(Pattern pattern)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(pattern.Xml);

            XmlNode complate = xmlDocument.DocumentElement;

            Color[] colors = new Color[4];

            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = Color.Empty;
            }

            //search for attributes category, type, surface Material
            XmlAttributeCollection complateAttributes = complate.Attributes;

            foreach (XmlAttribute attribute in complateAttributes)
            {
                if (attribute.Name == xmlComplateAttributCategory)
                {
                    pattern.Category = attribute.Value;
                }
                else if (attribute.Name == xmlComplateAttributType)
                {
                    pattern.Type = attribute.Value;
                }
                else if (attribute.Name == xmlComplateAttributSurfaceCategory)
                {
                    pattern.SurfaceMaterial = attribute.Value;
                }
            }

            //search for the param nodes
            foreach (XmlNode node in complate.ChildNodes)
            {
                if (node.Name == xmlVariablesNodeName)
                {
                    foreach (XmlNode subnode in node.ChildNodes)
                    {
                        if (subnode.Name == xmlParamNodeName)
                        {
                            //get the color params
                            if (subnode.Attributes[xmlTypeAttributName].Value == "color")
                            {
                                string colorName = subnode.Attributes[xmlNameAttributName].Value;
                                string colorValues = subnode.Attributes[xmlDefaultAttributName].Value;

                                string[] splitValues = colorValues.Split(',');

                                int colorID = Convert.ToInt32(colorName.Substring(colorName.Length - 1));

                                int alpha = (int)Math.Round(Convert.ToDouble(splitValues[3], CultureInfo.InvariantCulture.NumberFormat) * 255, 0, MidpointRounding.AwayFromZero);
                                int red = (int)Math.Round(Convert.ToDouble(splitValues[0], CultureInfo.InvariantCulture.NumberFormat) * 255, 0, MidpointRounding.AwayFromZero);
                                int green = (int)Math.Round(Convert.ToDouble(splitValues[1], CultureInfo.InvariantCulture.NumberFormat) * 255, 0, MidpointRounding.AwayFromZero);
                                int blue = (int)Math.Round(Convert.ToDouble(splitValues[2], CultureInfo.InvariantCulture.NumberFormat) * 255, 0, MidpointRounding.AwayFromZero);

                                Color color = System.Drawing.Color.FromArgb(alpha, red, green, blue);

                                colors[colorID] = color;
                            }
                        }
                    }
                }
            }

            pattern.Colors = colors;
        }
        /// <summary>
        /// reads title from the manifest
        /// </summary>
        /// <param name="pattern"></param>
        private void decodeManifestXml(Pattern pattern)
        {
            XmlDocument xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(pattern.Manifest);

            XmlNodeList titleElements = xmlDocument.GetElementsByTagName(xmlManifestTitelNodeName);
            if (titleElements.Count > 0)
            {
                pattern.Title = titleElements[0].InnerText;
            }
        }