コード例 #1
0
ファイル: MatchSet.cs プロジェクト: cccapon/KeepBack
 //--- constructor -----------------------
 public MatchSet( CtrlFilter[] list, bool isCaseSensitive )
 {
     List<MatchPath> ifo = new List<MatchPath>();
     List<MatchPath> ifi = new List<MatchPath>();
     List<MatchPath> hfo = new List<MatchPath>();
     List<MatchPath> hfi = new List<MatchPath>();
     if( list != null )
     {
         foreach( CtrlFilter f in list )
         {
             string s = f.Pattern;
             if( ! string.IsNullOrEmpty( s ) )
             {
                 s = s.Trim();
                 if( ! string.IsNullOrEmpty( s ) )
                 {
                     MatchPath mp = new MatchPath( f.Action, s, isCaseSensitive );
                     switch( f.Action )
                     {
                         case CtrlFilter.ActionType.Include:  if( mp.IsDirectory ) { ifo.Add( mp ); } else { ifi.Add( mp ); } break;
                         case CtrlFilter.ActionType.Exclude:  if( mp.IsDirectory ) { ifo.Add( mp ); } else { ifi.Add( mp ); } break;
                         case CtrlFilter.ActionType.History:  if( mp.IsDirectory ) { hfo.Add( mp ); } else { hfi.Add( mp ); } break;
                     }
                 }
             }
         }
     }
     this.includeFolder  = ifo.ToArray();
     this.includeFile    = ifi.ToArray();
     this.historyFolder  = hfo.ToArray();
     this.historyFile    = hfi.ToArray();
 }
コード例 #2
0
ファイル: MatchPath.cs プロジェクト: cccapon/KeepBack
        //--- constructor -----------------------
        public MatchPath( CtrlFilter.ActionType action, string pattern, bool caseSensitive )
        {
            this.action  = action;
            this.pattern = pattern;
            //..we use a directory separator test a lot, so prepare the sequence
            string ds = Regex.Escape( Path.DirectorySeparatorChar.ToString() + Path.AltDirectorySeparatorChar.ToString() );
            string dsY = @"[" + ds + @"]";
            string dsN = @"[^" + ds + @"]";
            //..if a pattern ends with a folder character, it is intended to only match a directory
            //..otherwise, it is only intended to match a file
            if( isDirectory = EndsWithDirectorySeparator( pattern ) )
            {
                //..remove ending directory character
                pattern = pattern.Substring( 0, pattern.Length - 1 );
            }
            //..if a pattern starts with a folder character we assume it must match the entire path.
            //..if a pattern doesn't start with a folder character, we add one to ensure the pattern doesn't match only the latter part of a folder name.
            //..preceed special characters with the '\' escape character
            isFullPath = StartsWithDirectorySeparator( pattern );
            string s = isFullPath ? (@"^" + Regex.Escape( pattern )) : Regex.Escape( Path.DirectorySeparatorChar.ToString() + pattern );

            //..switch alternate directory separator characters to regular directory separator characters
            s = s.Replace( Regex.Escape( Path.AltDirectorySeparatorChar.ToString() ), Regex.Escape( Path.DirectorySeparatorChar.ToString() ) );
            //..switch directory separator characters for a pattern which matches either directory separator
            s = s.Replace( Regex.Escape( Path.DirectorySeparatorChar.ToString() ), dsY );
            //..check for the ... elipse
            s = s.Replace( dsY + Regex.Escape( @"..." ) + dsY, dsY + @"(.*" + dsY + @")*" );
            //..convert '?' character
            s = s.Replace( Regex.Escape( @"?" ), dsN + @"?" );
            //..convert '*' character
            s = s.Replace( Regex.Escape( @"*" ), dsN + @"*" );
            //..all patterns have to match the end of string
            s = s + @"$";

            RegexOptions opts = RegexOptions.Compiled | RegexOptions.Singleline;
            if( ! caseSensitive )
            {
                opts |= RegexOptions.IgnoreCase;
            }

            reg = new Regex( s, opts );
        }
コード例 #3
0
ファイル: FormEdit.cs プロジェクト: cccapon/KeepBack
 public FolderPattern( CtrlFolder folder, CtrlFilter filter )
 {
     this.folder  = folder;
     this.filter  = filter;
 }
コード例 #4
0
ファイル: FormEdit.cs プロジェクト: cccapon/KeepBack
 private int FilterImage( CtrlFilter fi )
 {
     switch( fi.Action )
     {
         case CtrlFilter.ActionType.Include:  return fi.IsFolder ? IMAGE_INCLUDE_FOLDER : IMAGE_INCLUDE_FILE;
         case CtrlFilter.ActionType.Exclude:  return fi.IsFolder ? IMAGE_EXCLUDE_FOLDER : IMAGE_EXCLUDE_FILE;
         case CtrlFilter.ActionType.History:  return fi.IsFolder ? IMAGE_HISTORY_FOLDER : IMAGE_HISTORY_FILE;
     }
     return IMAGE_FOLDER;
 }