Ejemplo n.º 1
0
        public void SetFromPackage(SimPe.Interfaces.Files.IPackageFile pkg)
        {
            loaded = false;
            ClearScreen();
            this.pkg = pkg;
            if (pkg == null)
            {
                return;
            }
            if (!Helper.IsNeighborhoodFile(pkg.FileName))
            {
                return;
            }
            loaded = true;



            try
            {
                SimPe.PackedFiles.Wrapper.StrItemList strs = GetCtssItems();
                if (strs != null)
                {
                    this.llEdit.Enabled = true;
                    if (strs.Count > 0)
                    {
                        this.lbName.Text = strs[0].Title;
                    }
                    if (strs.Count > 1)
                    {
                        this.lbAbout.Text = strs[1].Title;
                    }
                }


                string tname = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(pkg.FileName), System.IO.Path.GetFileNameWithoutExtension(pkg.FileName) + ".png");
                pb.Image = null;
                if (System.IO.File.Exists(tname))
                {
                    try
                    {
                        pb.Image = ObjectPreview.GenerateImage(pb.Size, Image.FromFile(tname), false);
                    }
                    catch {}
                }

                if (pb.Image == null)
                {
                    pb.Image = defimg;
                }
                lbPop.Text = pkg.FindFiles(Data.MetaData.SIM_DESCRIPTION_FILE).Length.ToString();
                if (pkg.FileName != null)
                {
                    lbUni.Text = System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(pkg.FileName), "N*_University*.package").Length.ToString();
                }
                else
                {
                    lbUni.Text = "0";
                }

                ShowVersion();
            }
            catch (Exception ex)
            {
                this.lbAbout.Text = ex.Message;
            }
        }
Ejemplo n.º 2
0
        internal static bool DoConsume(Object o, ObjectLoader.LoadItemHandler LoadedItem, SimPe.Data.MetaData.Languages deflang)
        {
            SimPe.Cache.ObjectCacheItem oci = (SimPe.Cache.ObjectCacheItem)o;
            Interfaces.Scenegraph.IScenegraphFileIndexItem nrefitem = (Interfaces.Scenegraph.IScenegraphFileIndexItem)oci.Tag;


            //this item is new to the cache, so load the Data
            if ((!oci.Useable || oci.ObjectVersion != SimPe.Cache.ObjectCacheItemVersions.DockableOW) && nrefitem.FileDescriptor.Type == Data.MetaData.OBJD_FILE)
            {
                SimPe.PackedFiles.Wrapper.ExtObjd objd = new SimPe.PackedFiles.Wrapper.ExtObjd();
                nrefitem.FileDescriptor.UserData = nrefitem.Package.Read(nrefitem.FileDescriptor).UncompressedData;
                objd.ProcessData(nrefitem);

                oci.FileDescriptor     = nrefitem.FileDescriptor;
                oci.LocalGroup         = nrefitem.LocalGroup;
                oci.ObjectType         = objd.Type;
                oci.ObjectFunctionSort = (uint)objd.FunctionSubSort;
                oci.ObjectFileName     = objd.FileName;
                oci.Useable            = true;
                oci.Class = SimPe.Cache.ObjectClass.Object;

                //this is needed, so that objects get sorted into the right categories

                /*if (objd.Type == Data.ObjectTypes.Normal && objd.CTSSInstance==0)
                 * {
                 *      oci.Useable = false;
                 *      return true;
                 * }*/

                //Get the Name of the Object
                Interfaces.Scenegraph.IScenegraphFileIndexItem[] ctssitems = FileTable.FileIndex.FindFile(Data.MetaData.CTSS_FILE, nrefitem.LocalGroup);
                if (ctssitems.Length > 0)
                {
                    SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                    str.ProcessData(ctssitems[0]);
                    SimPe.PackedFiles.Wrapper.StrItemList items = str.LanguageItems(deflang);
                    if (items.Length > 0)
                    {
                        oci.Name = items[0].Title;
                    }
                    else
                    {
                        items = str.LanguageItems(1);
                        if (items.Length > 0)
                        {
                            oci.Name = items[0].Title;
                        }
                        else
                        {
                            oci.Name = "";
                        }
                    }
                }
                else
                {
                    oci.Name = "";
                }

                if (oci.Name == "")
                {
                    oci.Name = objd.FileName;
                }

                //now the ModeName File
                Interfaces.Scenegraph.IScenegraphFileIndexItem[] txtitems = FileTable.FileIndex.FindFile(Data.MetaData.STRING_FILE, nrefitem.LocalGroup, 0x85, null);
                if (txtitems.Length > 0)
                {
                    SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str(2);
                    str.ProcessData(txtitems[0]);
                    SimPe.PackedFiles.Wrapper.StrItemList items = str.LanguageItems(1);
                    if (items.Length > 1)
                    {
                        oci.ModelName = items[1].Title;
                    }
                }

                ObjectReader.changedcache = true;
            }             //if not loaded from objd

            if ((!oci.Useable || oci.ObjectVersion != SimPe.Cache.ObjectCacheItemVersions.DockableOW) && nrefitem.FileDescriptor.Type != Data.MetaData.OBJD_FILE)
            {
                ConsumeFromXobj(oci, nrefitem, deflang);
            }

            if (oci.Thumbnail == null)
            {
                oci.Thumbnail = ObjectPreview.GetThumbnail(nrefitem.FileDescriptor.Group, oci.ModelName);

                if (oci.Thumbnail != null)
                {
                    Wait.Image = oci.Thumbnail;
                    ObjectReader.changedcache = true;
                }
            }

#if DEBUG
            Data.Alias a = new Data.Alias(oci.FileDescriptor.Group, "---");            //, "{name} ({id}: {1}, {2}) ");
#else
            Data.Alias a = new Data.Alias(oci.FileDescriptor.Group, "---");            //, "{name} ({id}: {1}) ");
#endif
            object[] os = new object[4];
            os[0] = nrefitem.FileDescriptor;
            os[1] = nrefitem.LocalGroup;
            os[2] = oci.ModelName;
            os[3] = oci;

            a.Tag = os;

            if (Helper.WindowsRegistry.ShowObjdNames)
            {
                a.Name = oci.ObjectFileName;
            }
            else
            {
                a.Name = oci.Name;
            }
            a.Name += " (cached)";
            Image img = oci.Thumbnail;

            if (LoadedItem != null)
            {
                LoadedItem(oci, nrefitem, a);
            }

            return(true);
        }
