There are no available options for this view.

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1.9 - (download) (annotate)
Sun Dec 31 05:59:33 2006 UTC (3 years, 1 month ago) by chrislewis2030
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +18 -16 lines
Formatting
    1 using System;
    2 using System.IO;
    3 using System.Collections;
    4 using System.Configuration;
    5 using System.Web;
    6 
    7 namespace PhotoRoom.components
    8 {
    9 	/// <summary>
   10 	/// Summary description for DirectoryLister.
   11 	/// </summary>
   12 	public class DirectoryLister
   13 	{
   14 		/// <summary>
   15 		///
   16 		/// </summary>
   17 		public DirectoryLister()
   18 		{
   19 		}
   20 
   21 		/// <summary>
   22 		///
   23 		/// </summary>
   24 		/// <param name="directory"></param>
   25 		/// <returns></returns>
   26 		public string[] ListImages( string directory )
   27 		{
   28 			string s = Config.Current.ImageSearchPatterns;
   29 			string[] searchPatterns = s.Split( new Char[]{' '} );
   30 
   31 			ArrayList array = new ArrayList();
   32 			DirectoryInfo dir = new DirectoryInfo( HttpContext.Current.Server.MapPath( @".\" + directory ) );
   33 			for( int i=0; i < searchPatterns.Length; i++ )
   34 			{
   35 				foreach( FileInfo f in dir.GetFiles( searchPatterns[i] ))
   36 				{
   37 					array.Add( directory + @"\" + f.Name );
   38 				}
   39 			}
   40 			return (string[]) array.ToArray( typeof( string ) );
   41 		}
   42 
   43 		/// <summary>
   44 		///
   45 		/// </summary>
   46 		/// <param name="directory"></param>
   47 		/// <returns></returns>
   48 		public string[] ListDirectories( string directory )
   49 		{
   50 			const char SEPARATOR = '|';
   51 			string exclude = Config.Current.ExcludeDirectories;
   52 			string[] excludePatterns = exclude.Split(	new Char[]{SEPARATOR} );
   53 
   54 			ArrayList array = new ArrayList();
   55 			DirectoryInfo dir = new DirectoryInfo( HttpContext.Current.Server.MapPath( @".\" + directory ) );
   56 			foreach( DirectoryInfo d in dir.GetDirectories() )
   57 			{
   58 				bool addDirectory = true;
   59 				foreach( string str in excludePatterns)
   60 				{
   61 					if( string.Compare(d.Name, str, true) == 0 )
   62 					{
   63 						addDirectory = false;
   64 						break;
   65 					}
   66 				}
   67 				if( addDirectory) { array.Add( d.Name ); }
   68 			}
   69 
   70 			// Sort the array.
   71 			if( Config.Current.DirectorySortOrder == SortOrder.Ascending )
   72 			{
   73 				array.Sort();
   74 			}
   75 			else
   76 			{
   77 				array.Sort(
   78 					new ReverseComparer(
   79 					new GenericComparer( new GenericComparer.ComparisonDelegate( this.Compare ) )
   80 					));
   81 			}
   82 
   83 			return (string[]) array.ToArray( typeof( string ) );
   84 		}
   85 
   86 		/// <summary>
   87 		///
   88 		/// </summary>
   89 		/// <param name="x"></param>
   90 		/// <param name="y"></param>
   91 		/// <returns></returns>
   92 		public int Compare( object x, object y )
   93 		{
   94 			int i=0;
   95 			if( x is String && y is String )
   96 			{
   97 				i = ((String)x).CompareTo(y);
   98 			}
   99 			return i;
  100 		}
  101 	}
  102 }