@@ -7,7 +7,8 @@ rem | User Defined Variable(s) |
7
7
rem +------------------------------------------------+
8
8
9
9
rem WampServer custom install path.
10
- set $customInstallPath =
10
+ rem Note: Trailing slash is not required.
11
+ set $customInstallPath = E:\WampServer64
11
12
12
13
13
14
@@ -52,9 +53,6 @@ if "%1" neq "" (
52
53
set $cliSessionMode = 1
53
54
)
54
55
) else (
55
- rem Hack to define a backspace so the 'set /p' command can be offset from the windows edge.
56
- for /F %%a in ('" prompt $H &echo on &for %%b in (1) do rem" ') do set backspace = %%a
57
-
58
56
rem TUI mode in use.
59
57
cls
60
58
title WampServer PHP CLI Version Changer v%$scriptVersion%
@@ -101,7 +99,7 @@ rem -----------------------
101
99
rem Check PHP Folder Path
102
100
rem -----------------------
103
101
104
- rem Set the path to the PHP folders.
102
+ rem Set the absolute path to the PHP folders.
105
103
if %$installPath:~-1 % neq \ (
106
104
set $pathToPhpFolders = %$installPath% \%$pathToPhpFolders%
107
105
) else (
@@ -132,14 +130,15 @@ rem ----------------------------
132
130
rem Explode Environmental Path
133
131
rem ----------------------------
134
132
135
- rem Get the correctly referenced path string .
133
+ rem Get the correctly referenced environmental path .
136
134
if %$cliSessionMode% equ 0 (
137
135
rem Get the 'users' environmental path.
138
136
for /F " usebackq tokens=2,*" %%a in (`reg.exe query HKCU\Environment /v PATH`) do (
139
137
set $pathString = %%b
140
138
)) else (
141
- rem Get the command windows 'session' environmental path.
142
- rem This path is a combination of the system environmental path and the user environmental path.
139
+ rem Get the command window 'session' environmental path.
140
+ rem Note: This path is a combination of the system environmental
141
+ rem path and the user environmental path.
143
142
set $pathString = %Path%
144
143
)
145
144
@@ -163,8 +162,9 @@ rem ----------------------------
163
162
rem Find Active PHP Version(s)
164
163
rem ----------------------------
165
164
166
- rem If there is more than one PHP reference in the path, the operating system will
167
- rem only use the first one. Therefore, we only need to match the first one.
165
+ rem As the operating system only uses the first found PHP reference in the environmental path, then we will as well.
166
+ rem Note: If a PHP version other than an installed version is found, it will not be shown as an option,
167
+ rem though it will be removed from the environmental path when the newly selected version is added.
168
168
set $currentPhpVersionId = 0
169
169
170
170
rem Iterate through the path array.
@@ -204,14 +204,17 @@ if %$cliMode% equ 1 (
204
204
)
205
205
)
206
206
207
- rem Bypass displaying anything .
207
+ rem Bypass displaying the TUI .
208
208
goto checkUserInput
209
209
)
210
210
211
211
212
- rem ----------------------
213
- rem Display PHP Versions
214
- rem ----------------------
212
+ rem ------------------
213
+ rem Operation by TUI
214
+ rem ------------------
215
+
216
+ rem Hack to define a backspace so the 'set /p' command can be offset from the windows edge.
217
+ for /F %%a in ('" prompt $H &echo on &for %%b in (1) do rem" ') do set backspace = %%a
215
218
216
219
rem Show the header.
217
220
echo :
@@ -230,7 +233,7 @@ for /L %%a in (1,1,%$availablePhpCount%) do (
230
233
)
231
234
)
232
235
233
- rem Prompt the user to make a new selection.
236
+ rem Prompt the user to make a selection.
234
237
echo :
235
238
set /p $newSelectionId = %backspace% Selection (1-%$availablePhpCount%):
236
239
echo :
@@ -256,7 +259,7 @@ rem --------------------------
256
259
rem Implode Environment Path
257
260
rem --------------------------
258
261
259
- rem Rebuild the path string while excluding any and all found PHP path .
262
+ rem Rebuild the path string while excluding any and all found PHP paths .
260
263
set " $pathString = "
261
264
262
265
rem Iterate through the path array.
@@ -277,7 +280,7 @@ for /L %%a in (1,1,%$pathArrayCount%) do (
277
280
rem Check the last segment for a matching regex expression. IE: Any PHP folder.
278
281
echo !$lastSegment! | findstr /R /C:" ^php[1-9][0-9]*\.[0-9][0-9]*\.*[0-9]*[0-9]*" > nul
279
282
280
- rem If a match is not found, append the path to the path string.
283
+ rem If a match is not found, append the path to the path string and include a trailing semicolon .
281
284
if !errorlevel! neq 0 (
282
285
set $pathString = !$pathString!!$pathArray[%%a ]! ;
283
286
)
@@ -289,6 +292,9 @@ rem Add Chosen PHP Path
289
292
rem ---------------------
290
293
291
294
rem Add the selected PHP folder path to the end of the path string.
295
+ rem Note: Final path in environmental path not to include a trailing semicolon.
296
+ rem Adding selected PHP folder path to front of environmental path would
297
+ rem speed-up discoverability but unnecessarily complicate implosion.
292
298
set $pathString = %$pathString%%$pathToPhpFolders% \!$availablePhpArray[%$newSelectionId%]!
293
299
294
300
@@ -299,25 +305,27 @@ rem ----------------------------
299
305
rem Check if the CLI 'session' mode is being used.
300
306
if %$cliSessionMode% equ 1 (
301
307
302
- rem Message must come first as we loose reference to all variables.
308
+ rem Show the success message.
309
+ rem Note: Message must come first else we will loose
310
+ rem reference to newly selected PHP array value.
303
311
call :sessionUpdateSuccessful
304
312
305
- rem Set the sessions environmental path variable.
313
+ rem Set the 'session' environmental path variable.
306
314
endlocal && set " Path = %$pathString% " > nul
307
315
308
316
exit /B 0
309
317
) else (
310
318
311
319
rem Set the user environmental path variable.
312
- setx path " %$pathString% " > nul
320
+ setx Path " %$pathString% " > nul
313
321
314
322
rem Show the successful message.
315
323
goto updateSuccessful
316
324
)
317
325
318
326
319
327
rem ====================================================================================================================
320
- rem Success Message
328
+ rem Success Messages
321
329
rem ====================================================================================================================
322
330
323
331
rem -------------------
@@ -333,7 +341,8 @@ if %$cliMode% equ 0 (
333
341
pause > nul
334
342
exit 0
335
343
) else (
336
- echo Success - The PHP CLI version is now !$availablePhpArray[%$newSelectionId%]!
344
+ echo :
345
+ echo Success - The PHP CLI version is now !$availablePhpArray[%$newSelectionId%]!
337
346
exit /B 0
338
347
)
339
348
@@ -343,7 +352,8 @@ rem Session update successful
343
352
rem ---------------------------
344
353
:sessionUpdateSuccessful
345
354
346
- echo Success: This sessions PHP CLI version is now !$availablePhpArray[%$newSelectionId%]!
355
+ echo :
356
+ echo Success: This sessions PHP CLI version is now !$availablePhpArray[%$newSelectionId%]!
347
357
348
358
exit /B
349
359
@@ -365,7 +375,8 @@ if %$cliMode% equ 0 (
365
375
pause > nul
366
376
exit 0
367
377
) else (
368
- echo Notice: The PHP CLI version remains unchanged.
378
+ echo :
379
+ echo Notice: Current selection was given - The PHP CLI version remains unchanged.
369
380
exit /B 0
370
381
)
371
382
@@ -387,7 +398,8 @@ if %$cliMode% equ 0 (
387
398
pause > nul
388
399
exit 1
389
400
) else (
390
- echo Failure: An invalid php version was given - The PHP CLI version remains unchanged.
401
+ echo :
402
+ echo Failure: An invalid php version was given - The PHP CLI version remains unchanged.
391
403
exit /B 1
392
404
)
393
405
@@ -410,7 +422,8 @@ if %$cliMode% equ 0 (
410
422
pause > nul
411
423
exit 1
412
424
) else (
413
- echo Error: The $customInstallPath path " %$customInstallPath% " does not exist.
425
+ echo :
426
+ echo Error: The $customInstallPath path " %$customInstallPath% " does not exist.
414
427
exit /B 1
415
428
)
416
429
@@ -433,10 +446,13 @@ if %$cliMode% equ 0 (
433
446
pause > nul
434
447
exit 1
435
448
) else (
436
- echo Error: Neither of the default installation paths exists.
437
- echo 1. %$defaultInstallPath[0]%
438
- echo 2. %$defaultInstallPath[1]%
439
- echo WampServer does not appear to be installed.
449
+ echo :
450
+ echo Error: Neither of the default installation paths exists.
451
+ echo :
452
+ echo 1. %$defaultInstallPath[0]%
453
+ echo 2. %$defaultInstallPath[1]%
454
+ echo :
455
+ echo WampServer does not appear to be installed.
440
456
exit /B 1
441
457
)
442
458
@@ -457,7 +473,9 @@ if %$cliMode% equ 0 (
457
473
pause > nul
458
474
exit 1
459
475
) else (
460
- echo Error: The $pathToPhpFolders path " %$pathToPhpFolders% " does not exist.
461
- echo See the WampServer website for help.
476
+ echo :
477
+ echo Error: The $pathToPhpFolders path " %$pathToPhpFolders% " does not exist.
478
+ echo :
479
+ echo See the WampServer website for help.
462
480
exit /B 1
463
481
)
0 commit comments