private void btnBuild_Click(object sender, EventArgs e)
{
rtbInfo.Clear();
// Check Input
if(string.IsNullOrWhiteSpace(tbDir.Text)) {
rtbInfo.AppendText("ERROR: A Directory Must Be Entered");
return;
}
DirectoryInfo di = new DirectoryInfo(tbDir.Text);
if(!di.Exists) {
rtbInfo.AppendText("ERROR: Directory Does Not Exist - \n" + di.FullName);
return;
}
if(string.IsNullOrWhiteSpace(tbPrefix.Text)) {
rtbInfo.AppendText("ERROR: A Prefix Must Be Entered");
return;
}
FileInfo[] files = di.EnumerateFiles().Where((f) => {
return f.Name.StartsWith(tbPrefix.Text) && f.Extension.ToLower().Equals(".obj");
}).ToArray();
if(files.Length < 1) {
rtbInfo.AppendText("ERROR: Could Not Find Any Suitable Files Beginning With " + tbPrefix.Text);
return;
}
// Sort The Files By Taking Off The Prefix
FileInfo[] fSorted = files.OrderBy((f) => {
return f.Name.Substring(tbPrefix.Text.Length);
}).ToArray();
rtbInfo.AppendText("Found Files:\n");
foreach(var fi in fSorted) {
rtbInfo.AppendText(fi.Name + "\n");
}
// Set Output Image Path
string fn = di.FullName + "\\" + tbPrefix.Text + ".png";
// Perform Baking
rtbInfo.AppendText("\n\nSuper Baking...\n");
SuperBake(fSorted, fn, rtbInfo);
// Test The Procedure
rtbInfo.AppendText("\n\nTesting Baking Procedure...\n");
TestBake(fSorted, fn, rtbInfo);
}