Beispiel #1
0
static int
file_list_func (CameraFilesystem *fs, const char *folder,
		CameraList *list, void *data, GPContext *context)
{

	Camera *camera = data;
	int i = 0, filecount = 0;
	char temp_file[14];

	if (cam_has_flash(camera->pl) || cam_has_card(camera->pl) )
	{
		CHECK (spca50x_flash_get_TOC(camera->pl, &filecount));
		for (i=0; i<filecount; i++)
		{
			CHECK(spca50x_flash_get_file_name (camera->pl, i,
						temp_file));
			gp_list_append (list, temp_file, NULL);
		}
	}
	if (cam_has_sdram(camera->pl)) {
		if (camera->pl->dirty_sdram)
			CHECK (spca50x_sdram_get_info (camera->pl));

		for (i = 0; i < camera->pl->num_files_on_sdram; i++) {
			strncpy (temp_file, camera->pl->files[i].name, 12);
			temp_file[12] = 0;
			gp_list_append (list, temp_file, NULL);
		}
	}

	return GP_OK;
}
Beispiel #2
0
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		void *data, GPContext *context)
{
	Camera *camera = data;
	int i;
	unsigned int n;
	const char *name;

	/*
	 * Count the pictures on the camera. If we don't have any, we
	 * are done.
	 */
	CR (fuji_pic_count (camera, &n, context));
	if (!n)
		return (GP_OK);

	/*
	 * Try to get the name of the first file. If we can't, just come
	 * up with some dummy names.
	 */
	if (fuji_pic_name (camera, 1, &name, context) < 0) {
		CR (gp_list_populate (list, "DSCF%04i.JPG", n));
		return (GP_OK);
	}
	CR (gp_list_append (list, name, NULL));

	/* Get the names of the remaining files. */
	for (i = 2; i <= n; i++) {
		CR (fuji_pic_name (camera, i, &name, context));
		CR (gp_list_append (list, name, NULL));
	}

	return (GP_OK);
}
Beispiel #3
0
static int folder_list_func (CameraFilesystem *fs, const char *folder,
			     CameraList *list, void *data, GPContext *context)
{
    int res;
    int from_card;
    int folder_nr;
    Camera *camera = data;
    char *dc120_folder_card   = _("CompactFlash Card");
    
    res = find_folder( camera, folder, &from_card, &folder_nr, context);
    if( res != (GP_OK) ) {
	return res;
    }
    
    if( !from_card && folder_nr==0 ) {
	gp_list_append(list, dc120_folder_card, NULL);
	return (dc120_get_albums(camera, from_card, list, context));
    } 
    else if( from_card && folder_nr==0 ) {
	return (dc120_get_albums(camera, from_card, list, context));
    } 
    else {
	return (GP_OK);
    }
}
Beispiel #4
0
static int getpicsoverview_logitech_pd(
				       Camera *camera, GPContext *context,
				       int *numpics, CameraList *list
				       ) {
    GPPort *port = camera->port;
    unsigned char command[0x10];
    unsigned char retbuf[0x8000];
    int y;
    int np = 0;
    char fn[20];

    memset(command, 0, 16);
    command[0] = 0x12;

    CHECK_RESULT(ultrapocket_command(port, 1, command, 0x10));

    CHECK_RESULT(ultrapocket_command(port, 0, retbuf, 0x8000));
    np = *(unsigned char*)(retbuf + 0x105);
    for (y=0;y<np;y++) {
	memset(fn, 0, 20);
	memcpy(fn, retbuf+0x106+(y*0x10),11);
	/* bizzarely, the logitech camera returns a fname with a space
	 * in it, but requires a '.'. Go figure, eh?
	 */
	fn[7] = '.';
	gp_list_append(list, fn, NULL);
    }
    CHECK_RESULT(ultrapocket_command(port, 0, retbuf, 0x8000));

    *numpics = np;

    return GP_OK;
}
Beispiel #5
0
int lg_gsm_list_files (GPPort *port, CameraList *list) 
{
	int num_pics;
	int i;	

	char oknok[6];
	char photonumber[22];
	char photolist[142000]; /* max_photos * 142 */
	char name[44];
	char value[88];

	memset (oknok,0,6);
	memset (photonumber,0,22);
	memset (photolist,0,142000);
	memset (name,0,44);
	memset (value,0,88);

	GP_DEBUG("Running lg_gsm_list_files\n");

	/* set timeout to 3s */
	/*port->timeout=20000;*/
	/* syncstart */
	MSGWRITE(port, 0x13, 0x6, 0x0, "", 0);
	WRITE(port, sync_start, 6);
	READ(port, oknok, 6);

	/* lsphoto : write 0x04000800000040000000ffffffff */
	MSGWRITE(port, 0x13, 0xe, 0x0, "", 0);
	WRITE(port, list_all_photo, 0xe);
	READ(port, photonumber, 0x16);

	num_pics=photonumber[20]+256*photonumber[21];

	/* increase timeout to 20s */
	/*port->timeout=20000;*/
	/* read 142 * nb_photos */
	READ(port, photolist, 142*num_pics);

	for (i = 0; i < num_pics; i++){
		/* sprintf( name, "lg_gsm_pic%03i.jpg", i ); */
		memcpy(name,&photolist[6+142*i],44);
		memcpy(value,&photolist[50+142*i],80);
		gp_list_append(list, name, value);
	}
	/* restore timeout to 5s */
	/*port->timeout=5000; */
	/* syncstop */
	MSGWRITE(port, 0x13, 0x6, 0x0, "", 0);
	WRITE(port, sync_stop, 6);
	READ(port, oknok, 6);
	/*port->timeout=5000;*/

	GP_DEBUG("Number of pics : %03i\n", num_pics);

	GP_DEBUG("Leaving lg_gsm_list_files\n");

        return GP_OK;
}
bool photo_camera_list::filterCameraList( GPContext* context, const std::string match_string )
{
  CameraList *working_list = NULL;
  const char *name, *value;
  int count = 0;

  if( gp_list_new( &working_list ) != GP_OK )
  {
    photo_reporter::error( "gp_list_new()" );
    gp_list_free( working_list );
    return false;
  }

  // Autodetect the currently attached photo_cameras.
  if( gp_abilities_list_detect( abilities_list_, port_info_list_, working_list, context) != GP_OK )
  {
    photo_reporter::error( "gp_abilities_list_detect()" );
    gp_list_free( working_list );
    return false;
  }
  
 
  count = gp_list_count( working_list );
  if( count < GP_OK )
  {
    photo_reporter::error( "gp_list_count()" );
    gp_list_free( working_list );
    return false;
  }
  
  // Clear camera_list_ for appending
  if( gp_list_reset( camera_list_ ) != GP_OK )
  {
    photo_reporter::error( "gp_list_reset()" );
    gp_list_free( working_list );
    return false;
  }

  // Filter out the generic 'usb:' entry
  for( int i = 0; i < count; i++ )
  {

    gp_list_get_name( working_list, i, &name );
    gp_list_get_value( working_list, i, &value );

    if( match_string.compare( value ) != 0 )
    {
      gp_list_append( camera_list_, name, value );
    }
  }
  
  gp_list_free( working_list );

  return true;
}
static int
foreach_func (const char *filename, lt_ptr data)
{
	foreach_data_t *fd = data;
	CameraList *list = fd->list;

	GP_LOG_D ("Found '%s'.", filename);
	fd->result = gp_list_append (list, filename, NULL);

	return ((fd->result == GP_OK)?0:1);
}
static int
foreach_func (const char *filename, lt_ptr data)
{
	foreach_data_t *fd = data;
	CameraList *list = fd->list;

	gp_log (GP_LOG_DEBUG, "gphoto2-abilities-list",
		"Found '%s'.", filename);
	fd->result = gp_list_append (list, filename, NULL);

	return ((fd->result == GP_OK)?0:1);
}
Beispiel #9
0
static void
decode_dir(Camera *camera, struct tf_packet *p, int listdirs, CameraList *list)
{
	unsigned short count = (get_u16(&p->length) - PACKET_HEAD_SIZE) / sizeof(struct typefile);
	struct typefile *entries = (struct typefile *) p->data;
	int i;
	char *name;

	for(i = 0; i < count; i++) {
		switch (entries[i].filetype) {
		case 1:
			if (listdirs) {
				if (!strcmp ((char*)entries[i].name, ".."))
					continue;
				gp_list_append (list, (char*)entries[i].name, NULL);
			}
			break;
		case 2:
			if (!listdirs) {
				name = _convert_and_logname (camera, (char*)entries[i].name);
				gp_list_append (list, name, NULL);
			}
			break;
		default:
			break;
	}

#if 0
        /* This makes the assumption that the timezone of the Toppy and the system
         * that puppy runs on are the same. Given the limitations on the length of
         * USB cables, this condition is likely to be satisfied. */
        timestamp = tfdt_to_time(&entries[i].stamp);
        printf("%c %20llu %24.24s %s\n", type, get_u64(&entries[i].size),
               ctime(&timestamp), entries[i].name);
#endif
    }
}
Beispiel #10
0
static int file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		void *data, GPContext *context)
{
	Camera *camera = data;
	int	i, numpics;
        char tmp[20];

        CHECK(enigma13_get_toc(camera,&numpics,&enigma13_static_toc));

	for ( i=0; i < numpics; i=i+2 ) {
                sprintf(tmp,"sunp%04d.jpg",(i/2));
		gp_list_append( list, tmp, NULL);
	}
	return (GP_OK);
}
Beispiel #11
0
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
                void *data, GPContext *context)
{
        Camera *camera = data; 
	int num_lo_pics = aox_get_num_lo_pics (camera->pl->info);
	int num_hi_pics = aox_get_num_hi_pics (camera->pl->info);
	int n = num_hi_pics + num_lo_pics;
	char name[30];
	int i;	
	/* Low-resolution pictures are always downloaded first. We do not know 
	 * yet how to process them, so they will remain in RAW format. */
	
	for (i=0; i< num_lo_pics; i++){
		snprintf( name, sizeof(name), "aox_pic%03i.raw", i+1 );
		gp_list_append(list, name, NULL);	
	}

	for (i = num_lo_pics; i < n; i++){
		snprintf( name, sizeof(name), "aox_pic%03i.ppm", i+1 );		
		gp_list_append(list, name, NULL);	
	}
    	return GP_OK;
}
Beispiel #12
0
static int
folder_list_func (CameraFilesystem __unused__ *fs, const char *folder, 
		  CameraList *list,
		  void __unused__ *data, GPContext __unused__ *context)
{
	printf ("### -> The camera will list the folders in '%s' here.\n", 
		folder);

	if (!strcmp (folder, "/")) {
		gp_list_append (list, "whatever", NULL);
		gp_list_append (list, "another", NULL);
	}

	if (!strcmp (folder, "/whatever")) {
		gp_list_append (list, "directory", NULL);
		gp_list_append (list, "dir", NULL);
	}

	if (!strcmp (folder, "/whatever/directory")) {
		gp_list_append (list, "my_special_folder", NULL);
	}

	return (GP_OK);
}
Beispiel #13
0
/**
 * Autodetect all detectable camera
 *
 * @param list a #CameraList that receives the autodetected cameras
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * This camera will autodetected all cameras that can be autodetected.
 * This will for instance detect all USB cameras.
 *
 *   CameraList *list;
 *   gp_list_new (&list);
 *   gp_camera_autodetect (list, context);
 *   ... done! ...
 */
