/// <summary> /// Checks all patents if value is true, /// otherwise parents will be unchecked if no sibling is checked. /// </summary> /// <param name="value">The value to set to the Checked property to.</param> public void CheckParents(bool value) { if (!HasParent) { return; } ModNode parent = (Parent as ModNode); if (parent.Checked == value) { return; } if (value) { parent.SetChecked(true); parent.CheckParents(true); } else { if (!IsSiblingChecked) { parent.SetChecked(false); parent.CheckParents(false); } } }
/// <summary> /// Unchecks the modNode and all child and child child ... ModNodes. /// </summary> private void UncheckAllInternal(ModNode modNode) { modNode.SetChecked(false); foreach (ModNode child in modNode.Nodes) { UncheckAllInternal(child); } }
/// <summary> /// Creates a TreeNode for the XmlNode information. /// </summary> private static void FillModTreeNode(XmlNode mod, ref ModNode node) { string kspForumURL = string.Empty; string curseForgeURL = string.Empty; node.AddDate = DateTime.Now.ToString(); foreach (XmlAttribute att in mod.Attributes) { if (att.Name == Constants.NAME) node.Name = att.Value; else if (att.Name == Constants.KEY) node.Key = att.Value; else if (att.Name == Constants.ADDDATE) node.AddDate = att.Value; else if (att.Name == Constants.VERSION) node.Version = att.Value; else if (att.Name == Constants.GAMEVERSION) node.KSPVersion = att.Value; else if (att.Name == Constants.NOTE) node.Note = att.Value; else if (att.Name == Constants.PRODUCTID) node.ProductID = att.Value; else if (att.Name == Constants.CREATIONDATE) node.CreationDate = att.Value; else if (att.Name == Constants.CHANGEDATE) node.ChangeDate = att.Value; else if (att.Name == Constants.AUTHOR) node.Author = att.Value; else if (att.Name == Constants.RATING) node.Rating = att.Value; else if (att.Name == Constants.DOWNLOADS) node.Downloads = att.Value; else if (att.Name == Constants.MODURL) node.ModURL = att.Value; else if (att.Name == Constants.AVCURL) node.AvcURL = att.Value; else if (att.Name == Constants.ADDITIONALURL) node.AdditionalURL = att.Value; else if (att.Name == Constants.CHECKED) node.SetChecked((att.Value.Equals(Constants.TRUE, StringComparison.CurrentCultureIgnoreCase)), true); else if (att.Name == Constants.NODETYPE) node.NodeType = (NodeType)int.Parse(att.Value); else if (att.Name == Constants.DESTINATION) node.Destination = att.Value; else if (att.Name == Constants.FORUMURL) kspForumURL = att.Value; else if (att.Name == Constants.CURSEFORGEURL) curseForgeURL = att.Value; else if (att.Name == Constants.VERSIONCONTROLERNAME) { node.SiteHandlerName = att.Value; switch (att.Value) { case "KSPForum": // KSPForum if (string.IsNullOrEmpty(node.ModURL)) node.ModURL = kspForumURL; if (string.IsNullOrEmpty(node.AdditionalURL)) node.AdditionalURL = curseForgeURL; break; case "CurseForge": // CurseForge if (string.IsNullOrEmpty(node.ModURL)) node.ModURL = curseForgeURL; if (string.IsNullOrEmpty(node.AdditionalURL)) node.AdditionalURL = kspForumURL; break; } } } foreach (XmlNode modEntry in mod.ChildNodes) { ModNode newNode = new ModNode(); node.Nodes.Add(newNode); FillModTreeNode(modEntry, ref newNode); } }
/// <summary> /// Unchecks the modNode and all child and child child ... ModNodes. /// </summary> private void UncheckAllInternal(ModNode modNode) { modNode.SetChecked(false); foreach (ModNode child in modNode.Nodes) UncheckAllInternal(child); }
/// <summary> /// Resets the destination of the modNode and all its childs. /// </summary> /// <param name="modNode">The mod node to reset the destination.</param> public static void ResetDestination(ModNode modNode) { if (modNode == null) return; if (modNode.IsInstalled || modNode.HasInstalledChilds) MessageBox.Show(View.ParentForm, Messages.MSG_FOLDER_INSTALLED_UNINSTALL_IT_TO_CHANGE_DESTINATION, Messages.MSG_TITLE_ATTENTION, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); else { ModNodeHandler.SetDestinationPaths(modNode, string.Empty); modNode.SetChecked(false); modNode.CheckAllChildes(false); InvalidateView(); } }
/// <summary> /// Finds the root folder of the mod that can be installed to the KSP install folder. /// </summary> /// <param name="node">Node to start the search from.</param> /// <returns>The root folder of the mod that can be installed to the KSP install folder.</returns> private static bool FindAndSetDestinationPaths(ModNode node) { List<ModNode> kspFolders = new List<ModNode>(); List<ModNode> craftFiles = new List<ModNode>(); ModSelectionTreeModel.GetAllKSPFolders(node, ref kspFolders, ref craftFiles); if (kspFolders.Count == 1) { SetDestinationPaths(kspFolders[0], false); } else if (kspFolders.Count > 1) { kspFolders.Sort((node1, node2) => { if (node2.Depth == node1.Depth) return node1.Text.CompareTo(node2.Text); else return node2.Depth - node1.Depth; }); bool lastResult = false; foreach (ModNode kspFolder in kspFolders) lastResult = SetDestinationPaths(kspFolder, lastResult); } if (craftFiles.Count > 0) { foreach (ModNode craftNode in craftFiles) { string vab = KSPPathHelper.GetPath(KSPPaths.VAB); string sph = KSPPathHelper.GetPath(KSPPaths.SPH); if (!craftNode.HasDestination || (!craftNode.Destination.StartsWith(vab, StringComparison.CurrentCultureIgnoreCase) && !craftNode.Destination.StartsWith(sph, StringComparison.CurrentCultureIgnoreCase))) SetCraftDestination(craftNode); } } if (node.HasDestination || node.HasDestinationForChilds) node.SetChecked(true); return (kspFolders.Count > 0) || (craftFiles.Count > 0); }
/// <summary> /// Checks the node and all parents. /// </summary> /// <param name="node">The node to check.</param> private static void CheckNodeAndParents(ModNode node) { // check node and parent nodes. node.SetChecked(true); if (node.Parent == null || node.Parent.Index == -1) return; Node parent = node.Parent; while (parent != null && parent.Index > -1) { ((ModNode)parent).SetChecked(true); parent = parent.Parent; } }