private static void AddFromNode_Translation(TyMod tymod, XmlNode node) { string name; TyModTranslate modTranslate; try { name = node.Attributes.GetNamedItem("name").Value; } catch (Exception e) { Program.Log(tymod.ToString(), "Invalid or missing name attribute for translation \"" + node.OuterXml + "\"", e); return; } modTranslate = new TyModTranslate(name); foreach (XmlNode child in node.ChildNodes) { name = child.Name.ToLower(); if (child.HasTextChild()) { if (modTranslate.Translations.ContainsKey(name)) { modTranslate.Translations[name] = child.GetFirstTextChild(); } else { modTranslate.Translations.Add(name, child.GetFirstTextChild()); } } } tymod.Translations.Add(modTranslate); }
public static void ApplyImport(TyMod tymod, TyModImport import) { string src, dst; FileInfo fi; if (import.Source == null || (!File.Exists((src = (Path.IsPathRooted(import.Source) ? import.Source : Path.Combine(Program.ModDirectory, import.Source)))) && !Directory.Exists(src))) { Program.Log(tymod.ToString(), "Unable to find resource \"" + (import.Source ?? "(null)") + "\"", null, true); return; } if (import.Plugin) { // Add full path to plugins.ini file File.AppendAllText(Path.Combine(Program.OutDirectory, "plugins.ini"), (Path.IsPathRooted(import.Source) ? import.Source : Path.Combine(Program.ModDirectory, import.Source) + "\r\n")); } else if (import.Destination != null && import.Destination != String.Empty) { fi = new FileInfo(dst = Path.Combine(Program.OutDirectory, import.Destination)); // Determine if copying folder or file if (!File.Exists(src) && fi.Name == String.Empty) { // Delete any copy of the dst directory in the output folder unless the output folder is the dst directory if (Path.GetFullPath(dst) != Path.GetFullPath(Program.OutDirectory) && fi.Directory.Exists) { Directory.Delete(fi.Directory.FullName, true); // Wait until directory is deleted while (Directory.Exists(Program.OutDirectory)) { System.Threading.Thread.Sleep(10); } } ApplyImport_Directory(src, fi.Directory.FullName); } else { // Ensure the directory exists for copying if (!fi.Directory.Exists) { Directory.CreateDirectory(fi.Directory.FullName); } // Delete any pre-existing copy if (fi.Exists) { File.Delete(dst); } // Copy File.Copy(src, dst); } } }
private static void AddFromNode_Level(TyMod tymod, XmlNode node) { string directory = null, name = null; TyLevel level; try { directory = node.Attributes.GetNamedItem("directory").Value; } catch (Exception e) { Program.Log(tymod.ToString(), "Invalid directory attribute for level import \"" + node.OuterXml + "\"", e); return; } try { name = node.Attributes.GetNamedItem("name").Value; } catch (Exception e) { Program.Log(tymod.ToString(), "Invalid name attribute for level import \"" + node.OuterXml + "\"", e); return; } level = new TyLevel(Path.Combine(Program.ModDirectory, directory), name, tymod.ModVersion, tymod.Authors); foreach (XmlNode child in node.ChildNodes) { if (child.Name == "translation") { foreach (XmlNode grandchild in child.ChildNodes) { try { level.LanguageNames[grandchild.Name.ToLower()] = grandchild.GetFirstTextChild(); if (level.LanguageNames[grandchild.Name.ToLower()] == null) { Program.Log(tymod.ToString(), "Invalid " + grandchild.Name + " translation for level import \"" + node.OuterXml + "\""); } } catch (Exception e) { Program.Log(tymod.ToString(), "Invalid " + grandchild.Name ?? String.Empty + " translation for level import \"" + node.OuterXml + "\"", e); } } } else if (child.Name == "portal") { foreach (XmlNode grandchild in child.ChildNodes) { try { switch (grandchild.Name.ToLower()) { case "x": level.X = float.Parse(grandchild.GetFirstTextChild()); break; case "y": level.Y = float.Parse(grandchild.GetFirstTextChild()); break; case "z": level.Z = float.Parse(grandchild.GetFirstTextChild()); break; } } catch (Exception e) { Program.Log(tymod.ToString(), "Invalid directory attribute for level import \"" + node.OuterXml + "\"", e); return; } } } } // Add to list of levels tymod.Levels.Add(level); }
private static void AddFromNode_Plugin(TyMod tymod, XmlNode node) { if (node.HasTextChild()) { tymod.Imports.Add(new TyModImport(node.GetFirstTextChild(), null, true)); } else { Program.Log(tymod.ToString(), "Invalid value for plugin import \"" + node.OuterXml + "\""); } }
private static void AddFromNode_Resource(TyMod tymod, XmlNode node) { string source, dest = null; try { source = node.GetFirstTextChild(); } catch (Exception e) { Program.Log(tymod.ToString(), "Invalid value for resource import \"" + node.OuterXml + "\"", e); return; } try { dest = node.Attributes.GetNamedItem("destination").Value; } catch { } if (source == null || source == String.Empty) { Program.Log(tymod.ToString(), "Invalid value for resource import \"" + node.OuterXml + "\""); return; } tymod.Imports.Add(new TyModImport(source, dest, false)); }
private static void AddFromNode_Global(TyMod tymod, XmlNode node) { string source, type, context = null; TyModEdit.EditType editType = TyModEdit.EditType.inclusive; TyModEdit modEdit; if (node.Attributes == null) { Program.Log(tymod.ToString(), "No attributes assigned to global \"" + node.OuterXml + "\""); return; } try { source = node.Attributes.GetNamedItem("source").Value; } catch (Exception e) { Program.Log(tymod.ToString(), "Invalid source attribute for global \"" + node.OuterXml + "\"", e); return; } try { type = node.Attributes.GetNamedItem("type").Value; editType = (TyModEdit.EditType)Enum.Parse(typeof(TyModEdit.EditType), type); } catch (Exception) { } try { context = node.Attributes.GetNamedItem("context")?.Value?.ToLower(); } catch (Exception) { } modEdit = new TyModEdit(source, editType, context); foreach (XmlAttribute attr in node.Attributes) { if (attr.Name == "source" || attr.Name == "type" || attr.Name == "context") { continue; } modEdit.Attributes.Add(attr.Name, attr.Value); } if (node.HasTextChild()) { modEdit.Value = node.GetFirstTextChild(); } AddFromNode_Global_Recursive(modEdit, node); tymod.Edits.Add(modEdit); }