public static MVersion ParseAndSave(MVersionMetadata info, MinecraftPath savePath) { try { string json; if (!info.IsLocalVersion) { using (var wc = new WebClient()) { json = wc.DownloadString(info.Path); var path = savePath.GetVersionJsonPath(info.Name); Directory.CreateDirectory(Path.GetDirectoryName(path)); File.WriteAllText(path, json); return(ParseFromJson(json)); } } else { return(ParseFromFile(info.Path)); } } catch (MVersionParseException ex) { ex.VersionName = info.Name; throw ex; } }
public string InstallForge(string mcversion, string forgeversion) { var minecraftJar = Minecraft.GetVersionJarPath(mcversion); if (!File.Exists(minecraftJar)) { throw new IOException($"Install {mcversion} first"); } var installerPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); var installerStream = getInstallerStream(mcversion, forgeversion); // download installer var extractedFile = extractInstaller(installerStream, installerPath); // extract installer var profileObj = extractedFile.Item1; // version profile json var installerObj = extractedFile.Item2; // installer info // copy forge libraries to minecraft extractMaven(installerPath); // new installer extractUniversal(installerPath, installerObj["filePath"]?.ToString(), installerObj["path"]?.ToString()); // old installer // download libraries and processors checkLibraries(installerObj["libraries"] as JArray); // mapping client data var mapData = mapping(installerObj["data"] as JObject, "client", minecraftJar, installerPath); // process process(installerObj["processors"] as JArray, mapData); // version name like 1.16.2-forge-33.0.20 var versionName = installerObj["target"]?.ToString() ?? installerObj["version"]?.ToString() ?? GetForgeName(mcversion, forgeversion); var versionPath = Minecraft.GetVersionJsonPath(versionName); // write version profile json writeProfile(profileObj, versionPath); return(versionName); }
public static MVersion ParseAndSave(MVersionMetadata info, MinecraftPath savePath) { if (string.IsNullOrEmpty(info.Path)) { throw new NullReferenceException("info.Path was null"); } try { if (!info.IsLocalVersion) { using (var wc = new WebClient()) { var json = wc.DownloadString(info.Path); if (!string.IsNullOrEmpty(info.Name)) { string path = savePath.GetVersionJsonPath(info.Name); var directoryName = Path.GetDirectoryName(path); if (!string.IsNullOrEmpty((directoryName))) { Directory.CreateDirectory(directoryName); } File.WriteAllText(path, json); } return(ParseFromJson(json)); } } else { return(ParseFromFile(info.Path)); } } catch (MVersionParseException ex) { ex.VersionName = info.Name; throw; } }