diff --git a/api.cpp b/api.cpp index f51206d..6e568f7 100644 --- a/api.cpp +++ b/api.cpp @@ -131,31 +131,34 @@ class Context { val captureImageAsFile() { return gpp_rethrow([=]() { - struct TempCameraFile { - Camera &camera; - GPContext &context; - CameraFilePath path; - - ~TempCameraFile() { - gp_camera_file_delete(&camera, path.folder, path.name, &context); - } - }; - - TempCameraFile camera_file{ - .camera = *camera, - .context = *context, - }; - - strcpy(camera_file.path.folder, "/"); - strcpy(camera_file.path.name, "web-gphoto2"); - - gpp_try(gp_camera_capture(camera.get(), GP_CAPTURE_IMAGE, - &camera_file.path, context.get())); - auto &file = get_file(); - gpp_try(gp_camera_file_get(camera.get(), camera_file.path.folder, - camera_file.path.name, GP_FILE_TYPE_NORMAL, - &file, context.get())); + + { + struct TempCameraFile { + Camera &camera; + GPContext &context; + CameraFilePath path; + + ~TempCameraFile() { + gp_camera_file_delete(&camera, path.folder, path.name, &context); + } + }; + + TempCameraFile camera_file{ + .camera = *camera, + .context = *context, + }; + + strcpy(camera_file.path.folder, "/"); + strcpy(camera_file.path.name, "web-gphoto2"); + + gpp_try(gp_camera_capture(camera.get(), GP_CAPTURE_IMAGE, + &camera_file.path, context.get())); + + gpp_try(gp_camera_file_get(camera.get(), camera_file.path.folder, + camera_file.path.name, GP_FILE_TYPE_NORMAL, + &file, context.get())); + } gpp_try(gp_file_set_name(&file, "image.")); gpp_try(gp_file_adjust_name_for_mime_type(&file));