sound-juicer r2039 - in trunk: . src



Author: rburton
Date: Wed Feb 13 16:34:52 2008
New Revision: 2039
URL: http://svn.gnome.org/viewvc/sound-juicer?rev=2039&view=rev

Log:
2008-02-13  Ross Burton  <ross burtonini com>

	* src/sj-extracting.c:
	When extracting write to a temporary file and rename it when
	finished, so that cancelling when overwriting doesn't remove the
	previously ripped track (#172543, thanks Matthew Martin).


Modified:
   trunk/ChangeLog
   trunk/src/sj-extracting.c

Modified: trunk/src/sj-extracting.c
==============================================================================
--- trunk/src/sj-extracting.c	(original)
+++ trunk/src/sj-extracting.c	Wed Feb 13 16:34:52 2008
@@ -122,7 +122,7 @@
  * have finished with it.
  */
 static char*
-build_filename (const TrackDetails *track, GError **error)
+build_filename (const TrackDetails *track, gboolean temp_filename, GError **error)
 {
   GnomeVFSURI *uri, *new; 
   gchar *realfile, *realpath, *filename, *string;
@@ -156,7 +156,11 @@
     return NULL;
   }
   realfile = filepath_parse_pattern (file_pattern, track);
-  filename = g_strdup_printf("%.*s.%s", max_realfile, realfile, extension);
+  if (temp_filename) {
+    filename = g_strdup_printf (".%.*s.%s", max_realfile-1, realfile, extension);
+  } else {
+    filename = g_strdup_printf ("%.*s.%s", max_realfile, realfile, extension);
+  }
   new = gnome_vfs_uri_append_file_name (uri, filename);
   gnome_vfs_uri_unref (uri); uri = new;
   g_free (filename); g_free (realfile);
@@ -363,13 +367,17 @@
     g_assert_not_reached ();
   } else {
     TrackDetails *track = NULL;
-    char *file_path = NULL, *directory;
+    char *file_path = NULL, *temp_file_path = NULL, *directory;
     GError *error = NULL;
 
     /* Pop the next track to extract */
     gtk_tree_model_get (GTK_TREE_MODEL (track_store), &current, COLUMN_DETAILS, &track, -1);
     /* Build the filename for this track */
-    file_path = build_filename (track, &error);
+    file_path = build_filename (track, FALSE, &error);
+    if (error) {
+      goto error;
+    }
+    temp_file_path = build_filename (track, TRUE, &error);
     if (error) {
       goto error;
     }
@@ -418,7 +426,7 @@
     gtk_tree_path_free(path);
 
     /* Now actually do the extraction */
-    sj_extractor_extract_track (extractor, track, file_path, &error);
+    sj_extractor_extract_track (extractor, track, temp_file_path, &error);
     if (error) {
       goto error;
     }
@@ -428,6 +436,7 @@
     g_error_free (error);
 local_cleanup:
     g_free (file_path);
+    g_free (temp_file_path);
   }
 }
 
@@ -583,6 +592,7 @@
 on_completion_cb (SjExtractor *extractor, gpointer data)
 {
   TrackDetails *track = NULL;
+  char *temp_file_path, *new_file_path;
 
   /* Only manipulate the track state if we have an album, as we might be here if
      the disk was ejected mid-rip. */
@@ -596,6 +606,15 @@
   gtk_tree_model_get (GTK_TREE_MODEL (track_store), &current,
                       COLUMN_DETAILS, &track, -1);
 
+
+
+    temp_file_path = build_filename (track, TRUE, NULL);
+    new_file_path = build_filename (track, FALSE, NULL);
+    gnome_vfs_move (temp_file_path, new_file_path, TRUE);
+
+    g_free (temp_file_path);
+    g_free (new_file_path);
+
   if (find_next ()) {
     /* Increment the duration */
     current_duration += track->duration;
@@ -644,7 +663,18 @@
 void
 on_progress_cancel_clicked (GtkWidget *button, gpointer user_data)
 {
+  TrackDetails *track = NULL;
+  char *file_path;
+
   sj_extractor_cancel_extract (extractor);
+  
+  gtk_tree_model_get (GTK_TREE_MODEL (track_store), &current,
+                      COLUMN_DETAILS, &track, -1);
+
+  file_path = build_filename (track, TRUE, NULL);
+  gnome_vfs_unlink (file_path);
+  g_free (file_path);
+
   cleanup ();
 }
 



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