Reduce scope of temp camera file

This commit is contained in:
Ingvar Stepanyan
2021-07-21 14:14:58 +00:00
parent 3b85b63d20
commit 5e54c25c55

51
api.cpp
View File

@@ -131,31 +131,34 @@ class Context {
val captureImageAsFile() { val captureImageAsFile() {
return gpp_rethrow([=]() { 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(); 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_set_name(&file, "image."));
gpp_try(gp_file_adjust_name_for_mime_type(&file)); gpp_try(gp_file_adjust_name_for_mime_type(&file));