2008-04-01 21:30:41 +00:00
|
|
|
#include "ecdb.h"
|
|
|
|
|
2008-05-19 05:00:55 +00:00
|
|
|
int ecdb_source_init(Ecdb_Source *src);
|
|
|
|
|
|
|
|
Ecdb_Source *
|
|
|
|
ecdb_source_new(void)
|
|
|
|
{
|
|
|
|
Ecdb_Source *src;
|
|
|
|
|
|
|
|
src = calloc(1, sizeof(Ecdb_Source));
|
|
|
|
if (!src)
|
|
|
|
return NULL;
|
|
|
|
if (!ecdb_source_init(src))
|
|
|
|
{
|
|
|
|
FREE(src);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ecdb_source_init(Ecdb_Source *src)
|
|
|
|
{
|
|
|
|
src->rec = FALSE;
|
|
|
|
src->num_children = 0;
|
|
|
|
src->children = calloc(1, sizeof(Ecdb_Source));
|
|
|
|
if (!src->children)
|
|
|
|
return FALSE;
|
|
|
|
src->children[src->num_children] = NULL;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ecdb_source_data_set(Ecdb_Source *src, const char *dst, unsigned char rec)
|
|
|
|
{
|
|
|
|
if (!src)
|
|
|
|
return;
|
|
|
|
|
2008-05-23 03:33:04 +00:00
|
|
|
src->dst = strdup(dst);
|
2008-05-19 05:00:55 +00:00
|
|
|
src->rec = rec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ecdb_source_child_append(Ecdb_Source *src, Ecdb_Source *child)
|
|
|
|
{
|
2008-05-21 03:08:27 +00:00
|
|
|
if (src == child)
|
|
|
|
{
|
|
|
|
printf("Trying to make a parent of itself!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-05-19 05:00:55 +00:00
|
|
|
src->num_children++;
|
|
|
|
src->children = realloc(src->children, sizeof(Ecdb_Source) *
|
|
|
|
(src->num_children + 1));
|
2008-05-21 01:38:44 +00:00
|
|
|
src->children[src->num_children - 1] = child;
|
|
|
|
src->children[src->num_children] = NULL;
|
2008-05-27 23:28:01 +00:00
|
|
|
child->parent = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Basically here we can remove all occurences (who knows why we'd get
|
|
|
|
* multiple, but whatever), or just the first. For now remove the first, and
|
|
|
|
* see how that goes
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ecdb_source_child_remove(Ecdb_Source *src, Ecdb_Source *child)
|
|
|
|
{
|
|
|
|
Ecdb_Source **temp;
|
|
|
|
int i, cidx, f;
|
|
|
|
|
|
|
|
if (src == child)
|
|
|
|
{
|
|
|
|
printf("Trying to remove oneself\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = calloc(src->num_children, sizeof(Ecdb_Source));
|
|
|
|
temp[src->num_children - 1] = NULL;
|
|
|
|
|
|
|
|
cidx = f = 0;
|
|
|
|
for (i = 0; src->children[i]; i++)
|
|
|
|
{
|
|
|
|
if ((src->children[i] == child) && (!f))
|
|
|
|
{
|
|
|
|
f++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
temp[cidx] = src->children[i];
|
|
|
|
cidx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(src->children);
|
|
|
|
src->children = temp;
|
|
|
|
src->num_children--;
|
|
|
|
child->parent = NULL;
|
2008-05-19 05:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ecdb_source_add_children_rec(Ecdb_Source *parent, IsoImage *image)
|
|
|
|
{
|
2008-05-21 03:08:27 +00:00
|
|
|
IsoDir *cd = NULL;
|
2008-05-19 05:00:55 +00:00
|
|
|
Ecdb_Source *cs;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if ((!parent) || (!image))
|
|
|
|
return;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
while ((cs = parent->children[i]))
|
|
|
|
{
|
2008-05-21 03:08:27 +00:00
|
|
|
/* If recursive, let library add for us */
|
2008-05-19 05:00:55 +00:00
|
|
|
if (cs->rec)
|
2008-05-21 03:08:27 +00:00
|
|
|
{
|
|
|
|
iso_tree_add_new_dir(ISO_DIR(parent->node),
|
|
|
|
ecore_file_file_get(cs->dst), &cd);
|
|
|
|
iso_tree_add_dir_rec(image, cd, cs->dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the source has children, find the node from above
|
|
|
|
* (if applicable), and recursively add to it */
|
2008-05-19 05:00:55 +00:00
|
|
|
if (cs->num_children)
|
|
|
|
{
|
2008-05-21 03:08:27 +00:00
|
|
|
if (!cd)
|
2008-05-19 05:00:55 +00:00
|
|
|
{
|
|
|
|
iso_tree_add_new_dir(ISO_DIR(parent->node),
|
2008-05-21 03:08:27 +00:00
|
|
|
ecore_file_file_get(cs->dst), &cd);
|
2008-05-19 05:00:55 +00:00
|
|
|
}
|
2008-05-21 03:08:27 +00:00
|
|
|
cs->node = ISO_NODE(cd);
|
2008-05-19 05:00:55 +00:00
|
|
|
ecdb_source_add_children_rec(cs, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* file */
|
|
|
|
if ((!cs->rec) && (!cs->num_children))
|
2008-05-21 03:08:27 +00:00
|
|
|
{
|
2008-05-19 05:00:55 +00:00
|
|
|
iso_tree_add_node(image, ISO_DIR(parent->node),
|
|
|
|
cs->dst, NULL);
|
2008-05-21 03:08:27 +00:00
|
|
|
}
|
2008-05-19 05:00:55 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-21 01:01:37 +00:00
|
|
|
/* proj->files should only have children */
|
2008-04-01 21:30:41 +00:00
|
|
|
BurnSource *
|
2008-05-15 00:14:33 +00:00
|
|
|
ecdb_image_project(Ecdb_Burn_Project *proj)
|
2008-04-01 21:30:41 +00:00
|
|
|
{
|
|
|
|
IsoImage *image;
|
2008-05-21 01:01:37 +00:00
|
|
|
Ecdb_Source *c;
|
2008-04-01 21:30:41 +00:00
|
|
|
IsoWriteOpts *opts;
|
|
|
|
BurnSource *data_src, *fifo_src;
|
|
|
|
|
2008-05-21 01:38:44 +00:00
|
|
|
if ((!proj->files) || (!proj->files->num_children))
|
2008-04-01 21:30:41 +00:00
|
|
|
return NULL;
|
2008-05-21 01:01:37 +00:00
|
|
|
|
|
|
|
/* To handle already-suplied image files */
|
|
|
|
if (proj->files->num_children == 1)
|
2008-04-01 21:30:41 +00:00
|
|
|
{
|
2008-05-21 01:01:37 +00:00
|
|
|
efreet_mime_init();
|
|
|
|
c = proj->files->children[0];
|
|
|
|
if ((!ecore_file_is_dir(c->dst)) &&
|
|
|
|
(!strcmp(efreet_mime_type_get(c->dst),
|
2008-04-01 21:30:41 +00:00
|
|
|
"application/x-cd-image")))
|
|
|
|
{
|
2008-05-21 01:01:37 +00:00
|
|
|
data_src = burn_file_source_new(c->dst, NULL);
|
2008-04-01 21:30:41 +00:00
|
|
|
goto FIFO_CREATE;
|
|
|
|
}
|
2008-05-21 01:01:37 +00:00
|
|
|
efreet_mime_shutdown();
|
2008-04-01 21:30:41 +00:00
|
|
|
}
|
|
|
|
|
2008-05-21 01:01:37 +00:00
|
|
|
/* Otherwise we have a bunch of files */
|
|
|
|
if (!iso_image_new(proj->volume_id, &image))
|
2008-04-01 21:30:41 +00:00
|
|
|
{
|
2008-05-21 01:01:37 +00:00
|
|
|
printf("Failed to create image!\n");
|
2008-04-01 21:30:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-21 01:01:37 +00:00
|
|
|
/* Set all ids */
|
2008-04-01 21:30:41 +00:00
|
|
|
if (proj->publisher_id)
|
|
|
|
iso_image_set_publisher_id(image, proj->publisher_id);
|
|
|
|
if (proj->data_preparer_id)
|
|
|
|
iso_image_set_data_preparer_id(image,
|
|
|
|
proj->data_preparer_id);
|
|
|
|
if (proj->system_id)
|
|
|
|
iso_image_set_system_id(image, proj->system_id);
|
|
|
|
if (proj->application_id)
|
|
|
|
iso_image_set_application_id(image, proj->application_id);
|
|
|
|
if (proj->copywrite_id)
|
|
|
|
iso_image_set_copyright_file_id(image, proj->copywrite_id);
|
|
|
|
if (proj->abstract_id)
|
|
|
|
iso_image_set_abstract_file_id(image, proj->abstract_id);
|
|
|
|
if (proj->biblio_id)
|
|
|
|
iso_image_set_biblio_file_id(image, proj->biblio_id);
|
|
|
|
|
2008-05-21 01:01:37 +00:00
|
|
|
if (!iso_write_opts_new(&opts, 2))
|
2008-04-01 21:30:41 +00:00
|
|
|
{
|
|
|
|
printf("Failed to create writing options!\n");
|
|
|
|
iso_image_unref(image);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-05-21 01:01:37 +00:00
|
|
|
/* And some write opts stuff */
|
2008-04-01 21:30:41 +00:00
|
|
|
iso_write_opts_set_iso_level(opts, proj->iso_level);
|
|
|
|
iso_write_opts_set_joliet(opts, proj->use_joliet);
|
|
|
|
iso_write_opts_set_rockridge(opts, proj->use_rockridge);
|
|
|
|
iso_write_opts_set_iso1999(opts, proj->iso1990);
|
2008-05-21 01:01:37 +00:00
|
|
|
iso_write_opts_set_appendable(opts, proj->multi);
|
2008-04-01 21:30:41 +00:00
|
|
|
|
|
|
|
iso_tree_set_follow_symlinks(image, proj->follow_symlinks);
|
|
|
|
iso_tree_set_ignore_hidden(image, proj->ignore_hidden);
|
|
|
|
iso_tree_set_ignore_special(image, proj->ignore_special);
|
|
|
|
|
2008-05-21 01:01:37 +00:00
|
|
|
/* actually fill image with some files now */
|
|
|
|
proj->files->node = ISO_NODE(iso_image_get_root(image));
|
|
|
|
ecdb_source_add_children_rec(proj->files, image);
|
|
|
|
|
|
|
|
/* Make the burn source here */
|
2008-04-01 21:30:41 +00:00
|
|
|
iso_image_create_burn_source(image, opts, &data_src);
|
|
|
|
iso_write_opts_free(opts);
|
|
|
|
iso_image_unref(image);
|
|
|
|
|
2008-05-21 01:01:37 +00:00
|
|
|
/* And, convert to fifo */
|
|
|
|
FIFO_CREATE:
|
2008-04-01 21:30:41 +00:00
|
|
|
fifo_src = burn_fifo_source_new(data_src,
|
|
|
|
proj->fifo_chunksize, proj->fifo_chunks, 0);
|
|
|
|
burn_source_free(data_src);
|
|
|
|
return fifo_src;
|
|
|
|
}
|
|
|
|
|