Example #1
0
        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);
        }
Example #2
0
        private DownloadFile?checkClientFile(MinecraftPath path, MVersion version)
        {
            if (string.IsNullOrEmpty(version.ClientDownloadUrl) ||
                string.IsNullOrEmpty(version.Jar))
            {
                return(null);
            }

            string id         = version.Jar;
            string clientPath = path.GetVersionJarPath(id);

            if (!IOUtil.CheckFileValidation(clientPath, version.ClientHash, CheckHash))
            {
                return(new DownloadFile(clientPath, version.ClientDownloadUrl)
                {
                    Type = MFile.Minecraft,
                    Name = id
                });
            }
            else
            {
                return(null);
            }
        }