Commit 961c3bc9 authored by Philippe Rouquier's avatar Philippe Rouquier

Improve data project size accuracy

parent c303937a
......@@ -54,6 +54,10 @@ struct _BraseroDataOptionsPrivate
guint joliet_saved:1;
};
/* FIXME: we need to react to a valid signal so that if joliet is on and the
* session is invalid we can try to see if deactivating it can make things
* workable again. */
#define BRASERO_DATA_OPTIONS_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), BRASERO_TYPE_DATA_OPTIONS, BraseroDataOptionsPrivate))
enum {
......
......@@ -2644,6 +2644,7 @@ struct _MakeTrackDataSpan {
GSList *joliet_grafts;
guint64 files_num;
guint64 dir_num;
BraseroImageFS fs_type;
};
......@@ -2682,8 +2683,10 @@ brasero_data_project_span_explore_folder_children (MakeTrackDataSpan *data,
brasero_data_project_span_set_fs_type (data, node);
data->files_num ++;
}
else
else {
brasero_data_project_span_explore_folder_children (data, node);
data->dir_num ++;
}
}
}
......@@ -2778,6 +2781,44 @@ brasero_data_project_span_generate (BraseroDataProject *self,
brasero_track_data_set_source (track, grafts, excluded);
}
goffset
brasero_data_project_improve_image_size_accuracy (goffset sectors,
guint64 dir_num,
BraseroImageFS fs_type)
{
/* sector number should be increased in the following way to get
* a more accurate number:
* - the first (empty most of the time) 16 sectors
* - primary volume descriptor block
* - terminator volume descriptor block
* - one sector for root (and one more if there is joliet)
* - 4 sectors for the path table (at least!!)
* - for every directory add a block (for all entry records)
* and another one if there is joliet on
*/
sectors += 23;
sectors += dir_num * 1;
if (fs_type & BRASERO_IMAGE_FS_JOLIET) {
/* For joliet :
* - 1 sector for the volume descriptor
* - 1 sector for the root descriptor
* - 4 sectors for the path table (at least!!)
*/
sectors += 6;
/* For joliet 2 sectors per directory (at least!!) */
sectors += dir_num * 2;
}
/* Finally there is a 150 pad block at the end (only with mkisofs !!).
* That was probably done to avoid getting an image whose size would be
* less than 1 sec??? */
sectors += 150;
return sectors;
}
BraseroBurnResult
brasero_data_project_span (BraseroDataProject *self,
goffset max_sectors,
......@@ -2796,6 +2837,7 @@ brasero_data_project_span (BraseroDataProject *self,
if (!g_hash_table_size (priv->grafts))
return BRASERO_BURN_ERR;
callback_data.dir_num = 0;
callback_data.files_num = 0;
callback_data.grafts = NULL;
callback_data.joliet_grafts = NULL;
......@@ -2869,8 +2911,10 @@ brasero_data_project_span (BraseroDataProject *self,
brasero_data_project_span_set_fs_type (&callback_data, children);
callback_data.files_num ++;
}
else
else {
brasero_data_project_span_explore_folder_children (&callback_data, children);
callback_data.dir_num ++;
}
priv->spanned = g_slist_prepend (priv->spanned, children);
children = children->next;
......@@ -2887,6 +2931,10 @@ brasero_data_project_span (BraseroDataProject *self,
append_slash,
track);
total_sectors = brasero_data_project_improve_image_size_accuracy (total_sectors,
callback_data.dir_num,
callback_data.fs_type);
brasero_track_data_set_data_blocks (track, total_sectors);
brasero_track_data_add_fs (track, callback_data.fs_type);
brasero_track_data_set_file_num (track, callback_data.files_num);
......
......@@ -125,6 +125,10 @@ brasero_data_project_reset (BraseroDataProject *project);
goffset
brasero_data_project_get_sectors (BraseroDataProject *project);
goffset
brasero_data_project_improve_image_size_accuracy (goffset blocks,
guint64 dir_num,
BraseroImageFS fs_type);
goffset
brasero_data_project_get_folder_sectors (BraseroDataProject *project,
BraseroFileNode *node);
......
......@@ -771,7 +771,14 @@ brasero_file_node_add (BraseroFileNode *parent,
if (BRASERO_FILE_NODE_VIRTUAL (node))
return;
stats = brasero_file_node_get_tree_stats (node->parent, &depth);
if (!node->is_imported) {
/* book keeping */
if (!node->is_file)
stats->num_dir ++;
else
stats->children ++;
/* NOTE: parent will be changed afterwards !!! */
if (!node->is_grafted) {
/* propagate the size change*/
......@@ -785,7 +792,6 @@ brasero_file_node_add (BraseroFileNode *parent,
/* Even imported should be included. The only type of nodes that are not
* heeded are the virtual nodes. */
stats = brasero_file_node_get_tree_stats (node->parent, &depth);
if (node->is_file) {
if (depth < 6)
return;
......@@ -807,13 +813,19 @@ brasero_file_node_set_from_info (BraseroFileNode *node,
* creation of a graft). If someone wants to set a new name,
* then rename_node is the function. */
/* update the stats since a file could have been added to the tree but
* at this point we didn't know what it was (a file or a directory).
* Only do this if it wasn't a file before. */
if (!node->is_file
&& (g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY)) {
/* only count files */
stats->children ++;
if (node->parent) {
/* update the stats since a file could have been added to the tree but
* at this point we didn't know what it was (a file or a directory).
* Only do this if it wasn't a file before.
* Do this only if it's in the tree. */
if (!node->is_file && (g_file_info_get_file_type (info) != G_FILE_TYPE_DIRECTORY)) {
stats->children ++;
stats->num_dir --;
}
else if (node->is_file && (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY)) {
stats->children --;
stats->num_dir ++;
}
}
if (!node->is_symlink
......@@ -1129,9 +1141,13 @@ brasero_file_node_destroy_with_children (BraseroFileNode *node,
if (node->is_symlink)
stats->num_sym --;
/* update file number statistics */
if (!node->is_imported && node->is_file)
stats->children --;
/* update file/directory number statistics */
if (!node->is_imported) {
if (node->is_file)
stats->children --;
else
stats->num_dir --;
}
}
/* destruction */
......
......@@ -72,6 +72,7 @@ typedef struct _BraseroImport BraseroImport;
struct _BraseroFileTreeStats {
guint children;
guint num_dir;
guint num_deep;
guint num_2GiB;
guint num_sym;
......
......@@ -2251,8 +2251,22 @@ brasero_track_data_cfg_get_size (BraseroTrack *track,
priv = BRASERO_TRACK_DATA_CFG_PRIVATE (track);
sectors = brasero_data_project_get_sectors (BRASERO_DATA_PROJECT (priv->tree));
if (blocks)
if (blocks) {
BraseroFileNode *root;
BraseroImageFS fs_type;
BraseroFileTreeStats *stats;
if (!sectors)
return sectors;
fs_type = brasero_track_data_cfg_get_fs (BRASERO_TRACK_DATA (track));
root = brasero_data_project_get_root (BRASERO_DATA_PROJECT (priv->tree));
stats = BRASERO_FILE_NODE_STATS (root);
sectors = brasero_data_project_improve_image_size_accuracy (sectors,
stats->num_dir,
fs_type);
*blocks = sectors;
}
if (block_size)
*block_size = 2048;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment