Reduce scope of temp camera file
This commit is contained in:
51
api.cpp
51
api.cpp
@@ -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));
|
||||||
|
|||||||
Reference in New Issue
Block a user