|
| 1 | +@rem v3.5.2 This script install patch for android ndk(x64) and android sdk tools's .exe |
| 2 | +@echo off |
| 3 | + |
| 4 | +:: BatchGotAdmin |
| 5 | +:------------------------------------- |
| 6 | +REM --> Check for permissions |
| 7 | +>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" |
| 8 | + |
| 9 | +REM --> If error flag set, we do not have admin. |
| 10 | +if '%errorlevel%' NEQ '0' ( |
| 11 | + echo Requesting administrative privileges... |
| 12 | + goto UACPrompt |
| 13 | +) else ( goto gotAdmin ) |
| 14 | + |
| 15 | +:UACPrompt |
| 16 | +echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" |
| 17 | +echo UAC.ShellExecute "cmd.exe", "/c %~s0 %*", "", "runas", 1 >> "%temp%\getadmin.vbs" |
| 18 | + |
| 19 | +"%temp%\getadmin.vbs" |
| 20 | +del "%temp%\getadmin.vbs" |
| 21 | +exit /B |
| 22 | + |
| 23 | +:gotAdmin |
| 24 | +pushd %cd% |
| 25 | +cd /d "%~dp0" |
| 26 | + |
| 27 | +set instDir=%~dp1 |
| 28 | +set instApp=%~nx1 |
| 29 | + |
| 30 | +set realAppPrefix=wrl- |
| 31 | + |
| 32 | +echo [wsls] Installing ... |
| 33 | + |
| 34 | +set X86HASH= |
| 35 | +set X64HASH= |
| 36 | +for /f "delims=" %%i in ('wsls-hash "x86/wsls-shell.exe"') do set X86HASH=%%i |
| 37 | +for /f "delims=" %%i in ('wsls-hash "x64/wsls-shell.exe"') do set X64HASH=%%i |
| 38 | + |
| 39 | +echo X86HASH=%X86HASH% |
| 40 | +echo X64HASH=%X64HASH% |
| 41 | + |
| 42 | +rem Install wsls core binaires |
| 43 | +del /q %WINDIR%\System32\wsLongPaths.dll 2>nul |
| 44 | +if exist %WINDIR%\SysWow64\ ( |
| 45 | + del /q %WINDIR%\SysWow64\wsLongPaths.dll 2>nul |
| 46 | + |
| 47 | + copy /y x64\wow64helper.exe %WINDIR%\System32\ |
| 48 | + copy /y x64\wsls-core.dll %WINDIR%\System32\ |
| 49 | + |
| 50 | + copy /y x86\wow64helper.exe %WINDIR%\SysWow64\ |
| 51 | + copy /y x86\wsls-core.dll %WINDIR%\SysWow64\ |
| 52 | +) else ( |
| 53 | + copy /y x86\wow64helper.exe %WINDIR%\System32\ |
| 54 | + copy /y x86\wsls-core.dll %WINDIR%\System32\ |
| 55 | +) |
| 56 | + |
| 57 | +rem clear errorlevel before starting install patch |
| 58 | +set errorlevel= |
| 59 | + |
| 60 | +rem patching make.exe & cmp.exe |
| 61 | +call :InstallPatch %instDir% %instApp% |
| 62 | + |
| 63 | +REM exit install.bat script |
| 64 | +:L_exit |
| 65 | +echo Exiting install.bat...&ping /n 2 127.0.1 >nul |
| 66 | +goto :eof |
| 67 | + |
| 68 | +rem --------------------- the InstalPatch subprocedure ---------------- |
| 69 | +rem <params> |
| 70 | +rem <instDir>The target .exe directory</instDir> |
| 71 | +rem <instApp>The target .exe</instApp> |
| 72 | +rem <arch>The arch of target, optional: if not specific, will auto detect</arch> |
| 73 | +rem <redApp>The redirect App, don't use original of ndk, such as gnumake.exe</redApp> |
| 74 | +rem </params> |
| 75 | +:InstallPatch |
| 76 | +set instDir=%1 |
| 77 | +set instApp=%2 |
| 78 | +set arch=%3 |
| 79 | +set redApp=%4 |
| 80 | + |
| 81 | +rem -------- check parameters ------ |
| 82 | + |
| 83 | +rem -- clear parameter value if nil |
| 84 | +if "%arch%"=="nil" set arch= |
| 85 | +if "%redApp%"=="nil" set redApp= |
| 86 | + |
| 87 | +rem if the arch undefined or nil, detect it auto |
| 88 | +setlocal ENABLEDELAYEDEXPANSION |
| 89 | +set errorlevel= |
| 90 | + |
| 91 | +rem Notes: ensure always detect arch from real app, this will auto fix previous release 3.4.x arch mismatch bug |
| 92 | +if not defined arch ( |
| 93 | + if exist "%instDir%\%realAppPrefix%%instApp%" ( |
| 94 | + call wsls-arch.exe "%instDir%\%realAppPrefix%%instApp%" |
| 95 | + if !errorlevel! GTR 0 set arch=x!errorlevel! |
| 96 | + ) else ( |
| 97 | + call wsls-arch.exe "%instDir%\%instApp%" |
| 98 | + if !errorlevel! GTR 0 set arch=x!errorlevel! |
| 99 | + ) |
| 100 | +) |
| 101 | + |
| 102 | +set errorlevel= |
| 103 | +setlocal DISABLEDELAYEDEXPANSION |
| 104 | + |
| 105 | +if not "%arch%"=="x86" ( |
| 106 | + if not "%arch%"=="x64" ( |
| 107 | + echo Skipping target %instDir%\%instApp% with arch '%arch%', valid arch list: x86,x64 && goto :eof |
| 108 | + ) |
| 109 | +) |
| 110 | + |
| 111 | +rem -- print parameters |
| 112 | +rem echo instDir="%instDir%" |
| 113 | +rem echo instApp="%instApp%" |
| 114 | +rem echo arch="%arch%" |
| 115 | +rem echo redApp="%redApp%" |
| 116 | + |
| 117 | +rem custom such as gnumake.exe |
| 118 | +if defined redApp ( |
| 119 | + copy /y %arch%\%redApp% "%instDir%\%redApp%" |
| 120 | + if exist %arch%\%instApp%.bridge copy /y %arch%\%instApp%.bridge "%instDir%\%instApp%.bridge" |
| 121 | +) |
| 122 | + |
| 123 | +set instHash= |
| 124 | +for /f "delims=" %%i in ('wsls-hash "%instDir%\%instApp%"') do set instHash=%%i |
| 125 | + |
| 126 | +if "%arch%"=="x64" ( |
| 127 | + if "%instHash%"=="%X64HASH%" goto :L_installed |
| 128 | +) else ( |
| 129 | + if "%instHash%"=="%X86HASH%" goto :L_installed |
| 130 | +) |
| 131 | + |
| 132 | +echo Installing patch for %instApp%(%arch%)... |
| 133 | + |
| 134 | +rem --- perform install |
| 135 | +rem make a copy of original xxx.exe to wrl-xxx.exe |
| 136 | +if not exist "%instDir%\%realAppPrefix%%instApp%" copy /y "%instDir%\%instApp%" "%instDir%\%realAppPrefix%%instApp%" |
| 137 | + |
| 138 | +copy /y %arch%\wsls-shell.exe "%instDir%\%instApp%" |
| 139 | + |
| 140 | +echo Install patch for %instApp%(%arch%) succeed. |
| 141 | +goto :eof |
| 142 | + |
| 143 | +:L_installed |
| 144 | +echo The patch for %instApp%(%arch%) already installed. |
| 145 | +goto :eof |
0 commit comments