void addToBlackList(string p, string title, blackListType type) { blackListPart blp = new blackListPart(); blp.modName = p; blp.where = type; blp.title = title; blp.permapruned = false; Log.Info("addToBlackList: " + p); // If it's already there, then delete it and chagne the "where" to ALL blackListPart p1; if (blackList.TryGetValue(p, out p1)) { if (!p1.permapruned) { blackList.Remove(p); blp.where = blackListType.ALL; } } blackList.Add(p, blp); EditorPartList.Instance.Refresh(); HidePruneMenu(); FileOperations.Instance.saveBlackListData(blackList); }
public IEnumerator pruning() { permapruneInProgress = true; Log.Info("PermaPrune.pruner"); renamedFilesList = FileOperations.Instance.loadRenamedFiles(); Log.Info("sizeof renamedFilesList: " + renamedFilesList.Count.ToString()); Log.Info("pruner, sizeof blacklist:" + JanitorsCloset.blackList.Count.ToString()); ShowRenamed.Instance.Show(); List <string> prunedParts = new List <string>(); foreach (blackListPart blp in JanitorsCloset.blackList.Values) { yield return(0); Log.Info("permapruneInProgress: " + permapruneInProgress.ToString()); if (!permapruneInProgress) { break; } if (blp.where != blackListType.ALL || blp.permapruned) { continue; } Log.Info("pruned part: " + blp.modName); //AvailablePart part = PartLoader.Instance.parts.Find(item => item.name.Equals(blp.modName)); AvailablePart part = PartLoader.getPartInfoByName(blp.modName); if (part == null) { continue; } prunedParts.Add(blp.modName); // Rename cfg file string s1 = part.configFileFullName.Substring(part.configFileFullName.IndexOf("GameData") + 9); RenameFile(s1, part.name); string partPath = part.partUrl; for (int x = 0; x < 1; x++) { int backslash = partPath.LastIndexOf('\\'); int slash = partPath.LastIndexOf('/'); int i = Math.Max(backslash, slash); partPath = partPath.Substring(0, i); } partPath += "/"; // rename resource file // Look for model = // model has complete path // Look for mesh = // with mesh, get patch from cfg file path Log.Info("searching for model"); Log.Info("Part: " + part.name); ConfigNode[] nodes = part.partConfig.GetNodes("MODEL"); ConfigNode[] nodes2; bool b; #if true if (nodes != null) { Log.Info("Nodes count: " + nodes.Length.ToString()); foreach (ConfigNode modelNode in nodes) { b = false; if (modelNode != null) { Log.Info("modelNode: " + modelNode.name); string model = GetModelURL(part, modelNode); Log.Info("ModelUrl: " + GetModelURL(part, modelNode)); if (model != null) { Log.Info("model: " + model); // Make sure it isn't being used in another part b = false; Log.Info("Part count: " + PartLoader.LoadedPartsList.Count.ToString()); string s; foreach (AvailablePart pSearch in PartLoader.LoadedPartsList) { Log.Info("pSearch: " + pSearch.name); if (part != pSearch && pSearch.partConfig != null) { nodes2 = pSearch.partConfig.GetNodes("MODEL"); if (nodes2 != null) { Log.Info("nodes2"); foreach (ConfigNode searchNode in nodes2) { if (searchNode != null) { Log.Info("searchNode"); if (model == GetModelURL(pSearch, searchNode)) { b = true; break; } } } } s = GetMeshURL(pSearch); Log.Info("Mesh URL: " + GetMeshURL(pSearch) + " ModelUrl: " + GetModelURL(part, modelNode)); if (GetMeshURL(pSearch) == model) { b = true; break; } } if (b) { break; } } } if (!b) { Log.Info("MODEL: " + model); string mURL = FindTexturePathFromModel.getModelURL(model); Log.Info("MODEL URL: " + mURL); model = model + ".mu"; RenameFile(model, part.name); } } } } #endif yield return(0); if (!permapruneInProgress) { break; } Log.Info("searching for meshes"); string mesh = GetMeshURL(part); if (mesh != null && mesh != "") { // Make sure it isn't being used in another part b = false; foreach (AvailablePart pSearch in PartLoader.LoadedPartsList) { if (part != pSearch) { string searchMesh = GetMeshURL(pSearch); if (searchMesh == mesh) { b = true; break; } if (pSearch.partConfig != null) { nodes2 = pSearch.partConfig.GetNodes("MODEL"); if (nodes2 != null) { foreach (ConfigNode searchNode in nodes2) { if (searchNode != null) { string model = GetModelURL(pSearch, searchNode); if (mesh == model) { b = true; break; } } } } } } } if (!b) { Log.Info("Renaming mesh: " + mesh + " partPath: " + partPath); string mURL = FindTexturePathFromModel.getModelURL(mesh); partPath = partPath.Substring(0, partPath.LastIndexOf("/")) + "/"; if (!(mesh.Contains("/") || mesh.Contains("\\"))) { mesh = partPath + mesh; } RenameFile(mesh, part.name); } } // this gets the model Log.Info("searching for model (INTERNAL)"); nodes = part.partConfig.GetNodes("INTERNAL"); if (nodes != null) { foreach (ConfigNode internalNode in nodes) { if (internalNode != null) { UrlDir.UrlConfig config; if (GetInternalSpaceConfigUrl.FindInternalSpaceConfigByName(internalNode.GetValue("name"), out config)) { // Make sure it isn't being used in another part b = false; foreach (AvailablePart pSearch in PartLoader.Instance.parts) { if (part != pSearch) { nodes2 = part.partConfig.GetNodes("INTERNAL"); if (nodes2 != null) { foreach (ConfigNode internalNodeSearch in nodes2) { UrlDir.UrlConfig configSearch; if (GetInternalSpaceConfigUrl.FindInternalSpaceConfigByName(internalNode.GetValue("name"), out configSearch)) { if (configSearch.url == config.url) { b = true; break; } } if (b) { break; } } } } if (b) { break; } } if (!b) { string s = config.url.Substring(0, config.url.LastIndexOf("/")) + ".cfg"; RenameFile(s, part.name); } } // // We aren't going to check to see if the different models inside the space are // used elsewhere. An assumption that the same model won't be used by multiple spaces // Log.Info("searching for internal space nodes"); ConfigNode cfgNode; bool b1 = GetInternalSpaceConfigUrl.FindInternalSpaceConfigNode(config.name, out cfgNode); if (b1) { nodes = cfgNode.GetNodes("MODEL"); if (nodes != null) { foreach (ConfigNode modelNode in nodes) { string model = modelNode.GetValue("model"); //Log.Info("MODEL: " + model); string mURL = FindTexturePathFromModel.getModelURL(model); // Log.Info("MODEL URL: " + mURL); model = model + ".mu"; RenameFile(model, part.name); } } } } } } } foreach (var s in prunedParts) { blackListPart blp = JanitorsCloset.blackList[s]; blp.permapruned = true; JanitorsCloset.blackList[s] = blp; } Log.Info("before saveRenamedFiles"); FileOperations.Instance.saveRenamedFiles(renamedFilesList); permapruneInProgress = false; yield break; //JanitorsCloset.Instance.clearBlackList(); }
void BlockedWindowContent(int windowID) { string unblock = ""; blackListPart unblockBlp = null; GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Mod Name", GUILayout.Width(MODNAMEWIDTH))) { if (lastSort != "modname") { sortAscending = true; } else { sortAscending = !sortAscending; } if (sortAscending) { blpList.Sort((x, y) => x.title.CompareTo(y.title)); } else { blpList.Sort((y, x) => x.title.CompareTo(y.title)); } lastSort = "modname"; } if (GUILayout.Button("Where", GUILayout.Width(WHEREWIDTH))) { if (lastSort != "where") { sortAscending = true; } else { sortAscending = !sortAscending; } if (sortAscending) { blpList.Sort((x, y) => x.where.CompareTo(y.where)); } else { blpList.Sort((y, x) => x.where.CompareTo(y.where)); } lastSort = "where"; } if (GUILayout.Button("Unblock All")) { clearBlackList(); CloseWindow(); } GUILayout.EndHorizontal(); sitesScrollPosition = GUILayout.BeginScrollView(sitesScrollPosition, false, true, GUILayout.Height(HEIGHT - LINEHEIGHT)); // foreach (var blp in JanitorsCloset.blackList) foreach (var blp in blpList) { GUILayout.BeginHorizontal(); GUILayout.Label(blp.title, GUILayout.Width(MODNAMEWIDTH)); GUILayout.Label(blp.where.ToString(), GUILayout.Width(WHEREWIDTH)); GUILayout.FlexibleSpace(); //AvailablePart p = PartLoader.Instance.parts.Find(item => item.name.Equals(blp.modName)); AvailablePart p = PartLoader.getPartInfoByName(blp.modName); if (p == null || blp.permapruned) { GUI.enabled = false; } if (GUILayout.Button("Unblock", GUILayout.ExpandWidth(true))) { unblock = blp.modName; unblockBlp = blp; } GUI.enabled = true; GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); if (GUILayout.Button("OK")) { CloseWindow(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUI.DragWindow(); if (unblock != "") { JanitorsCloset.blackList.Remove(unblock); EditorPartList.Instance.Refresh(); blpList.Remove(unblockBlp); } }
public Dictionary <string, blackListPart> loadData(string fname) { Dictionary <string, blackListPart> blpList = new Dictionary <string, blackListPart>(); List <AvailablePart> loadedParts = new List <AvailablePart>(); if (PartLoader.Instance != null) { loadedParts.AddRange(PartLoader.LoadedPartsList); } #if false // This code is used to export various information about parts and their resources // used to rebalance fuel tanks foreach (AvailablePart part in loadedParts) { List <Bounds> list = new List <Bounds>(); if (!(part.partPrefab.Modules.GetModule <LaunchClamp>(0) != null)) { Bounds[] partRendererBounds = PartGeometryUtil.GetPartRendererBounds(part.partPrefab); int num = partRendererBounds.Length; for (int j = 0; j < num; j++) { Bounds bounds2 = partRendererBounds[j]; Bounds bounds3 = bounds2; bounds3.size *= part.partPrefab.boundsMultiplier; Vector3 size = bounds3.size; bounds3.Expand(part.partPrefab.GetModuleSize(size, ModifierStagingSituation.CURRENT)); list.Add(bounds2); } } var pg = PartGeometryUtil.MergeBounds(list.ToArray(), part.partPrefab.transform.root).size; string resources = ""; foreach (AvailablePart.ResourceInfo r in part.resourceInfos) { if (r.resourceName != "ElectricCharge" && r.resourceName != "Ablator") { resources += r.resourceName + ","; } } if (resources != "") { Log.Info("part: " + part.name + ", part.title: " + part.title + ", descr: " + part.description.Replace(",", ".") + ", mass: " + part.partPrefab.mass + ", techRequired: " + part.TechRequired + ", height x,y,z: " + pg.x.ToString() + ", " + pg.y.ToString() + ", " + pg.z.ToString() + "," + resources); } } #endif Log.Info("loadData, fname: " + fname); if (fname != "" && File.Exists(fname)) { using (StreamReader f = File.OpenText(fname)) { string l = ""; while ((l = f.ReadLine()) != null) { string[] s = l.Split(','); if (s.Length >= 2) { blackListPart blp = new blackListPart(); blp.modName = s[0]; if (s[1] == "ALL") { blp.where = blackListType.ALL; } if (s[1] == "SPH") { blp.where = blackListType.SPH; } if (s[1] == "VAB") { blp.where = blackListType.VAB; } AvailablePart p = loadedParts.Find(part => part.name == blp.modName); if (p != null) { blp.title = p.title; Log.Info("Blacklist mod: " + blp.modName); Log.Info("partTitle: " + blp.title); blp.permapruned = false; blpList.Add(blp.modName, blp); } } } } return(blpList); } else { return(blpList); } }