int
gp_camera_autodetect (CameraList *list, GPContext *context)
{
	CameraAbilitiesList	*al = NULL;
	GPPortInfoList		*il = NULL;
	int			ret, i;
	CameraList		*xlist = NULL;

	ret = gp_list_new (&xlist);
	if (ret < GP_OK) goto out;
	if (!il) {
		/* Load all the port drivers we have... */
		ret = gp_port_info_list_new (&il);
		if (ret < GP_OK) goto out;
		ret = gp_port_info_list_load (il);
		if (ret < 0) goto out;
		ret = gp_port_info_list_count (il);
		if (ret < 0) goto out;
	}
	/* Load all the camera drivers we have... */
	ret = gp_abilities_list_new (&al);
	if (ret < GP_OK) goto out;
	ret = gp_abilities_list_load (al, context);
	if (ret < GP_OK) goto out;

	/* ... and autodetect the currently attached cameras. */
        ret = gp_abilities_list_detect (al, il, xlist, context);
	if (ret < GP_OK) goto out;

	/* Filter out the "usb:" entry */
        ret = gp_list_count (xlist);
	if (ret < GP_OK) goto out;
	for (i=0;i<ret;i++) {
		const char *name, *value;

		gp_list_get_name (xlist, i, &name);
		gp_list_get_value (xlist, i, &value);
		if (!strcmp ("usb:",value)) continue;
		gp_list_append (list, name, value);
	}
out:
	if (il) gp_port_info_list_free (il);
	if (al) gp_abilities_list_free (al);
	gp_list_free (xlist);
	if (ret < GP_OK)
		return ret;
	return gp_list_count(list);
}
Beispiel #14
0
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		void *data, GPContext *context)
{
	Camera *camera = data;
	unsigned int n, i;
	const char *name;

	CR (ricoh_get_num (camera, context, &n));
	for (i = 0; i < n; i++) {
		CR (ricoh_get_pic_name (camera, context, i + 1, &name));
		CR (gp_list_append (list, name, NULL));
	}

	return (GP_OK);
}
Beispiel #15
0
/*
 * For most ultrapocket compatibles, call this.
 */
