Ejemplo n.º 1
0
 internal static void PrepareForClone(SimPe.Interfaces.Files.IPackageFile package, SimPe.Interfaces.IAlias current, out SimPe.Interfaces.IAlias a, out uint localgroup, out SimPe.Interfaces.Files.IPackedFileDescriptor pfd)
 {
     FileTable.FileIndex.Load();
     a          = null;
     pfd        = null;
     localgroup = Data.MetaData.LOCAL_GROUP;
     if (package != null)
     {
         if (package.FileName != null)
         {
             SimPe.Interfaces.Wrapper.IGroupCacheItem gci = SimPe.FileTable.GroupCache.GetItem(package.FileName);
             if (gci != null)
             {
                 localgroup = gci.LocalGroup;
             }
         }
     }
     else
     {
         if (current != null)
         {
             a          = current;
             pfd        = (Interfaces.Files.IPackedFileDescriptor)a.Tag[0];
             localgroup = (uint)a.Tag[1];
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a 1:1 Clone based on the passed GUID
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public static SimPe.Packages.GeneratableFile CreatCloneByGuid(uint guid)
        {
            SimPe.Packages.GeneratableFile         package = SimPe.Packages.GeneratableFile.CreateNew();
            SimPe.Interfaces.IAlias                a;
            Interfaces.Files.IPackedFileDescriptor pfd;
            uint            localgroup;
            OWCloneSettings cs;

            ObjectWorkshopHelper.PrepareForClone(package, out a, out localgroup, out pfd, out cs);
            SimPe.Interfaces.Scenegraph.IScenegraphFileIndex fii = FileTable.FileIndex.AddNewChild();

            SimPe.Cache.MemoryCacheItem mci = SimPe.PackedFiles.Wrapper.ObjectComboBox.ObjectCache.FindItem(guid);
            if (mci != null)
            {
                localgroup = mci.FileDescriptor.Group;
                if (localgroup == Data.MetaData.LOCAL_GROUP)
                {
                    SimPe.Interfaces.Wrapper.IGroupCacheItem gci = SimPe.FileTable.GroupCache.GetItem(mci.ParentCacheContainer.FileName);
                    if (gci != null)
                    {
                        if (!FileTable.FileIndex.Contains(mci.ParentCacheContainer.FileName))
                        {
                            fii.AddIndexFromPackage(mci.ParentCacheContainer.FileName);
                        }

                        localgroup = gci.LocalGroup;
                    }
                }
                ObjectWorkshopHelper.BaseClone(localgroup, package, false);
            }

            SimPe.Packages.GeneratableFile ret = ObjectWorkshopHelper.Start(package, a, ref pfd, localgroup, cs, true);
            fii.CloseAssignedPackages();
            FileTable.FileIndex.RemoveChild(fii);

            return(ret);
        }
Ejemplo n.º 3
0
        public void ScanPackage(ScannerItem si, SimPe.Cache.PackageState ps, System.Windows.Forms.ListViewItem lvi)
        {
            System.Drawing.Size sz = AbstractScanner.ThumbnailSize;
            if (si.PackageCacheItem.Type == PackageType.Object || si.PackageCacheItem.Type == PackageType.MaxisObject || si.PackageCacheItem.Type == PackageType.Recolor)
            {
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.OBJD_FILE);

                uint group = 0;
                if (pfds.Length > 0)
                {
                    group = pfds[0].Group;
                }

                if (group == Data.MetaData.LOCAL_GROUP)
                {
                    SimPe.Interfaces.Wrapper.IGroupCacheItem gci = FileTable.GroupCache.GetItem(si.FileName);
                    if (gci != null)
                    {
                        group = gci.LocalGroup;
                    }
                }
                string[] modelnames = SimPe.Plugin.Scenegraph.FindModelNames(si.Package);

                foreach (string modelname in modelnames)
                {
                    System.Drawing.Image img = SimPe.Plugin.Workshop.GetThumbnail(group, modelname);
                    if (img != null)
                    {
                        si.PackageCacheItem.Thumbnail = img;
                        ps.State = TriState.True;
                        break;
                    }
                }
            }

            //no Thumbnail, do we have a Image File?
            if (ps.State == TriState.Null)
            {
                SimPe.PackedFiles.Wrapper.Picture pic = new Picture();
                uint[] types = pic.AssignableTypes;
                foreach (uint type in types)
                {
                    SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(type);
                    if (pfds.Length > 0)
                    {
                        //get image with smallest Instance
                        SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pfds[0];
                        foreach (SimPe.Interfaces.Files.IPackedFileDescriptor p in pfds)
                        {
                            if (p.Instance < pfd.Instance)
                            {
                                pfd = p;
                            }
                        }

                        pic.ProcessData(pfd, si.Package, false);

                        si.PackageCacheItem.Thumbnail = pic.Image;
                        if (si.PackageCacheItem.Thumbnail != null)
                        {
                            si.PackageCacheItem.Thumbnail = ImageLoader.Preview(si.PackageCacheItem.Thumbnail, sz);
                            ps.State = TriState.True;
                        }

                        break;
                    }
                }                 //foreach
            }

            //no Thumbnail generated by the Game?
            if (ps.State == TriState.Null)
            {
                //load the Texture Image
                SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = si.Package.FindFiles(Data.MetaData.TXTR);
                if (pfds.Length > 0)
                {
                    SimPe.Plugin.GenericRcol rcol = new GenericRcol(null, false);

                    //get biggest texture
                    SimPe.Interfaces.Files.IPackedFileDescriptor pfd = pfds[0];
                    foreach (SimPe.Interfaces.Files.IPackedFileDescriptor p in pfds)
                    {
                        if (p.Size > pfd.Size)
                        {
                            pfd = p;
                        }
                    }

                    rcol.ProcessData(pfd, si.Package, false);

                    SimPe.Plugin.ImageData id = (SimPe.Plugin.ImageData)rcol.Blocks[0];

                    SimPe.Plugin.MipMap mm = id.GetLargestTexture(sz);

                    if (mm.Texture != null)
                    {
                        si.PackageCacheItem.Thumbnail = ImageLoader.Preview(mm.Texture, sz);
                        ps.State = TriState.True;
                    }

                    rcol.Dispose();
                }
            }

            if (si.PackageCacheItem.Thumbnail != null)
            {
                if (WaitingScreen.Running)
                {
                    WaitingScreen.UpdateImage(si.PackageCacheItem.Thumbnail);
                }
            }
            UpdateState(si, ps, lvi);
        }