00001 // PathFilter.cs 00002 // 00003 // Copyright 2005 John Reilly 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // Linking this library statically or dynamically with other modules is 00020 // making a combined work based on this library. Thus, the terms and 00021 // conditions of the GNU General Public License cover the whole 00022 // combination. 00023 // 00024 // As a special exception, the copyright holders of this library give you 00025 // permission to link this library with independent modules to produce an 00026 // executable, regardless of the license terms of these independent 00027 // modules, and to copy and distribute the resulting executable under 00028 // terms of your choice, provided that you also meet, for each linked 00029 // independent module, the terms and conditions of the license of that 00030 // module. An independent module is a module which is not derived from 00031 // or based on this library. If you modify this library, you may extend 00032 // this exception to your version of the library, but you are not 00033 // obligated to do so. If you do not wish to do so, delete this 00034 // exception statement from your version. 00035 00036 00037 using System; 00038 using System.IO; 00039 00040 namespace ICSharpCode.SharpZipLib.Core 00041 { 00045 public interface IScanFilter 00046 { 00052 bool IsMatch(string name); 00053 } 00054 00058 public class PathFilter : IScanFilter 00059 { 00064 public PathFilter(string filter) 00065 { 00066 nameFilter = new NameFilter(filter); 00067 } 00068 00074 public virtual bool IsMatch(string name) 00075 { 00076 return nameFilter.IsMatch(Path.GetFullPath(name)); 00077 } 00078 00079 #region Instance Fields 00080 NameFilter nameFilter; 00081 #endregion 00082 } 00083 00087 public class NameAndSizeFilter : PathFilter 00088 { 00089 00096 public NameAndSizeFilter(string filter, long minSize, long maxSize) : base(filter) 00097 { 00098 this.minSize = minSize; 00099 this.maxSize = maxSize; 00100 } 00101 00107 public override bool IsMatch(string fileName) 00108 { 00109 FileInfo fileInfo = new FileInfo(fileName); 00110 long length = fileInfo.Length; 00111 return base.IsMatch(fileName) && 00112 (MinSize <= length) && (MaxSize >= length); 00113 } 00114 00115 long minSize = 0; 00116 00120 public long MinSize 00121 { 00122 get { return minSize; } 00123 set { minSize = value; } 00124 } 00125 00126 long maxSize = long.MaxValue; 00127 00131 public long MaxSize 00132 { 00133 get { return maxSize; } 00134 set { maxSize = value; } 00135 } 00136 } 00137 }