/// <summary> /// Imports a mod to the current selected KSP install path. /// </summary> /// <param name="importInfo">The ImportInfo </param> /// <param name="copyDest">Flag to determine if the destination should be copied or if the auto destination detection should be used.</param> /// <param name="addOnly">Flag to determine if the mod should be installed or only added to the ModSelection.</param> private static void ImportMod(ImportInfo importInfo, bool copyDest, bool addOnly) { ModInfo modInfo = importInfo.ModInfo; ModNode addedMod = ModSelectionController.AddMods(new ModInfo[] { modInfo }, false).FirstOrDefault(); if (addedMod != null) { if (copyDest) { // remove all destinations and uncheck all nodes. ModNodeHandler.SetDestinationPaths(addedMod, string.Empty); addedMod._Checked = false; // copy destination UpdateMessage(string.Format(Messages.MSG_COPY_MOD_DESTINATION_0, addedMod.Name)); if (!ModNodeHandler.TryCopyDestToMatchingNodes(importInfo, addedMod)) { UpdateMessage(string.Format(Messages.MSG_COPY_MOD_0_DESTINATION_FAILED, addedMod.Name)); UpdateMessage(string.Format(Messages.MSG_IMPORT_0_FAILED, importInfo.Name), importInfo); return; } } // install the mod. if (!addOnly) { UpdateMessage(string.Format(Messages.MSG_INSTALLING_MOD_0, addedMod.Name)); ModSelectionController.ProcessMods(new ModNode[] { addedMod }); } } else { UpdateMessage(string.Format(Messages.MSG_IMPORT_0_FAILED, importInfo.Name), importInfo); } }
/// <summary> /// Solves the destination collision for a Mod. /// Removes the destination of all mod files registered to the destination of /// </summary> /// <param name="modRoot">The mod to keep the destination.</param> public static void SolveCollisions(ModNode modRoot) { var collidingNodes = GetAllCollisionNodes(modRoot); foreach (ModNode collidingNode in collidingNodes) { if (string.IsNullOrEmpty(collidingNode.Destination) || !mRegisterdModFiles.ContainsKey(collidingNode.Destination.ToLower())) { collidingNode.HasCollision = false; continue; } List <ModNode> removeDestinationNodes = mRegisterdModFiles[collidingNode.Destination.ToLower()].Where(node => node != collidingNode).ToList(); foreach (ModNode delNode in removeDestinationNodes) { RemoveRegisteredModFile(delNode); // TODO: ////TreeViewEx.ChangeCheckedState(delNode, false, true, true); if (!delNode.IsFile && delNode.IsInstalled) { ModSelectionController.ProcessMods(new ModNode[] { delNode }, true); } delNode.SetDestinationPaths(string.Empty); } } }