private void buildWorker_DoWork(object sender, DoWorkEventArgs e)
{
// Don't remove the _en suffix by default
_remove_en = false;
// Set up wit
_showWit = Environment.GetCommandLineArgs().Contains("--show-wit") || Environment.GetCommandLineArgs().Contains("--show-wit-debug");
if (!File.Exists(_basePath + @"\Resources\wit\wit.exe"))
StopWorker("Unable to find wit executable, stopping build...");
ProcessStartInfo pStartInfo = new ProcessStartInfo(_basePath + @"\Resources\wit\wit.exe");
pStartInfo.CreateNoWindow = !_showWit;
pStartInfo.UseShellExecute = _showWit;
pStartInfo.RedirectStandardOutput = !_showWit;
pStartInfo.RedirectStandardError = !_showWit;
if (buildWorker.CancellationPending)
{
e.Cancel = true;
return;
}
// Check if wit is already running
Process[] wits = Process.GetProcessesByName("wit");
if (wits.Length != 0)
{
DialogResult result = MessageBox.Show("One or more instances of wit are already running. This could potentially cause issues with the build. Would you like the program to try and kill all instances of wit before continuing?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
foreach (Process wit in wits)
{
wit.Kill();
wit.WaitForExit(5000); // Wait for up to 5 seconds for wit to be killed
}
// Make sure it worked
wits = Process.GetProcessesByName("wit");
if (wits.Length != 0)
StopWorker("Unable to kill all instances of wit, stopping build...");
}
}
if (buildWorker.CancellationPending)
{
e.Cancel = true;
return;
}
File.Delete(_basePath + @"\Resources\temp.gct"); // Make sure any leftover gct gets removed
// Set state to the starting state
_state = State.Analyze;
while (_state != State.Finish)
{
switch (_state)
{
case State.Analyze:
if (gctFile.Text != "" && !Environment.GetCommandLineArgs().Contains("--no-gct-patch"))
{
if (!Analyze())
{
e.Cancel = true;
return;
}
}
_state = State.Extract;
break;
case State.Extract:
if (!Extract(pStartInfo))
{
e.Cancel = true;
return;
}
_state = State.Verify;
break;
case State.Verify:
if (!Verify())
{
e.Cancel = true;
return;
}
_state = State.DeleteSSE;
break;
case State.DeleteSSE:
if (removeSubspace.Checked)
{
if (!DeleteSSE())
{
e.Cancel = true;
return;
}
}
_state = State.CopyModFiles;
break;
case State.CopyModFiles:
if (modFolder.Text != "")
{
if (!CopyModFiles())
{
e.Cancel = true;
return;
}
}
_state = State.CopyBanner;
break;
case State.CopyBanner:
if (customBanner.Checked)
{
if (!CopyBanner())
{
e.Cancel = true;
return;
}
}
_state = State.Patch;
break;
case State.Patch:
if (gctFile.Text != "" || customID.Checked)
{
if (!Patch(pStartInfo))
{
e.Cancel = true;
return;
}
}
_state = State.Build;
break;
case State.Build:
if (!Build(pStartInfo))
{
e.Cancel = true;
return;
}
_state = State.Finish;
break;
}
}
// Clean up
DeleteBrawlFolder();
}