3 // Copyright 2005 John Reilly
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software
\r
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
19 // Linking this library statically or dynamically with other modules is
\r
20 // making a combined work based on this library. Thus, the terms and
\r
21 // conditions of the GNU General Public License cover the whole
\r
24 // As a special exception, the copyright holders of this library give you
\r
25 // permission to link this library with independent modules to produce an
\r
26 // executable, regardless of the license terms of these independent
\r
27 // modules, and to copy and distribute the resulting executable under
\r
28 // terms of your choice, provided that you also meet, for each linked
\r
29 // independent module, the terms and conditions of the license of that
\r
30 // module. An independent module is a module which is not derived from
\r
31 // or based on this library. If you modify this library, you may extend
\r
32 // this exception to your version of the library, but you are not
\r
33 // obligated to do so. If you do not wish to do so, delete this
\r
34 // exception statement from your version.
\r
40 namespace ICSharpCode.SharpZipLib.Core
\r
43 /// Scanning filters support these operations.
\r
45 public interface IScanFilter
\r
48 /// Test a name to see if is 'matches' the filter.
\r
50 /// <param name="name">The name to test.</param>
\r
51 /// <returns>Returns true if the name matches the filter, false if it does not match.</returns>
\r
52 bool IsMatch(string name);
\r
56 /// PathFilter filters directories and files by full path name.
\r
58 public class PathFilter : IScanFilter
\r
61 /// Initialise a new instance of <see cref="PathFilter"></see>.
\r
63 /// <param name="filter">The <see cref="NameFilter"></see>filter expression to apply.</param>
\r
64 public PathFilter(string filter)
\r
66 nameFilter = new NameFilter(filter);
\r
70 /// Test a name to see if it matches the filter.
\r
72 /// <param name="name">The name to test.</param>
\r
73 /// <returns>True if the name matches, false otherwise.</returns>
\r
74 public virtual bool IsMatch(string name)
\r
76 return nameFilter.IsMatch(Path.GetFullPath(name));
\r
79 #region Instance Fields
\r
80 NameFilter nameFilter;
\r
85 /// NameAnsSizeFilter filters based on name and file size.
\r
87 public class NameAndSizeFilter : PathFilter
\r
91 /// Initialise a new instance of NameAndSizeFilter.
\r
93 /// <param name="filter">The filter to apply.</param>
\r
94 /// <param name="minSize">The minimum file size to include.</param>
\r
95 /// <param name="maxSize">The maximum file size to include.</param>
\r
96 public NameAndSizeFilter(string filter, long minSize, long maxSize) : base(filter)
\r
98 this.minSize = minSize;
\r
99 this.maxSize = maxSize;
\r
103 /// Test a filename to see if it matches the filter.
\r
105 /// <param name="fileName">The filename to test.</param>
\r
106 /// <returns>True if the filter matches, false otherwise.</returns>
\r
107 public override bool IsMatch(string fileName)
\r
109 FileInfo fileInfo = new FileInfo(fileName);
\r
110 long length = fileInfo.Length;
\r
111 return base.IsMatch(fileName) &&
\r
112 (MinSize <= length) && (MaxSize >= length);
\r
118 /// The minimum size for a file that will match this filter.
\r
120 public long MinSize
\r
122 get { return minSize; }
\r
123 set { minSize = value; }
\r
126 long maxSize = long.MaxValue;
\r
129 /// The maximum size for a file that will match this filter.
\r
131 public long MaxSize
\r
133 get { return maxSize; }
\r
134 set { maxSize = value; }
\r