/// <summary> /// Try to delete all not processed directories. /// </summary> /// <param name="node">The dir node to delete.</param> /// <param name="silent">Determines if info messages should be added displayed.</param> /// <returns>True on success.</returns> private static bool DeleteDirectory(ModNode node, bool silent = false) { string destination = node.Destination; if (!string.IsNullOrEmpty(destination)) { destination = KSPPathHelper.GetAbsolutePath(destination); } try { if (!Directory.Exists(destination)) { Messenger.AddInfo(string.Format(Messages.MSG_DIR_0_NOT_EXISTS, destination)); return(false); } if (KSPPathHelper.IsKSPDir(destination)) { Messenger.AddInfo(string.Format(Messages.MSG_DIR_0_IS_KSPDIR, destination)); return(false); } if (Directory.GetDirectories(destination).Any() || Directory.GetFiles(destination).Any()) { Messenger.AddInfo(string.Format(Messages.MSG_DIR_0_IS_NOT_EMPTY, destination)); return(false); } Directory.Delete(destination, true); if (!silent) { Messenger.AddInfo(string.Format(Messages.MSG_DIR_DELETED_0, destination)); } return(true); } catch (Exception ex) { Messenger.AddError(string.Format(Messages.MSG_DIR_DELETED_ERROR_0, destination), ex); } return(false); }
/// <summary> /// Creates a directory entry for the TreeView. /// </summary> /// <param name="dirName">Name of the directory.</param> /// <param name="parent">The parent node where the created node will be attached attach to.</param> /// <returns>The new created ModNode.</returns> private static ModNode CreateDirListEntry(string dirName, ModNode parent) { // dir already created? ModNode dirNode = ModSelectionTreeModel.SearchNodeByPath(parent.Text + "/" + dirName, parent, '/'); if (null == dirNode) { dirNode = new ModNode(dirName, dirName); // TODO:!!! ////dirNode.ToolTipText = "<No path selected>"; dirNode.NodeType = (KSPPathHelper.IsKSPDir(dirName.ToLower())) ? NodeType.KSPFolder : NodeType.UnknownFolder; parent.Nodes.Add(dirNode); Messenger.AddInfo(string.Format(Messages.MSG_DIR_ADDED_0, dirName)); } return(dirNode); }