public ModInfo ToInfo(Analyzer analyzer) { ModInfo info = new ModInfo() { ID = this.ID, Name = this.Name, Description = this.Description, Version = this.Version, URL = this.URL, Credits = this.Credits, Authors = this.Authors, }; if (this.MinecraftVersion != null) { info.MinecraftVersion = VersionTools.ToVersion(this.MinecraftVersion); } string[] dependencies = null; if (this.Dependencies1 != null && this.Dependencies1.Length > 0) { dependencies = this.Dependencies1; } else if (this.Dependencies2 != null && this.Dependencies2.Length > 0) { dependencies = this.Dependencies2; } if (dependencies != null) { info.Dependencies = VersionTools.AllToVersion(dependencies); } if (this.LogoFile != null) { info.Logo = analyzer.ReadFile(this.LogoFile); } return(info); }
private ModInfo ReadFromClassFile(ZipFileInfo file) { if (file.IsVolumeLabel || file.IsFolder || !file.Name.ToLower().EndsWith(".class")) { return(null); } ClassAnalyzer analyzer = null; using (Stream stream = file.OpenStream()) analyzer = ClassAnalyzer.Read(stream); if (analyzer == null) { return(null); } ModInfo info = new ModInfo(); foreach (JavaAttribute attribute in analyzer.Attributes) { if (attribute == null) { continue; } if (attribute is JavaRuntimeAnnotations) { foreach (JavaAnnotation annotation in ((JavaRuntimeAnnotations)attribute).Annotations) { if (annotation.Name.EndsWith("/fml/common/Mod;")) { if (annotation.Elements.ContainsKey("modid")) { info.ID = (string)annotation.Elements["modid"]; } if (annotation.Elements.ContainsKey("name")) { info.Name = (string)annotation.Elements["name"]; } if (annotation.Elements.ContainsKey("version")) { info.Version = (string)annotation.Elements["version"]; } if (annotation.Elements.ContainsKey("acceptedMinecraftVersions")) { info.MinecraftVersion = VersionTools.ToVersion((string)annotation.Elements["acceptedMinecraftVersions"]); } if (annotation.Elements.ContainsKey("dependencies")) { info.Dependencies = VersionTools.ToVersion((string)annotation.Elements["dependencies"]); } } else if (annotation.Name.EndsWith("/fml/relauncher/IFMLLoadingPlugin$Name;")) { info.Name = (string)annotation.Elements["value"]; if (info.ID == null) { info.ID = info.Name; } } else if (annotation.Name.EndsWith("/fml/relauncher/IFMLLoadingPlugin$MCVersion;")) { info.MinecraftVersion = VersionTools.ToVersion((string)annotation.Elements["value"]); } } } } return(info); }