2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . IO ;
5
+ using System . Linq ;
5
6
using System . Text . Json ;
6
7
using System . Text . Json . Serialization ;
7
8
@@ -16,12 +17,14 @@ public class ExternalTool
16
17
public string Executable { get ; private set ; }
17
18
public string OpenCmdArgs { get ; private set ; }
18
19
public Bitmap IconImage { get ; private set ; } = null ;
20
+ public Func < string , string > ArgTransform { get ; private set ; }
19
21
20
- public ExternalTool ( string name , string icon , string executable , string openCmdArgs )
22
+ public ExternalTool ( string name , string icon , string executable , string openCmdArgs , Func < string , string > argsTransform )
21
23
{
22
24
Name = name ;
23
25
Executable = executable ;
24
26
OpenCmdArgs = openCmdArgs ;
27
+ ArgTransform = argsTransform ?? ( ( s ) => s ) ;
25
28
26
29
try
27
30
{
@@ -37,11 +40,16 @@ public ExternalTool(string name, string icon, string executable, string openCmdA
37
40
38
41
public void Open ( string repo )
39
42
{
43
+ string arguments = string . Format ( OpenCmdArgs , repo ) ;
44
+
45
+ if ( ArgTransform != null )
46
+ arguments = ArgTransform . Invoke ( arguments ) ;
47
+
40
48
Process . Start ( new ProcessStartInfo ( )
41
49
{
42
50
WorkingDirectory = repo ,
43
51
FileName = Executable ,
44
- Arguments = string . Format ( OpenCmdArgs , repo ) ,
52
+ Arguments = arguments ,
45
53
UseShellExecute = false ,
46
54
} ) ;
47
55
}
@@ -110,17 +118,17 @@ public ExternalToolsFinder()
110
118
_customPaths = new ExternalToolPaths ( ) ;
111
119
}
112
120
113
- public void TryAdd ( string name , string icon , string args , string key , Func < string > finder )
121
+ public void TryAdd ( string name , string icon , string args , string key , Func < string > finder , Func < string , string > argsTransform = null )
114
122
{
115
123
if ( _customPaths . Tools . TryGetValue ( key , out var customPath ) && File . Exists ( customPath ) )
116
124
{
117
- Founded . Add ( new ExternalTool ( name , icon , customPath , args ) ) ;
125
+ Founded . Add ( new ExternalTool ( name , icon , customPath , args , argsTransform ) ) ;
118
126
}
119
127
else
120
128
{
121
129
var path = finder ( ) ;
122
130
if ( ! string . IsNullOrEmpty ( path ) && File . Exists ( path ) )
123
- Founded . Add ( new ExternalTool ( name , icon , path , args ) ) ;
131
+ Founded . Add ( new ExternalTool ( name , icon , path , args , argsTransform ) ) ;
124
132
}
125
133
}
126
134
@@ -154,6 +162,25 @@ public void Zed(Func<string> platformFinder)
154
162
TryAdd ( "Zed" , "zed" , "\" {0}\" " , "ZED" , platformFinder ) ;
155
163
}
156
164
165
+ public void VisualStudio ( Func < string > platformFinder )
166
+ {
167
+ TryAdd ( "Visual Studio" , "vs" , "\" {0}\" " , "VISUALSTUDIO" , platformFinder , VisualStudioTryFindSolution ) ;
168
+ }
169
+
170
+ private static string VisualStudioTryFindSolution ( string path )
171
+ {
172
+ try
173
+ {
174
+ if ( Directory . GetFiles ( path . Trim ( '\" ' ) , "*.sln" , SearchOption . AllDirectories ) . FirstOrDefault ( ) is string solutionPath )
175
+ return Path . GetFullPath ( solutionPath ) ;
176
+ }
177
+ catch
178
+ {
179
+ // do nothing
180
+ }
181
+ return path ;
182
+ }
183
+
157
184
public void FindJetBrainsFromToolbox ( Func < string > platformFinder )
158
185
{
159
186
var exclude = new List < string > { "fleet" , "dotmemory" , "dottrace" , "resharper-u" , "androidstudio" } ;
@@ -171,7 +198,8 @@ public void FindJetBrainsFromToolbox(Func<string> platformFinder)
171
198
$ "{ tool . DisplayName } { tool . DisplayVersion } ",
172
199
supported_icons . Contains ( tool . ProductCode ) ? $ "JetBrains/{ tool . ProductCode } " : "JetBrains/JB" ,
173
200
Path . Combine ( tool . InstallLocation , tool . LaunchCommand ) ,
174
- "\" {0}\" " ) ) ;
201
+ "\" {0}\" " ,
202
+ null ) ) ;
175
203
}
176
204
}
177
205
}
0 commit comments