private void button5_Click(object sender, EventArgs e) { if (button5.Text == @"Start dumping all zone.obj file navmeshes") { button5.Text = @"Stop dumping all zone.obj file navmeshes"; Thread.Sleep(100); if (DumpMeshes.IsBusy) { DumpMeshes.CancelAsync(); } else { DumpMeshes.RunWorkerAsync(); } Logger.AddDebugText(rtbDebug, @"Dumping all zone.obj file navmeshes = True"); } else if (button5.Text == @"Stop dumping all zone.obj file navmeshes") { Logger.AddDebugText(rtbDebug, @"Dumping all zone.obj file navmeshes = false, Finishing off Current build."); DumpMeshes.CancelAsync(); NavBuilder.DumpingMesh = false; NavBuilder.UnloadMeshBuilder(); Thread.Sleep(200); button5.Text = @"Start dumping all zone.obj file navmeshes"; Thread.Sleep(200); } }
private void DumpMeshes_DoWork(object sender, DoWorkEventArgs e) { try { var stopWatch1 = new Stopwatch(); stopWatch1.Start(); while (!DumpMeshes.CancellationPending) { if (DumpMeshes.CancellationPending) { e.Cancel = true; break; } var path = $"{Application.StartupPath}\\Map Collision obj files\\"; var fileCount = Directory.GetFiles(path, "*.obj", SearchOption.AllDirectories).Length; Logger.AddDebugText(rtbDebug, $@"{fileCount.ToString()}.obj files fould in Map Collision obj folder"); foreach (var file in Directory.EnumerateFiles(string.Format(path, "*.obj"))) { if (DumpMeshes.CancellationPending) { button5.BeginInvoke(new MethodInvoker(() => { button5.Text = @"Start dumping all zone.obj file navmeshes"; })); e.Cancel = true; break; } var result = Path.GetFileName(file); var result2 = result.Substring(0, result.LastIndexOf(".", StringComparison.Ordinal) + 1); if (File.Exists($@"{Application.StartupPath}\\Dumped NavMeshes\\{result2}nav")) { var box = MessageBox.Show($@"Are you sure you want to overwrite {result2}.nav", @"Question", MessageBoxButtons.YesNoCancel); if (box == DialogResult.Yes) { if (!NavBuilder.DumpingMesh && !DumpMeshes.CancellationPending) { var stopWatch = new Stopwatch(); stopWatch.Start(); Logger.AddDebugText(rtbDebug, $@"Dumping NavMesh for {result2}"); if (NavBuilder.Dump_NavMesh(file) && !DumpMeshes.CancellationPending) { stopWatch.Stop(); NavBuilder.UnloadMeshBuilder(); var ts = stopWatch.Elapsed; // Format and display the TimeSpan value. var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}"; Logger.AddDebugText(rtbDebug, $@"Time Taken to dump mesh {result2} = {elapsedTime} "); } } } else if (box == DialogResult.Cancel) { button5.BeginInvoke(new MethodInvoker(() => { button5.Text = @"Start dumping all zone.obj file navmeshes"; })); DumpMeshes.CancelAsync(); break; } else if (box == DialogResult.No) { continue; } } if (!File.Exists($@"{Application.StartupPath}\\Dumped NavMeshes\\{result2}nav")) { if (!NavBuilder.DumpingMesh && !DumpMeshes.CancellationPending) { var stopWatch = new Stopwatch(); stopWatch.Start(); Logger.AddDebugText(rtbDebug, $@"Dumping NavMesh for {result2}"); if (NavBuilder.Dump_NavMesh(file) && !DumpMeshes.CancellationPending) { stopWatch.Stop(); NavBuilder.UnloadMeshBuilder(); var ts = stopWatch.Elapsed; // Format and display the TimeSpan value. var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}"; Logger.AddDebugText(rtbDebug, $@"Time Taken to dump mesh {result2} = {elapsedTime} "); } } } if (DumpMeshes.CancellationPending) { button5.BeginInvoke(new MethodInvoker(() => { button5.Text = @"Start dumping all zone.obj file navmeshes"; })); e.Cancel = true; break; } } stopWatch1.Stop(); var ts1 = stopWatch1.Elapsed; var elapsedTime1 = $"{ts1.Hours:00}:{ts1.Minutes:00}:{ts1.Seconds:00}.{ts1.Milliseconds / 10:00}"; Logger.AddDebugText(rtbDebug, @"Finished dumping NavMesh data"); Logger.AddDebugText(rtbDebug, string.Format(@"Time Taken to dump all zones NavMeshes = " + elapsedTime1)); var dInfo = new DirectoryInfo($@"{Application.StartupPath}\Dumped NavMeshes\"); var sizeOfDir = DirectorySize(dInfo, true); Logger.AddDebugText(rtbDebug, $@"NavMeshes data disk space used = {(double)sizeOfDir / (1024 * 1024):N2} MB"); button5.BeginInvoke(new MethodInvoker(() => { button5.Text = @"Start dumping all zone.obj file navmeshes"; })); progressBar1.Enabled = false; progressBar1.Visible = false; DumpMeshes.CancelAsync(); return; } } catch (Exception es) { Logger.AddDebugText(rtbDebug, es.ToString()); } }