legacy/experimental/ecdb/trunk/src/ecdb_drives.c

181 lines
4.7 KiB
C
Raw Normal View History

/* vim: set sw=3 ts=3 sts=3 expandtab: */
#include "ecdb.h"
int
ecdb_aquire_drive_info(void)
{
2008-12-23 02:37:34 +00:00
int ret, i;
2008-12-09 05:47:59 +00:00
unsigned int drive_num;
struct burn_drive_info *drives_current;
struct burn_speed_descriptor *speeds;
ret = 0;
if (em->drives)
{
2008-12-18 18:54:50 +00:00
ecdb_drive_info_list_free(em->drives);
2008-12-09 05:47:59 +00:00
}
while (!ret)
{
ret = burn_drive_scan(&drives_current, &drive_num);
}
for (i = 0; i < drive_num; i++)
{
Ecdb_Drive_Info *drive;
drive = calloc(1, sizeof(Ecdb_Drive_Info));
if (!drive)
{
return FALSE;
}
drive->product = eina_stringshare_add(drives_current[i].product);
drive->vendor = eina_stringshare_add(drives_current[i].vendor);
drive->revision = eina_stringshare_add(drives_current[i].revision);
2008-12-09 05:47:59 +00:00
drive->location = strdup(drives_current[i].location);
drive->read_dvdram = drives_current[i].read_dvdram;
drive->read_dvdr = drives_current[i].read_dvdr;
drive->read_dvdrom = drives_current[i].read_dvdrom;
drive->read_cdr = drives_current[i].read_cdr;
drive->read_cdrw = drives_current[i].read_cdrw;
drive->write_dvdram = drives_current[i].write_dvdram;
drive->write_dvdr = drives_current[i].write_dvdr;
drive->write_cdr = drives_current[i].write_cdr;
drive->write_simulate = drives_current[i].write_simulate;
burn_drive_get_speedlist(drives_current[i].drive, &speeds);
drive->profile_name = eina_stringshare_add(speeds->profile_name);
2008-12-09 05:47:59 +00:00
drive->profile_loaded = speeds->profile_loaded;
if (burn_drive_grab(drives_current[i].drive, 1))
{
drive->capacity = burn_disc_available_space(drives_current[i].drive,
NULL);
burn_drive_release(drives_current[i].drive, 0);
}
2008-12-09 05:47:59 +00:00
while (speeds->next)
{
i++;
speeds = speeds->next;
}
drive->read_speeds = calloc(i + 2, sizeof(int));
drive->write_speeds = calloc(i + 2, sizeof(int));
drive->read_speeds[0] = i + 1;
drive->write_speeds[0] = i + 1;
for (ret = 1; ret <= i; ret++)
{
2008-12-23 02:37:34 +00:00
drive->write_speeds[ret] = speeds->write_speed;
drive->read_speeds[ret] = speeds->read_speed;
2008-12-09 05:47:59 +00:00
speeds = speeds->prev;
}
burn_drive_free_speedlist(&speeds);
2008-12-18 18:54:50 +00:00
em->drives = eina_list_append(em->drives, drive);
2008-12-09 05:47:59 +00:00
}
burn_drive_info_free(drives_current);
return TRUE;
}
void
2008-12-18 18:54:50 +00:00
ecdb_drive_info_list_free(Eina_List *list)
{
2008-12-09 05:47:59 +00:00
Ecdb_Drive_Info *info;
2008-12-18 18:54:50 +00:00
Eina_List *l;
2008-12-09 05:47:59 +00:00
2008-12-18 18:54:50 +00:00
EINA_LIST_FOREACH(list, l, info)
{
FREE(info->read_speeds);
FREE(info->write_speeds);
FREE(info->location);
eina_stringshare_del(info->vendor);
eina_stringshare_del(info->product);
eina_stringshare_del(info->revision);
eina_stringshare_del(info->profile_name);
2008-12-18 18:54:50 +00:00
FREE(info);
}
2008-12-09 05:47:59 +00:00
2008-12-18 18:54:50 +00:00
list = eina_list_free(list);
}
void
ecdb_print_drive_info(void)
{
2008-12-18 18:54:50 +00:00
Eina_List *l;
2008-12-09 05:47:59 +00:00
Ecdb_Drive_Info *drive;
int j, i, h;
2008-12-18 18:54:50 +00:00
em->drives = eina_list_nth_list(em->drives, 0);
EINA_LIST_FOREACH(em->drives, l, drive)
2008-12-09 05:47:59 +00:00
{
EINA_ERROR_PINFO("Vendor: %s, Product: %s, Revision: %s, "
2008-12-09 05:47:59 +00:00
"Location: %s\n",
drive->vendor, drive->product,
drive->revision, drive->location);
EINA_ERROR_PINFO("Profile name: %s, Loaded: %d\n",
2008-12-09 05:47:59 +00:00
drive->profile_name,
drive->profile_loaded);
EINA_ERROR_PINFO("Read DVDRAM: %d, Read DVDR: %d, Read DVDROM: %d, "
2008-12-09 05:47:59 +00:00
"Read CDR: %d, Read CDRW: %d\n",
drive->read_dvdram,
drive->read_dvdr,
drive->read_dvdrom,
drive->read_cdr,
drive->read_cdrw);
EINA_ERROR_PINFO("Write DVDRAM: %d, Write DVDR: %d, Write CDR: %d, "
2008-12-09 05:47:59 +00:00
"Write Simulate: %d\n",
drive->write_dvdram,
drive->write_dvdr,
drive->write_cdr,
drive->write_simulate);
j = drive->read_speeds[0];
for (i = 1; i < j; i ++)
{
if ((h = drive->write_speeds[i]))
{
EINA_ERROR_PINFO("Write: %d\n", h);
2008-12-09 05:47:59 +00:00
}
if ((h = drive->read_speeds[i]))
{
EINA_ERROR_PINFO("Read: %d\n", h);
2008-12-09 05:47:59 +00:00
}
}
}
}
int
ecdb_aquire_drive(Ecdb_Project *proj, unsigned int idx)
{
2008-12-09 05:47:59 +00:00
Ecdb_Drive_Info *info;
char adr[BURN_DRIVE_ADR_LEN];
2008-12-18 18:54:50 +00:00
info = eina_list_nth(em->drives, idx);
2008-12-09 05:47:59 +00:00
if (burn_drive_convert_fs_adr(info->location, adr) <= 0)
{
EINA_ERROR_PWARN("Error: Address doesn't provide cd burner!\n");
2008-12-09 05:47:59 +00:00
return FALSE;
}
if (burn_drive_scan_and_grab(&info->tangible, adr, 1) > 0)
{
proj->drive = info;
return TRUE;
}
else
{
info->tangible = NULL;
return FALSE;
}
}
2008-12-09 05:47:59 +00:00