Beispiel #1
0
        /// <summary>
        /// Load a Cache File from the Disk
        /// </summary>
        /// <param name="flname">the name of the File</param>
        /// <param name="withprogress">true if you want  to set the Progress in the current Wait control</param>
        /// <exception cref="CacheException">Thrown if the File is not readable (ie, wrong Version or Signature)</exception>
        public void Load(string flname, bool withprogress)
        {
            this.filename = flname;
            containers.Clear();

            if (!System.IO.File.Exists(flname))
            {
                return;
            }

            StreamItem si = StreamFactory.UseStream(flname, FileAccess.Read, true);

            try
            {
                BinaryReader reader = new BinaryReader(si.FileStream);

                try
                {
                    ulong sig = reader.ReadUInt64();
                    if (sig != SIGNATURE)
                    {
                        throw new CacheException("Unknown Cache File Signature (" + Helper.HexString(sig) + ")", flname, 0);
                    }

                    version = reader.ReadByte();
                    if (version > VERSION)
                    {
                        throw new CacheException("Unable to read Cache", flname, version);
                    }

                    int count = reader.ReadInt32();
                    if (withprogress)
                    {
                        Wait.MaxProgress = count;
                    }
                    for (int i = 0; i < count; i++)
                    {
                        CacheContainer cc = new CacheContainer(DEFAULT_TYPE);
                        cc.Load(reader);
                        containers.Add(cc);
                        if (withprogress)
                        {
                            Wait.Progress = i;
                        }
                        if (i % 10 == 0)
                        {
                            System.Windows.Forms.Application.DoEvents();
                        }
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            finally
            {
                si.Close();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Returns a container for the passed type and File
        /// </summary>
        /// <param name="ct">The Container Type</param>
        /// <param name="name">The name of the FIle</param>
        /// <remarks>If no container is Found, a new one will be created for this File and Type!</remarks>
        public CacheContainer UseConatiner(ContainerType ct, string name)
        {
            if (name == null)
            {
                name = "";
            }
            name = name.Trim().ToLower();

            CacheContainer mycc = null;

            foreach (CacheContainer cc in containers)
            {
                if (cc.Type == ct && cc.Valid && cc.FileName == name)
                {
                    mycc = cc;
                    break;
                }
            }             //foreach

            if (mycc == null)
            {
                mycc          = new CacheContainer(ct);
                mycc.FileName = name;
                containers.Add(mycc);
            }

            return(mycc);
        }
Beispiel #3
0
        /// <summary>
        /// Add a MaterialOverride to the Cache
        /// </summary>
        /// <param name="mmat">The Material Override to add</param>
        public void AddItem(SimPe.Plugin.MmatWrapper mmat)
        {
            CacheContainer mycc = this.UseConatiner(ContainerType.MaterialOverride, mmat.Package.FileName);

            MMATCacheItem mci = new MMATCacheItem();

            mci.Default        = mmat.DefaultMaterial;
            mci.ModelName      = mmat.ModelName.Trim().ToLower();
            mci.Family         = mmat.Family.Trim().ToLower();
            mci.FileDescriptor = mmat.FileDescriptor;

            mycc.Items.Add(mci);
        }
Beispiel #4
0
        /// <summary>
        /// Add a MaterialOverride to the Cache
        /// </summary>
        /// <param name="want">The Want File</param>
        public void AddItem(WantInformation want)
        {
            CacheContainer mycc = this.UseConatiner(ContainerType.Want, want.XWant.Package.FileName);

            WantCacheItem wci = new WantCacheItem();

            wci.FileDescriptor = want.XWant.FileDescriptor;
            wci.Folder         = want.XWant.Folder;
            wci.Guid           = want.Guid;
            wci.Icon           = want.Icon;
            wci.Influence      = want.XWant.Influence;
            wci.Name           = want.Name;
            wci.ObjectType     = want.XWant.ObjectType;
            wci.Score          = want.XWant.Score;

            mycc.Items.Add(wci);
        }
Beispiel #5
0
        /// <summary>
        /// Load/Add a Cache Item for the passed File
        /// </summary>
        /// <param name="filename">The Name of the File</param>
        public ScannerItem LoadItem(string filename)
        {
            CacheContainer mycc = this.UseConatiner(ContainerType.Package, filename);

            if (mycc.Items.Count == 0)
            {
                PackageCacheItem pci  = new PackageCacheItem();
                ScannerItem      item = new ScannerItem(pci, mycc);
                item.FileName = filename;
                pci.Name      = System.IO.Path.GetFileNameWithoutExtension(filename);
                mycc.Items.Add(pci);

                return(item);
            }
            else
            {
                ScannerItem item = new ScannerItem((PackageCacheItem)mycc.Items[0], mycc);
                item.FileName = filename;

                return(item);
            }
        }
Beispiel #6
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);
        }
Beispiel #7
0
        /// <summary>
        /// Add a Object Item to the Cache
        /// </summary>
        /// <param name="oci">The Cache Item</param>
        /// <param name="filename">name of the package File where the Object was in</param>
        public void AddItem(ObjectCacheItem oci, string filename)
        {
            CacheContainer mycc = this.UseConatiner(ContainerType.Object, filename);

            mycc.Items.Add(oci);
        }
Beispiel #8
0
 public int Add(CacheContainer item)
 {
     return(base.Add(item));
 }
Beispiel #9
0
 public bool Contains(CacheContainer item)
 {
     return(base.Contains(item));
 }
Beispiel #10
0
 public void Remove(CacheContainer item)
 {
     base.Remove(item);
 }
Beispiel #11
0
 public void Insert(int index, CacheContainer item)
 {
     base.Insert(index, item);
 }
Beispiel #12
0
 public ScannerItem(PackageCacheItem pci, SimPe.Cache.CacheContainer cc)
 {
     this.pci = pci;
     this.cc  = cc;
     filename = "";
 }