@@ -187,16 +187,20 @@ public static void AddEnvironmentVariable(string variable)
187187 /// Update browser driver environment variable if it's already exist and different from current
188188 /// </summary>
189189 /// <param name="variable">Environment variable</param>
190- // TODO : Temporary disable this functionality because of wrong path override
191- public static void UpdatePath ( string variable )
190+ /// <param name="extendPath">Extend PATH variable with driver variable</param>
191+ public static void UpdatePath ( string variable , bool extendPath = false )
192192 {
193193 try
194194 {
195- // const string name = "PATH";
196- // var pathVariable = Environment.GetEnvironmentVariable(name);
197- // var newPathVariable = pathVariable + (pathVariable != null && pathVariable.EndsWith(";") ? string.Empty : ";") + $@"%{variable}%";
198- // if (pathVariable != null && !pathVariable.Contains(DesticationFolder) && !pathVariable.Contains(variable))
199- // Environment.SetEnvironmentVariable(newPathVariable, name, EnvironmentVariableTarget.Machine);
195+ if ( ! extendPath ) return ;
196+ const string name = "PATH" ;
197+ var pathVariable = Environment . GetEnvironmentVariable ( name ) ;
198+ var newPathVariable = pathVariable +
199+ ( pathVariable != null && pathVariable . EndsWith ( ";" ) ? string . Empty : ";" ) +
200+ $@ "%{ variable } %";
201+ if ( pathVariable != null && ! pathVariable . Contains ( DesticationFolder ) &&
202+ ! pathVariable . Contains ( variable ) )
203+ Environment . SetEnvironmentVariable ( newPathVariable , name , EnvironmentVariableTarget . Machine ) ;
200204 }
201205 catch ( Exception ex )
202206 {
@@ -213,29 +217,31 @@ public static void Install(string command)
213217 {
214218 try
215219 {
216- if ( File . Exists ( DesticationFile ) && IsNew )
220+ if ( ! File . Exists ( DesticationFile ) || ! IsNew ) return ;
221+ var startInfo = new ProcessStartInfo
217222 {
218- ProcessStartInfo startInfo = new ProcessStartInfo
219- {
220- UseShellExecute = false ,
221- WindowStyle = ProcessWindowStyle . Hidden ,
222- FileName = DesticationFile ,
223- Arguments = command
224- } ;
225- Process process = new Process
226- {
227- StartInfo = startInfo
228- } ;
229- process . Start ( ) ;
230- process . WaitForExit ( ) ;
231- }
223+ UseShellExecute = false ,
224+ WindowStyle = ProcessWindowStyle . Hidden ,
225+ FileName = DesticationFile ,
226+ Arguments = command
227+ } ;
228+ var process = new Process
229+ {
230+ StartInfo = startInfo
231+ } ;
232+ process . Start ( ) ;
233+ process . WaitForExit ( ) ;
232234 }
233235 catch ( Exception ex )
234236 {
235237 HLog . Error ( ex ,
236- $ "Error occurred during application installation from file '{ DesticationFile } ' using command '{ command } '") ;
238+ "Error occurred during application installation " +
239+ $ "from file '{ DesticationFile } ' " +
240+ $ "using command '{ command } '") ;
237241 throw new WebDriverManagerException (
238- $ "Error occurred during application installation from file '{ DesticationFile } ' using command '{ command } '",
242+ "Error occurred during application installation " +
243+ $ "from file '{ DesticationFile } ' " +
244+ $ "using command '{ command } '",
239245 ex ) ;
240246 }
241247 }
0 commit comments