Example #1
0
        public static Image makePatternThumb(Stream input)
        {
            Wrappers.Database db      = new MadScience.Wrappers.Database(input, true);
            patternDetails    pattern = parsePatternComplate(MadScience.Package.Search.getStream(db, 0x0333406C, -1, -1));

            Image img = makePatternThumb(pattern, db);

            return(img);
        }
Example #2
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                return;
            }

            ListViewItem item      = listView1.SelectedItems[0];
            Stream       fileinput = Sims3PackFile.PackagedFiles[item.Index].DBPF;

            fileinput.Position = 0;
            Stream input = Stream.Null;

            switch (this.detective.pType.ToType(item.SubItems[3].Text))
            {
            case MadScience.Detective.PackageTypes.pngThumbnail:
                picThumb.Image   = Image.FromStream(fileinput);
                picThumb.Visible = true;
                break;

            case MadScience.Detective.PackageTypes.objectGeneric:
                MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(fileinput);
                input = MadScience.Package.Search.getStream(db, 0x2E75C764, -1, -1);
                if (!MadScience.StreamHelpers.isValidStream(input))
                {
                    input = MadScience.Package.Search.getStream(db, 0x2E75C765, -1, -1);
                    if (!MadScience.StreamHelpers.isValidStream(input))
                    {
                        input = MadScience.Package.Search.getStream(db, 0x2E75C766, -1, -1);
                    }
                }
                if (MadScience.StreamHelpers.isValidStream(input))
                {
                    picThumb.Image   = Image.FromStream(input);
                    picThumb.Visible = true;
                }
                else
                {
                    picThumb.Visible = false;
                }
                break;

            case MadScience.Detective.PackageTypes.patternGeneric:
                picThumb.Image   = MadScience.Patterns.makePatternThumb(fileinput);
                picThumb.Visible = true;
                break;

            default:
                picThumb.Visible = false;
                break;
            }
        }
Example #3
0
        private void showCacheInfo(string cachePath, string cacheName)
        {
            if (!String.IsNullOrEmpty(cachePath) && !File.Exists(cachePath))
            {
                return;
            }


            // CAS Part Cache
            ListViewItem item = new ListViewItem();

            item.Text = cacheName;
            item.SubItems.Add(cachePath);

            if (!String.IsNullOrEmpty(cachePath))
            {
                if (!File.Exists(cachePath))
                {
                    item.SubItems.Add("0");
                    item.SubItems.Add("0");
                }
                else
                {
                    FileInfo f = new FileInfo(cachePath);
                    if (f.Length > 0)
                    {
                        item.SubItems.Add(((f.Length / 1024) + 1).ToString());
                    }
                    else
                    {
                        item.SubItems.Add("0");
                    }

                    Stream casPartCache             = File.OpenRead(cachePath);
                    MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(casPartCache, true);
                    item.SubItems.Add(db.dbpf.Entries.Count.ToString());
                    casPartCache.Close();
                }
            }
            else
            {
                item.SubItems.Add("");
                item.SubItems.Add("");
            }

            listView2.Items.Add(item);
        }
Example #4
0
        public static Stream searchForKey(string keyString, string filename)
        {
            // Validate keystring
            if (validateKey(keyString) == false)
            {
                return(null);
            }

            if (!File.Exists(filename))
            {
                return(null);
            }

            keyName tKey    = new keyName(keyString);
            Stream  tStream = null;

            Stream input = File.OpenRead(filename);

            MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(input, true);

            try
            {
                tStream = db.GetResourceStream(tKey.ToResourceKey());
            }
            catch (System.Collections.Generic.KeyNotFoundException ex)
            {
                Helpers.logMessageToFile(ex.Message);
            }
            catch (Exception ex)
            {
                Helpers.logMessageToFile(ex.Message);
            }

            input.Close();

            return(tStream);
        }
        /*
        public Stream findPattern(patternsFile pattern)
        {
            if (File.Exists(pattern.subcategory))
            {
                Stream cast = File.Open(pattern.subcategory, FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database castdb = new MadScience.Wrappers.Database(cast, true);

                MadScience.Wrappers.ResourceKey temp = new MadScience.Wrappers.ResourceKey(pattern.texturename);
                Stream patternThumb = null;

                try
                {
                    patternThumb = castdb.GetResourceStream(temp);
                }
                catch (System.Collections.Generic.KeyNotFoundException ex)
                {
                }
                catch (Exception ex)
                {
                    Helpers.logMessageToFile(ex.Message);
                }
                cast.Close();

                if (patternThumb != null)
                {
                    return patternThumb;
                }
            }

            return Stream.Null;
        }
        */
        /*
        public patternsFile findPattern(string resKey)
        {
            // Get pattern details from XML
            keyName patternXML = new keyName(resKey);
            patternsFile temp = new patternsFile();

            bool hasMatch = false;

            for (int i = 0; i < this.customPatterns.Items.Count; i++)
            {
                patternsFile pattern = this.customPatterns.Items[i];

                if (MadScience.StringHelpers.ParseHex32(pattern.typeid) == patternXML.typeId && MadScience.StringHelpers.ParseHex32(pattern.groupid) == patternXML.groupId && MadScience.StringHelpers.ParseHex64(pattern.instanceid) == patternXML.instanceId)
                {
                    hasMatch = true;
                    temp = pattern;
                    break;
                }
            }

            if (!hasMatch)
            {
                for (int i = 0; i < this.patterns.Items.Count; i++)
                {
                    patternsFile pattern = this.patterns.Items[i];

                    if (MadScience.StringHelpers.ParseHex32(pattern.typeid) == patternXML.typeId && MadScience.StringHelpers.ParseHex32(pattern.groupid) == patternXML.groupId && MadScience.StringHelpers.ParseHex64(pattern.instanceid) == patternXML.instanceId)
                    {
                        hasMatch = true;
                        temp = pattern;
                        break;
                    }
                }
            }

            return temp;
        }
        */
        /*
        public Image makePatternThumb(string resKey)
        {
            return makePatternThumb(findPattern(resKey), null);
        }
        */
        /*
        public patternsFile pDetailsTopFile(patternDetails pDetails)
        {
            patternsFile pFile = new patternsFile();

            keyName pKey = new keyName(pDetails.key);
            pFile.casPart = pDetails.filename;
            pFile.typeid = "0x" + pKey.typeId.ToString("X8");
            pFile.groupid = "0x" + pKey.groupId.ToString("X8");
            pFile.instanceid = "0x" + pKey.instanceId.ToString("X16");

            pFile.category = pDetails.category;
            pFile.color0 = pDetails.ColorP[0];
            pFile.color1 = pDetails.ColorP[1];
            pFile.color2 = pDetails.ColorP[2];
            pFile.color3 = pDetails.ColorP[3];
            pFile.color4 = pDetails.ColorP[4];

            pFile.HBg = pDetails.HBg;
            pFile.SBg = pDetails.SBg;
            pFile.VBg = pDetails.VBg;

            return pFile;
        }
        */
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            panel1.Visible = false;

            label2.Text = "Loading patterns... Please wait...";
            label2.Refresh();

            numFound = 0;
            horizontal = 0;
            vertical = 0;

            ToolTip tt = new ToolTip();

            DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile();

            if (comboBox1.Text == "* Custom")
            {

                for (int i = 0; i < this.customPatterns.Items.Count; i++)
                {
                    patternsFile pattern = this.customPatterns.Items[i];
                    //if (pattern.category == comboBox1.Text)
                    //{

                        numFound++;

                        PictureBox picBox = new PictureBox();
                        picBox.BackColor = System.Drawing.Color.White;
                        picBox.Name = pattern.casPart;

                        string toolTip = pattern.category + "\\";
                        //if (pattern.subcategory != "")
                        //{
                            //toolTip += pattern.subcategory + "\\";
                        //}
                        toolTip += pattern.casPart;
                        tt.SetToolTip(picBox, toolTip);

                        // Find thumbnail
                        if (File.Exists(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png"))))
                        {
                            Stream tmpImage = File.OpenRead(Path.Combine(Application.StartupPath, Path.Combine("patterncache",  pattern.casPart + ".png")));
                            picBox.Image = Image.FromStream(tmpImage);
                            tmpImage.Close();
                        }
                        else
                        {
                            if (File.Exists(pattern.subcategory))
                            {

                                //if (pattern.typeid.StartsWith("0x")) pattern.typeid = pattern.typeid.Remove(0, 2);
                                //if (pattern.groupid.StartsWith("0x")) pattern.groupid = pattern.groupid.Remove(0, 2);
                                //if (pattern.instanceid.StartsWith("0x")) pattern.instanceid = pattern.instanceid.Remove(0, 2);

                                Stream patternXml = KeyUtils.searchForKey(pattern.key, pattern.subcategory);
                                if (StreamHelpers.isValidStream(patternXml))
                                {
                                    Patterns.patternDetails pDetails = Patterns.parsePatternComplate(patternXml);
                                    //Stream patternThumb = KeyUtils.searchForKey(pattern.texturename, pattern.subcategory);
                                    //if (Helpers.isValidStream(patternThumb))
                                    //{
                                        //picBox.Image = Patterns.makePatternThumb(patternThumb, pDetails);
                                    picBox.Image = Patterns.makePatternThumb(pDetails);
                                        try
                                        {
                                            picBox.Image.Save(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png")), System.Drawing.Imaging.ImageFormat.Png);
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    //}
                                }
                            }

                        }

                        addToPanel(picBox);
                    //}

                }

            }
            else
            {

                string s3root = MadScience.Helpers.findSims3Root();
                string thumbnailPackage = Helpers.getGameSubPath(@"\GameData\Shared\Packages\FullBuild2.package");

                Console.WriteLine("Starting at: " + DateTime.Now.ToString());

                Stream cast = File.Open(Path.Combine(s3root, thumbnailPackage), FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database castdb = new MadScience.Wrappers.Database(cast);

                Stream fullBuild0 = File.Open(Path.Combine(s3root, Helpers.getGameSubPath(@"\GameData\Shared\Packages\FullBuild0.package")), FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database xmldb = new MadScience.Wrappers.Database(fullBuild0);

                for (int i = 0; i < this.patterns.Items.Count; i++)
                {
                    patternsFile pattern = this.patterns.Items[i];
                    if (pattern.category == comboBox1.Text)
                    {

                        numFound++;

                        PictureBox picBox = new PictureBox();
                        picBox.BackColor = System.Drawing.Color.White;
                        picBox.Name = pattern.casPart;

                        string toolTip = pattern.category + "\\";
                        if (pattern.subcategory != "")
                        {
                            toolTip += pattern.subcategory + "\\";
                        }
                        toolTip += pattern.casPart;
                        tt.SetToolTip(picBox, toolTip);

                        // Find thumbnail
                        if (File.Exists(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png"))))
                        {
                            Stream tmpImage = File.OpenRead(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png")));
                            picBox.Image = Image.FromStream(tmpImage);
                            tmpImage.Close();
                        }
                        else
                        {
                            //Console.WriteLine(pattern.casPart);

                            Stream patternXml = KeyUtils.findKey(new MadScience.Wrappers.ResourceKey(pattern.key), 0, xmldb);
                            if (StreamHelpers.isValidStream(patternXml))
                            {
                                Patterns.patternDetails pDetails2 = Patterns.parsePatternComplate(patternXml);
                                //Stream patternThumb = KeyUtils.findKey(new MadScience.Wrappers.ResourceKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails2.name).ToString("X16")), 0, castdb);
                                //if (!Helpers.isValidStream(patternThumb))
                                //{
                                //    patternThumb = KeyUtils.findKey(new MadScience.Wrappers.ResourceKey(pDetails2.BackgroundImage), 0, castdb);
                                //}
                                //if (Helpers.isValidStream(patternThumb))
                                //{
                                    picBox.Image = Patterns.makePatternThumb(pDetails2, castdb);
                                    try
                                    {
                                        picBox.Image.Save(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png")), System.Drawing.Imaging.ImageFormat.Png);
                                    }
                                    catch (Exception)
                                    {
                                    }
                                //}
                            }
                        }

                        addToPanel(picBox);

                    }

                }

                Console.WriteLine("Stopping at: " + DateTime.Now.ToString());

                //dbpf = null;
                fullBuild0.Close();
                cast.Close();
                //castdb = null;
            }
            label2.Text = numFound.ToString() + " patterns";
            panel1.Visible = true;
            this.curCategory = comboBox1.SelectedIndex;
        }
        private void btnLoadCustom_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Sims 3 Package|*.package";
            if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName != "")
            {
                Stream cast = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database castdb = new MadScience.Wrappers.Database(cast, true);

                // Open XML file
                //patternsFile cPattern = new patternsFile();
                Patterns.patternDetails pDetails = new Patterns.patternDetails();

                foreach (MadScience.Wrappers.ResourceKey key in castdb._Entries.Keys)
                {
                    if ((key.groupId == 0x00000000) && (key.typeId == 0x0333406C))
                    {
                        pDetails = Patterns.parsePatternComplate(castdb.GetResourceStream(key));
                        patternsFile cPattern = new patternsFile();

                        //MadScience.Wrappers.ResourceKey rKey = new MadScience.Wrappers.ResourceKey(pDetails.key);

                        //cPattern.typeid = rKey.typeId.ToString("X8");
                        //cPattern.groupid = rKey.groupId.ToString("X8");
                        //cPattern.instanceid = rKey.instanceId.ToString("X16");

                        cPattern.key = pDetails.key;

                        if (!StreamHelpers.isValidStream(KeyUtils.findKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1)).ToString("X16"))))
                        {
                            if (String.IsNullOrEmpty(pDetails.BackgroundImage))
                            {
                                cPattern.texturename = pDetails.rgbmask;
                            }
                            else
                            {
                                cPattern.texturename = pDetails.BackgroundImage;
                            }
                        }
                        else
                        {
                            cPattern.texturename = "key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1)).ToString("X16");
                        }
                        cPattern.casPart = pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1);

                        cPattern.subcategory = openFileDialog1.FileName;
                        pDetails.customFilename = openFileDialog1.FileName;
                        cPattern.isCustom = true;
                        pDetails.isCustom = true;

                        customPatterns.Items.Add(cPattern);

                            TextWriter r = new StreamWriter(Path.Combine(Application.StartupPath, Path.Combine("xml", "customPatterns.xml")));
                            XmlSerializer s = new XmlSerializer(typeof(patterns));
                            s.Serialize(r, customPatterns);
                            r.Close();

                        break;
                    }
                }

                //Stream patternThumb = KeyUtils.searchForKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name), openFileDialog1.FileName);
                //if (!Helpers.isValidStream(patternThumb))
                //{
                //    patternThumb = KeyUtils.searchForKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.BackgroundImage), openFileDialog1.FileName);
                //}

                //if (Helpers.isValidStream(patternThumb))
                //{
                    //Stream patternDDS = File.OpenWrite(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pDetails.name + ".dds")));
                    //Helpers.CopyStream(patternThumb, patternDDS, true);
                    //patternDDS.Close();

                    //patternThumb.Seek(0, SeekOrigin.Begin);

                    PictureBox picBox = new PictureBox();
                    picBox.BackColor = System.Drawing.Color.White;
                    //picBox.Location = new System.Drawing.Point(horizontal, vertical);
                    picBox.Name = pDetails.name;

                    string toolTip = pDetails.category + "\\";
                    ToolTip tt = new ToolTip();
                    toolTip += pDetails.name;
                    tt.SetToolTip(picBox, toolTip);

                    picBox.Image = Patterns.makePatternThumb(pDetails, castdb);
                    //picBox.Image =     castdb.GetResourceStream(entry.Key);
                    try
                    {
                        picBox.Image.Save(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pDetails.name + ".png")), System.Drawing.Imaging.ImageFormat.Png);
                    }
                    catch (Exception)
                    {
                    }

                    addToPanel(picBox);

                    cast.Close();
                    //picBox.Dispose();
                //}

                comboBox1.SelectedIndex = 15;
            }
        }
        public static Image makePatternThumb(Stream input)
        {
            Wrappers.Database db = new MadScience.Wrappers.Database(input, true);
            patternDetails pattern = parsePatternComplate(MadScience.Package.Search.getStream(db, 0x0333406C, -1, -1));

            Image img = makePatternThumb(pattern, db);
            return img;
        }
Example #8
0
        public static List <Stream> findKey(List <MadScience.Wrappers.ResourceKey> resourceKeys, int fullBuildNum, MadScience.Wrappers.Database db)
        {
            List <Stream> tempChunks = new List <Stream>();

            // Add one Stream per keyName, even if null
            for (int i = 0; i < resourceKeys.Count; i++)
            {
                tempChunks.Add(new MemoryStream());
            }

            // Check local files first
            if (Helpers.localFiles.Count > 0)
            {
                for (int i = 0; i < resourceKeys.Count; i++)
                {
                    if (Helpers.localFiles.ContainsKey(resourceKeys[i].ToString()))
                    {
                        Stream blah = File.OpenRead((string)Helpers.localFiles[resourceKeys[i].ToString()]);
                        StreamHelpers.CopyStream(blah, tempChunks[i]);
                        tempChunks[i].Seek(0, SeekOrigin.Begin);
                        blah.Close();
                    }
                }
            }

            //check current package
            if (!String.IsNullOrEmpty(Helpers.currentPackageFile))
            {
                Stream localPackage = File.Open(Helpers.currentPackageFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database localDb = new MadScience.Wrappers.Database(localPackage, true);

                for (int i = 0; i < resourceKeys.Count; i++)
                {
                    if (tempChunks[i].Length == 0)
                    {
                        try
                        {
                            tempChunks[i] = localDb.GetResourceStream(resourceKeys[i]);
                        }
                        catch (System.Collections.Generic.KeyNotFoundException)
                        {
                            //Helpers.logMessageToFile(ex.Message);
                        }
                        catch (Exception)
                        {
                            //Helpers.logMessageToFile(ex.Message);
                        }
                    }
                }

                localPackage.Close();
            }

            //check global packages
            foreach (string filename in Helpers.globalPackageFiles)
            {
                if (!String.IsNullOrEmpty(filename))
                {
                    using (Stream localPackage = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        MadScience.Wrappers.Database localDb = new MadScience.Wrappers.Database(localPackage, true);

                        for (int i = 0; i < resourceKeys.Count; i++)
                        {
                            if (tempChunks[i].Length == 0)
                            {
                                try
                                {
                                    tempChunks[i] = localDb.GetResourceStream(resourceKeys[i]);
                                }
                                catch (System.Collections.Generic.KeyNotFoundException)
                                {
                                    //Helpers.logMessageToFile(ex.Message);
                                }
                                catch (Exception)
                                {
                                    //Helpers.logMessageToFile(ex.Message);
                                }
                            }
                        }

                        localPackage.Close();
                    }
                }
            }

            // If input stream isn't null then we use that, otherwise open the fullbuild we want...
            Stream input   = Stream.Null;
            bool   closeDb = false;

            if (db == null)
            {
                closeDb = true;
                try
                {
                    input = File.OpenRead(Path.Combine(Helpers.findSims3Root(), Helpers.getGameSubPath("\\GameData\\Shared\\Packages\\FullBuild" + fullBuildNum.ToString() + ".package")));
                    db    = new MadScience.Wrappers.Database(input, true);
                }
                catch (Exception)
                {
                    return(tempChunks);
                }
            }

            for (int i = 0; i < resourceKeys.Count; i++)
            {
                if (tempChunks[i].Length == 0)
                {
                    //keyName tKey = new keyName(resourceKeys[i]);
                    try
                    {
                        tempChunks[i] = db.GetResourceStream(resourceKeys[i]);
                    }
                    catch (System.Collections.Generic.KeyNotFoundException)
                    {
                        //Helpers.logMessageToFile(ex.Message);
                    }
                    catch (Exception)
                    {
                        //Helpers.logMessageToFile(ex.Message);
                    }
                }
            }
            if (closeDb)
            {
                input.Close();
            }

            return(tempChunks);
        }
Example #9
0
        private void checkPackage(string filename, ListViewItem item)
        {
            // Check 0 byte file
            FileInfo f = new FileInfo(filename);

            if (!alwaysUseFastScanToolStripMenuItem.Checked)
            {
                toolStripStatusLabel1.Text = "Checking " + f.Name;
                statusStrip1.Refresh();
            }

            detective.isCorrupt  = false;
            detective.isDisabled = false;

            if (f.Length == 0)
            {
                item.BackColor        = detective.pType.ToColor(MadScience.Detective.PackageTypes.emptyPackage);
                item.SubItems[2].Text = detective.pType.ToString(MadScience.Detective.PackageTypes.emptyPackage);
                return;
            }

            if (filename.EndsWith(".disabled"))
            {
                detective.isDisabled = true;
                item.BackColor       = detective.pType.ToColor(MadScience.Detective.PackageTypes.disabledPackage);
            }

            Stream input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read);

            MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(input, true, false);

            try
            {
                if (filename.Contains(".dbc"))
                {
                    MadScience.Detective.PackageType packageType = detective.getType(db, true);
                }
                else
                {
                    MadScience.Detective.PackageType packageType = detective.getType(db, false);
                }
            }
            catch (System.Exception excpt)
            {
                MessageBox.Show(excpt.Message + " " + excpt.StackTrace, f.Name);
                detective.pType.MainType = MadScience.Detective.PackageTypes.corruptBadDownload;
                detective.isCorrupt      = true;
                item.BackColor           = detective.pType.ToColor();
                item.SubItems[2].Text    = detective.pType.ToString();
                input.Close();
                return;
            }

            if (detective.pType.MainType == MadScience.Detective.PackageTypes.sims2Package)
            {
                item.SubItems[2].Text = detective.pType.ToString();
                if (!detective.isDisabled)
                {
                    item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.sims2Package);
                }
                input.Close();
                return;
            }

            // Game number
            switch (db.dbpf.gameNumber)
            {
            case MadScience.Helpers.GameNumber.baseGame:
                item.SubItems[7].Text = "Base";
                break;

            case MadScience.Helpers.GameNumber.worldAdventures:
                item.SubItems[7].Text = "WA";
                break;

            case MadScience.Helpers.GameNumber.highEndLoftStuff:
                item.SubItems[7].Text = "HELS";
                break;

            case MadScience.Helpers.GameNumber.ambitions:
                item.SubItems[7].Text = "AMB";
                break;
            }

            if (detective.isCorrupt)
            {
                item.SubItems[2].Text = detective.pType.ToString();
                item.SubItems[6].Text = detective.pType.SubType;
                if (!detective.isDisabled)
                {
                    item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.corruptTXTC);
                }
                input.Close();
                return;
            }

            if (!detective.isDisabled)
            {
                item.BackColor = listView1.BackColor;
            }
            string pType = detective.pType.ToString();

            // Check if any of this packages types exist in the entriesdb
            for (int i = 0; i < db.dbpf.Entries.Count; i++)
            {
                MadScience.Wrappers.DatabasePackedFile.Entry entry = db.dbpf.Entries[i];
                bool   dealtWith   = false;
                string entryString = entry.Key.ToString();

                if (Enum.IsDefined(typeof(ConflictTypes), entry.Key.typeId))
                //foreach (uint typeHash in Enum.GetValues(typeof(ResourceTypes)))
                //{
                //	if (typeHash == entry.Key.typeId)
                {
                    if (conflictList.ContainsKey(entryString))
                    {
                        // Something already has this ResourceKey - mark file as conflicted.
                        // But wait!  Check if it's pointing to itself first. :)
                        if (conflictList[entryString] == (int)item.Tag)
                        {
                            break;
                        }

                        // Check if it's an entire duplicate, or merely part
                        FileInfo f2 = new FileInfo(packageList[conflictList[entryString]].SubItems[1].Text);
                        //FileInfo f2 = new FileInfo(listView1.Items[conflictList[entryString]].SubItems[1].Text);
                        if (f.Length == f2.Length)
                        {
                            pType = "Duplicate of " + Path.Combine(packageList[conflictList[entryString]].SubItems[5].Text, packageList[conflictList[entryString]].Text);
                            if (!detective.isDisabled)
                            {
                                item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.duplicatePackage);
                                packageList[conflictList[entryString]].BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.duplicatePackage);
                            }
                            dealtWith = true;
                            break;
                        }
                        else
                        {
                            pType = "Conflicts with " + Path.Combine(packageList[conflictList[entryString]].SubItems[5].Text, packageList[conflictList[entryString]].Text);
                            if (!detective.isDisabled)
                            {
                                item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.conflictPackage);

                                if (packageList[conflictList[entryString]].BackColor != detective.pType.ToColor(MadScience.Detective.PackageTypes.corruptTXTC))
                                {
                                    packageList[conflictList[entryString]].BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.conflictPackage);
                                }
                            }
                            dealtWith = true;
                            break;
                        }
                    }
                    else
                    {
                        conflictList.Add(entryString, (int)item.Tag);
                    }
                    //	}
                }

                if (dealtWith == true)
                {
                    break;
                }
            }

            input.Close();

            //if (packageType == "unknown")
            //{
            //packageType = "Sims 3 Package";
            //}

            item.SubItems[2].Text = pType;
            item.SubItems[6].Text = detective.pType.SubType;
        }
        private void showCacheInfo(string cachePath, string cacheName)
        {
            if (!String.IsNullOrEmpty(cachePath) && !File.Exists(cachePath)) return;

            // CAS Part Cache
            ListViewItem item = new ListViewItem();

            item.Text = cacheName;
            item.SubItems.Add(cachePath);

            if (!String.IsNullOrEmpty(cachePath))
            {
                if (!File.Exists(cachePath))
                {
                    item.SubItems.Add("0");
                    item.SubItems.Add("0");

                }
                else
                {

                    FileInfo f = new FileInfo(cachePath);
                    if (f.Length > 0)
                    {
                        item.SubItems.Add(((f.Length / 1024) + 1).ToString());
                    }
                    else
                    {
                        item.SubItems.Add("0");
                    }

                    Stream casPartCache = File.OpenRead(cachePath);
                    MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(casPartCache, true);
                    item.SubItems.Add(db.dbpf.Entries.Count.ToString());
                    casPartCache.Close();
                }
            }
            else
            {
                item.SubItems.Add("");
                item.SubItems.Add("");
            }

            listView2.Items.Add(item);
        }
        public static Stream searchForKey(string keyString, string filename)
        {
            // Validate keystring
            if (validateKey(keyString) == false)
            {
                return null;
            }

            if (!File.Exists(filename))
            {
                return null;
            }

            keyName tKey = new keyName(keyString);
            Stream tStream = null;

            Stream input = File.OpenRead(filename);
            MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(input, true);

            try
            {

                tStream = db.GetResourceStream(tKey.ToResourceKey());
            }
            catch (System.Collections.Generic.KeyNotFoundException ex)
            {
                Helpers.logMessageToFile(ex.Message);
            }
            catch (Exception ex)
            {
                Helpers.logMessageToFile(ex.Message);
            }

            input.Close();

            return tStream;
        }
        public static List<Stream> findKey(List<MadScience.Wrappers.ResourceKey> resourceKeys, int fullBuildNum, MadScience.Wrappers.Database db)
        {
            List<Stream> tempChunks = new List<Stream>();

            // Add one Stream per keyName, even if null
            for (int i = 0; i < resourceKeys.Count; i++)
            {
                tempChunks.Add(new MemoryStream());
            }

            // Check local files first
            if (Helpers.localFiles.Count > 0)
            {

                for (int i = 0; i < resourceKeys.Count; i++)
                {
                    if (Helpers.localFiles.ContainsKey(resourceKeys[i].ToString()))
                    {
                        Stream blah = File.OpenRead((string)Helpers.localFiles[resourceKeys[i].ToString()]);
                        StreamHelpers.CopyStream(blah, tempChunks[i]);
                        tempChunks[i].Seek(0, SeekOrigin.Begin);
                        blah.Close();
                    }
                }

            }

            //check current package
            if (!String.IsNullOrEmpty(Helpers.currentPackageFile))
            {
                Stream localPackage = File.Open(Helpers.currentPackageFile, FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database localDb = new MadScience.Wrappers.Database(localPackage, true);

                for (int i = 0; i < resourceKeys.Count; i++)
                {
                    if (tempChunks[i].Length == 0)
                    {
                        try
                        {
                            tempChunks[i] = localDb.GetResourceStream(resourceKeys[i]);
                        }
                        catch (System.Collections.Generic.KeyNotFoundException)
                        {
                            //Helpers.logMessageToFile(ex.Message);
                        }
                        catch (Exception)
                        {
                            //Helpers.logMessageToFile(ex.Message);
                        }
                    }
                }

                localPackage.Close();
            }

            //check global packages
            foreach (string filename in Helpers.globalPackageFiles)
            {
                if (!String.IsNullOrEmpty(filename))
                {
                    using (Stream localPackage = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        MadScience.Wrappers.Database localDb = new MadScience.Wrappers.Database(localPackage, true);

                        for (int i = 0; i < resourceKeys.Count; i++)
                        {
                            if (tempChunks[i].Length == 0)
                            {
                                try
                                {
                                    tempChunks[i] = localDb.GetResourceStream(resourceKeys[i]);
                                }
                                catch (System.Collections.Generic.KeyNotFoundException)
                                {
                                    //Helpers.logMessageToFile(ex.Message);
                                }
                                catch (Exception)
                                {
                                    //Helpers.logMessageToFile(ex.Message);
                                }
                            }
                        }

                        localPackage.Close();
                    }
                }
            }

            // If input stream isn't null then we use that, otherwise open the fullbuild we want...
            Stream input = Stream.Null;
            bool closeDb = false;
            if (db == null)
            {
                closeDb = true;
                try
                {
                    input = File.OpenRead(Path.Combine(Helpers.findSims3Root(), Helpers.getGameSubPath("\\GameData\\Shared\\Packages\\FullBuild" + fullBuildNum.ToString() + ".package")));
                    db = new MadScience.Wrappers.Database(input, true);
                }
                catch (Exception)
                {
                    return tempChunks;
                }
            }

            for (int i = 0; i < resourceKeys.Count; i++)
            {
                if (tempChunks[i].Length == 0)
                {

                    //keyName tKey = new keyName(resourceKeys[i]);
                    try
                    {
                        tempChunks[i] = db.GetResourceStream(resourceKeys[i]);
                    }
                    catch (System.Collections.Generic.KeyNotFoundException)
                    {
                        //Helpers.logMessageToFile(ex.Message);
                    }
                    catch (Exception)
                    {
                        //Helpers.logMessageToFile(ex.Message);
                    }
                }
            }
            if (closeDb)
            {
                input.Close();
            }

            return tempChunks;
        }
        private void btnLoadCustom_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "Sims 3 Package|*.package";
            if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName != "")
            {
                Stream cast = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database castdb = new MadScience.Wrappers.Database(cast, true);

                // Open XML file
                //patternsFile cPattern = new patternsFile();
                Patterns.patternDetails pDetails = new Patterns.patternDetails();

                foreach (MadScience.Wrappers.ResourceKey key in castdb._Entries.Keys)
                {
                    if ((key.groupId == 0x00000000) && (key.typeId == 0x0333406C))
                    {
                        pDetails = Patterns.parsePatternComplate(castdb.GetResourceStream(key));
                        patternsFile cPattern = new patternsFile();

                        //MadScience.Wrappers.ResourceKey rKey = new MadScience.Wrappers.ResourceKey(pDetails.key);

                        //cPattern.typeid = rKey.typeId.ToString("X8");
                        //cPattern.groupid = rKey.groupId.ToString("X8");
                        //cPattern.instanceid = rKey.instanceId.ToString("X16");

                        cPattern.key = pDetails.key;

                        if (!StreamHelpers.isValidStream(KeyUtils.findKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1)).ToString("X16"))))
                        {
                            if (String.IsNullOrEmpty(pDetails.BackgroundImage))
                            {
                                cPattern.texturename = pDetails.rgbmask;
                            }
                            else
                            {
                                cPattern.texturename = pDetails.BackgroundImage;
                            }
                        }
                        else
                        {
                            cPattern.texturename = "key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1)).ToString("X16");
                        }
                        cPattern.casPart = pDetails.name.Substring(pDetails.name.LastIndexOf("\\") + 1);

                        cPattern.subcategory    = openFileDialog1.FileName;
                        pDetails.customFilename = openFileDialog1.FileName;
                        cPattern.isCustom       = true;
                        pDetails.isCustom       = true;

                        customPatterns.Items.Add(cPattern);

                        TextWriter    r = new StreamWriter(Path.Combine(Application.StartupPath, Path.Combine("xml", "customPatterns.xml")));
                        XmlSerializer s = new XmlSerializer(typeof(patterns));
                        s.Serialize(r, customPatterns);
                        r.Close();

                        break;
                    }
                }

                //Stream patternThumb = KeyUtils.searchForKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.name), openFileDialog1.FileName);
                //if (!Helpers.isValidStream(patternThumb))
                //{
                //    patternThumb = KeyUtils.searchForKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails.BackgroundImage), openFileDialog1.FileName);
                //}

                //if (Helpers.isValidStream(patternThumb))
                //{
                //Stream patternDDS = File.OpenWrite(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pDetails.name + ".dds")));
                //Helpers.CopyStream(patternThumb, patternDDS, true);
                //patternDDS.Close();

                //patternThumb.Seek(0, SeekOrigin.Begin);

                PictureBox picBox = new PictureBox();
                picBox.BackColor = System.Drawing.Color.White;
                //picBox.Location = new System.Drawing.Point(horizontal, vertical);
                picBox.Name = pDetails.name;


                string  toolTip = pDetails.category + "\\";
                ToolTip tt      = new ToolTip();
                toolTip += pDetails.name;
                tt.SetToolTip(picBox, toolTip);

                picBox.Image = Patterns.makePatternThumb(pDetails, castdb);
                //picBox.Image =     castdb.GetResourceStream(entry.Key);
                try
                {
                    picBox.Image.Save(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pDetails.name + ".png")), System.Drawing.Imaging.ImageFormat.Png);
                }
                catch (Exception)
                {
                }

                addToPanel(picBox);


                cast.Close();
                //picBox.Dispose();
                //}

                comboBox1.SelectedIndex = 15;
            }
        }
        /*
         * public Stream findPattern(patternsFile pattern)
         * {
         *  if (File.Exists(pattern.subcategory))
         *  {
         *      Stream cast = File.Open(pattern.subcategory, FileMode.Open, FileAccess.Read, FileShare.Read);
         *      MadScience.Wrappers.Database castdb = new MadScience.Wrappers.Database(cast, true);
         *
         *      MadScience.Wrappers.ResourceKey temp = new MadScience.Wrappers.ResourceKey(pattern.texturename);
         *      Stream patternThumb = null;
         *
         *      try
         *      {
         *          patternThumb = castdb.GetResourceStream(temp);
         *      }
         *      catch (System.Collections.Generic.KeyNotFoundException ex)
         *      {
         *      }
         *      catch (Exception ex)
         *      {
         *          Helpers.logMessageToFile(ex.Message);
         *      }
         *      cast.Close();
         *
         *      if (patternThumb != null)
         *      {
         *          return patternThumb;
         *      }
         *  }
         *
         *  return Stream.Null;
         * }
         */
        /*
         * public patternsFile findPattern(string resKey)
         * {
         *  // Get pattern details from XML
         *  keyName patternXML = new keyName(resKey);
         *  patternsFile temp = new patternsFile();
         *
         *  bool hasMatch = false;
         *
         *  for (int i = 0; i < this.customPatterns.Items.Count; i++)
         *  {
         *      patternsFile pattern = this.customPatterns.Items[i];
         *
         *      if (MadScience.StringHelpers.ParseHex32(pattern.typeid) == patternXML.typeId && MadScience.StringHelpers.ParseHex32(pattern.groupid) == patternXML.groupId && MadScience.StringHelpers.ParseHex64(pattern.instanceid) == patternXML.instanceId)
         *      {
         *          hasMatch = true;
         *          temp = pattern;
         *          break;
         *      }
         *  }
         *
         *  if (!hasMatch)
         *  {
         *      for (int i = 0; i < this.patterns.Items.Count; i++)
         *      {
         *          patternsFile pattern = this.patterns.Items[i];
         *
         *          if (MadScience.StringHelpers.ParseHex32(pattern.typeid) == patternXML.typeId && MadScience.StringHelpers.ParseHex32(pattern.groupid) == patternXML.groupId && MadScience.StringHelpers.ParseHex64(pattern.instanceid) == patternXML.instanceId)
         *          {
         *              hasMatch = true;
         *              temp = pattern;
         *              break;
         *          }
         *      }
         *  }
         *
         *  return temp;
         * }
         */
        /*
         * public Image makePatternThumb(string resKey)
         * {
         *  return makePatternThumb(findPattern(resKey), null);
         * }
         */
        /*
         * public patternsFile pDetailsTopFile(patternDetails pDetails)
         * {
         *  patternsFile pFile = new patternsFile();
         *
         *  keyName pKey = new keyName(pDetails.key);
         *  pFile.casPart = pDetails.filename;
         *  pFile.typeid = "0x" + pKey.typeId.ToString("X8");
         *  pFile.groupid = "0x" + pKey.groupId.ToString("X8");
         *  pFile.instanceid = "0x" + pKey.instanceId.ToString("X16");
         *
         *  pFile.category = pDetails.category;
         *  pFile.color0 = pDetails.ColorP[0];
         *  pFile.color1 = pDetails.ColorP[1];
         *  pFile.color2 = pDetails.ColorP[2];
         *  pFile.color3 = pDetails.ColorP[3];
         *  pFile.color4 = pDetails.ColorP[4];
         *
         *  pFile.HBg = pDetails.HBg;
         *  pFile.SBg = pDetails.SBg;
         *  pFile.VBg = pDetails.VBg;
         *
         *  return pFile;
         * }
         */

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            panel1.Controls.Clear();
            panel1.Visible = false;

            label2.Text = "Loading patterns... Please wait...";
            label2.Refresh();

            numFound   = 0;
            horizontal = 0;
            vertical   = 0;

            ToolTip tt = new ToolTip();


            DdsFileTypePlugin.DdsFile ddsP = new DdsFileTypePlugin.DdsFile();

            if (comboBox1.Text == "* Custom")
            {
                for (int i = 0; i < this.customPatterns.Items.Count; i++)
                {
                    patternsFile pattern = this.customPatterns.Items[i];
                    //if (pattern.category == comboBox1.Text)
                    //{

                    numFound++;

                    PictureBox picBox = new PictureBox();
                    picBox.BackColor = System.Drawing.Color.White;
                    picBox.Name      = pattern.casPart;

                    string toolTip = pattern.category + "\\";
                    //if (pattern.subcategory != "")
                    //{
                    //toolTip += pattern.subcategory + "\\";
                    //}
                    toolTip += pattern.casPart;
                    tt.SetToolTip(picBox, toolTip);

                    // Find thumbnail
                    if (File.Exists(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png"))))
                    {
                        Stream tmpImage = File.OpenRead(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png")));
                        picBox.Image = Image.FromStream(tmpImage);
                        tmpImage.Close();
                    }
                    else
                    {
                        if (File.Exists(pattern.subcategory))
                        {
                            //if (pattern.typeid.StartsWith("0x")) pattern.typeid = pattern.typeid.Remove(0, 2);
                            //if (pattern.groupid.StartsWith("0x")) pattern.groupid = pattern.groupid.Remove(0, 2);
                            //if (pattern.instanceid.StartsWith("0x")) pattern.instanceid = pattern.instanceid.Remove(0, 2);

                            Stream patternXml = KeyUtils.searchForKey(pattern.key, pattern.subcategory);
                            if (StreamHelpers.isValidStream(patternXml))
                            {
                                Patterns.patternDetails pDetails = Patterns.parsePatternComplate(patternXml);
                                //Stream patternThumb = KeyUtils.searchForKey(pattern.texturename, pattern.subcategory);
                                //if (Helpers.isValidStream(patternThumb))
                                //{
                                //picBox.Image = Patterns.makePatternThumb(patternThumb, pDetails);
                                picBox.Image = Patterns.makePatternThumb(pDetails);
                                try
                                {
                                    picBox.Image.Save(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png")), System.Drawing.Imaging.ImageFormat.Png);
                                }
                                catch (Exception)
                                {
                                }
                                //}
                            }
                        }
                    }

                    addToPanel(picBox);
                    //}
                }
            }
            else
            {
                string s3root           = MadScience.Helpers.findSims3Root();
                string thumbnailPackage = Helpers.getGameSubPath(@"\GameData\Shared\Packages\FullBuild2.package");

                Console.WriteLine("Starting at: " + DateTime.Now.ToString());

                Stream cast = File.Open(Path.Combine(s3root, thumbnailPackage), FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database castdb = new MadScience.Wrappers.Database(cast);

                Stream fullBuild0 = File.Open(Path.Combine(s3root, Helpers.getGameSubPath(@"\GameData\Shared\Packages\FullBuild0.package")), FileMode.Open, FileAccess.Read, FileShare.Read);
                MadScience.Wrappers.Database xmldb = new MadScience.Wrappers.Database(fullBuild0);


                for (int i = 0; i < this.patterns.Items.Count; i++)
                {
                    patternsFile pattern = this.patterns.Items[i];
                    if (pattern.category == comboBox1.Text)
                    {
                        numFound++;

                        PictureBox picBox = new PictureBox();
                        picBox.BackColor = System.Drawing.Color.White;
                        picBox.Name      = pattern.casPart;


                        string toolTip = pattern.category + "\\";
                        if (pattern.subcategory != "")
                        {
                            toolTip += pattern.subcategory + "\\";
                        }
                        toolTip += pattern.casPart;
                        tt.SetToolTip(picBox, toolTip);

                        // Find thumbnail
                        if (File.Exists(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png"))))
                        {
                            Stream tmpImage = File.OpenRead(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png")));
                            picBox.Image = Image.FromStream(tmpImage);
                            tmpImage.Close();
                        }
                        else
                        {
                            //Console.WriteLine(pattern.casPart);

                            Stream patternXml = KeyUtils.findKey(new MadScience.Wrappers.ResourceKey(pattern.key), 0, xmldb);
                            if (StreamHelpers.isValidStream(patternXml))
                            {
                                Patterns.patternDetails pDetails2 = Patterns.parsePatternComplate(patternXml);
                                //Stream patternThumb = KeyUtils.findKey(new MadScience.Wrappers.ResourceKey("key:00B2D882:00000000:" + StringHelpers.HashFNV64(pDetails2.name).ToString("X16")), 0, castdb);
                                //if (!Helpers.isValidStream(patternThumb))
                                //{
                                //    patternThumb = KeyUtils.findKey(new MadScience.Wrappers.ResourceKey(pDetails2.BackgroundImage), 0, castdb);
                                //}
                                //if (Helpers.isValidStream(patternThumb))
                                //{
                                picBox.Image = Patterns.makePatternThumb(pDetails2, castdb);
                                try
                                {
                                    picBox.Image.Save(Path.Combine(Application.StartupPath, Path.Combine("patterncache", pattern.casPart + ".png")), System.Drawing.Imaging.ImageFormat.Png);
                                }
                                catch (Exception)
                                {
                                }
                                //}
                            }
                        }

                        addToPanel(picBox);
                    }
                }

                Console.WriteLine("Stopping at: " + DateTime.Now.ToString());

                //dbpf = null;
                fullBuild0.Close();
                cast.Close();
                //castdb = null;
            }
            label2.Text      = numFound.ToString() + " patterns";
            panel1.Visible   = true;
            this.curCategory = comboBox1.SelectedIndex;
        }
        private void checkPackage(string filename, ListViewItem item)
        {
            // Check 0 byte file
            FileInfo f = new FileInfo(filename);

            if (!alwaysUseFastScanToolStripMenuItem.Checked)
            {
                toolStripStatusLabel1.Text = "Checking " + f.Name;
                statusStrip1.Refresh();
            }

            detective.isCorrupt = false;
            detective.isDisabled = false;

            if (f.Length == 0)
            {
                item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.emptyPackage);
                item.SubItems[2].Text = detective.pType.ToString(MadScience.Detective.PackageTypes.emptyPackage);
                return;
            }

            if (filename.EndsWith(".disabled"))
            {
                detective.isDisabled = true;
                item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.disabledPackage);
            }

            Stream input = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
            MadScience.Wrappers.Database db = new MadScience.Wrappers.Database(input, true, false);

            try
            {
                if (filename.Contains(".dbc"))
                {
                    MadScience.Detective.PackageType packageType = detective.getType(db, true);
                }
                else
                {
                    MadScience.Detective.PackageType packageType = detective.getType(db, false);
                }
            }
            catch (System.Exception excpt)
            {
                MessageBox.Show(excpt.Message + " " + excpt.StackTrace, f.Name);
                detective.pType.MainType = MadScience.Detective.PackageTypes.corruptBadDownload;
                detective.isCorrupt = true;
                item.BackColor = detective.pType.ToColor();
                item.SubItems[2].Text = detective.pType.ToString();
                input.Close();
                return;
            }

            if (detective.pType.MainType == MadScience.Detective.PackageTypes.sims2Package)
            {
                item.SubItems[2].Text = detective.pType.ToString();
                if (!detective.isDisabled) item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.sims2Package);
                input.Close();
                return;
            }

            // Game number
            switch (db.dbpf.gameNumber)
            {
                case MadScience.Helpers.GameNumber.baseGame:
                    item.SubItems[7].Text = "Base";
                    break;
                case MadScience.Helpers.GameNumber.worldAdventures:
                    item.SubItems[7].Text = "WA";
                    break;
                case MadScience.Helpers.GameNumber.highEndLoftStuff:
                    item.SubItems[7].Text = "HELS";
                    break;
                case MadScience.Helpers.GameNumber.ambitions:
                    item.SubItems[7].Text = "AMB";
                    break;
            }

            if (detective.isCorrupt)
            {
                item.SubItems[2].Text = detective.pType.ToString();
                item.SubItems[6].Text = detective.pType.SubType;
                if (!detective.isDisabled) item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.corruptTXTC);
                input.Close();
                return;
            }

            if (!detective.isDisabled) item.BackColor = listView1.BackColor;
            string pType = detective.pType.ToString();

            // Check if any of this packages types exist in the entriesdb
            for (int i = 0; i < db.dbpf.Entries.Count; i++)
            {
                MadScience.Wrappers.DatabasePackedFile.Entry entry = db.dbpf.Entries[i];
                bool dealtWith = false;
                string entryString = entry.Key.ToString();

                if (Enum.IsDefined(typeof(ConflictTypes), entry.Key.typeId))
                //foreach (uint typeHash in Enum.GetValues(typeof(ResourceTypes)))
                //{
                //	if (typeHash == entry.Key.typeId)
                    {
                        if (conflictList.ContainsKey(entryString))
                        {
                            // Something already has this ResourceKey - mark file as conflicted.
                            // But wait!  Check if it's pointing to itself first. :)
                            if (conflictList[entryString] == (int)item.Tag) break;

                            // Check if it's an entire duplicate, or merely part
                            FileInfo f2 = new FileInfo(packageList[conflictList[entryString]].SubItems[1].Text);
                            //FileInfo f2 = new FileInfo(listView1.Items[conflictList[entryString]].SubItems[1].Text);
                            if (f.Length == f2.Length)
                            {
                                pType = "Duplicate of " + Path.Combine(packageList[conflictList[entryString]].SubItems[5].Text, packageList[conflictList[entryString]].Text);
                                if (!detective.isDisabled)
                                {
                                    item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.duplicatePackage);
                                    packageList[conflictList[entryString]].BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.duplicatePackage);
                                }
                                dealtWith = true;
                                break;
                            }
                            else
                            {
                                pType = "Conflicts with " + Path.Combine(packageList[conflictList[entryString]].SubItems[5].Text, packageList[conflictList[entryString]].Text);
                                if (!detective.isDisabled)
                                {
                                    item.BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.conflictPackage);

                                    if (packageList[conflictList[entryString]].BackColor != detective.pType.ToColor(MadScience.Detective.PackageTypes.corruptTXTC))
                                    {
                                        packageList[conflictList[entryString]].BackColor = detective.pType.ToColor(MadScience.Detective.PackageTypes.conflictPackage);
                                    }
                                }
                                dealtWith = true;
                                break;
                            }
                        }
                        else
                        {
                            conflictList.Add(entryString, (int)item.Tag);
                        }
                //	}
                }

                if (dealtWith == true) break;
            }

            input.Close();

            //if (packageType == "unknown")
            //{
                //packageType = "Sims 3 Package";
            //}

            item.SubItems[2].Text = pType;
            item.SubItems[6].Text = detective.pType.SubType;
        }