/// <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);
}
}