[brasero] Recheck the flags after a blanking/formatting was done to update them as they may have changed



commit 84a823b7bbef119f208b8c9a1bcf029f92a869bb
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Sun Sep 6 13:58:38 2009 +0200

    Recheck the flags after a blanking/formatting was done to update them as they may have changed

 libbrasero-burn/brasero-burn.c |  327 +++++++++++++++++++++------------------
 1 files changed, 176 insertions(+), 151 deletions(-)
---
diff --git a/libbrasero-burn/brasero-burn.c b/libbrasero-burn/brasero-burn.c
index 390f45f..1c836e8 100644
--- a/libbrasero-burn/brasero-burn.c
+++ b/libbrasero-burn/brasero-burn.c
@@ -1760,10 +1760,125 @@ start:
 	return BRASERO_BURN_ERR;
 }
 
+static BraseroBurnResult
+brasero_burn_check_session_consistency (BraseroBurn *burn,
+					GError **error)
+{
+	BraseroMedia media;
+	BraseroBurnFlag flag;
+	BraseroBurnFlag flags;
+	BraseroBurnFlag retval;
+	BraseroBurnResult result;
+	BraseroTrackType *type = NULL;
+	BraseroBurnFlag supported = BRASERO_BURN_FLAG_NONE;
+	BraseroBurnFlag compulsory = BRASERO_BURN_FLAG_NONE;
+	BraseroBurnPrivate *priv = BRASERO_BURN_PRIVATE (burn);
+
+	BRASERO_BURN_DEBUG (burn, "Checking session consistency");
+
+	/* make sure there is a track in the session. */
+	type = brasero_track_type_new ();
+	brasero_burn_session_get_input_type (priv->session, type);
+
+	if (brasero_track_type_is_empty (type)
+	|| !brasero_burn_session_get_tracks (priv->session)) {
+		brasero_track_type_free (type);
+
+		BRASERO_BURN_DEBUG (burn, "No track set");
+		g_set_error (error,
+			     BRASERO_BURN_ERROR,
+			     BRASERO_BURN_ERROR_GENERAL,
+			     _("There is no track to be burnt"));
+		return BRASERO_BURN_ERR;
+	}
+	brasero_track_type_free (type);
+
+	/* make sure there is a drive set as burner. */
+	if (!brasero_burn_session_is_dest_file (priv->session)) {
+		BraseroDrive *burner;
+
+		burner = brasero_burn_session_get_burner (priv->session);
+		if (!burner) {
+			BRASERO_BURN_DEBUG (burn, "No burner specified.");
+			g_set_error (error,
+				     BRASERO_BURN_ERROR,
+				     BRASERO_BURN_ERROR_OUTPUT_NONE,
+				     _("No burner specified"));
+			return BRASERO_BURN_ERR;	
+		}
+	}
+
+	media = brasero_burn_session_get_dest_media (priv->session);
+
+	/* save then wipe out flags from session to check them one by one */
+	flags = brasero_burn_session_get_flags (priv->session);
+	brasero_burn_session_set_flags (BRASERO_BURN_SESSION (priv->session), BRASERO_BURN_FLAG_NONE);
+
+	result = brasero_burn_session_get_burn_flags (priv->session,
+						      &supported,
+						      &compulsory);
+
+	if (result != BRASERO_BURN_OK)
+		return result;
+
+	for (flag = 1; flag < BRASERO_BURN_FLAG_LAST; flag <<= 1) {
+		/* see if this flag was originally set */
+		if (!(flags & flag))
+			continue;
+
+		/* Check each flag before re-adding it. Emit warnings to user
+		 * to know if he wants to carry on for some flags when they are
+		 * not supported; namely DUMMY. Other flags trigger an error.
+		 * No need for BURNPROOF since that usually means it is just the
+		 * media type that doesn't need it. */
+		if (supported & flag) {
+			brasero_burn_session_add_flag (priv->session, flag);
+			brasero_burn_session_get_burn_flags (priv->session,
+							     &supported,
+							     &compulsory);
+		}
+		else {
+			BRASERO_BURN_LOG_FLAGS (flag, "Flag set but not supported:");
+
+			if (flag & BRASERO_BURN_FLAG_DUMMY) {
+				/* This is simply a warning that it's not possible */
+
+			}
+			else if (flag & BRASERO_BURN_FLAG_MERGE) {
+				/* we pay attention to one flag in particular
+				 * (MERGE) if it was set then it must be
+				 * supported. Otherwise error out. */
+				g_set_error (error,
+					     BRASERO_BURN_ERROR,
+					     BRASERO_BURN_ERROR_GENERAL,
+					     _("Merging data is impossible with this disc"));
+				return BRASERO_BURN_ERR;
+			}
+			/* No need to tell the user burnproof is not supported
+			 * as these drives handle errors differently which makes
+			 * burnproof useless for them. */
+		}
+	}
+
+	retval = brasero_burn_session_get_flags (priv->session);
+	if (retval != flags)
+		BRASERO_BURN_LOG_FLAGS (retval, "Some flags were not supported. Corrected to");
+
+	if (retval != (retval | compulsory)) {
+		retval |= compulsory;
+		BRASERO_BURN_LOG_FLAGS (retval, "Some compulsory flags were forgotten. Corrected to");
+	}
+
+	brasero_burn_session_set_flags (priv->session, retval);
+	BRASERO_BURN_LOG_FLAGS (retval, "Flags after checking =");
+	return BRASERO_BURN_OK;
+}
+
 /* FIXME: at the moment we don't allow for mixed CD type */
 static BraseroBurnResult
 brasero_burn_run_tasks (BraseroBurn *burn,
 			gboolean erase_allowed,
+                        gboolean *dummy_session,
 			GError **error)
 {
 	BraseroBurnResult result;
@@ -1780,6 +1895,16 @@ brasero_burn_run_tasks (BraseroBurn *burn,
 	priv->task_nb = g_slist_length (tasks);
 	BRASERO_BURN_LOG ("%i tasks to perform", priv->task_nb);
 
+	/* push the session settings to keep the original session untainted */
+	brasero_burn_session_push_settings (priv->session);
+
+	/* check flags consistency */
+	result = brasero_burn_check_session_consistency (burn, error);
+	if (result != BRASERO_BURN_OK) {
+		brasero_burn_session_pop_settings (priv->session);
+		return result;
+	}
+
 	/* run all imaging tasks first */
 	for (iter = tasks; iter; iter = next) {
 		goffset len = 0;
@@ -1800,9 +1925,19 @@ brasero_burn_run_tasks (BraseroBurn *burn,
 				  G_CALLBACK (brasero_burn_action_changed),
 				  burn);
 
-		/* see what type of task it is. It could be a blank/erase one */
+		/* see what type of task it is. It could be a blank/erase one. */
+		/* FIXME!
+		 * If so then that's time to test the size of the image against
+		 * the size of the disc since erasing/formatting is always left
+		 * for the end, just before burning. We would not like to 
+		 * blank a disc and tell the user right after that the size of
+		 * the disc is not enough. */
 		action = brasero_task_ctx_get_action (BRASERO_TASK_CTX (priv->task));
 		if (action == BRASERO_TASK_ACTION_ERASE) {
+			/* FIXME: how could it be possible for a drive to test
+			 * with a CLOSED CDRW for example. Maybe we should
+			 * format/blank anyway. */
+
 			/* This is to avoid a potential problem when running a 
 			 * dummy session first. When running dummy session the 
 			 * media gets erased if need be. Since it is not
@@ -1812,6 +1947,31 @@ brasero_burn_run_tasks (BraseroBurn *burn,
 				result = brasero_burn_run_eraser (burn, error);
 				if (result != BRASERO_BURN_OK)
 					break;
+
+				/* Reprobe. It can happen (like with dvd+rw-format) that
+				 * for the whole OS, the disc doesn't exist during the 
+				 * formatting. Wait for the disc to reappear */
+				/*  Likewise, this is necessary when we do a
+				 * simulation before blanking since it blanked the disc
+				 * and then to create all tasks necessary for the real
+				 * burning operation, we'll need the real medium status 
+				 * not to include a blanking job again. */
+				result = brasero_burn_reprobe (burn);
+				if (result != BRASERO_BURN_OK)
+					break;
+
+				/* Since we blanked/formatted we need to recheck the burn 
+				 * flags with the new medium type as some flags could have
+				 * been given the benefit of the double (MULTI with a CLOSED
+				 * CD for example). Recheck the original flags as they were
+				 * passed. */
+				/* FIXME: for some important flags we should warn the user
+				 * that it won't be possible */
+				brasero_burn_session_pop_settings (priv->session);
+				brasero_burn_session_push_settings (priv->session);
+				result = brasero_burn_check_session_consistency (burn, error);
+				if (result != BRASERO_BURN_OK)
+					break;
 			}
 			else
 				result = BRASERO_BURN_OK;
@@ -1820,18 +1980,6 @@ brasero_burn_run_tasks (BraseroBurn *burn,
 			priv->task = NULL;
 			priv->tasks_done ++;
 
-			/* Reprobe. It can happen (like with dvd+rw-format) that
-			 * for the whole OS, the disc doesn't exist during the 
-			 * formatting. Wait for the disc to reappear */
-			/*  Likewise, this is necessary when we do a
-			 * simulation before blanking since it blanked the disc
-			 * and then to create all tasks necessary for the real
-			 * burning operation, we'll need the real medium status 
-			 * not to include a blanking job again. */
-			result = brasero_burn_reprobe (burn);
-			if (result != BRASERO_BURN_OK)
-				break;
-
 			continue;
 		}
 
@@ -1864,10 +2012,12 @@ brasero_burn_run_tasks (BraseroBurn *burn,
 
 		/* see if we reached a recording task: it's the last task */
 		if (!next) {
-			if (brasero_burn_session_is_dest_file (priv->session))
-				result = brasero_burn_run_imager (burn, FALSE, error);
-			else
+			if (!brasero_burn_session_is_dest_file (priv->session)) {
+				*dummy_session = (brasero_burn_session_get_flags (priv->session) & BRASERO_BURN_FLAG_DUMMY);
 				result = brasero_burn_run_recorder (burn, error);
+			}
+			else
+				result = brasero_burn_run_imager (burn, FALSE, error);
 
 			if (result == BRASERO_BURN_OK)
 				priv->tasks_done ++;
@@ -1885,6 +2035,11 @@ brasero_burn_run_tasks (BraseroBurn *burn,
 		priv->tasks_done ++;
 	}
 
+	/* restore the session settings. Keep the used flags
+	 * nevertheless to make sure we actually use the flags that were
+	 * set after checking for session consistency. */
+	brasero_burn_session_pop_settings (priv->session);
+
 	if (priv->task) {
 		g_object_unref (priv->task);
 		priv->task = NULL;
@@ -1972,120 +2127,6 @@ brasero_burn_check_real (BraseroBurn *self,
 	return result;
 }
 
-static BraseroBurnResult
-brasero_burn_check_session_consistency (BraseroBurn *burn,
-					GError **error)
-{
-	BraseroMedia media;
-	BraseroBurnFlag flag;
-	BraseroBurnFlag flags;
-	BraseroBurnFlag retval;
-	BraseroBurnResult result;
-	BraseroTrackType *type = NULL;
-	BraseroBurnFlag supported = BRASERO_BURN_FLAG_NONE;
-	BraseroBurnFlag compulsory = BRASERO_BURN_FLAG_NONE;
-	BraseroBurnPrivate *priv = BRASERO_BURN_PRIVATE (burn);
-
-	BRASERO_BURN_DEBUG (burn, "Checking session consistency");
-
-	/* make sure there is a track in the session. */
-	type = brasero_track_type_new ();
-	brasero_burn_session_get_input_type (priv->session, type);
-
-	if (brasero_track_type_is_empty (type)
-	|| !brasero_burn_session_get_tracks (priv->session)) {
-		brasero_track_type_free (type);
-
-		BRASERO_BURN_DEBUG (burn, "No track set");
-		g_set_error (error,
-			     BRASERO_BURN_ERROR,
-			     BRASERO_BURN_ERROR_GENERAL,
-			     _("There is no track to be burnt"));
-		return BRASERO_BURN_ERR;
-	}
-	brasero_track_type_free (type);
-
-	/* make sure there is a drive set as burner. */
-	if (!brasero_burn_session_is_dest_file (priv->session)) {
-		BraseroDrive *burner;
-
-		burner = brasero_burn_session_get_burner (priv->session);
-		if (!burner) {
-			BRASERO_BURN_DEBUG (burn, "No burner specified.");
-			g_set_error (error,
-				     BRASERO_BURN_ERROR,
-				     BRASERO_BURN_ERROR_OUTPUT_NONE,
-				     _("No burner specified"));
-			return BRASERO_BURN_ERR;	
-		}
-	}
-
-	media = brasero_burn_session_get_dest_media (priv->session);
-
-	/* save then wipe out flags from session to check them one by one */
-	flags = brasero_burn_session_get_flags (priv->session);
-	brasero_burn_session_set_flags (BRASERO_BURN_SESSION (priv->session), BRASERO_BURN_FLAG_NONE);
-
-	result = brasero_burn_session_get_burn_flags (priv->session,
-						      &supported,
-						      &compulsory);
-
-	if (result != BRASERO_BURN_OK)
-		return result;
-
-	for (flag = 1; flag < BRASERO_BURN_FLAG_LAST; flag <<= 1) {
-		/* see if this flag was originally set */
-		if (!(flags & flag))
-			continue;
-
-		/* Check each flag before re-adding it. Emit warnings to user
-		 * to know if he wants to carry on for some flags when they are
-		 * not supported; namely DUMMY. Other flags trigger an error.
-		 * No need for BURNPROOF since that usually means it is just the
-		 * media type that doesn't need it. */
-		if (supported & flag) {
-			brasero_burn_session_add_flag (priv->session, flag);
-			brasero_burn_session_get_burn_flags (priv->session,
-							     &supported,
-							     &compulsory);
-		}
-		else {
-			BRASERO_BURN_LOG_FLAGS (flag, "Flag set but not supported:");
-
-			if (flag & BRASERO_BURN_FLAG_DUMMY) {
-				/* This is simply a warning that it's not possible */
-
-			}
-			else if (flag & BRASERO_BURN_FLAG_MERGE) {
-				/* we pay attention to one flag in particular
-				 * (MERGE) if it was set then it must be
-				 * supported. Otherwise error out. */
-				g_set_error (error,
-					     BRASERO_BURN_ERROR,
-					     BRASERO_BURN_ERROR_GENERAL,
-					     _("Merging data is impossible with this disc"));
-				return BRASERO_BURN_ERR;
-			}
-			/* No need to tell the user burnproof is not supported
-			 * as these drives handle errors differently which makes
-			 * burnproof useless for them. */
-		}
-	}
-
-	retval = brasero_burn_session_get_flags (priv->session);
-	if (retval != flags)
-		BRASERO_BURN_LOG_FLAGS (retval, "Some flags were not supported. Corrected to");
-
-	if (retval != (retval | compulsory)) {
-		retval |= compulsory;
-		BRASERO_BURN_LOG_FLAGS (retval, "Some compulsory flags were forgotten. Corrected to");
-	}
-
-	brasero_burn_session_set_flags (priv->session, retval);
-	BRASERO_BURN_LOG_FLAGS (retval, "Flags after checking =");
-	return BRASERO_BURN_OK;
-}
-
 static void
 brasero_burn_unset_checksums (BraseroBurn *self)
 {
@@ -2112,33 +2153,22 @@ brasero_burn_record_session (BraseroBurn *burn,
 			     GError **error)
 {
 	const gchar *checksum = NULL;
-	BraseroBurnFlag session_flags;
 	BraseroTrack *track = NULL;
 	BraseroChecksumType type;
 	BraseroBurnPrivate *priv;
 	BraseroBurnResult result;
 	GError *ret_error = NULL;
 	BraseroMedium *medium;
+	gboolean dummy_session;
 	GSList *tracks;
 
 	priv = BRASERO_BURN_PRIVATE (burn);
 
-	/* unset checksum since no image has the exact same even if it is 
-	 * created from the same files */
+	/* unset checksum since no image has the exact
+	 * same even if it is created from the same files */
 	brasero_burn_unset_checksums (burn);
 
-	session_flags = BRASERO_BURN_FLAG_NONE;
 	do {
-		/* push the session settings to keep the original session untainted */
-		brasero_burn_session_push_settings (priv->session);
-
-		/* check flags consistency */
-		result = brasero_burn_check_session_consistency (burn, error);
-		if (result != BRASERO_BURN_OK) {
-			brasero_burn_session_pop_settings (priv->session);
-			break;
-		}
-
 		if (ret_error) {
 			g_error_free (ret_error);
 			ret_error = NULL;
@@ -2146,13 +2176,8 @@ brasero_burn_record_session (BraseroBurn *burn,
 
 		result = brasero_burn_run_tasks (burn,
 						 erase_allowed,
+		                                 &dummy_session,
 						 &ret_error);
-
-		/* restore the session settings. Keep the used flags
-		 * nevertheless to make sure we actually use the flags that were
-		 * set after checking for session consistency. */
-		session_flags = brasero_burn_session_get_flags (priv->session);
-		brasero_burn_session_pop_settings (priv->session);
 	} while (result == BRASERO_BURN_RETRY);
 
 	if (result != BRASERO_BURN_OK) {
@@ -2171,7 +2196,7 @@ brasero_burn_record_session (BraseroBurn *burn,
 	if (brasero_burn_session_is_dest_file (priv->session))
 		return BRASERO_BURN_OK;
 
-	if (session_flags & BRASERO_BURN_FLAG_DUMMY) {
+	if (dummy_session) {
 		/* if we are in dummy mode and successfully completed then:
 		 * - no need to checksum the media afterward (done later)
 		 * - no eject to have automatic real burning */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]