55using PreLaunchTaskr . Core . Repositories . Implementations ;
66using PreLaunchTaskr . Core . Repositories . Interfaces ;
77
8+ using System ;
89using System . Collections . Generic ;
910using System . Diagnostics ;
1011using System . IO ;
@@ -52,22 +53,49 @@ public static Launcher Init(string baseDirectory)
5253 new EnvironmentVariableRepositoryImpl ( connection ) ) ;
5354 }
5455
55- public async Task < bool > Launch ( int programId , string [ ] args )
56+ public bool Launch ( int programId , string [ ] args )
5657 {
5758 ProgramInfo ? programInfo = programRepository . GetById ( programId ) ;
5859 if ( programInfo is null )
5960 return false ;
6061
61- return await Launch ( programInfo , args , false , false ) ;
62+ return Launch ( programInfo , args , false , false ) ;
6263 }
6364
64- public async Task < bool > Launch ( string path , string [ ] args )
65+ public bool Launch ( string path , string [ ] args )
6566 {
6667 ProgramInfo ? programInfo = programRepository . GetByPath ( path ) ;
6768 if ( programInfo is null )
6869 return false ;
6970
70- return await Launch ( programInfo , args , false , false ) ;
71+ return Launch ( programInfo , args , false , false ) ;
72+ }
73+
74+ public bool Launch (
75+ int programId ,
76+ string [ ] originArgs ,
77+ bool asAdmin ,
78+ bool waitForExit )
79+ {
80+
81+ ProgramInfo ? programInfo = programRepository . GetById ( programId ) ;
82+ if ( programInfo is null )
83+ return false ;
84+
85+ return Launch ( programInfo , originArgs , asAdmin , waitForExit ) ;
86+ }
87+
88+ public bool Launch (
89+ string path ,
90+ string [ ] originArgs ,
91+ bool asAdmin ,
92+ bool waitForExit )
93+ {
94+ ProgramInfo ? programInfo = programRepository . GetByPath ( path ) ;
95+ if ( programInfo is null )
96+ return false ;
97+
98+ return Launch ( programInfo , originArgs , asAdmin , waitForExit ) ;
7199 }
72100
73101 /// <summary>
@@ -76,7 +104,7 @@ public async Task<bool> Launch(string path, string[] args)
76104 /// <param name="programInfo">添加的程序的信息</param>
77105 /// <param name="originArgs">原启动参数,不包含用户附加,不剔除用户屏蔽。</param>
78106 /// <returns></returns>
79- public async Task < bool > Launch (
107+ public bool Launch (
80108 ProgramInfo programInfo ,
81109 string [ ] originArgs ,
82110 bool asAdmin ,
@@ -85,7 +113,14 @@ public async Task<bool> Launch(
85113 string symlinkPath = GlobalProperties . SymbolicLinkPath ( programInfo . Path ) ;
86114 if ( ! File . Exists ( symlinkPath ) )
87115 {
88- File . CreateSymbolicLink ( symlinkPath , programInfo . Path ) ;
116+ try
117+ {
118+ File . CreateSymbolicLink ( symlinkPath , programInfo . Path ) ;
119+ }
120+ catch ( Exception )
121+ {
122+ return false ;
123+ }
89124 }
90125 ProcessStartInfo programStartInfo = new ( )
91126 {
@@ -180,7 +215,7 @@ public async Task<bool> Launch(
180215 }
181216 }
182217 taskProcess . Start ( ) ;
183- await taskProcess . WaitForExitAsync ( ) ;
218+ taskProcess . WaitForExit ( ) ;
184219 }
185220
186221 // 带上处理后的启动参数、专属环境变量,去启动程序
@@ -199,7 +234,7 @@ public async Task<bool> Launch(
199234 return false ;
200235
201236 if ( waitForExit )
202- await programProcess . WaitForExitAsync ( ) ;
237+ programProcess . WaitForExit ( ) ;
203238
204239 return true ;
205240 }
@@ -224,7 +259,7 @@ public async Task<bool> Launch(
224259 return false ;
225260
226261 if ( waitForExit )
227- await programProcessAdmin . WaitForExitAsync ( ) ;
262+ programProcessAdmin . WaitForExit ( ) ;
228263
229264 return true ;
230265 }
0 commit comments