From fad12d9b5286ecb507c0907e6de345ba485dddce Mon Sep 17 00:00:00 2001 From: tiagohm Date: Sat, 27 Jan 2024 21:09:14 -0300 Subject: [PATCH] [api]: Fix cannot access the file because it is being used by another process --- .../api/wizard/flat/FlatWizardStep.kt | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardStep.kt b/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardStep.kt index 33d815729..2f9215ba0 100644 --- a/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardStep.kt +++ b/api/src/main/kotlin/nebulosa/api/wizard/flat/FlatWizardStep.kt @@ -83,26 +83,25 @@ data class FlatWizardStep( val savedPath = cameraExposureStep.savedPath if (!stopped && savedPath != null) { - Fits(savedPath).also(Fits::read).use { fits -> - image = image?.load(fits, false) ?: Image.open(fits, false) - - val statistics = STATISTICS.compute(image!!) - - LOG.info("flat frame captured. duration={}, statistics={}", exposureTime, statistics) - - if (statistics.mean in meanRange) { - val path = request.captureRequest.makeSavePath(true) - savedPath.inputStream().transferAndClose(path.outputStream()) - savedPath.deleteIfExists() - LOG.info("Found an optimal exposure time. exposure={}, path={}", exposureTime, path) - flatWizardExecutionListeners.forEach { it.onFlatCaptured(this, path, exposureTime) } - } else if (statistics.mean < meanRange.start) { - exposureMin = cameraExposureStep.exposureTime - return StepResult.CONTINUABLE - } else { - exposureMax = cameraExposureStep.exposureTime - return StepResult.CONTINUABLE - } + image = Fits(savedPath).also(Fits::read).use { fits -> + image?.load(fits, false) ?: Image.open(fits, false) + } + + val statistics = STATISTICS.compute(image!!) + LOG.info("flat frame captured. duration={}, statistics={}", exposureTime, statistics) + + if (statistics.mean in meanRange) { + val path = request.captureRequest.makeSavePath(true) + savedPath.inputStream().transferAndClose(path.outputStream()) + savedPath.deleteIfExists() + LOG.info("Found an optimal exposure time. exposure={}, path={}", exposureTime, path) + flatWizardExecutionListeners.forEach { it.onFlatCaptured(this, path, exposureTime) } + } else if (statistics.mean < meanRange.start) { + exposureMin = cameraExposureStep.exposureTime + return StepResult.CONTINUABLE + } else { + exposureMax = cameraExposureStep.exposureTime + return StepResult.CONTINUABLE } }