File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . IO ;
4+ using System . Linq ;
5+ using System . Text . RegularExpressions ;
6+
7+ namespace OpenWith . Filters . impl
8+ {
9+ public class NameFilter : IFilter
10+ {
11+ public static NameFilter Build ( object config ) {
12+ if ( config is IEnumerable < object > list ) {
13+ return new NameFilter ( list . Where ( s => s != null ) . Select ( s => s . ToString ( ) ) ) ;
14+ }
15+ if ( config != null ) {
16+ return new NameFilter ( config . ToString ( ) ) ;
17+ }
18+ return null ;
19+ }
20+
21+ private readonly ISet < string > _set ;
22+ private readonly Regex _regex ;
23+
24+ public NameFilter ( string expr ) {
25+ if ( expr == null ) {
26+ throw new ArgumentNullException ( nameof ( expr ) ) ;
27+ }
28+ _set = null ;
29+ _regex = new Regex ( $ "^({ expr } )$", RegexOptions . IgnoreCase | RegexOptions . Singleline ) ;
30+ }
31+
32+ public NameFilter ( IEnumerable < string > list ) {
33+ _regex = null ;
34+ _set = new HashSet < string > ( list . Select ( s => s . ToLowerInvariant ( ) ) ) ;
35+ }
36+
37+ public bool Accepts ( string path ) {
38+ if ( path == null ) {
39+ throw new ArgumentNullException ( nameof ( path ) ) ;
40+ }
41+ if ( string . IsNullOrEmpty ( path ) ) {
42+ return false ;
43+ }
44+
45+ var ext = Path . GetFileNameWithoutExtension ( path ) ;
46+ if ( _set != null ) {
47+ return _set . Contains ( ext . ToLowerInvariant ( ) ) ;
48+ }
49+ if ( _regex != null ) {
50+ return _regex . IsMatch ( ext ) ;
51+ }
52+ return false ;
53+ }
54+ }
55+ }
Original file line number Diff line number Diff line change 115115 </ItemGroup >
116116 <ItemGroup >
117117 <Compile Include =" Behaviors\ApplyThemeStyleBehavior.cs" />
118+ <Compile Include =" Filters\impl\NameFilter.cs" />
118119 <Compile Include =" Filters\impl\MagicBytesFilter.cs" />
119120 <Compile Include =" Filters\impl\SizeFilter.cs" />
120121 <Compile Include =" Model\Mapping.cs" />
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ mappings:
1414 ext : ' bik'
1515 command : ' %PortableApps%\player\RADTools\binkplay.exe'
1616 args : ' %1 /W-0.4 /H-0.4'
17-
17+
1818 - name : Word
1919 filters :
2020 ext : ' docx?'
@@ -29,3 +29,8 @@ mappings:
2929 filters :
3030 ext : ['mkv', 'mp4', 'avi']
3131 command : ' %PortableApps%\video\mkvtoolnix\mkvtoolnix-gui1.exe'
32+
33+ - name : DICOM
34+ filters :
35+ name : ['DICOMDIR']
36+ command : ' %PortableApps%\gfx\MicroDICOM\mDicom.exe'
Original file line number Diff line number Diff line change @@ -39,14 +39,15 @@ public static void Main() {
3939 configProvider ,
4040 dialogService ,
4141 new FilterFactory ( )
42+ . WithFilter ( "name" , NameFilter . Build )
4243 . WithFilter ( "ext" , ExtensionFilter . Build )
4344 . WithFilter ( "size" , SizeFilter . Build )
4445 . WithFilter ( "magic" , MagicBytesFilter . Build ) ,
4546 new DefaultProcessStarter ( ) ,
4647 new FileIconProvider ( )
4748 ) ;
4849
49- Stopwatch stopwatch = Stopwatch . StartNew ( ) ;
50+ // Stopwatch stopwatch = Stopwatch.StartNew();
5051
5152 var args = Environment . GetCommandLineArgs ( ) ;
5253 app . Run ( args ) ;
You can’t perform that action at this time.
0 commit comments