func (camera *Camera) findAllFilesInDir(basedirPath *string) ([]string, error) { var err error returnedSlice := []string{} gpDirPath := C.CString(*basedirPath) defer C.free(unsafe.Pointer(gpDirPath)) gpFileList, err := newGphotoList() if err != nil { return nil, err } defer C.gp_list_free(gpFileList) if retval := C.gp_camera_folder_list_files(camera.gpCamera, gpDirPath, gpFileList, camera.gpContext); retval != gpOk { return nil, fmt.Errorf("Cannot get file list from dir %s, error code %v", *basedirPath, retval) } listSize := int(C.gp_list_count(gpFileList)) for i := 0; i < listSize; i++ { var gpListElementName *C.char C.gp_list_get_name(gpFileList, (C.int)(i), (**C.char)(&gpListElementName)) returnedSlice = append(returnedSlice, C.GoString(gpListElementName)) } return returnedSlice, nil }
func cameraListToMap(cameraList *C.CameraList) (map[string]string, int) { size := int(C.gp_list_count(cameraList)) vals := make(map[string]string) if size < 0 { return vals, size } for i := 0; i < size; i++ { var cKey *C.char var cVal *C.char C.gp_list_get_name(cameraList, C.int(i), &cKey) C.gp_list_get_value(cameraList, C.int(i), &cVal) defer C.free(unsafe.Pointer(cKey)) defer C.free(unsafe.Pointer(cVal)) key := C.GoString(cKey) val := C.GoString(cVal) vals[key] = val } return vals, 0 }