2
2
using System . Collections . Generic ;
3
3
using System . Diagnostics ;
4
4
using System . IO ;
5
- using System . Linq ;
6
5
using System . Text . Json ;
7
6
using System . Text . Json . Serialization ;
8
7
@@ -14,17 +13,13 @@ namespace SourceGit.Models
14
13
public class ExternalTool
15
14
{
16
15
public string Name { get ; private set ; }
17
- public string Executable { get ; private set ; }
18
- public string OpenCmdArgs { get ; private set ; }
19
16
public Bitmap IconImage { get ; private set ; } = null ;
20
- public Func < string , string > ArgTransform { get ; private set ; }
21
17
22
- public ExternalTool ( string name , string icon , string executable , string openCmdArgs , Func < string , string > argsTransform )
18
+ public ExternalTool ( string name , string icon , string execFile , Func < string , string > execArgsGenerator = null )
23
19
{
24
20
Name = name ;
25
- Executable = executable ;
26
- OpenCmdArgs = openCmdArgs ;
27
- ArgTransform = argsTransform ?? ( ( s ) => s ) ;
21
+ _execFile = execFile ;
22
+ _execArgsGenerator = execArgsGenerator ?? ( repo => $ "\" { repo } \" ") ;
28
23
29
24
try
30
25
{
@@ -40,19 +35,17 @@ public ExternalTool(string name, string icon, string executable, string openCmdA
40
35
41
36
public void Open ( string repo )
42
37
{
43
- string arguments = string . Format ( OpenCmdArgs , repo ) ;
44
-
45
- if ( ArgTransform != null )
46
- arguments = ArgTransform . Invoke ( arguments ) ;
47
-
48
38
Process . Start ( new ProcessStartInfo ( )
49
39
{
50
40
WorkingDirectory = repo ,
51
- FileName = Executable ,
52
- Arguments = arguments ,
41
+ FileName = _execFile ,
42
+ Arguments = _execArgsGenerator . Invoke ( repo ) ,
53
43
UseShellExecute = false ,
54
44
} ) ;
55
45
}
46
+
47
+ private string _execFile = string . Empty ;
48
+ private Func < string , string > _execArgsGenerator = null ;
56
49
}
57
50
58
51
public class JetBrainsState
@@ -118,67 +111,48 @@ public ExternalToolsFinder()
118
111
_customPaths = new ExternalToolPaths ( ) ;
119
112
}
120
113
121
- public void TryAdd ( string name , string icon , string args , string key , Func < string > finder , Func < string , string > argsTransform = null )
114
+ public void TryAdd ( string name , string icon , Func < string > finder , Func < string , string > execArgsGenerator = null )
122
115
{
123
- if ( _customPaths . Tools . TryGetValue ( key , out var customPath ) && File . Exists ( customPath ) )
116
+ if ( _customPaths . Tools . TryGetValue ( name , out var customPath ) && File . Exists ( customPath ) )
124
117
{
125
- Founded . Add ( new ExternalTool ( name , icon , customPath , args , argsTransform ) ) ;
118
+ Founded . Add ( new ExternalTool ( name , icon , customPath , execArgsGenerator ) ) ;
126
119
}
127
120
else
128
121
{
129
122
var path = finder ( ) ;
130
123
if ( ! string . IsNullOrEmpty ( path ) && File . Exists ( path ) )
131
- Founded . Add ( new ExternalTool ( name , icon , path , args , argsTransform ) ) ;
124
+ Founded . Add ( new ExternalTool ( name , icon , path , execArgsGenerator ) ) ;
132
125
}
133
126
}
134
127
135
128
public void VSCode ( Func < string > platformFinder )
136
129
{
137
- TryAdd ( "Visual Studio Code" , "vscode" , " \" {0} \" " , "VSCODE" , platformFinder ) ;
130
+ TryAdd ( "Visual Studio Code" , "vscode" , platformFinder ) ;
138
131
}
139
132
140
133
public void VSCodeInsiders ( Func < string > platformFinder )
141
134
{
142
- TryAdd ( "Visual Studio Code - Insiders" , "vscode_insiders" , " \" {0} \" " , "VSCODE_INSIDERS" , platformFinder ) ;
135
+ TryAdd ( "Visual Studio Code - Insiders" , "vscode_insiders" , platformFinder ) ;
143
136
}
144
137
145
138
public void VSCodium ( Func < string > platformFinder )
146
139
{
147
- TryAdd ( "VSCodium" , "codium" , " \" {0} \" " , "VSCODIUM" , platformFinder ) ;
140
+ TryAdd ( "VSCodium" , "codium" , platformFinder ) ;
148
141
}
149
142
150
143
public void Fleet ( Func < string > platformFinder )
151
144
{
152
- TryAdd ( "Fleet" , "fleet" , " \" {0} \" " , "FLEET" , platformFinder ) ;
145
+ TryAdd ( "Fleet" , "fleet" , platformFinder ) ;
153
146
}
154
147
155
148
public void SublimeText ( Func < string > platformFinder )
156
149
{
157
- TryAdd ( "Sublime Text" , "sublime_text" , " \" {0} \" " , "SUBLIME_TEXT" , platformFinder ) ;
150
+ TryAdd ( "Sublime Text" , "sublime_text" , platformFinder ) ;
158
151
}
159
152
160
153
public void Zed ( Func < string > platformFinder )
161
154
{
162
- TryAdd ( "Zed" , "zed" , "\" {0}\" " , "ZED" , platformFinder ) ;
163
- }
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 ;
155
+ TryAdd ( "Zed" , "zed" , platformFinder ) ;
182
156
}
183
157
184
158
public void FindJetBrainsFromToolbox ( Func < string > platformFinder )
@@ -197,9 +171,7 @@ public void FindJetBrainsFromToolbox(Func<string> platformFinder)
197
171
Founded . Add ( new ExternalTool (
198
172
$ "{ tool . DisplayName } { tool . DisplayVersion } ",
199
173
supported_icons . Contains ( tool . ProductCode ) ? $ "JetBrains/{ tool . ProductCode } " : "JetBrains/JB" ,
200
- Path . Combine ( tool . InstallLocation , tool . LaunchCommand ) ,
201
- "\" {0}\" " ,
202
- null ) ) ;
174
+ Path . Combine ( tool . InstallLocation , tool . LaunchCommand ) ) ) ;
203
175
}
204
176
}
205
177
}
0 commit comments