File tree Expand file tree Collapse file tree 2 files changed +60
-4
lines changed
Rubberduck.VBEEditor/Utility Expand file tree Collapse file tree 2 files changed +60
-4
lines changed Original file line number Diff line number Diff line change 1
- using System . IO ;
1
+ using System . Collections . Generic ;
2
+ using System . IO ;
2
3
using System . Linq ;
3
4
using System . Text ;
5
+ using Rubberduck . JunkDrawer . Extensions ;
4
6
using Rubberduck . VBEditor . Extensions ;
7
+ using Rubberduck . VBEditor . SafeComWrappers ;
5
8
6
9
namespace Rubberduck . VBEditor . Utility
7
10
{
@@ -19,10 +22,9 @@ public string ModuleName(string filename)
19
22
return null ;
20
23
}
21
24
22
- //We cannot read binary files.
23
- if ( ComponentTypeExtensions . FormBinaryExtension . Equals ( Path . GetExtension ( filename ) ) )
25
+ if ( ! SupportedExtensions . Contains ( Path . GetExtension ( filename ) ) )
24
26
{
25
- return Path . GetFileNameWithoutExtension ( filename ) ;
27
+ return null ;
26
28
}
27
29
28
30
var contents = File . ReadLines ( filename , Encoding . Default ) ;
@@ -35,5 +37,10 @@ public string ModuleName(string filename)
35
37
//The format is Attribute VB_Name = "ModuleName"
36
38
return nameLine . Substring ( "Attribute VB_Name = " . Length + 1 , nameLine . Length - "Attribute VB_Name = " . Length - 2 ) ;
37
39
}
40
+
41
+ private static ICollection < string > SupportedExtensions =>
42
+ ComponentTypeExtensions . ComponentTypesForExtension ( VBEKind . Hosted ) . Keys
43
+ . Concat ( ComponentTypeExtensions . ComponentTypesForExtension ( VBEKind . Standalone ) . Keys )
44
+ . ToHashSet ( ) ;
38
45
}
39
46
}
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using System . IO ;
3
+ using System . Text ;
4
+ using System . Text . RegularExpressions ;
5
+ using Rubberduck . VBEditor . Extensions ;
6
+ using Rubberduck . VBEditor . SafeComWrappers ;
7
+ using Path = System . IO . Path ;
8
+
9
+ namespace Rubberduck . VBEditor . Utility
10
+ {
11
+ public class UserFormRequiredBinaryFileNameExtractor : IRequiredBinaryFilesFromFileNameExtractor
12
+ {
13
+ public ICollection < ComponentType > SupportedComponentTypes => new List < ComponentType > { ComponentType . UserForm } ;
14
+
15
+ public ICollection < string > RequiredBinaryFiles ( string fileName , ComponentType componentType )
16
+ {
17
+ if ( ! File . Exists ( fileName ) )
18
+ {
19
+ return null ;
20
+ }
21
+
22
+ if ( ! SupportedComponentTypes . Contains ( componentType ) )
23
+ {
24
+ return null ;
25
+ }
26
+
27
+ if ( componentType . FileExtension ( ) != Path . GetExtension ( fileName ) )
28
+ {
29
+ return null ;
30
+ }
31
+
32
+ var regExPattern = "OleObjectBlob\\ s+=\\ s+\" ([^\" ]+)\" :" ;
33
+ var regEx = new Regex ( regExPattern ) ;
34
+ var contents = File . ReadLines ( fileName , Encoding . Default ) ;
35
+
36
+ foreach ( var codeLine in contents )
37
+ {
38
+ var match = regEx . Match ( codeLine ) ;
39
+ if ( match . Success )
40
+ {
41
+ return new List < string > { match . Groups [ 1 ] . Value } ;
42
+ }
43
+ }
44
+
45
+ var fallbackBinaryName = Path . GetFileNameWithoutExtension ( fileName ) + componentType . BinaryFileExtension ( ) ;
46
+ return new List < string > { fallbackBinaryName } ;
47
+ }
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments