Example #1
0
        /// <summary>
        /// Remove some unreferenced and useless Files
        /// </summary>
        public void CleanUp()
        {
            if (WaitingScreen.Running)
            {
                WaitingScreen.UpdateMessage("Cleaning up");
            }
            Interfaces.Files.IPackedFileDescriptor[] mpfds = package.FindFiles(Data.MetaData.MMAT);             //MMAT
            ArrayList mmats = new ArrayList();

            foreach (Interfaces.Files.IPackedFileDescriptor pfd in mpfds)
            {
                SimPe.PackedFiles.Wrapper.Cpf mmat = new SimPe.PackedFiles.Wrapper.Cpf();
                mmat.ProcessData(pfd, package);

                string content = Scenegraph.MmatContent(mmat);

                if (!mmats.Contains(content))
                {
                    string txmtname = (string)Hashes.StripHashFromName(mmat.GetSaveItem("name").StringValue.Trim().ToLower()) + "_txmt";
                    string cresname = (string)Hashes.StripHashFromName(mmat.GetSaveItem("modelName").StringValue.Trim().ToLower());

                    if (package.FindFile(Hashes.StripHashFromName(txmtname), 0x49596978).Length < 0)
                    {
                        pfd.MarkForDelete = true;
                    }
                    if (package.FindFile(Hashes.StripHashFromName(cresname), 0xE519C933).Length < 0)
                    {
                        pfd.MarkForDelete = true;
                    }

                    if (!pfd.MarkForDelete)
                    {
                        mmats.Add(content);
                    }
                }
                else
                {
                    pfd.MarkForDelete = true;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Adds all know MMATs that reference one of the models;
        /// </summary>
        /// <param name="pkg"></param>
        /// <param name="onlydefault">true, if you only want to read default MMATS</param>
        /// <param name="subitems">true, if you also want to load MMAT Files that reference Files ouside the passed package</param>
        /// <param name="exception">true if you want to throw an exception when something goes wrong</param>
        /// <returns>List of all referenced GUIDs</returns>
        public void AddMaterialOverrides(SimPe.Interfaces.Files.IPackageFile pkg, bool onlydefault, bool subitems, bool exception)
        {
            LoadCache();

            SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile(Data.MetaData.MMAT, true);
            ArrayList itemlist    = new ArrayList();
            ArrayList contentlist = new ArrayList();
            ArrayList defaultfam  = new ArrayList();
            ArrayList guids       = new ArrayList();

            //create an UpTo Date Cache
            bool chgcache = false;

            foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item in items)
            {
                string pname = item.Package.FileName.Trim().ToLower();
                SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] citems = cachefile.FileIndex.FindFile(item.FileDescriptor, item.Package);
                bool have = false;
                foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem citem in citems)
                {
                    if (citem.FileDescriptor.Filename == pname)
                    {
                        have = true;
                        break;
                    }
                }

                //Not in cache, so add that File
                if (!have)
                {
                    SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
                    mmat.ProcessData(item.FileDescriptor, item.Package);

                    cachefile.AddItem(mmat);
                    chgcache = true;
                }
            }
            if (chgcache)
            {
                SaveCache();
            }

            //collect a list of Default Material Override family values first
            if (onlydefault)
            {
                foreach (SimPe.Cache.MMATCacheItem mci in (SimPe.Cache.CacheItems)cachefile.DefaultMap[true])
                {
                    defaultfam.Add(mci.Family);
                }
            }

            //now do the real collect
            foreach (string k in modelnames)
            {
                SimPe.Cache.CacheItems list = (SimPe.Cache.CacheItems)cachefile.ModelMap[k.Trim().ToLower()];
                if (list != null)
                {
                    foreach (SimPe.Cache.MMATCacheItem mci in list)
                    {
                        if (onlydefault && !defaultfam.Contains(mci.Family))
                        {
                            continue;
                        }

                        string name = k;
                        items = FileTable.FileIndex.FindFile(mci.FileDescriptor, null);

                        foreach (Interfaces.Scenegraph.IScenegraphFileIndexItem item in items)
                        {
                            if (itemlist.Contains(item))
                            {
                                continue;
                            }
                            itemlist.Add(item);
                            SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
                            mmat.ProcessData(item);

                            string content = Scenegraph.MmatContent(mmat);
                            content = content.Trim().ToLower();
                            if (!contentlist.Contains(content))
                            {
                                mmat.FileDescriptor = Clone(mmat.FileDescriptor);
                                mmat.SynchronizeUserData();

                                if (subitems)
                                {
                                    if (pkg.FindFile(mmat.FileDescriptor) == null)
                                    {
                                        pkg.Add(mmat.FileDescriptor);
                                    }

                                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem txmtitem = SimPe.FileTable.FileIndex.FindFileByName(mmat.GetSaveItem("name").StringValue + "_txmt", Data.MetaData.TXMT, Data.MetaData.LOCAL_GROUP, true);
                                    if (txmtitem != null)
                                    {
                                        try
                                        {
                                            SimPe.Plugin.GenericRcol sub = new GenericRcol(null, false);
                                            sub.ProcessData(txmtitem.FileDescriptor, txmtitem.Package, false);
                                            ArrayList newfiles = new ArrayList();
                                            LoadReferenced(this.modelnames, this.exclude, newfiles, itemlist, sub, txmtitem, true, setup);
                                            BuildPackage(newfiles, pkg);
                                        }
                                        catch (Exception ex)
                                        {
                                            Helper.ExceptionMessage("", new CorruptedFileException(txmtitem, ex));
                                        }
                                    }
                                    else
                                    {
                                        continue;
                                        //if (exception) throw new ScenegraphException("Invalid Scenegraph Link", new ScenegraphException("Unable to find Referenced File "+name+"_txmt.", mmat.FileDescriptor), mmat.FileDescriptor);
                                    }
                                }
                                else
                                {
                                    if (pkg.FindFile(mmat.FileDescriptor) == null)
                                    {
                                        string txmtname = mmat.GetSaveItem("name").StringValue.Trim();
                                        if (!txmtname.EndsWith("_txmt"))
                                        {
                                            txmtname += "_txmt";
                                        }
                                        if (pkg.FindFile(txmtname, Data.MetaData.TXMT).Length > 0)
                                        {
                                            pkg.Add(mmat.FileDescriptor);
                                        }
                                    }
                                }
                                contentlist.Add(content);
                            }     //if contentlist
                        }         //foreach item
                    }             //foreach MMATCacheItem
                }                 // if list !=null
            }
        }