Improve handling of cancelled slicing operations

- Issue MatterHackers/MCCentral#4532
We should not load incomplete gcode when a slice is canceled
This commit is contained in:
John Lewin 2018-11-08 05:38:46 -08:00
parent 55ab1c19e2
commit 83b2b7851a

View file

@ -263,21 +263,22 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
commandArgs = $"-v -o \"{gcodeFilePath}\" -c \"{configFilePath}\"";
bool forcedExit = false;
if (AggContext.OperatingSystem == OSType.Android
|| AggContext.OperatingSystem == OSType.Mac
|| RunInProcess)
{
EventHandler WriteOutput = (s, e) =>
{
if(cancellationToken.IsCancellationRequested)
if (cancellationToken.IsCancellationRequested)
{
MatterHackers.MatterSlice.MatterSlice.Stop();
forcedExit = true;
}
if (s is string stringValue)
{
sliceProgressReporter?.Report(new ProgressStatus()
{
Status = stringValue
@ -290,11 +291,11 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
MatterSlice.MatterSlice.ProcessArgs(commandArgs);
MatterSlice.LogOutput.GetLogWrites -= WriteOutput;
slicingSucceeded = !forcedExit;
}
else
{
bool forcedExit = false;
var slicerProcess = new Process()
{
StartInfo = new ProcessStartInfo()
@ -350,7 +351,8 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
try
{
if (File.Exists(gcodeFilePath)
if (slicingSucceeded
&& File.Exists(gcodeFilePath)
&& File.Exists(configFilePath))
{
// make sure we have not already written the settings onto this file