static int getpicsoverview_generic(
    Camera *camera, GPContext *context,
    int *numpics, CameraList *list
				   ) {
   GPPort **pport = &camera->port;
   GPPort *port = *pport;
   unsigned char command[0x10];
   unsigned char retbuf[0x1000];
   int y;
   int np = 0;
   char fn[20];
   int picid;
   int reset_needed;
   
   CHECK_RESULT(ultrapocket_sync(camera));

   memset(command, 0, 16);
   command[0] = 0x12;

   CHECK_RESULT(ultrapocket_command(port, 1, command, 0x10));

   CHECK_RESULT(ultrapocket_command(port, 0, retbuf, 0x1000));
   np = *(unsigned char*)(retbuf + 0x104);
   for (y=0;y<np;y++) {
      picid = retbuf[0x106+y*2] + (retbuf[0x107+y*2] << 8);
      sprintf(fn, "IMG%4.4d.PPM",picid);
      gp_list_append(list, fn, NULL);
   }
   reset_needed = (*(retbuf + 2) & UP_FLAG_NEEDS_RESET);
   ultrapocket_skip(port, 7);

#if 0
   CHECK_RESULT(ultrapocket_sync(camera));
#endif
   if (reset_needed) {
      CHECK_RESULT(ultrapocket_reset(camera));
      port = *pport;
   }
#if 0
   CHECK_RESULT(ultrapocket_sync(camera));
#endif

   *numpics = np;

   return GP_OK;
}
Beispiel #16
0
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		void *data, GPContext *context)
{
	Camera *camera = data; 
	int i, ret;

	for (i = 0; i < ST2205_MAX_NO_FILES; i++) {
		if (camera->pl->filenames[i][0]) {
			ret = gp_list_append (list, camera->pl->filenames[i],
					      NULL);
			if (ret < 0) return ret;
		}
	}

	return GP_OK;
}
Beispiel #17
0
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
                void *data, GPContext *context)
{
        Camera *camera = data;
	int i;
	unsigned char buf[1024];
	GP_DEBUG ("List files in %s\n", folder);

	gp_list_reset (list);
	for (i = 0; i < camera->pl->nb_entries; i++) {
		snprintf((char *)buf, sizeof(buf), "img%03i.ppm", i + 1);
		gp_list_append (list, (char *)buf, NULL);
	}

	return GP_OK;
}
Beispiel #18
0
static int
file_list_func (CameraFilesystem *fs, const char *folder,
		CameraList *list, void *data, GPContext *context)
{
	Camera *camera = data;
	int i;
	char temp_file[14];

	if (camera->pl->dirty)
		CHECK (gsmart300_get_info (camera->pl));

	for (i = 0; i < camera->pl->num_files; i++) {
		strncpy (temp_file, camera->pl->files[i].name, 12);
		temp_file[12] = 0;
		gp_list_append (list, temp_file, NULL);
	}

	return GP_OK;
}
Beispiel #19
0
static int file_list_func (CameraFilesystem *fs, const char *folder, 
			   CameraList *list, void *data, GPContext *context) {
 
    Camera *camera=data;
    int i;
    char temp_file[14];

    GP_DEBUG ("camera_file_list %s\n", folder);
   
    if (soundvision_get_file_list(camera->pl) < 0) {
       GP_DEBUG ("Could not soundvision_file_list!");
       return GP_ERROR;
    }
       
    for(i=0; i < camera->pl->num_pictures; i++) {
       strncpy(temp_file,camera->pl->file_list+(13*i),12);
       temp_file[12]=0;
       gp_list_append (list, temp_file, NULL);
    }
    return GP_OK;
}
Beispiel #20
0
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		void *data, GPContext *context)
{
	unsigned char buffer[SDSC_INFOSIZE];
	Camera *camera = data;

	/* Rewind */
	CHECK_RESULT (SDSC_initialize (camera->port)); 

	/* Count the pictures */
	while (1) {
		CHECK_RESULT (SDSC_send (camera->port, SDSC_NEXT));
		CHECK_RESULT (SDSC_send (camera->port, SDSC_START));
		CHECK_RESULT (SDSC_receive (camera->port,
				buffer, SDSC_INFOSIZE));
		if (is_null (buffer))
			break;
		gp_list_append(list, buffer, NULL);
	}
	return (GP_OK);
}
Beispiel #21
0
static void
_get_widget_names (CameraWidget *widget, CameraList *list)
{
	CameraWidgetType	type;

	gp_widget_get_type (widget, &type);
	switch (type) {
        case GP_WIDGET_MENU:
        case GP_WIDGET_RADIO:
        case GP_WIDGET_TEXT:
        case GP_WIDGET_RANGE:
        case GP_WIDGET_TOGGLE:
        case GP_WIDGET_DATE: {
		const char *name;

		gp_widget_get_name (widget, &name);
		gp_list_append (list, name, NULL);
                break;
	}
        case GP_WIDGET_SECTION:
        case GP_WIDGET_WINDOW: {
		int i, nrofchildren;

		nrofchildren = gp_widget_count_children (widget);
		for (i = 0; i < nrofchildren; i++) {
			CameraWidget *child;

			gp_widget_get_child (widget, i, &child);
			_get_widget_names (child, list);
		}
		break;
	}
        case GP_WIDGET_BUTTON:
        default:
		break;
	}

}
Beispiel #22
0
static int
file_list_func (CameraFilesystem __unused__ *fs, const char *folder, 
		CameraList *list,
		void __unused__ *data, GPContext __unused__ *context)
{
	printf ("### -> The camera will list the files in '%s' here.\n", folder);

	if (!strcmp (folder, "/whatever")) {
		gp_list_append (list, "file1", NULL);
		gp_list_append (list, "file2", NULL);
		gp_list_append (list, "file3", NULL);
		gp_list_append (list, "file4", NULL);
		gp_list_append (list, "file5", NULL);
		gp_list_append (list, "file6", NULL);
	}

	return (GP_OK);
}
Beispiel #23
0
int pdrm11_get_filenames(GPPort *port, CameraList *list)
{
	int i, j;
	uint32_t numPics;
	char name[20];
	char buf[30];


	gp_port_set_timeout(port, 10000);
	CHECK(gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_NUMPICS, 0, buf, 10));
	/* trying to remain endian friendly */
	numPics = le16atoh(&buf[2]) + (le16atoh(&buf[0]) * 1024);
	GP_DEBUG("found %d pictures", numPics);

	

	for(i=1;  i<numPics+1;  i++) {
		CHECK( pdrm11_select_file(port, i) );

		CHECK(gp_port_usb_msg_read(port, 0x01, 0xe600, i, buf, 14));

		/* the filename is 12 chars starting at the third byte */
		CHECK(gp_port_usb_msg_read(port, 0x01, PDRM11_CMD_GET_FILENAME, i, buf, 26));
		for(j=0; j<12; j+=2) {
			name[j] = buf[j+2+1];
			name[j+1] = buf[j+2];
		}
		name[12] = '\0';

		GP_DEBUG("%s",name);
		gp_list_append(list, name, NULL);
	}


	return(GP_OK);
}
static int
file_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
                void *data, GPContext *context)
{
    Camera *camera = data;
    int mpeg, rc = GP_OK;

    GP_DEBUG("camera_folder_list_files()");

    for (mpeg = 0; mpeg <= 1 && rc == GP_OK; mpeg++) {
        int i, count;
        SonyFileType file_type;

        file_type = mpeg ? SONY_FILE_MPEG : SONY_FILE_IMAGE;

        rc = sony_file_count(camera, file_type, &count);
        if (rc != GP_OK) {
            break;
        }

        for (i = 1; i <= count; i++) {
            char buf[13];
            rc = sony_file_name_get(camera, i, file_type, buf);
            if (rc != GP_OK) {
                break;
            }
            gp_list_append(list, buf, NULL);

            if (gp_context_cancel(context)
                    == GP_CONTEXT_FEEDBACK_CANCEL) {
                rc = GP_ERROR_CANCEL;
            }
        }
    }
    return rc;
}
Beispiel #25
0
static int file_list_func (CameraFilesystem *fs, const char *folder,
			   CameraList *list, void *data, GPContext *context) {

	Camera *camera = data;
	int	num = 0;
	int	width;
	int	year;
	int	size;
	uint8_t	month;
	uint8_t	day;
	uint8_t	hour;
	uint8_t	minute;
	uint8_t	byte1;
	uint8_t	byte2;
	uint8_t	byte3;
	char	*filename;

	GP_DEBUG ("Camera List Files");

	if (l859_sendcmd(camera, 0xa0) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xb0) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, 0xc0) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;
	if (l859_sendcmd(camera, L859_CMD_PREVIEW) != GP_OK)
		return GP_ERROR;
	if (l859_retrcmd(camera) == GP_ERROR)
		return GP_ERROR;

	while (camera->pl->buf[13] == num) {

		byte1 = camera->pl->buf[8];
		byte2 = camera->pl->buf[9];
		width = (byte1 * 256) + byte2;
		byte1 = camera->pl->buf[22];
		year = byte1 + 1900;
		month = camera->pl->buf[23];
		day = camera->pl->buf[24];
		hour = camera->pl->buf[25];
		minute = camera->pl->buf[26];

		byte1 = camera->pl->buf[5];
		byte2 = camera->pl->buf[6];
		byte3 = camera->pl->buf[7];
		size = (byte1 * 256 * 256) + (byte2 * 256) + byte3;

		/* Check for no images */
		if (size == 0)
			return GP_OK;

		if (!(filename = (char*)malloc(30))) {
			GP_DEBUG ("Unable to allocate memory for filename.");
			return GP_ERROR_NO_MEMORY;
		}

		sprintf(filename, "%.4i%s%i-%i-%i(%i-%i).jpg", num + 1,
			width == 640 ? "F" : "N", year, month, day, hour, minute);
		GP_DEBUG ("Filename: %s.", filename);

		gp_list_append (list, filename, NULL);
/*		GP_DEBUG ("Num %i Filename %s", num, filename); */
		free (filename);
		num = num + 1;
		if (l859_sendcmd(camera, L859_CMD_PREVIEW_NEXT) != GP_OK)
			return GP_ERROR;
		if (l859_retrcmd(camera) == GP_ERROR)
			return GP_ERROR;
	}
	GP_DEBUG ("Camera List Files Done");
	return GP_OK;
}
Beispiel #26
0
static int
folder_list_func (CameraFilesystem *fs, const char *folder, CameraList *list,
		  void *data, GPContext *context)
{
	gp_system_dir dir;
	gp_system_dirent de;
	char buf[1024], f[1024];
	unsigned int id, n;
	struct stat st;
	Camera *camera = (Camera*)data;

	if (camera->port->type == GP_PORT_DISK) {
		char		*path;
		GPPortInfo	info;
		int		ret;

		ret = gp_port_get_info (camera->port, &info);
		if (ret < GP_OK)
			return ret;
		path = strchr (info.path,':');
		if (!path) path = info.path; else path++;

		snprintf (f, sizeof(f), "%s/%s/", path, folder);
		gp_log (GP_LOG_DEBUG, "directory/folder_list_func", "%s", f);
		/* UNIX / is empty, or we recurse through the whole fs */
		if (	(!strcmp(path, "") || !strcmp(path, "/")) &&
			!strcmp(folder,"/")
		)
			return GP_OK;
	} else {
		/* old style access */
		/* Make sure we have 1 delimiter */
		if (folder[strlen(folder)-1] != '/') {
			snprintf (f, sizeof(f), "%s%c", folder, '/');
		} else {
			strncpy (f, folder, sizeof(f));
		}
	}
	dir = gp_system_opendir ((char*) f);
	if (!dir)
		return GP_ERROR;
	/* Count the files */
	n = 0;
	while (gp_system_readdir (dir))
		n++;
	gp_system_closedir (dir);

	dir = gp_system_opendir (f);
	if (!dir)
		return GP_ERROR;
	id = gp_context_progress_start (context, n, _("Listing folders in '%s'..."), folder);
	n = 0;
	while ((de = gp_system_readdir (dir))) {
		const char * filename = NULL;

		/* Give some feedback */
		gp_context_progress_update (context, id, n + 1);
		gp_context_idle (context);
		if (gp_context_cancel (context) == GP_CONTEXT_FEEDBACK_CANCEL) {
			gp_system_closedir (dir);
			return GP_ERROR_CANCEL;
		}
		filename = gp_system_filename (de);
		if (*filename != '.') {
			snprintf (buf, sizeof(buf), "%s%s", f, filename);
			
			/* lstat ... do not follow symlinks */
			if (lstat (buf, &st) != 0) {
				gp_context_error (context, _("Could not get information about '%s' (%m)."), buf);
				return GP_ERROR;
			}
			if (S_ISDIR (st.st_mode)) {
				gp_list_append(list,	filename,	NULL);
			}
		}
		n++;
	}
	gp_system_closedir (dir);
	gp_context_progress_stop (context, id);
	return (GP_OK);
}
Beispiel #27
0
static int file_list_func (CameraFilesystem *fs, const char *folder,
			   CameraList *list, void *user_data,
			   GPContext *context)
{
	Camera		*camera = user_data;
	unsigned char	*data = NULL;
	long unsigned	data_len = 0;
	unsigned char	*ptr_data_buff;
	char		filename[13];
	int		res, i;

	if(camera->pl->context)
	{
		gp_context_error(context, CONTEXT_EXISTS);
		return GP_ERROR;
	}

	if(check_last_use(camera) == GP_ERROR)
	{
		return GP_ERROR;
	}
	
	/* get file list data */
	res = dc3200_get_data (camera, &data, &data_len, CMD_LIST_FILES, folder,
			       NULL);
	if (res == GP_ERROR)
	{
		return GP_ERROR;
	}
	
	/* check the data length */
	if(data_len%20 != 0 || data_len < 1)
	{
		return GP_ERROR;
	}

	if(data == NULL)
	{
		return GP_ERROR;
	}

	/* add files to the list */
	ptr_data_buff = data;
	i = 0;
	
	while(i < data_len) {
		/* files don't have 0x10 in their attribute */
		if(ptr_data_buff[11] & 0x10) {
			ptr_data_buff += 20;
			i += 20;
			continue;
		}
		
		/* copy the first 8 bytes of filename */
		strncpy(filename, (char *)ptr_data_buff, 8);
		filename[8] = 0;
		/* add dot */
		strcat(filename, ".");
		/* copy extension, last 3 bytes*/
		strncat(filename, (char *)ptr_data_buff+8, 3);
		
		if(!strstr(filename, ".JPG") && !strstr(filename, ".jpg")) {
			ptr_data_buff += 20;
			i += 20;
			continue;
		}

		/* append file to the list */
		gp_list_append(list, filename, NULL);
		
		ptr_data_buff += 20;
		i += 20;
	}

	free(data);
	return (dc3200_keep_alive(camera));
}
Beispiel #28
0
static int folder_list_func (CameraFilesystem *fs, const char *folder,
			     CameraList *list, void *user_data,
			     GPContext *context)
{
	Camera 		*camera = user_data;
	unsigned char	*data = NULL;
	long unsigned 	data_len = 0;
	unsigned char	*ptr_data_buff;
	char		filename[13], *ptr;
	int		res, i;

	if(camera->pl->context)
	{
		gp_context_error(context, CONTEXT_EXISTS);
		return GP_ERROR;
	}

	if(check_last_use(camera) == GP_ERROR)
	{
		return GP_ERROR;
	}

	/* get file list data */
	res = dc3200_get_data (camera, &data, &data_len, CMD_LIST_FILES, folder,
			       NULL);
	if (res == GP_ERROR)
	{
		return GP_ERROR;
	}

	/* check the data length, each record is 20 bytes */
	if(data_len%20 != 0 || data_len < 1)
	{
		return GP_ERROR;
	}
	
	if (data == NULL)
	{
		return GP_ERROR;
	}

	/* add directories to the list */
	ptr_data_buff = data;
	i = 0;

	while(i < data_len) {
		/* directories have 0x10 in their attribute */
		if(!(ptr_data_buff[11] & 0x10)) {
			ptr_data_buff += 20;
			i += 20;
			continue;
		}
		
		/* skip directories starting with . */
		if(ptr_data_buff[0] == '.') {
			ptr_data_buff += 20;
			i += 20;
			continue;
		}
		
		/* copy the filename */
		strncpy(filename, (char *)ptr_data_buff, sizeof(filename));

		/* chop off the trailing spaces and null terminate */
		ptr = strchr(filename, 0x20);
		if(ptr) ptr[0] = 0;

		/* in case of long directory */
		filename[12] = 0;
		
		/* append dir to the list */
		gp_list_append(list, filename, NULL);
		
		ptr_data_buff += 20;
		i += 20;
	}

	free (data);
	return (dc3200_keep_alive (camera));
}
/**
 * \param list a CameraAbilitiesList
 * \param info_list the GPPortInfoList of ports to use for detection
 * \param l a #CameraList that contains the autodetected cameras after the call
 * \param context a #GPContext
 *
 * Tries to detect any camera connected to the computer using the supplied
 * list of supported cameras and the supplied info_list of ports.
 *
 * \return a gphoto2 error code
 */
