/// <summary> /// Add all Files that could be borrowed from the current package by the passed one, to the passed package /// </summary> /// <param name="orgmodelnames">List of available modelnames in this package</param> /// <param name="pkg">The package that should receive the Files</param> /// <remarks>Simply Copies MMAT, LIFO, TXTR and TXMT Files</remarks> public void AddParentFiles(string[] orgmodelnames, SimPe.Interfaces.Files.IPackageFile pkg) { if (WaitingScreen.Running) { WaitingScreen.UpdateMessage("Loading Parent Files"); } ArrayList names = new ArrayList(); foreach (string s in orgmodelnames) { names.Add(s); } ArrayList types = new ArrayList(); types.Add(Data.MetaData.MMAT); types.Add(Data.MetaData.TXMT); types.Add(Data.MetaData.TXTR); types.Add(Data.MetaData.LIFO); foreach (uint type in types) { SimPe.Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(type); foreach (SimPe.Interfaces.Files.IPackedFileDescriptor pfd in pfds) { if (pkg.FindFile(pfd) != null) { continue; } SimPe.Interfaces.Files.IPackedFile file = package.Read(pfd); pfd.UserData = file.UncompressedData; //Update the modeName in the MMAT if ((pfd.Type == Data.MetaData.MMAT) && (names.Count > 0)) { SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(pfd, package); string n = mmat.ModelName.Trim().ToLower(); if (!n.EndsWith("_cres")) { n += "_cres"; } if (!names.Contains(n)) { n = names[0].ToString(); //n = n.Substring(0, n.Length-5); mmat.ModelName = n; mmat.SynchronizeUserData(); } } pkg.Add(pfd); } } //foreach type }
/// <summary> /// Adds all know MMATs that reference one of the models; /// </summary> /// <param name="pkg"></param> /// <param name="onlydefault">true, if you only want to read default MMATS</param> /// <param name="subitems">true, if you also want to load MMAT Files that reference Files ouside the passed package</param> /// <param name="exception">true if you want to throw an exception when something goes wrong</param> /// <returns>List of all referenced GUIDs</returns> public void AddMaterialOverrides(SimPe.Interfaces.Files.IPackageFile pkg, bool onlydefault, bool subitems, bool exception) { LoadCache(); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] items = FileTable.FileIndex.FindFile(Data.MetaData.MMAT, true); ArrayList itemlist = new ArrayList(); ArrayList contentlist = new ArrayList(); ArrayList defaultfam = new ArrayList(); ArrayList guids = new ArrayList(); //create an UpTo Date Cache bool chgcache = false; foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem item in items) { string pname = item.Package.FileName.Trim().ToLower(); SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem[] citems = cachefile.FileIndex.FindFile(item.FileDescriptor, item.Package); bool have = false; foreach (SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem citem in citems) { if (citem.FileDescriptor.Filename == pname) { have = true; break; } } //Not in cache, so add that File if (!have) { SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(item.FileDescriptor, item.Package); cachefile.AddItem(mmat); chgcache = true; } } if (chgcache) { SaveCache(); } //collect a list of Default Material Override family values first if (onlydefault) { foreach (SimPe.Cache.MMATCacheItem mci in (SimPe.Cache.CacheItems)cachefile.DefaultMap[true]) { defaultfam.Add(mci.Family); } } //now do the real collect foreach (string k in modelnames) { SimPe.Cache.CacheItems list = (SimPe.Cache.CacheItems)cachefile.ModelMap[k.Trim().ToLower()]; if (list != null) { foreach (SimPe.Cache.MMATCacheItem mci in list) { if (onlydefault && !defaultfam.Contains(mci.Family)) { continue; } string name = k; items = FileTable.FileIndex.FindFile(mci.FileDescriptor, null); foreach (Interfaces.Scenegraph.IScenegraphFileIndexItem item in items) { if (itemlist.Contains(item)) { continue; } itemlist.Add(item); SimPe.Plugin.MmatWrapper mmat = new MmatWrapper(); mmat.ProcessData(item); string content = Scenegraph.MmatContent(mmat); content = content.Trim().ToLower(); if (!contentlist.Contains(content)) { mmat.FileDescriptor = Clone(mmat.FileDescriptor); mmat.SynchronizeUserData(); if (subitems) { if (pkg.FindFile(mmat.FileDescriptor) == null) { pkg.Add(mmat.FileDescriptor); } SimPe.Interfaces.Scenegraph.IScenegraphFileIndexItem txmtitem = SimPe.FileTable.FileIndex.FindFileByName(mmat.GetSaveItem("name").StringValue + "_txmt", Data.MetaData.TXMT, Data.MetaData.LOCAL_GROUP, true); if (txmtitem != null) { try { SimPe.Plugin.GenericRcol sub = new GenericRcol(null, false); sub.ProcessData(txmtitem.FileDescriptor, txmtitem.Package, false); ArrayList newfiles = new ArrayList(); LoadReferenced(this.modelnames, this.exclude, newfiles, itemlist, sub, txmtitem, true, setup); BuildPackage(newfiles, pkg); } catch (Exception ex) { Helper.ExceptionMessage("", new CorruptedFileException(txmtitem, ex)); } } else { continue; //if (exception) throw new ScenegraphException("Invalid Scenegraph Link", new ScenegraphException("Unable to find Referenced File "+name+"_txmt.", mmat.FileDescriptor), mmat.FileDescriptor); } } else { if (pkg.FindFile(mmat.FileDescriptor) == null) { string txmtname = mmat.GetSaveItem("name").StringValue.Trim(); if (!txmtname.EndsWith("_txmt")) { txmtname += "_txmt"; } if (pkg.FindFile(txmtname, Data.MetaData.TXMT).Length > 0) { pkg.Add(mmat.FileDescriptor); } } } contentlist.Add(content); } //if contentlist } //foreach item } //foreach MMATCacheItem } // if list !=null } }