コード例 #1
0
ファイル: photos.go プロジェクト: groovemonkey/gphoto
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
}
コード例 #2
0
ファイル: gphoto2go.go プロジェクト: micahwedemeyer/gphoto2go
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
}