Example #1
0
        /// <summary>
        /// Returns an Alias for the given Guid
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public SimPe.Interfaces.IAlias FindObject(uint guid)
        {
            MemoryCacheItem mci = FindItem(guid);

            SimPe.Data.Alias a;
            if (mci == null)
            {
                a = new SimPe.Data.Alias(guid, Localization.Manager.GetString("Unknown"));
            }
            else
            {
                a = new SimPe.Data.Alias(guid, mci.Name);
            }

            object[] o = new object[3];
            o[0]  = mci.FileDescriptor;
            o[1]  = mci.ObjectType;
            o[2]  = mci.Icon;
            a.Tag = o;

            return(a);
        }
Example #2
0
        /// <summary>
        /// Add a MaterialOverride to the Cache
        /// </summary>
        /// <param name="objd">The Object Data File</param>
        public MemoryCacheItem AddItem(SimPe.PackedFiles.Wrapper.ExtObjd objd)
        {
            CacheContainer mycc = this.UseConatiner(ContainerType.Memory, objd.Package.FileName);

            MemoryCacheItem mci = new MemoryCacheItem();

            mci.FileDescriptor       = objd.FileDescriptor;
            mci.Guid                 = objd.Guid;
            mci.ObjectType           = objd.Type;
            mci.ObjdName             = objd.FileName;
            mci.ParentCacheContainer = mycc;

            try
            {
                Interfaces.Scenegraph.IScenegraphFileIndexItem[] sitems = FileTable.FileIndex.FindFile(Data.MetaData.CTSS_FILE, objd.FileDescriptor.Group, objd.CTSSInstance, null);
                if (sitems.Length > 0)
                {
                    SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                    str.ProcessData(sitems[0]);
                    SimPe.PackedFiles.Wrapper.StrItemList strs = str.LanguageItems(Helper.WindowsRegistry.LanguageCode);
                    if (strs.Length > 0)
                    {
                        mci.Name = strs[0].Title;
                    }

                    //not found?
                    if (mci.Name == "")
                    {
                        strs = str.LanguageItems(1);
                        if (strs.Length > 0)
                        {
                            mci.Name = strs[0].Title;
                        }
                    }
                }
            }
            catch (Exception) {}

            try
            {
                Interfaces.Scenegraph.IScenegraphFileIndexItem[] sitems = FileTable.FileIndex.FindFile(Data.MetaData.STRING_FILE, objd.FileDescriptor.Group, 0x100, null);
                if (sitems.Length > 0)
                {
                    SimPe.PackedFiles.Wrapper.Str str = new SimPe.PackedFiles.Wrapper.Str();
                    str.ProcessData(sitems[0]);
                    SimPe.PackedFiles.Wrapper.StrItemList strs = str.LanguageItems(Data.MetaData.Languages.English);
                    string[] res = new string[strs.Count];
                    for (int i = 0; i < res.Length; i++)
                    {
                        res[i] = strs[i].Title;
                    }
                    mci.ValueNames = res;
                }
            }
            catch (Exception) {}

            //still no name?
            if (mci.Name == "")
            {
                mci.Name = objd.FileName;
            }

            //having an icon?
            SimPe.PackedFiles.Wrapper.Picture pic = new SimPe.PackedFiles.Wrapper.Picture();
            Interfaces.Scenegraph.IScenegraphFileIndexItem[] iitems = FileTable.FileIndex.FindFile(Data.MetaData.SIM_IMAGE_FILE, objd.FileDescriptor.Group, 1, null);
            if (iitems.Length > 0)
            {
                pic.ProcessData(iitems[0]);
                mci.Icon   = pic.Image;
                Wait.Image = mci.Icon;
            }

            Wait.Message = mci.Name;
            //mci.ParentCacheContainer = mycc; //why was this disbaled?
            mycc.Items.Add(mci);

            return(mci);
        }
Example #3
0
        /// <summary>
        /// Returns an Alias for the given Guid
        /// </summary>
        /// <param name="guid"></param>
        /// <returns></returns>
        public MemoryCacheItem FindItem(uint guid)
        {
            MemoryCacheItem mci = (MemoryCacheItem)Map[guid];

            return(mci);
        }
Example #4
0
        /// <summary>
        /// Load the Container from the Stream
        /// </summary>
        /// <param name="reader">the Stream Reader</param>
        internal void Load(System.IO.BinaryReader reader)
        {
            valid = ContainerValid.FileNotFound;
            items.Clear();
            int offset = reader.ReadInt32();

            version = reader.ReadByte();
            type    = (ContainerType)reader.ReadByte();
            int count = reader.ReadInt32();

            long pos = reader.BaseStream.Position;

            try
            {
                if (version <= VERSION)
                {
                    reader.BaseStream.Seek(offset, System.IO.SeekOrigin.Begin);
                    added    = DateTime.FromFileTime(reader.ReadInt64());
                    filename = reader.ReadString();

                    if (System.IO.File.Exists(filename))
                    {
                        DateTime mod = System.IO.File.GetLastWriteTime(filename);
                        if (mod <= added)
                        {
                            valid = ContainerValid.Yes;
                        }
                        else
                        {
                            valid = ContainerValid.Modified;
                        }
                    }

                    if (valid == ContainerValid.Yes)
                    {
                        switch (type)
                        {
                        case ContainerType.Object:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                ObjectCacheItem oci = new ObjectCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }

                        case ContainerType.MaterialOverride:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                MMATCacheItem oci = new MMATCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }

                        case ContainerType.Rcol:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                RcolCacheItem oci = new RcolCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }

                        case ContainerType.Want:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                WantCacheItem oci = new WantCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }

                        case ContainerType.Memory:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                MemoryCacheItem oci = new MemoryCacheItem();
                                oci.Load(reader);
                                oci.ParentCacheContainer = this;
                                if (oci.Version >= MemoryCacheItem.DISCARD_VERSIONS_SMALLER_THAN)
                                {
                                    items.Add(oci);
                                }
                            }

                            break;
                        }

                        case ContainerType.Package:
                        {
                            for (int i = 0; i < count; i++)
                            {
                                PackageCacheItem oci = new PackageCacheItem();
                                oci.Load(reader);
                                items.Add(oci);
                            }

                            break;
                        }
                        }         //switch
                    }             // if valid
                }                 //if VERSION
                else
                {
                    valid = ContainerValid.UnknownVersion;
                }
            }
            finally
            {
                reader.BaseStream.Seek(pos, System.IO.SeekOrigin.Begin);
            }
        }