private void LoadFromFileSystem(IReadOnlyFileSystem fileSystem, string directory) { var modpackFilename = Path.Combine(directory, "modpack.json"); var modFilename = Path.Combine(directory, "mod.json"); if (fileSystem.FileExists(modpackFilename)) { metadata = JsonConvert.DeserializeObject <ModpackMetadata>(fileSystem.ReadAllText(modpackFilename)); } else if (fileSystem.FileExists(modFilename)) { var modMetadata = JsonConvert.DeserializeObject <ModMetadata>(fileSystem.ReadAllText(modFilename)); modMetadata.Enabled = true; metadata = new ModpackMetadata { Name = modMetadata.Name, Description = modMetadata.Description, Mods = new List <ModMetadata> { modMetadata } }; } else { throw new FileNotFoundException("Could not find a modpack.json or a mod.json file in the given directory"); } mods = metadata.Mods.Select(m => new Mod(m, directory, fileSystem)).ToList(); }
public FileDescriptionTemplate(XmlElement xml, IReadOnlyFileSystem fileSystem) { TemplateLoadException.AssertAttributeExists(xml, "name"); this.FileSystem = fileSystem; name = xml.GetAttribute("name"); language = xml.GetAttribute("language"); if (xml.HasAttribute("buildAction")) { itemType = xml.GetAttribute("buildAction"); } foreach (XmlAttribute attribute in xml.Attributes) { string attributeName = attribute.Name; if (!knownAttributes.Contains(attributeName)) { if (attributeName == "copyToOutputDirectory") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "CopyToOutputDirectory"; } if (attributeName == "dependentUpon") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "DependentUpon"; } if (attributeName == "subType") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "SubType"; } metadata[attributeName] = attribute.Value; } } if (xml.HasAttribute("src")) { FileName fileName = FileName.Create(StringParser.Parse(xml.GetAttribute("src"))); try { if (xml.HasAttribute("binary") && bool.Parse(xml.GetAttribute("binary"))) { binaryFileName = fileName; } else { content = fileSystem.ReadAllText(fileName); } } catch (Exception e) { content = "Error reading content from " + fileName + ":\n" + e.ToString(); LoggingService.Warn(content); } } else { content = xml.InnerText; } }
public FileDescriptionTemplate(XmlElement xml, IReadOnlyFileSystem fileSystem) { TemplateLoadException.AssertAttributeExists(xml, "name"); this.FileSystem = fileSystem; name = xml.GetAttribute("name"); language = xml.GetAttribute("language"); if (xml.HasAttribute("buildAction")) { itemType = xml.GetAttribute("buildAction"); } foreach (XmlAttribute attribute in xml.Attributes) { string attributeName = attribute.Name; if (!knownAttributes.Contains(attributeName)) { if (attributeName == "copyToOutputDirectory") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "CopyToOutputDirectory"; } if (attributeName == "dependentUpon") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "DependentUpon"; } if (attributeName == "subType") { ProjectTemplateImpl.WarnObsoleteAttribute(xml, attributeName, "Use upper-case attribute names for MSBuild metadata values!"); attributeName = "SubType"; } metadata[attributeName] = attribute.Value; } } if (xml.HasAttribute("src")) { FileName fileName = FileName.Create(StringParser.Parse(xml.GetAttribute("src"))); try { if (xml.HasAttribute("binary") && bool.Parse(xml.GetAttribute("binary"))) { binaryFileName = fileName; } else { content = fileSystem.ReadAllText(fileName); } } catch (Exception e) { content = "Error reading content from " + fileName + ":\n" + e.ToString(); LoggingService.Warn(content); } } else { content = xml.InnerText; } }
/// <summary> /// Reads a file from the mod /// </summary> /// <param name="resourcePath">Path of the resource file, relative to the directory in which the mod.json or the modpack.json is located.</param> /// <returns>A string containing the resource data</returns> public string ReadResourceText(string resourcePath) { var absolutePath = Path.Combine(GetBaseDirectory(), resourcePath); return(fileSystem.ReadAllText(absolutePath)); }