/// <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; } } } } }
/// <summary> /// Builds and sets the destination path to the passed node and its childes. /// </summary> /// <param name="srcNode">Node to set the destination path.</param> /// <param name="destPath">The destination path.</param> public static void SetDestinationPaths(ModNode srcNode, string destPath, bool copyContent = false) { if (!copyContent) { ////if (srcNode.Text.ToLower() == Constants.GAMEDATA) //// srcNode.Destination = destPath; ////else srcNode.Destination = (!string.IsNullOrEmpty(destPath)) ? Path.Combine(destPath, srcNode.Text) : string.Empty; destPath = (!string.IsNullOrEmpty(srcNode.Destination)) ? srcNode.Destination : string.Empty; if (!string.IsNullOrEmpty(srcNode.Destination)) { srcNode.Destination = KSPPathHelper.GetRelativePath(srcNode.Destination); } } SetToolTips(srcNode); foreach (ModNode child in srcNode.Nodes) { SetDestinationPaths(child, destPath); } }