Ejemplo n.º 3
0
 static void SetFunctionSortForXObj(SimPe.PackedFiles.Wrapper.Cpf cpf, SimPe.Cache.ObjectCacheItem oci)
 {
     oci.ObjectFunctionSort = (uint)ObjectPreview.GetFunctionSort(cpf);
 }
Ejemplo n.º 4
0
        static void ConsumeFromXobj(SimPe.Cache.ObjectCacheItem oci, Interfaces.Scenegraph.IScenegraphFileIndexItem nrefitem, SimPe.Data.MetaData.Languages deflang)
        {
            SimPe.PackedFiles.Wrapper.Cpf cpf = new SimPe.PackedFiles.Wrapper.Cpf();
            nrefitem.FileDescriptor.UserData = nrefitem.Package.Read(nrefitem.FileDescriptor).UncompressedData;
            cpf.ProcessData(nrefitem);

            oci.FileDescriptor = nrefitem.FileDescriptor;
            oci.LocalGroup     = nrefitem.LocalGroup;
            oci.ObjectType     = SimPe.Data.ObjectTypes.Normal;

            SetFunctionSortForXObj(cpf, oci);

            oci.ObjectFileName = cpf.GetSaveItem("filename").StringValue;
            if (oci.ObjectFileName == "")
            {
                oci.ObjectFileName = cpf.GetSaveItem("name").StringValue;
            }

            oci.Useable = true;
            oci.Class   = SimPe.Cache.ObjectClass.XObject;



            Interfaces.Scenegraph.IScenegraphFileIndexItem[] ctssitems = FileTable.FileIndex.FindFile(cpf.GetSaveItem("stringsetrestypeid").UIntegerValue, cpf.GetSaveItem("stringsetgroupid").UIntegerValue, cpf.GetSaveItem("stringsetid").UIntegerValue, null);             //Data.MetaData.STRING_FILE
            if (ctssitems.Length > 0)
            {
                SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                str.ProcessData(ctssitems[0]);
                SimPe.PackedFiles.Wrapper.StrItemList items = str.LanguageItems(deflang);
                if (items.Length > 0)
                {
                    oci.Name = items[0].Title;
                }
                else
                {
                    items = str.LanguageItems(1);
                    if (items.Length > 0)
                    {
                        oci.Name = items[0].Title;
                    }
                    else
                    {
                        oci.Name = "";
                    }
                }
            }
            else
            {
                oci.Name = "";
            }

            if (oci.Name == "")
            {
                oci.Name = oci.ObjectFileName;
            }

            //now the ModeName File
            if (cpf.GetItem("texturetname") != null)
            {
                oci.ModelName = cpf.GetItem("texturetname").StringValue;
            }
            else if (cpf.GetItem("filename") != null)
            {
                oci.ModelName = cpf.GetItem("filename").StringValue;
            }
            else
            {
                oci.ModelName = cpf.GetSaveItem("material").StringValue;
            }

            //oci.Name = cpf.GetSaveItem("type").StringValue + " - "+ cpf.GetSaveItem("subsort").StringValue;


            if (oci.Thumbnail == null)
            {
                oci.Thumbnail = ObjectPreview.GetXThumbnail(cpf);
            }
            ObjectReader.changedcache = true;
        }
