It doesn't do much, but I've felt that we should at least index the
files stored in an archive for the longest time, so I'm starting that
project. I'll add the tar/gzip variants later tonight.

This indexes the names of all the files in an archive, as well as the
metadata dc:numFiles

I'm looking for feedback, so be brutal ;)

Cheers,
Kevin Kubasik
//
// FilterZip.cs: Very simplistic Zip filter, just gets names of all files in archive
//
// Author:
//   Kevin Kubasik <[EMAIL PROTECTED]>
//

using System;
using System.IO;
using System.Diagnostics;

using Beagle.Util;
using Beagle.Daemon;
namespace Beagle.Filters {

	public class FilterZip : Beagle.Daemon.Filter {
		StreamReader reader= null;
		public FilterZip(){
			AddSupportedFlavor (FilterFlavor.NewFromMimeType ("application/zip"));
			AddSupportedFlavor (FilterFlavor.NewFromExtension (".zip"));
			SnippetMode = true;
		}
		
		override protected void DoPull (){
			Process pc = new Process ();
			pc.StartInfo.FileName = "zipinfo";
			// FIXME: We probably need to quote special chars in the path
			pc.StartInfo.Arguments = String.Format ("-2 " + FileInfo.FullName);
			pc.StartInfo.RedirectStandardInput = false;
			pc.StartInfo.RedirectStandardOutput = true;
			pc.StartInfo.UseShellExecute = false;
			try {
				pc.Start ();
			} catch (System.ComponentModel.Win32Exception) {
				Logger.Log.Warn ("Unable to find zipinfo in path; ZIP archive not indexed.");
				Finished ();
				return;
			}

			// Try to not kill CPU
			pc.PriorityClass = ProcessPriorityClass.Idle;

			StreamReader pout = pc.StandardOutput;			
			string str;
			while ((str = pout.ReadLine()) != null) {
				AppendText (str);
				AppendStructuralBreak ();
			}
			pout.Close ();
			pc.WaitForExit ();
			pc.Close ();
			Finished ();
		}
		
		override protected void DoPullProperties (){
			Process pc = new Process ();
			pc.StartInfo.FileName = "zipinfo";
			// FIXME: We probably need to quote special chars in the path
			pc.StartInfo.Arguments = String.Format ("-h " + FileInfo.FullName);
			pc.StartInfo.RedirectStandardInput = false;
			pc.StartInfo.RedirectStandardOutput = true;
			pc.StartInfo.UseShellExecute = false;
			try {
				pc.Start ();
			} catch (System.ComponentModel.Win32Exception) {
				Logger.Log.Warn ("Unable to find zipinfo in path; ZIP archive not indexed.");
				Finished ();
				return;
			}

			// Try to not kill CPU
			StreamReader pout = pc.StandardOutput;
			string str = null;
			string[] tokens = null;
			str = pout.ReadLine();
			tokens = str.Split (' ');
			AddProperty (Beagle.Property.NewKeyword ("dc:numFiles",tokens[tokens.Length-2]));
						
			pout.Close ();
			pc.WaitForExit ();
			pc.Close ();
			
		}
	
	}
	
}

_______________________________________________
Dashboard-hackers mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/dashboard-hackers

Reply via email to