[ease] Archive restructuring.



commit f22ec520af3cfb051e211d6dd866bd5ceffc2554
Author: Nate Stedman <natesm gmail com>
Date:   Thu Aug 19 19:13:37 2010 -0400

    Archive restructuring.
    
    - extract function moves from Temp to Archiver.
    - "archive" becomes "create"

 ease-core/ease-archiver.vala |   73 ++++++++++++++++++++++++++++++++++++------
 ease-core/ease-document.vala |    4 +-
 ease-core/ease-slide.vala    |    2 +-
 ease-core/ease-temp.vala     |   53 ------------------------------
 4 files changed, 66 insertions(+), 66 deletions(-)
---
diff --git a/ease-core/ease-archiver.vala b/ease-core/ease-archiver.vala
index 156acd6..2a97589 100644
--- a/ease-core/ease-archiver.vala
+++ b/ease-core/ease-archiver.vala
@@ -15,7 +15,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-internal class Ease.Archiver : GLib.Object
+private class Ease.Archiver.Archiver : GLib.Object
 {
 	private string temp_path;
 	private string filename;
@@ -26,8 +26,6 @@ internal class Ease.Archiver : GLib.Object
 	private Gee.LinkedList<string> include_files;
 	
 	private static GLib.List<Archiver> archivers = new GLib.List<Archiver>();
-	
-	private const int ARCHIVE_BUFFER = 4096;
 	private const string LABEL_TEXT = _("Saving \"%s\"");
 	
 	/**
@@ -75,7 +73,7 @@ internal class Ease.Archiver : GLib.Object
 	 * Does the actual archiving of a directory.
 	 */
 	private void* archive_real()
-	{	
+	{
 		// create a writable archive
 		var archive = new Archive.Write();
 		var buffer = new char[ARCHIVE_BUFFER];
@@ -151,8 +149,10 @@ internal class Ease.Archiver : GLib.Object
 	}
 }
 
-namespace Ease
+namespace Ease.Archiver
 {
+	private const int ARCHIVE_BUFFER = 4096;
+	
 	/**
 	 * Asynchronously (if supported) creates an archive from a temporary
 	 * directory. Otherwise, falls back on synchronous archiving.
@@ -165,11 +165,11 @@ namespace Ease
 	 * @param files The files to include in the archive.
 	 * @param win The window to display a progress dialog modal for.
 	 */
-	internal static void archive(string temp_path,
-		                         string filename,
-		                         string title,
-		                         Gee.LinkedList<string> files,
-		                         Gtk.Window? win) throws Error
+	internal static void create(string temp_path,
+		                        string filename,
+		                        string title,
+		                        Gee.LinkedList<string> files,
+		                        Gtk.Window? win) throws Error
 	{
 		// create a progress dialog
 		var dialog = new Dialog.Progress(title, false, 1, win);
@@ -177,4 +177,57 @@ namespace Ease
 		// archive away!
 		var arc = new Archiver(temp_path, filename, files, dialog);
 	}
+	
+	/**
+	 * Creates a temporary directory and extracts an archive to it.
+	 *
+	 * extract() uses libarchive for extraction. It will automatically request
+	 * a new temporary directory, extract the archive, and return the path
+	 * to the extracted files.
+	 *
+	 * @param filename The path of the archive to extract.
+	 */
+	internal static string extract(string filename) throws GLib.Error
+	{
+		// initialize the archive
+		var archive = new Archive.Read();
+		
+		// automatically detect archive type
+		archive.support_compression_all();
+		archive.support_format_all();
+		
+		// open the archive
+		archive.open_filename(filename, ARCHIVE_BUFFER);
+		
+		// create a temporary directory to extract to
+		string path = Temp.request();
+		
+		// extract the archive
+		weak Archive.Entry entry;
+		while (archive.next_header(out entry) == Archive.Result.OK)
+		{
+			var fpath = Path.build_filename(path, entry.pathname());
+			var file = GLib.File.new_for_path(fpath);
+			
+			if (Posix.S_ISDIR(entry.mode()))
+			{
+				file.make_directory_with_parents(null);
+			}
+			else
+			{
+				var parent = file.get_parent();
+				if (!parent.query_exists(null))
+				{
+					parent.make_directory_with_parents(null);
+				}
+				
+				file.create(FileCreateFlags.REPLACE_DESTINATION, null);
+				int fd = Posix.open(fpath, Posix.O_WRONLY, 0644);
+				archive.read_data_into_fd(fd);
+				Posix.close(fd);
+			}
+		}
+		
+		return path;
+	}
 }
diff --git a/ease-core/ease-document.vala b/ease-core/ease-document.vala
index 9a9d398..8289b99 100644
--- a/ease-core/ease-document.vala
+++ b/ease-core/ease-document.vala
@@ -129,7 +129,7 @@ public class Ease.Document : GLib.Object, UndoSource
 		this();
 		
 		filename = absolute_path(file_path);
-		path = Temp.extract(filename);
+		path = Archiver.extract(filename);
 	
 		var parser = new Json.Parser();
 		
@@ -257,7 +257,7 @@ public class Ease.Document : GLib.Object, UndoSource
 		}
 		
 		// archive
