/// <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); }
/// <summary> /// Load Informations about a specific Want /// </summary> /// <param name="guid">The GUID of the want</param> /// <returns>A Want Information Structure</returns> public static WantCacheInformation LoadWant(SimPe.Cache.WantCacheItem wci) { WantCacheInformation ret = new WantCacheInformation(); ret.icon = wci.Icon; ret.name = wci.Name; ret.guid = wci.Guid; XWant w = new XWant(); SimPe.PackedFiles.Wrapper.CpfItem i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "id"; i.UIntegerValue = wci.Guid; w.AddItem(i, true); i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "folder"; i.StringValue = wci.Folder; w.AddItem(i, true); i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "score"; i.IntegerValue = wci.Score; w.AddItem(i, true); i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "influence"; i.IntegerValue = wci.Influence; w.AddItem(i, true); i = new SimPe.PackedFiles.Wrapper.CpfItem(); i.Name = "objectType"; i.StringValue = wci.ObjectType; w.AddItem(i, true); ret.wnt = w; return(ret); }
/// <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); } }