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

219 lines
4.7 KiB
C
Raw Normal View History

#include "ecdb.h"
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;
src->dst = dst;
src->rec = rec;
}
void
ecdb_source_child_append(Ecdb_Source *src, Ecdb_Source *child)
{
src->num_children++;
src->children = realloc(src->children, sizeof(Ecdb_Source) *
(src->num_children + 1));
src->children[src->num_children] = child;
src->children[src->num_children + 1] = NULL;
}
void
ecdb_source_add_children_rec(Ecdb_Source *parent, IsoImage *image)
{
IsoDir *cd;
IsoNode *cn;
Ecdb_Source *cs;
int i;
if ((!parent) || (!image))
return;
i = 0;
while ((cs = parent->children[i]))
{
if (cs->rec)
iso_tree_add_dir_rec(image, ISO_DIR(parent->node),
cs->dst);
if (cs->num_children)
{
/* If not created above, make one here */
if (!iso_tree_path_to_node(image, cs->dst, &cn))
{
iso_tree_add_new_dir(ISO_DIR(parent->node),
cs->dst, &cd);
cs->node = ISO_NODE(cd);
}
else
cs->node = cn;
ecdb_source_add_children_rec(cs, image);
}
/* file */
if ((!cs->rec) && (!cs->num_children))
iso_tree_add_node(image, ISO_DIR(parent->node),
cs->dst, NULL);
i++;
}
}
/* Deprecated code */
/* Some limitations here need to be worked out
* Handle: audio, etc */
BurnSource *
2008-05-15 00:14:33 +00:00
ecdb_image_project(Ecdb_Burn_Project *proj)
{
IsoImage *image;
IsoDir *root;
IsoWriteOpts *opts;
BurnSource *data_src, *fifo_src;
char *path;
int ret;
efreet_mime_init();
if ((!proj->files) || (ecore_list_empty_is(proj->files)))
return NULL;
else if (ecore_list_count(proj->files) == 1)
{
path = ecore_list_first(proj->files);
if ((path) && (!ecore_file_is_dir(path)) &&
(!strcmp(efreet_mime_type_get(path),
"application/x-cd-image")))
{
path = ecore_list_first_remove(proj->files);
data_src = burn_file_source_new(path, NULL);
FREE(path);
goto FIFO_CREATE;
}
}
ret = iso_image_new(proj->volume_id, &image);
if (!ret)
{
printf("Failed to create an iso image!\n");
iso_finish();
return NULL;
}
/* Disk ids */
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);
/* Write Options - default to distribution for now */
ret = iso_write_opts_new(&opts, 2);
if (!ret)
{
printf("Failed to create writing options!\n");
iso_image_unref(image);
iso_finish();
return NULL;
}
/* Most set by default with 2 ^ */
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);
//iso_write_opts_set_appendable(opts, proj->appendable);
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);
root = iso_image_get_root(image);
ecore_list_first_goto(proj->files);
ret = 0;
while ((path = ecore_list_remove(proj->files)))
{
/* For now just this, in future special, symlink */
if (ecore_file_is_dir(path))
iso_tree_add_dir_rec(image, root, path);
else if (ecore_file_exists(path))
iso_tree_add_node(image, root, path, NULL);
else
{
FREE(path);
continue;
}
FREE(path);
ret++;
}
if (!ret)
{
printf("No files appended to image!\n");
iso_image_unref(image);
iso_write_opts_free(opts);
iso_finish();
2008-04-07 23:02:05 +00:00
return NULL;
}
iso_image_create_burn_source(image, opts, &data_src);
iso_write_opts_free(opts);
iso_image_unref(image);
FIFO_CREATE:
fifo_src = burn_fifo_source_new(data_src,
proj->fifo_chunksize, proj->fifo_chunks, 0);
burn_source_free(data_src);
2008-04-08 01:45:30 +00:00
/* I can't call this now, as it destroys the libiso_msgr before the
* library is finished - I'll just init and finish once...
*/
2008-05-15 00:14:33 +00:00
2008-04-08 01:45:30 +00:00
//iso_finish();
efreet_mime_shutdown();
return fifo_src;
}