-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathxphp.bat
More file actions
176 lines (150 loc) · 4.85 KB
/
Copy pathxphp.bat
File metadata and controls
176 lines (150 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
@echo off
title Xampp PHP Switcher
setlocal EnableExtensions EnableDelayedExpansion
cd /D %~dp0
rem ---------------------------------------------
for /F "tokens=* USEBACKQ" %%v in (`where php`) do (
if not exist "%%v" goto phpBinNotFound
)
set XPHP_APP_DIR=%~dp0
if not "%XPHP_APP_DIR:~-2%"==":\" set XPHP_APP_DIR=%XPHP_APP_DIR:~0,-1%
set XPHP_SRC_DIR=%XPHP_APP_DIR%\src
set XPHP_TMP_DIR=%XPHP_APP_DIR%\tmp
set XPHP_PHP_CONTROLLER=%XPHP_SRC_DIR%\xphp.php
set XPHP_POWER_EXECUTOR=%XPHP_SRC_DIR%\power_exec.vbs
if not exist "%XPHP_TMP_DIR%" mkdir "%XPHP_TMP_DIR%"
goto startCommand
rem ---------------------------------------------
:phpBinNotFound
echo.
echo Cannot find PHP CLI.
echo Make sure you have add the path to your PHP directory into Windows Path Environment Variable.
call %~fx0:clearEnvVars
exit /B 1
rem ---------------------------------------------
:installed
echo.
echo Xampp PHP Switcher is already integrated into Xampp.
echo No need to do it again.
echo.
pause>nul|set/p =Press any key to exit terminal...
call :clearEnvVars
exit /B
rem ---------------------------------------------
:installationFailed
echo.
echo Installation Xampp PHP Switcher failed.
echo Please review the instructions carefully before installation.
if exist "%XPHP_APP_DIR%\settings.ini" del /Q "%XPHP_APP_DIR%\settings.ini"
echo.
pause>nul|set/p =Press any key to exit terminal...
call :clearEnvVars
exit 1
rem ---------------------------------------------
:missingArgs
echo.
echo Xampp PHP Switcher error: The "command" argument is missing.
echo.
goto help
call :clearEnvVars
exit /B 1
rem ---------------------------------------------
:clearEnvVars
set XPHP_APP_DIR=
set XPHP_TMP_DIR=
set XPHP_POWER_EXECUTOR=
set XPHP_PHP_CONTROLLER=
exit /B
rem ---------------------------------------------
:help
type %XPHP_APP_DIR%\xphp.hlp
call :clearEnvVars
exit /B
rem ---------------------------------------------
:install
if exist "%XPHP_APP_DIR%\settings.ini" goto installed
FSUTIL dirty query %SystemDrive%>nul
if %errorLevel% NEQ 0 (
echo.
echo This process can only be run with elevated permission.
pause>nul|set/p =Press any key to start this process in Administrator mode...
echo.
cscript //NoLogo "%XPHP_POWER_EXECUTOR%" -e -x -n "%~fx0" "install"
if errorLevel 1 (
echo The installation was canceled by user.
exit /B 1
) else (
echo The installation started in new window with Elevated permission.
exit /B
)
)
php -n -d output_buffering=0 "%XPHP_PHP_CONTROLLER%" "install"
if %errorLevel% EQU 1 goto installationFailed
if %errorLevel% EQU 2 (
echo.
pause>nul|set/p =Press any key to exit terminal...
call :clearEnvVars
exit /B 2
)
echo|set/p =Moving directory of the current PHP build into the repository...
for /F "tokens=* USEBACKQ" %%v in ("%XPHP_TMP_DIR%\.phpdir") do (set XPHP_PHP_DIR=%%v)
for /F "tokens=* USEBACKQ" %%v in ("%XPHP_TMP_DIR%\.storage_path") do (set XPHP_PHP_REPO=%%v)
move /Y "%XPHP_PHP_DIR%" "%XPHP_PHP_REPO%" >nul 2>&1
echo Successful
echo|set/p =Creating symbolic link to the current PHP build in repository...
mklink /J "%XPHP_PHP_DIR%" "%XPHP_PHP_REPO%" >nul 2>&1
echo Successful
del /Q "%XPHP_TMP_DIR%\."
set XPHP_PHP_DIR=
set XPHP_PHP_REPO=
echo.
echo -----------------------------------------------------------------------------------
echo XAMPP PHP SWITCHER WAS INSTALLED SUCCESSFULLY.
echo TO START USING IT, PLEASE EXIT YOUR TERMINAL TO
echo DELETE TEMPORARY PROCESS ENVIRONMENT VARIABLES.
echo.
pause>nul|set/p =Press any key to exit terminal...
call :clearEnvVars
exit
rem ---------------------------------------------
:addVersion
php -n -d output_buffering=0 %XPHP_PHP_CONTROLLER% "addVersion" "%~2"
call :clearEnvVars
exit /B %errorLevel%
rem ---------------------------------------------
:removeVersion
php -n -d output_buffering=0 %XPHP_PHP_CONTROLLER% "removeVersion" "%~2"
call :clearEnvVars
exit /B %errorLevel%
rem ---------------------------------------------
:listVersions
php -n -d output_buffering=0 %XPHP_PHP_CONTROLLER% "listVersions"
call :clearEnvVars
exit /B %errorLevel%
rem ---------------------------------------------
:showVersion
php -n -d output_buffering=0 %XPHP_PHP_CONTROLLER% "showVersion" "%~2"
call :clearEnvVars
exit /B %errorLevel%
rem ---------------------------------------------
:switchVersion
php -n -d output_buffering=0 %XPHP_PHP_CONTROLLER% "switchVersion" "%~2"
call :clearEnvVars
exit /B %errorLevel%
rem ---------------------------------------------
:startCommand
cls
if "%~1"=="" goto missingArgs
if "%~1"=="help" goto help
if "%~1"=="install" goto install
if "%~1"=="add" goto addVersion
if "%~1"=="remove" goto removeVersion
if "%~1"=="list" goto listVersions
if "%~1"=="info" goto showVersion
if "%~1"=="switch" goto switchVersion
rem Call command with unknown param -------------
echo.
echo Xampp PHP Switcher error: "%~1" is invalid xphp command.
echo.
goto help
endlocal