/// <summary> /// Goes through the process of checking the BuildTools environment and running it. If autoUpate is /// true, it will first call <see cref="UpdateJar()"/>. /// </summary> /// <param name="autoUpdate">If true, this will first call <see cref="UpdateJar()"/> Before continuing.</param> /// <param name="version">Version to build.</param> public void RunBuildTools(bool autoUpdate, string version) { if (!Environment.Is64BitOperatingSystem) { _form.AppendText("BuildTools does not reliably work on 32 bit systems, if you have problems please re-run this on a 64 bit system."); } if (!Directory.Exists(Dir)) { Directory.CreateDirectory(Dir); } _form.ProgressShow(); _form.ProgressIndeterminate(); if (autoUpdate) { if (!UpdateJar()) { return; } } else { // We still need to grab data even if not updating if (!GetJson()) { return; } } // Java check if (!CheckJava(out bool javaInstalled)) { string javaFile = Dir + (string)_json["java"]["name"]; if (!javaInstalled) { // Java is not installed _form.AppendText("Downloading Java installer"); bool success = DownloadJava(javaFile); if (!success) { _form.AppendText("Java could not be downloaded, canceling"); } _form.ProgressIndeterminate(); success = InstallJava(javaFile); if (!success) { _form.AppendText("Java could not be installed, canceling"); } if (CheckJava()) { _form.AppendText("Java installed successfully"); } else { _form.AppendText("Java could not be installed, canceling"); return; } } else { // Java is installed _form.AppendText("This is a 64 bit operating system, but the 32 bit JRE is installed. Downloading 64 bit JRE"); bool success = DownloadJava(javaFile); if (!success) { _form.AppendText("Unable to download the 64 bit Java installer, will continue with the 32 bit JRE. This may cause the build to fail"); } else { _form.AppendText("Uninstalling current 32 bit JRE"); success = UninstallJava(); if (!success) { _form.AppendText("There was an error while attempting to uninstall the 32 bit JRE"); CheckJava(out javaInstalled); if (javaInstalled) { _form.AppendText("Java still seems to be installed, though. Will continue with the 32 bit JRE. This may cause the build to fail"); } else { _form.AppendText("In spite of the error, it seems Java has been uninstalled. Will now install the 64 bit JRE"); success = InstallJava(javaFile); if (!success) { _form.AppendText("Java failed to install, canceling"); return; } if (!FullJavaCheck()) { return; } } } else { _form.AppendText("Installing the 64 bit JRE"); success = InstallJava(javaFile); if (!success) { _form.AppendText("Java failed to install, canceling"); return; } if (!FullJavaCheck()) { return; } } } } } // Git check if (!CheckGit()) { string gitFile = Dir + "portable_git.7z.exe"; _form.AppendText("Downloading portable Git"); bool success; if (Environment.Is64BitOperatingSystem) { success = DownloadFile((string)_json["git"]["64"], gitFile); } else { success = DownloadFile((string)_json["git"]["32"], gitFile); } if (!success) { _form.AppendText("Portable Git could not be downloaded, canceling"); return; } _form.ProgressIndeterminate(); using (Process extractProcess = new Process()) { _form.AppendText("Extracting portable Git"); _disposables.Add(extractProcess); try { extractProcess.StartInfo.FileName = gitFile; extractProcess.StartInfo.UseShellExecute = true; extractProcess.StartInfo.Arguments = "-y -gm1 -nr"; extractProcess.Start(); AddProcessToJob(extractProcess); extractProcess.WaitForExit(); if (extractProcess.ExitCode != 0) { throw new Exception(); } } catch (Exception) { _form.AppendText("Portable Git could not be installed, canceling"); return; } finally { _disposables.Remove(extractProcess); } } Thread.Sleep(100); File.Delete(gitFile); _form.AppendText("Checking portable Git installation (this may take a while)"); if (CheckGit()) { _form.AppendText("Portable Git installed Successfully"); } else { _form.AppendText("Portable Git could not be installed, canceling"); return; } } // Check and fix commit.gpgpsign CheckGpg(); if (isGpg) { _form.AppendText("Setting commit.gpgsign to false (needed for BuildTools, will reset once finished)"); SetGpg(false); } _form.AppendRawText(""); _form.AppendText("Running BuildTools.jar\n"); // Run Build Tools using (Process buildProcess = new Process()) { _disposables.Add(buildProcess); try { buildProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; buildProcess.StartInfo.CreateNoWindow = true; buildProcess.StartInfo.FileName = GitDir + "/bin/bash.exe"; buildProcess.StartInfo.UseShellExecute = false; buildProcess.StartInfo.RedirectStandardOutput = true; buildProcess.StartInfo.RedirectStandardError = true; buildProcess.StartInfo.WorkingDirectory = Path.GetFullPath(Dir); buildProcess.StartInfo.Arguments = "--login -c \"git config --global --replace-all core.autocrlf true & java -jar " + (string)_json["buildTools"]["name"] + " --rev " + version + "\""; buildProcess.OutputDataReceived += (sender, args) => _form.AppendRawText(args.Data); buildProcess.ErrorDataReceived += (sender, args) => _form.AppendRawText(args.Data); buildProcess.Start(); AddProcessToJob(buildProcess); buildProcess.BeginOutputReadLine(); buildProcess.BeginErrorReadLine(); buildProcess.WaitForExit(); if (buildProcess.ExitCode != 0) { throw new Exception(); } } catch (Exception) { _form.AppendText("There was an error while running BuildTools"); } finally { _disposables.Remove(buildProcess); } } // Reset gpg if we disabled it if (isGpg) { _form.AppendText("Resetting commit.gpgsign"); SetGpg(true); } }
/// <summary> /// Goes through the process of checking the BuildTools environment and running it. If autoUpate is /// true, it will first call <see cref="UpdateJar()"/>. /// </summary> /// <param name="autoUpdate">If true, this will first call <see cref="UpdateJar()"/> Before continuing.</param> /// <param name="version">Version to build.</param> public void RunBuildTools(bool autoUpdate, string version, bool remapped) { if (!Environment.Is64BitOperatingSystem) { _form.AppendText("BuildTools does not reliably work on 32 bit systems, if you have problems please re-run this on a 64 bit system."); } if (!Directory.Exists(Dir)) { Directory.CreateDirectory(Dir); } _form.ProgressShow(); _form.ProgressIndeterminate(); if (autoUpdate) { if (!UpdateJar()) { return; } } else { // We still need to grab data even if not updating if (!GetJson()) { return; } } // get version jar from spigot _version = DownloadJson("https://hub.spigotmc.org/versions/" + version + ".json"); int javaVersion = int.Parse((string)_version["javaVersions"][0]); // the minimal java version switch (javaVersion) { case 51: { _javaVersion = "7"; break; } case 52: { _javaVersion = "8"; break; } case 53: { _javaVersion = "9"; break; } case 54: { _javaVersion = "10"; break; } case 55: { _javaVersion = "11"; break; } case 56: { _javaVersion = "12"; break; } case 57: { _javaVersion = "13"; break; } case 58: { _javaVersion = "14"; break; } case 59: { _javaVersion = "15"; break; } case 60: { _javaVersion = "16"; break; } case 61: { _javaVersion = "17"; break; } case 62: { _javaVersion = "18"; break; } default: { _javaVersion = "17"; break; } } if (!CheckJava()) { // java version not installed // download java _form.AppendText("Downloading Java " + _javaVersion); string javaFile = Dir + @"java\" + _javaVersion + ".zip"; bool success = DownloadJava(javaFile); if (!success) { _form.AppendText("Java could not be downloaded, canceling"); return; } ExtractJava(javaFile); File.Delete(javaFile); // check java again. if (!CheckJava()) { _form.AppendText("Java could not be downloaded, canceling"); return; } } // Git check if (!CheckGit()) { string gitFile = Dir + "portable_git.7z.exe"; _form.AppendText("Downloading portable Git"); bool success; if (Environment.Is64BitOperatingSystem) { success = DownloadFile((string)_json["git"]["64"], gitFile); } else { success = DownloadFile((string)_json["git"]["32"], gitFile); } if (!success) { _form.AppendText("Portable Git could not be downloaded, canceling"); return; } _form.ProgressIndeterminate(); using (Process extractProcess = new Process()) { _form.AppendText("Extracting portable Git"); _disposables.Add(extractProcess); try { extractProcess.StartInfo.FileName = gitFile; extractProcess.StartInfo.UseShellExecute = true; extractProcess.StartInfo.Arguments = "-gm1 -nr -y"; extractProcess.Start(); AddProcessToJob(extractProcess); extractProcess.WaitForExit(); if (extractProcess.ExitCode != 0) { throw new Exception(); } } catch (Exception) { _form.AppendText("Portable Git could not be installed, canceling"); return; } finally { _disposables.Remove(extractProcess); } } Thread.Sleep(100); File.Delete(gitFile); _form.AppendText("Checking portable Git installation (this may take a while)"); if (CheckGit()) { _form.AppendText("Portable Git installed Successfully"); } else { _form.AppendText("Portable Git could not be installed, canceling"); return; } } // Check and fix commit.gpgpsign CheckGpg(); if (isGpg) { _form.AppendText("Setting commit.gpgsign to false (needed for BuildTools, will reset once finished)"); SetGpg(false); } _form.AppendRawText(""); _form.AppendText("Running BuildTools.jar\n"); string startArgs = "--login -c \"git config --global --replace-all core.autocrlf true & " + GetBashJavaPath() + " -jar " + (string)_json["buildTools"]["name"] + " --rev " + version; if (remapped) { startArgs += " --remapped"; } startArgs += "\""; _form.AppendText("Arguments: " + startArgs); // Run Build Tools using (Process buildProcess = new Process()) { _disposables.Add(buildProcess); try { buildProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; buildProcess.StartInfo.CreateNoWindow = true; buildProcess.StartInfo.FileName = GitDir + "/bin/bash.exe"; buildProcess.StartInfo.UseShellExecute = false; buildProcess.StartInfo.RedirectStandardOutput = true; buildProcess.StartInfo.RedirectStandardError = true; buildProcess.StartInfo.WorkingDirectory = Path.GetFullPath(Dir); buildProcess.StartInfo.Arguments = startArgs; buildProcess.OutputDataReceived += (sender, args) => _form.AppendRawText(args.Data); buildProcess.ErrorDataReceived += (sender, args) => _form.AppendRawText(args.Data); buildProcess.Start(); AddProcessToJob(buildProcess); buildProcess.BeginOutputReadLine(); buildProcess.BeginErrorReadLine(); buildProcess.WaitForExit(); if (buildProcess.ExitCode != 0) { throw new Exception(); } } catch (Exception) { _form.AppendText("There was an error while running BuildTools"); } finally { _disposables.Remove(buildProcess); } } // Reset gpg if we disabled it if (isGpg) { _form.AppendText("Resetting commit.gpgsign"); SetGpg(true); } }