/// <summary> /// Splits the filename (at '\') and searches the tree for the Node where name and path matches. /// </summary> /// <param name="filename">Zip-File path of the node to search for.</param> /// <param name="startNode">Node to start the search from.</param> /// <param name="pathSeparator">Separator of the path in filename.</param> /// <returns>The matching TreeNodeMod.</returns> public static ModNode SearchNodeByPath(string filename, Node startNode, char pathSeparator) { string[] dirs = filename.Split(new[] { pathSeparator }, StringSplitOptions.RemoveEmptyEntries); ModNode result = null; foreach (string dir in dirs) { startNode = SearchNode(dir, startNode); if (startNode == null) { break; } result = startNode as ModNode; } if (result != null && result.GetFullTreePath().Contains(filename)) { return(result); } return(null); }
/// <summary> /// Creates a instance of the ConflictInfoNode. /// This node will be a child ConflictInfoNode and represents one conflicting ModNode file. /// </summary> /// <param name="conflictingNode">The conflicting ModNode file.</param> private ConflictInfoNode(ModNode conflictingNode) { FileName = LINE; Destination = LINE; ConflictingNode = conflictingNode; ModName = ConflictingNode.ZipRoot.Name; ModVersion = ConflictingNode.ZipRoot.Version; TreePath = ConflictingNode.GetFullTreePath(); ArchivePath = ConflictingNode.ZipRoot.ArchivePath; }
/// <summary> /// Tries to reads the content of the file that is represented by the passed ModNode. /// </summary> /// <param name="node">The ModNode that contains the File information.</param> /// <returns>The content of the file.</returns> private static string TryReadFile(ModNode node) { if (node == null || !node.IsFile) return string.Empty; ModNode root = node.ZipRoot; string fullpath = root.Key; try { if (File.Exists(fullpath)) { using (IArchive archiv = ArchiveFactory.Open(fullpath)) { string fullPath = node.GetFullTreePath(); foreach (IArchiveEntry entry in archiv.Entries) { if (entry.IsDirectory) continue; if (fullPath.Contains(entry.FilePath)) { using (MemoryStream memStream = new MemoryStream()) { entry.WriteTo(memStream); memStream.Position = 0; StreamReader reader = new StreamReader(memStream); return reader.ReadToEnd(); } } } } } else Messenger.AddInfo(string.Format(Messages.MSG_FILE_NOT_FOUND_0, fullpath)); } catch (Exception ex) { Messenger.AddError(string.Format(Messages.MSG_ERROR_WHILE_READING_0, fullpath), ex); } return string.Empty; }