int
gp_abilities_list_detect (CameraAbilitiesList *list,
			  GPPortInfoList *info_list, CameraList *l,
			  GPContext *context)
{
	GPPortInfo info;
	GPPort *port;
	int i, info_count;

	CHECK_NULL (list && info_list && l);

	gp_list_reset (l);

	CHECK_RESULT (info_count = gp_port_info_list_count (info_list));

	CHECK_RESULT (gp_port_new (&port));
	for (i = 0; i < info_count; i++) {
		int res;
		char *xpath;
		GPPortType	type;

		CHECK_RESULT (gp_port_info_list_get_info (info_list, i, &info));
		CHECK_RESULT (gp_port_set_info (port, info));
		gp_port_info_get_type (info, &type);
		res = gp_port_info_get_path (info, &xpath);
		if (res <GP_OK)
			continue;
		switch (type) {
		case GP_PORT_USB:
		case GP_PORT_USB_SCSI:
		case GP_PORT_USB_DISK_DIRECT: {
			int ability;
			
			res = gp_abilities_list_detect_usb (list, &ability, port);
			if (res == GP_OK) {
				gp_list_append(l,
					list->abilities[ability].model,
					xpath);
			} else if (res < 0)
				gp_port_set_error (port, NULL);

			break;
		}
		case GP_PORT_DISK: {
			char	*s, path[1024];
			struct stat stbuf;
		
			s = strchr (xpath, ':');
			if (!s)
				break;
			s++;
			snprintf (path, sizeof(path), "%s/DCIM", s);
			if (-1 == stat(path, &stbuf)) {
				snprintf (path, sizeof(path), "%s/dcim", s);
				if (-1 == stat(path, &stbuf))
					continue;
			}
			gp_list_append (l, "Mass Storage Camera", xpath);
			break;
		}
		case GP_PORT_PTPIP: {
			char	*s;

			s = strchr (xpath, ':');
			if (!s) break;
			s++;
			if (!strlen(s)) break;
			gp_list_append (l, "PTP/IP Camera", xpath);
			break;
		}
		default:
			/*
			 * We currently cannot detect any cameras on this
			 * port
			 */
			break;
		}
	}

	gp_port_free (port);

	return (GP_OK);
}