Ejemplo n.º 1
0
        protected virtual bool BeforeLoadContent(SimPe.Cache.PackageType type, SimPe.Interfaces.Files.IPackageFile pkg)
        {
            bool ret = false;

            DisposeTmpPkg();

            SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = pkg.FindFiles(Data.MetaData.MMAT);
            if (pfds.Length > 0)
            {
                SimPe.Plugin.MmatWrapper mmat = new MmatWrapper();
                mmat.ProcessData(pfds[0], pkg);
                nfo.Name = mmat.ModelName + ", " + mmat.SubsetName;

                if (SimPe.Plugin.DownloadsToolFactory.Settings.LoadBasedataForRecolors)
                {
                    SimPe.Interfaces.Scenegraph.IScenegraphFileIndex fii = SimPe.Plugin.DownloadsToolFactory.TeleportFileIndex.AddNewChild();
                    if (System.IO.File.Exists(pkg.SaveFileName))
                    {
                        string   dir   = System.IO.Path.GetDirectoryName(pkg.SaveFileName);
                        string[] files = System.IO.Directory.GetFiles(dir);
                        foreach (string file in files)
                        {
                            if (file.EndsWith(".package") || file.EndsWith(".sims"))
                            {
                                if (!FileTable.FileIndex.Contains(file))
                                {
                                    fii.AddIndexFromPackage(file);
                                }
                            }
                        }
                    }

                    //SimPe.Plugin.DownloadsToolFactory.TeleportFileIndex.WriteContentToConsole();
                    tmppkg = SimPe.Plugin.Tool.Dockable.ObjectWorkshopHelper.CreatCloneByGuid(mmat.ObjectGUID);
                    if (SimPe.Plugin.DownloadsToolFactory.Settings.BuildPreviewForRecolors)
                    {
                        if (tmppkg.Index.Length > 0)
                        {
                            ret = true;
                        }
                        tmppkg.CopyDescriptors(pkg);
                        foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in tmppkg.Index)
                        {
                            if (pfd.Equals(mmat.FileDescriptor))
                            {
                                mmat.ProcessData(pfd, tmppkg);
                            }
                        }

                        string name  = "render.tmp";
                        int    index = 0;

                        string rname = null;
                        do
                        {
                            rname = System.IO.Path.Combine(Helper.SimPeTeleportPath, index + "_" + name);
                            index++;
                        } while (System.IO.File.Exists(rname));
                        tmppkg.Save(rname);

                        nfo.RenderData        = new object[] { mmat, tmppkg.SaveFileName };
                        nfo.PostponedRenderer = new EventHandler(PostponedRender);
                    }

                    fii.CloseAssignedPackages();
                    SimPe.Plugin.DownloadsToolFactory.TeleportFileIndex.RemoveChild(fii);
                }
            }

            return(ret);
        }