-		archive(path, filename, _("Saving Document"), files, window);
+		Archiver.create(path, filename, _("Saving Document"), files, window);
 	}
 	
 	/**
diff --git a/ease-core/ease-slide.vala b/ease-core/ease-slide.vala
index 44e7733..bf847d0 100644
--- a/ease-core/ease-slide.vala
+++ b/ease-core/ease-slide.vala
@@ -675,7 +675,7 @@ public class Ease.Slide : GLib.Object, UndoSource
 	
 	/**
 	 * Updates the slide's title if the given object is a TextElement with the
-	 * { link Theme.TITLE_TEXT} identifier.
+	 * { link Theme.TITLE_TEXT} or { link HEADER_TEXT} identifier.
 	 */
 	private void update_title(GLib.Object object)
 	{
diff --git a/ease-core/ease-temp.vala b/ease-core/ease-temp.vala
index 0d197cb..05e5bde 100644
--- a/ease-core/ease-temp.vala
+++ b/ease-core/ease-temp.vala
@@ -124,59 +124,6 @@ public static class Ease.Temp : Object
 	}
 	
 	/**
-	 * Creates a temporary directory and extracts an archive to it.
-	 *
-	 * extract() uses libarchive for extraction. It will automatically request
-	 * a new temporary directory, extract the archive, and return the path
-	 * to the extracted files.
-	 *
-	 * @param filename The path of the archive to extract.
-	 */
-	internal static string extract(string filename) throws GLib.Error
-	{
-		// initialize the archive
-		var archive = new Archive.Read();
-		
-		// automatically detect archive type
-		archive.support_compression_all();
-		archive.support_format_all();
-		
-		// open the archive
-		archive.open_filename(filename, ARCHIVE_BUFFER);
-		
-		// create a temporary directory to extract to
-		string path = request();
-		
-		// extract the archive
-		weak Archive.Entry entry;
-		while (archive.next_header(out entry) == Archive.Result.OK)
-		{
-			var fpath = Path.build_filename(path, entry.pathname());
-			var file = GLib.File.new_for_path(fpath);
-			
-			if (Posix.S_ISDIR(entry.mode()))
-			{
-				file.make_directory_with_parents(null);
-			}
-			else
-			{
-				var parent = file.get_parent();
-				if (!parent.query_exists(null))
-				{
-					parent.make_directory_with_parents(null);
-				}
-				
-				file.create(FileCreateFlags.REPLACE_DESTINATION, null);
-				int fd = Posix.open(fpath, Posix.O_WRONLY, 0644);
-				archive.read_data_into_fd(fd);
-				Posix.close(fd);
-			}
-		}
-		
-		return path;
-	}
-	
-	/**
 	 * Deletes all temporary directories created by this instance of Ease.
 	 * Call when exiting.
 	 */



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