Beispiel #1
0
        /// <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>
        /// Handles a mod add via URL.
        /// Validates the URL, gets ModInfos, downloads mod archive, adds it to the ModSelection and installs the mod if selected.
        /// </summary>
        /// <param name="url">The URL to the mod.</param>
        /// <param name="modName">The name for the mod.</param>
        /// <param name="install">Flag to determine if the mod should be installed after adding.</param>
        /// <param name="downloadProgressCallback">Callback function for download progress.</param>
        /// <returns>The root node of the added mod, or null.</returns>
        public ModNode HandleAdd(string url, string modName, bool install, DownloadProgressCallback downloadProgressCallback = null)
        {
            url = ReduceToPlainUrl(url);

            ModInfo modInfo = GetModInfo(url);

            if (modInfo == null)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(modName))
            {
                modInfo.Name = modName;
            }

            ModNode newMod = null;

            if (DownloadMod(ref modInfo, downloadProgressCallback))
            {
                newMod = ModSelectionController.HandleModAddViaModInfo(modInfo, install);
            }

            return(newMod);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a XmlNode for the child nodes of the mod.
        /// </summary>
        /// <param name="doc">The XmlDocument for XmlNode creation.</param>
        /// <param name="mod">The mod node to get the information for the XMLNode.</param>
        /// <returns>A XmlNode with the infos from the mod.</returns>
        private static XmlNode CreateModChildEntryXmlNode(XmlDocument doc, ModNode mod)
        {
            XmlNode modEntryNode = doc.CreateElement(Constants.MOD_ENTRY);

            XmlAttribute nodeAttribute = doc.CreateAttribute(Constants.NAME);

            nodeAttribute.Value = mod.Text;
            modEntryNode.Attributes.Append(nodeAttribute);

            nodeAttribute       = doc.CreateAttribute(Constants.ISFILE);
            nodeAttribute.Value = mod.IsFile ? ONE : ZERO;
            modEntryNode.Attributes.Append(nodeAttribute);

            nodeAttribute       = doc.CreateAttribute(Constants.INSTALL);
            nodeAttribute.Value = mod.IsInstalled ? ONE : ZERO;
            modEntryNode.Attributes.Append(nodeAttribute);

            nodeAttribute       = doc.CreateAttribute(Constants.INSTALLDIR);
            nodeAttribute.Value = mod.Destination;
            modEntryNode.Attributes.Append(nodeAttribute);

            foreach (ModNode child in mod.Nodes)
            {
                modEntryNode.AppendChild(CreateModChildEntryXmlNode(doc, child));
            }

            return(modEntryNode);
        }
 private void OpenFolder(ModNode node)
 {
     if (node != null && !node.IsFile && node.IsInstalled)
     {
         OptionsController.OpenFolder(KSPPathHelper.GetAbsolutePath(SelectedNode.Destination));
     }
 }
 private void OpenFile(ModNode node)
 {
     if (node != null && node.IsFile)
     {
         ModSelectionController.OpenTextDisplayer(node);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Returns all colliding mods (ZipRoots) that collides with the passed mod.
        /// </summary>
        /// <param name="modNode">The mod to get the collision mods for.</param>
        /// <returns>All colliding mods (ZipRoots) that collides with the passed mod.</returns>
        public static List <ModNode> GetCollisionModsByCollisionMod(ModNode modNode)
        {
            List <ModNode> result = new List <ModNode>();

            if (!ConflictDetectionOnOff)
            {
                return(result);
            }

            foreach (var fileNode in modNode.ZipRoot.GetAllFileNodes())
            {
                if (mRegisterdModFiles.ContainsKey(fileNode.Destination.ToLower()))
                {
                    foreach (var regFileNode in mRegisterdModFiles[fileNode.Destination.ToLower()])
                    {
                        if (regFileNode != modNode && !result.Contains(regFileNode.ZipRoot))
                        {
                            result.Add(regFileNode.ZipRoot);
                        }
                    }
                }
            }

            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// Returns a flat list of all colliding modNodes for all fileNodes of the passed node.
        /// </summary>
        /// <returns>A flat list of all colliding modNodes for all fileNodes of the passed node.</returns>
        public static List <ModNode> GetCollisionModFiles(ModNode modNode)
        {
            List <ModNode> result = new List <ModNode>();

            if (!ConflictDetectionOnOff)
            {
                return(result);
            }

            if (modNode.IsFile)
            {
                if (mRegisterdModFiles.ContainsKey(modNode.Destination.ToLower()))
                {
                    result.AddRange(mRegisterdModFiles[modNode.Destination.ToLower()].Where(node => node != modNode));
                }
            }
            else
            {
                foreach (var fileNode in modNode.ZipRoot.GetAllFileNodes())
                {
                    if (mRegisterdModFiles.ContainsKey(fileNode.Destination.ToLower()))
                    {
                        result.AddRange(mRegisterdModFiles[fileNode.Destination.ToLower()].Where(regFileNode => regFileNode != modNode));
                    }
                }
            }
            return(result);
        }
Beispiel #8
0
        /// <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);
                }
            }
        }
        /// <summary>
        /// Creates a directory for the ModNodes destination.
        /// </summary>
        /// <param name="node">The ModNode to get the destination of.</param>
        /// <param name="silent">Determines if info messages should be added displayed.</param>
        private static void CreateDirectory(ModNode node, bool silent)
        {
            string destination = node.Destination;

            if (!string.IsNullOrEmpty(destination))
            {
                destination = KSPPathHelper.GetAbsolutePath(destination);
            }

            node.IsInstalled = false;
            if (!Directory.Exists(destination))
            {
                try
                {
                    Directory.CreateDirectory(destination);
                    node.IsInstalled = true;

                    if (!silent)
                    {
                        Messenger.AddInfo(string.Format(Messages.MSG_DIR_CREATED_0, destination));
                    }
                }
                catch
                {
                    Messenger.AddInfo(string.Format(Messages.MSG_DIR_CREATED_ERROR_0, destination));
                }
            }

            node.NodeType = (node.IsKSPFolder) ? NodeType.KSPFolderInstalled : NodeType.UnknownFolderInstalled;
        }
        /// <summary>
        /// Removes the file the ModNodes destination points to.
        /// </summary>
        /// <param name="node">The ModNode to get the destination of.</param>
        /// <param name="silent">Determines if info messages should be added displayed.</param>
        private static void RemoveFile(ModNode node, bool silent)
        {
            string destination = node.Destination;

            if (!string.IsNullOrEmpty(destination))
            {
                destination = KSPPathHelper.GetAbsolutePath(destination);
            }

            node.IsInstalled = false;
            bool installedByOtherMod = ModRegister.GetCollisionModFiles(node).Any(n => n.IsInstalled);

            if (File.Exists(destination) && !installedByOtherMod)
            {
                try
                {
                    File.Delete(destination);
                    node.IsInstalled = false;
                    if (!silent)
                    {
                        Messenger.AddInfo(string.Format(Messages.MSG_FILE_DELETED_0, destination));
                    }
                }
                catch (Exception ex)
                {
                    Messenger.AddError(string.Format(Messages.MSG_FILE_DELETED_ERROR_0, destination), ex);
                }
            }

            node.NodeType = NodeType.UnknownFile;
        }
        /// <summary>
        /// Processes all passed nodes. (Adds/Removes the MOD to/from the KSP install folders).
        /// </summary>
        /// <param name="modArray">The NodeArray to process.</param>
        /// <param name="processedNodeCount">For internal use only!</param>
        /// <param name="silent">Determines if info messages should be added displayed.</param>
        /// <param name="overrideOn">Flag to set override of files on.</param>
        /// <param name="progressChanged">Callback function when the progress of the processing changed.</param>
        /// <returns>Count of processed nodes.</returns>
        private static int ProcessNodes(ModNode[] modArray, ref int processedNodeCount, bool silent = false, bool overrideOn = false, AsyncProgressChangedHandler progressChanged = null)
        {
            foreach (ModNode node in modArray)
            {
                if (node.HasDestination)
                {
                    if (!silent)
                    {
                        Messenger.AddInfo(string.Format(Messages.MSG_ROOT_IDENTIFIED, node.Text));
                    }

                    ProcessNode(node, ref processedNodeCount, silent, overrideOn, progressChanged);
                }
                else if (node.HasDestinationForChilds)
                {
                    if (progressChanged != null)
                    {
                        progressChanged(processedNodeCount += 1);
                    }

                    ModNode[] nodes = new ModNode[node.Nodes.Count];
                    for (int i = 0; i < node.Nodes.Count; ++i)
                    {
                        nodes[i] = (ModNode)node.Nodes[i];
                    }

                    ProcessNodes(nodes, ref processedNodeCount, silent, overrideOn, progressChanged);
                }
            }

            return(processedNodeCount);
        }
        /// <summary>
        /// Processes all passed nodes. (Adds/Removes the MOD to/from the KSP install folders).
        /// </summary>
        /// <param name="mod">The mod to process.</param>
        /// <param name="silent">Determines if info messages should be added displayed.</param>
        /// <param name="overrideOn">Flag to set override of files on.</param>
        /// <param name="progressChanged">Callback function when the progress of the processing changed.</param>
        /// <returns>Count of processed nodes.</returns>
        public static int ProcessMod(ModNode mod, bool silent = false, bool overrideOn = false, AsyncProgressChangedHandler progressChanged = null, int processedNodeCount = 0)
        {
            if (!silent)
            {
                Messenger.AddInfo(Constants.SEPARATOR);
                Messenger.AddInfo(string.Format(Messages.MSG_START_PROCESSING_0, mod.Name));
                Messenger.AddInfo(Constants.SEPARATOR);
            }

            int processedNode = processedNodeCount;

            try
            {
                processedNode = ProcessNodes(new ModNode[] { mod }, ref processedNode, silent, overrideOn, progressChanged);
            }
            catch (Exception ex)
            {
                Messenger.AddError(string.Format(Messages.MSG_ERROR_DURING_PROCESSING_MOD_0, mod.Name), ex);
            }

            DeleteNotProcessedDirectorys(silent);

            if (!silent)
            {
                Messenger.AddInfo(Constants.SEPARATOR);
            }

            return(processedNode);
        }