Ejemplo n.º 5
0
        public static Image GetXThumbnail(SimPe.PackedFiles.Wrapper.Cpf cpf)
        {
            if (xthumbs == null)
            {
                xthumbs = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.SimSavegameFolder, "Thumbnails\\BuildModeThumbnails.package"));
            }

            SimPe.Packages.File      tmbs = xthumbs;
            Data.XObjFunctionSubSort fss  = ObjectPreview.GetFunctionSort(cpf);

            uint inst = cpf.GetSaveItem("guid").UIntegerValue;
            uint grp  = cpf.FileDescriptor.Group;

            if (cpf.GetItem("thumbnailinstanceid") != null)
            {
                inst = cpf.GetSaveItem("thumbnailinstanceid").UIntegerValue;
                grp  = cpf.GetSaveItem("thumbnailgroupid").UIntegerValue;
            }


            //get Thumbnail Type
            uint[] types = new uint[] { 0x8C311262, 0x8C31125E };           //floors, walls
            if (fss == Data.XObjFunctionSubSort.Roof)
            {
                types = new uint[] { 0xCC489E46 }
            }
            ;
            else if (fss == Data.XObjFunctionSubSort.Fence_Rail || fss == Data.XObjFunctionSubSort.Fence_Halfwall)
            {
                types = new uint[] { 0xCC30CDF8 }
            }
            ;
            else if (fss == Data.XObjFunctionSubSort.Roof)
            {
                types = new uint[] { 0xCC489E46 }
            }
            ;
            else if (fss == Data.XObjFunctionSubSort.Terrain)
            {
                types = new uint[] { 0xEC3126C4 };
                if (cpf.GetItem("texturetname") != null)
                {
                    inst = Hashes.GetCrc32(Hashes.StripHashFromName(cpf.GetItem("texturetname").StringValue.Trim().ToLower()));
                }
            }
            else if (cpf.FileDescriptor.Type == Data.MetaData.XNGB)
            {
                types = new uint[] { 0x4D533EDD };
                if (nthumbs == null)
                {
                    nthumbs = SimPe.Packages.File.LoadFromFile(System.IO.Path.Combine(PathProvider.SimSavegameFolder, "Thumbnails\\CANHObjectsThumbnails.package"));
                }
                tmbs = nthumbs;
            }


            return(GetThumbnail(cpf.GetSaveItem("name").StringValue, types, grp, inst, tmbs));
            //tmbs = null;

            /*ArrayList types = new ArrayList();
             * types.Add(0xEC3126C4); // Terrain
             * types.Add(0xCC30CDF8); //fences
             * types.Add(0x8C311262); //floors
             * types.Add(0xCC489E46); //roof
             * types.Add(0x8C31125E); //wall*/
        }