void ApplyAllChanges() { for (int i = 0; i < availablePatches.Count(); i++) { pi = availablePatches[i]; if (pi.toggle) { if (pi.enabled) { Log.InfoAlways("Removing active patch: " + pi.activePatchName); Log.InfoAlways("activePatchPath: " + pi.activePatchPath + ", inactivePatchPath: " + pi.inactivePatchPath); // Save the file if it doesn't exist at the dstination, otherwise delete it if (!System.IO.File.Exists(pi.activePatchPath)) { ScreenMessages.PostScreenMessage("Patch file: " + pi.activePatchPath + " missing", 5); Log.InfoAlways("Patch file: " + pi.activePatchPath + " missing"); } else { if (!System.IO.File.Exists(pi.inactivePatchPath)) { File.Move(pi.activePatchPath, pi.inactivePatchPath); } else { File.Delete(pi.activePatchPath); } } } else { Log.InfoAlways("Activating patch: " + pi.activePatchName); Log.InfoAlways("activePatchPath: " + pi.activePatchPath + ", inactivePatchPath: " + pi.inactivePatchPath); if (System.IO.File.Exists(pi.inactivePatchPath)) { File.Copy(pi.inactivePatchPath, pi.activePatchPath); } else { ScreenMessages.PostScreenMessage("Patch file: " + pi.inactivePatchPath + " missing", 5); } Log.InfoAlways("Patch file: " + pi.inactivePatchPath + " missing"); } } } restartMsg = true; }
bool exclusionsOK(PatchInfo pi) { if (pi.exclusions == null || pi.exclusions.Count() == 0) { Log.Info("No exclusions"); return(true); } Log.Info("pi.patchName: " + pi.patchName); Log.Info("pi.modName: " + pi.modName); Log.Info("pi.exclusions: " + pi.exclusions); List <string> stringList = pi.exclusions.Split(',').ToList(); for (int i = 0; i < stringList.Count; i++) { var s = stringList[i]; s = pi.modName + "_" + s; s = s.Replace(' ', '_'); stringList[i] = s; Log.Info("stringlist[" + i + "]: " + s); } for (int i = 0; i < availablePatches.Count(); i++) { pi = availablePatches[i]; string s = pi.exclusionPatchName; Log.Info("Checking Exclusion: " + s + " enabled: " + pi.enabled.ToString() + " toggle: " + pi.toggle.ToString()); if ((pi.enabled && !pi.toggle) || (!pi.enabled && pi.toggle)) { if (stringList.Contains(s)) { Log.Info("exclusion found"); return(false); } else { Log.Info("stringList does NOT contain [" + s + "]"); } } } Log.Info("No exclusion found"); return(true); }
// // Main window // void drawPatchWindow(int windowid) { //Log.Info("==================================================================================================="); string lastModDisplayed = ""; GUILayout.BeginHorizontal(); fileSelectionScrollPosition = GUILayout.BeginScrollView(fileSelectionScrollPosition); GUILayout.BeginVertical(); for (int i = 0; i < availablePatches.Count(); i++) { pi = availablePatches[i]; //Log.Info("i: " + i.ToString() + ", modname: " + pi.modName + ", lastModDisplayed: " + lastModDisplayed); if (!expanded && pi.modName == lastModDisplayed) { continue; } if (expanded && pi.modName != expandedMod && expandedMod != "" && pi.modName == lastModDisplayed) { continue; } GUILayout.BeginHorizontal(); GUIStyle gs = bodyButtonStyle; GUILayout.BeginVertical(); // Disply Mod Buttons //string s = ""; //GUILayout.BeginVertical(); Texture2D Image = null; if (pi.icon != null && pi.icon.Length > 0) { Image = GameDatabase.Instance.GetTexture(pi.icon, false); } GUI.enabled = !expanded || exclusionsOK(pi); if (Image == null) { if (GUILayout.Button("", HighLogic.Skin.label, GUILayout.Width(38), GUILayout.Height(38))) { //ToggleActivation(pi); } } else { if (GUILayout.Button(Image, HighLogic.Skin.label, GUILayout.Width(38), GUILayout.Height(38))) { // ToggleActivation(pi); } } GUILayout.EndVertical(); GUILayout.BeginVertical(); if (!expanded || lastModDisplayed != pi.modName) { if (GUILayout.Button(pi.modName, GUILayout.Width(175))) { if (expanded && expandedMod == pi.modName) { expanded = false; } else if (!expanded) { expanded = !expanded; } expandedMod = pi.modName; } } else { GUILayout.Label(" ", GUILayout.Width(175)); } lastModDisplayed = pi.modName; GUILayout.EndVertical(); // End of Mod button display GUI.enabled = exclusionsOK(pi); GUILayout.BeginVertical(); if (expanded && pi.modName == expandedMod) { if (pi.enabled) { if (!pi.toggle) { gs = bodyButtonStyleGreen; } else { gs = bodyButtonStyleRed; } } else { if (!pi.toggle) { gs = bodyButtonStyleRed; } else { gs = bodyButtonStyleGreen; } } if (GUILayout.Button(pi.shortDescr, gs, GUILayout.Width(175))) { ToggleActivation(pi); } GUILayout.EndVertical(); GUILayout.BeginVertical(); GUILayout.Label(pi.longDescr + "\n" + pi.author + "\n", GUILayout.Width(WIDTH - 175 * 2 - 38 - 2)); } else { GUILayout.Label("\n\n", GUILayout.Width(WIDTH - 175 - 38 - 2)); } GUI.enabled = true; GUILayout.EndVertical(); GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUILayout.EndScrollView(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button(Localizer.Format("pm_applyall"), GUILayout.Width(90))) { ApplyAllChanges(); HideWindow(); } GUILayout.FlexibleSpace(); if (GUILayout.Button(Localizer.Format("pm_cancel"), GUILayout.Width(90))) { HideWindow(); } GUILayout.FlexibleSpace(); if (GUILayout.Button(Localizer.Format("pm_settings"))) { showSettings = true; } GUILayout.EndHorizontal(); GUI.DragWindow(); }
void ToggleActivation(PatchInfo pi) { pi.toggle = !pi.toggle; }