/// <summary> /// Remove all Files that are referenced by a SHPE and belong to a subset as named in the esclude List /// </summary> /// <param name="exclude">List of subset names</param> /// <param name="modelnames">null or a List of allowed Modelnames. If a List is passed, only references to files /// starting with one of the passed Modelnames will be keept</param> public void RemoveSubsetReferences(ArrayList exclude, string[] modelnames) { if (WaitingScreen.Running) { WaitingScreen.UpdateMessage("Removing unwanted Subsets"); } //Build the ModelName List ArrayList mn = new ArrayList(); if (modelnames != null) { foreach (string s in modelnames) { string n = s; if (s.EndsWith("_cres")) { n = s.Substring(0, s.Length - 5); } mn.Add(n); } } bool deleted = false; Interfaces.Files.IPackedFileDescriptor[] pfds = package.FindFiles(Data.MetaData.SHPE); foreach (Interfaces.Files.IPackedFileDescriptor pfd in pfds) { Rcol rcol = new GenericRcol(null, false); rcol.ProcessData(pfd, package); foreach (ShapePart p in ((Shape)rcol.Blocks[0]).Parts) { string s = p.Subset.Trim().ToLower(); bool remove = exclude.Contains(s); if ((modelnames != null) && !remove) { remove = true; string fl = p.FileName.Trim().ToLower(); foreach (string n in mn) { if (fl.StartsWith(n)) { remove = false; continue; } } } if (remove) { string n = p.FileName.Trim().ToLower(); if (!n.EndsWith("_txmt")) { n += "_txmt"; } ArrayList names = new ArrayList(); Interfaces.Files.IPackedFileDescriptor[] rpfds = package.FindFile(n, Data.MetaData.TXMT); foreach (Interfaces.Files.IPackedFileDescriptor rpfd in rpfds) { names.Add(rpfd); } int pos = 0; while (pos < names.Count) { Interfaces.Files.IPackedFileDescriptor rpfd = (Interfaces.Files.IPackedFileDescriptor)names[pos++]; rpfd = package.FindFile(rpfd); if (rpfd != null) { rpfd.MarkForDelete = true; deleted = true; GenericRcol fl = new GenericRcol(null, false); fl.ProcessData(rpfd, package); Hashtable ht = fl.ReferenceChains; foreach (string k in ht.Keys) { foreach (Interfaces.Files.IPackedFileDescriptor lpfd in (ArrayList)ht[k]) { if (!names.Contains(lpfd)) { names.Add(lpfd); } } } } } //while } } //foreach p } //foreach SHPE //now remova all deleted Files from the Index if (deleted) { package.RemoveMarked(); } }