Beispiel #13
0
        /// <summary>
        /// Removes the mod file from the registration.
        /// </summary>
        /// <param name="fileNode">The file node to unregister.</param>
        public static void RemoveRegisteredModFile(ModNode fileNode)
        {
            if (!string.IsNullOrEmpty(fileNode.Destination) && mRegisterdModFiles.ContainsKey(fileNode.Destination.ToLower()) &&
                mRegisterdModFiles[fileNode.Destination.ToLower()].Contains(fileNode))
            {
                mRegisterdModFiles[fileNode.Destination.ToLower()].Remove(fileNode);
                fileNode.HasCollision = false;

                if (mRegisterdModFiles[fileNode.Destination.ToLower()].Count == 0)
                {
                    mRegisterdModFiles.Remove(fileNode.Destination.ToLower());
                }
                else if (mRegisterdModFiles[fileNode.Destination.ToLower()].Count == 1)
                {
                    mRegisterdModFiles[fileNode.Destination.ToLower()][0].HasCollision = false;
                }
                else if (mRegisterdModFiles[fileNode.Destination.ToLower()].Count > 1)
                {
                    if (HaveCollisionsSameRoot(fileNode))
                    {
                        mRegisterdModFiles[fileNode.Destination.ToLower()][0].HasCollision = false;
                    }
                }
            }
        }
        /// <summary>
        /// Loads the config.
        /// </summary>
        public static void Load(string path, ref List <ModNode> modNodes)
        {
            ModNode root = new ModNode()
            {
                Key = Constants.ROOT
            };

            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(path);
                XmlNodeList moVersion = doc.GetElementsByTagName(Constants.VERSION);
                if (moVersion.Count > 0)
                {
                    switch (moVersion[0].InnerText.ToLower())
                    {
                    case "v1.0":
                        root = LoadV1_0(doc);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Messenger.AddError(string.Format("Error during KSPMods.cfg. \"{0}\"", ex.Message), ex);
            }

            modNodes.AddRange(root.Nodes.Cast <ModNode>());
        }
Beispiel #15
0
        private ExpressionNode ParseTerm()
        {
            var lhs = ParseUnary();

            while (true)
            {
                if (_reader.Peek() is Asterisk)
                {
                    Match <Asterisk>();
                    lhs = new MultiplicationNode(lhs, ParseUnary());
                }
                else if (_reader.Peek() is Slash)
                {
                    Match <Slash>();
                    lhs = new DivisionNode(lhs, ParseUnary());
                }
                else if (_reader.Peek() is Percent)
                {
                    Match <Percent>();
                    lhs = new ModNode(lhs, ParseUnary());
                }
                else
                {
                    break;
                }
            }

            return(lhs);
        }
Beispiel #16
0
        /// <summary>
        /// Creates a zip for each root node in the passed node list.
        /// </summary>
        /// <param name="nodes">List of root nodes to create zips for.</param>
        /// <param name="filePath">the path (folder) where the new Zip should be saved to.</param>
        /// <returns>True on success.</returns>
        public static bool CreateZip(List <ModNode> nodes, string filePath)
        {
            // create the zip
            List <string> done = new List <string>();

            foreach (ModNode node in nodes)
            {
                ModNode root = node.ZipRoot;
                if (root != null && !File.Exists(root.LocalPath) && !done.Contains(root.LocalPath))
                {
                    string zipPath = Path.Combine(filePath, Path.GetFileNameWithoutExtension(root.Name) + Constants.EXT_ZIP);
                    using (var zip = ZipArchive.Create())
                    {
                        int nodecount = 0;
                        foreach (ModNode child in root.Nodes)
                        {
                            nodecount = CreateZipEntry(zip, child, nodecount);
                        }

                        zip.SaveTo(zipPath, CompressionType.None);
                    }
                    Messenger.AddInfo(string.Format(Messages.MSG_ZIP_0_CREATED, root.Name));
                    done.Add(root.Name);
                    root.Key = zipPath;
                }
            }

            return(true);
        }
Beispiel #17
0
 /*multiplicative-expression-p:
  | multiplicative-operators unary-expression multiplicative-expression-p
  | EPSILON */
 private ExpressionNode multiplicative_expression_p(ExpressionNode leftExpression)
 {
     printIfDebug("multiplicative_expression_p");
     if (pass(multiplicativeOperatorOptions))
     {
         Token multiplicativeOperator = token;
         consumeToken();
         var            unaryExpression  = unary_expression();
         ExpressionNode resultExpression = null;
         if (multiplicativeOperator.type == TokenType.OP_MULTIPLICATION)
         {
             resultExpression = new MultNode(leftExpression, unaryExpression, multiplicativeOperator);
         }
         else if (multiplicativeOperator.type == TokenType.OP_DIVISION)
         {
             resultExpression = new DivNode(leftExpression, unaryExpression, multiplicativeOperator);
         }
         else
         {
             resultExpression = new ModNode(leftExpression, unaryExpression, multiplicativeOperator);
         }
         return(multiplicative_expression_p(resultExpression));
     }
     return(leftExpression);
 }
Beispiel #18
0
 /// <summary>
 /// Removes the registered mod files of a mod.
 /// </summary>
 /// <param name="modRoot">The root node of the mod from which the files should be unregistered.</param>
 public static void RemoveRegisteredMod(ModNode modRoot)
 {
     RemoveRegisteredModFile(modRoot);
     foreach (ModNode child in modRoot.Nodes)
     {
         RemoveRegisteredMod(child);
     }
 }
Beispiel #19
0
        /// <summary>
        /// Handles a mod add via URL.
        /// Validates the URL, gets ModInfos, downloads mod archive, adds it to the ModSelection and installs the mod if selected.
        /// </summary>
        /// <param name="url">The URL to the mod.</param>
        /// <param name="modName">The name for the mod.</param>
        /// <param name="install">Flag to determine if the mod should be installed after adding.</param>
        /// <param name="downloadProgressCallback">Callback function for download progress.</param>
        /// <returns>The root node of the added mod, or null.</returns>
        public ModNode HandleAdd(string url, string modName, bool install, DownloadProgressCallback downloadProgressCallback = null)
        {
            ISiteHandler curseForge = SiteHandlerManager.GetSiteHandlerByName("CurseForge");
            ModNode      modNode    = curseForge.HandleAdd(GetDownloadURL(url), modName, install, downloadProgressCallback);

            ////modNode.VersionControllerName = Name;

            return(modNode);
        }
        /// <summary>
        /// Returns the destination path of the craft.
        /// </summary>
        /// <param name="craftNode">The craft to get the destination for.</param>
        public static void SetCraftDestination(ModNode craftNode)
        {
            string zipPath = craftNode.ZipRoot.Key;

            using (IArchive archive = ArchiveFactory.Open(zipPath))
            {
                foreach (IArchiveEntry entry in archive.Entries)
                {
                    if (!entry.FilePath.EndsWith(craftNode.Text, StringComparison.CurrentCultureIgnoreCase))
                    {
                        continue;
                    }

                    using (MemoryStream ms = new MemoryStream())
                    {
                        entry.WriteTo(ms);
                        ms.Position = 0;
                        using (StreamReader sr = new StreamReader(ms))
                        {
                            string fullText = sr.ReadToEnd();
                            int    index    = fullText.IndexOf(TYPE);
                            if (index == -1)
                            {
                                continue;
                            }

                            string filename = Path.GetFileName(entry.FilePath);
                            if (string.IsNullOrEmpty(filename))
                            {
                                continue;
                            }

                            string shipType = fullText.Substring(index + 7, 3);
                            if (shipType.Equals(Constants.SPH, StringComparison.CurrentCultureIgnoreCase))
                            {
                                craftNode.Destination = Path.Combine(KSPPathHelper.GetPath(KSPPaths.SPH), filename);
                            }
                            else
                            {
                                craftNode.Destination = Path.Combine(KSPPathHelper.GetPath(KSPPaths.VAB), filename);
                            }

                            if (!string.IsNullOrEmpty(craftNode.Destination))
                            {
                                craftNode.Destination = KSPPathHelper.GetRelativePath(craftNode.Destination);
                            }

                            SetToolTips(craftNode);

                            break;
                        }
                    }
                }
            }
        }
        private void cmsModSelectionOneMod_Opened(object sender, EventArgs e)
        {
            int     selectedModCount = SelectedMods.Count;
            ModNode selectedNode     = SelectedNode;

            if (HasSelectedNode)
            {
                if (selectedModCount != 1)
                {
                    tsmiCmsDestinationPath.Text = "<" + Messages.MSG_NOT_AVAILABLE + ">";
                }
                else
                {
                    tsmiCmsDestinationPath.Text = string.IsNullOrEmpty(selectedNode.Destination) ? "<" + Messages.MSG_NO_DESTINATION + ">" : selectedNode.Destination;
                }

                tsmiCmsSelectNewDestination.Enabled = (selectedModCount == 1);
                tsmiCmsResetDestination.Enabled     = (selectedModCount == 1);
                tsmiCmsRedetectDestination.Enabled  = (selectedModCount == 1);
                tsmiCmsRefreschCheckedState.Visible = (selectedModCount == 1);
                tsmiCmsRefreshCheckedStateForHighlightedMods.Visible = !tsmiCmsRefreschCheckedState.Visible;
                tsmiCmsEditModInfos.Enabled   = (selectedModCount == 1);
                tsmiCmsCopyModInfos.Enabled   = (selectedModCount == 1);
                tsmiCmsUpdatecheckMod.Visible = (selectedModCount == 1);
                tsmiCmsCheckHighlightedModsForUpdates.Visible = !tsmiCmsUpdatecheckMod.Visible;
                tsmiUpdateMod.Visible                  = (selectedModCount == 1);
                tsmiUpdateHiglightedMods.Visible       = !tsmiUpdateMod.Visible;
                tsmiCmsVisitVersionControlSite.Enabled = !string.IsNullOrEmpty(selectedNode.ZipRoot.ModURL);
                tsmiCmsVisitAdditionalLink.Enabled     = !string.IsNullOrEmpty(selectedNode.ZipRoot.AdditionalURL);
                tsmiCmsRemoveMod.Visible               = (selectedModCount == 1);
                tsmiCmsRemoveHighlightedMods.Visible   = !tsmiCmsRemoveMod.Visible;
                tsmiCmsProceedMod.Visible              = (selectedModCount == 1);
                tsmiCmsProceedHighlightedMods.Visible  = !tsmiCmsProceedMod.Visible;
                tsmiCmsCreateZip.Enabled               = !selectedNode.ZipExists;
                tsmiCmsOneModOpenFile.Visible          = selectedNode.IsFile;
                tsmiCmsOneModOpenFolder.Visible        = !selectedNode.IsFile && selectedNode.IsInstalled;
                tsmiCmsSolveConflicts.Enabled          = ModRegister.HasConflicts;
            }

            if (tvModSelection.SelectedNodes.Count > 1)
            {
                tsmiCmsDestinationPath.Text         = "<" + Messages.MSG_NOT_AVAILABLE + ">";
                tsmiCmsSelectNewDestination.Enabled = false;
                tsmiCmsRedetectDestination.Enabled  = false;
                tsmiCmsResetDestination.Visible     = false;
                tsmiCmsResetDestinations.Visible    = true;
                tsmiCmsOneModOpenFile.Visible       = false;
                tsmiCmsOneModOpenFolder.Visible     = false;
            }
            else
            {
                tsmiCmsResetDestination.Visible  = true;
                tsmiCmsResetDestinations.Visible = false;
            }
        }
        /// <summary>
        /// Sets the ToolTip text of the node and all its childes.
        /// </summary>
        /// <param name="node">The node to set the ToolTip to.</param>
        public static void SetToolTips(ModNode node)
        {
            // TODO:!!!
            ////if (node.Destination != string.Empty)
            ////    node.ToolTipText = node.Destination.ToLower().Replace(MainForm.GetPath(KSP_Paths.KSP_Root).ToLower(), "KSP install folder");
            ////else
            ////    node.ToolTipText = "<No path selected>";

            ////foreach (TreeNodeMod child in node.Nodes)
            ////    SetToolTips(child);
        }
Beispiel #23
0
 /// <summary>
 /// Returns the absolute path of the ModNode.
 /// </summary>
 /// <param name="node">The ModNode to get the absolute path from.</param>
 /// <returns>The absolute path of the ModNode.</returns>
 public static string GetAbsolutePath(ModNode node)
 {
     if (node.HasDestination)
     {
         return(GetAbsolutePath(node.Destination));
     }
     else
     {
         return(string.Empty);
     }
 }
 /// <summary>
 /// Creates a TreeNode.
 /// </summary>
 /// <param name="filename">Zip-File path</param>
 /// <param name="parent">The parent node where the created node will be attached attach to.</param>
 /// <param name="pathSeperator">The separator character used within the filename.</param>
 /// <param name="isDirectory">Flag that indicates if entry is a directory entry or not.</param>
 /// <param name="silent">Determines if info messages should be added.</param>
 private static void CreateModNode(string filename, ModNode parent, char pathSeperator, bool isDirectory, bool silent = false)
 {
     // ignore directory entries.
     if (!isDirectory)
     {
         HandleFileEntry(filename, parent, pathSeperator, silent);
     }
     else
     {
         ModNode node = CreateNeededDirNodes(filename + "fake.file", parent, pathSeperator);
     }
 }
        /// <summary>
        /// Checks the node and all child nodes that have a destination.
        /// </summary>
        /// <param name="node">The node to check.</param>
        public static void CheckNodesWithDestination(ModNode node)
        {
            if (node.HasDestination)
            {
                CheckNodeAndParents(node);
            }

            foreach (ModNode child in node.Nodes)
            {
                CheckNodesWithDestination(child);
            }
        }
        /// <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>
 /// Handles and creates a file entry.
 /// </summary>
 /// <param name="filename">Zip-File path</param>
 /// <param name="parent">The parent node where the created node will be attached attach to.</param>
 /// <param name="pathSeperator">The separator character used within the filename.</param>
 /// <param name="silent">Determines if info messages should be added.</param>
 private static void HandleFileEntry(string filename, ModNode parent, char pathSeperator, bool silent = false)
 {
     // plain filename?
     if (!filename.Contains(pathSeperator))
     {
         CreateFileListEntry(filename, parent, silent);
     }
     else // filename with dir(s) infront
     {
         ModNode node = CreateNeededDirNodes(filename, parent, pathSeperator);
         CreateFileListEntry(filename, node, silent);
     }
 }
        /// <summary>
        /// Creates a file entry for the TreeView.
        /// </summary>
        /// <param name="fileName">Zip-File path of the file.</param>
        /// <param name="parent">The parent node where the created node will be attached attach to.</param>
        /// <param name="silent">Determines if info messages should be added.</param>
        private static void CreateFileListEntry(string fileName, ModNode parent, bool silent = false)
        {
            ModNode node = new ModNode(fileName, Path.GetFileName(fileName), NodeType.UnknownFile);

            // TODO:!!!
            ////node.ToolTipText = "<No path selected>";
            parent.Nodes.Add(node);

            if (!silent)
            {
                Messenger.AddInfo(string.Format(Messages.MSG_FILE_ADDED_0, fileName));
            }
        }
Beispiel #29
0
        /// <summary>
        /// Registers all mod files that have a destination.
        /// </summary>
        /// <param name="modRoot">The root node of the mod to register the file nodes from.</param>
        /// <returns>True if a collision with another mod was detected.</returns>
        public static bool RegisterMod(ModNode modRoot)
        {
            bool           collisionDetected = false;
            List <ModNode> fileNodes         = GetAllNodesWithDestination(modRoot);

            foreach (ModNode fileNode in fileNodes)
            {
                if (RegisterModFile(fileNode))
                {
                    collisionDetected = true;
                }
            }

            return(collisionDetected);
        }
Beispiel #30
0
        /// <summary>
        /// Adds a source folder to the CB_Source for the passed node and all its childs.
        /// </summary>
        /// <param name="node">The node to add as source folder.</param>
        /// <param name="depth">The depth of the recursive call.</param>
        /// <note>Recursive function!</note>
        private void AddSrcFolder(ModNode node, int depth = 0)
        {
            if (!cbListFoldersOnly.Checked || (cbListFoldersOnly.Checked && !node.IsFile))
            {
                CB_Source.Items.Add(node);
            }

            foreach (ModNode child in node.Nodes)
            {
                if (!cbListFoldersOnly.Checked || (cbListFoldersOnly.Checked && !child.IsFile))
                {
                    AddSrcFolder(child, depth + 1);
                }
            }
        }