Skip to content

Commit

Permalink
Update ProperTree.bat
Browse files Browse the repository at this point in the history
  • Loading branch information
corpnewt authored Jul 15, 2020
1 parent 49d5725 commit 2e7608d
Showing 1 changed file with 37 additions and 41 deletions.
78 changes: 37 additions & 41 deletions ProperTree.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ REM FORCE = Use py3
set "use_py3=TRUE"

REM Get the system32 (or equivalent) path
call :setcomspec
set "syspath=%ComSpec:cmd.exe=%"
call :getsyspath "syspath"

goto checkscript

Expand All @@ -46,14 +45,14 @@ if not exist "!thisDir!\!script_name!" (
)
goto checkpy

:setcomspec
:getsyspath <variable_name>
REM Helper method to return the "proper" path to cmd.exe, reg.exe, and where.exe by walking the ComSpec var
REM Prep the LF variable to use the "line feed" approach
(SET LF=^
%=this line is empty=%
)
REM Strip double semi-colons
call :undouble "ComSpec" ";"
call :undouble "ComSpec" "%ComSpec%" ";"
set "testpath=%ComSpec:;=!LF!%"
REM Let's walk each path and test if cmd.exe, reg.exe, and where.exe exist there
set /a found=0
Expand All @@ -76,6 +75,7 @@ for /f "tokens=* delims=" %%i in ("!testpath!") do (
if EXIST "!temppath!where.exe" (
set /a found=1
set "ComSpec=!temppath!cmd.exe"
set "%~1=!temppath!"
)
)
)
Expand All @@ -100,17 +100,16 @@ if not "%spath%" == "" (
set "PATH=%upath%"
)
REM Remove double semicolons from the adjusted PATH
call :undouble "PATH" ";"
call :undouble "PATH" "%PATH%" ";"
goto :EOF

:undouble <string_name> <character>
:undouble <string_name> <string_value> <character>
REM Helper function to strip doubles of a single character out of a string recursively
set "string_name=%~1"
set "character=%~2"
set "check=!%string_name%:%character%%character%=%character%!"
if not "!check!" == "!%~1!" (
set "!string_name!=!check!"
call :undouble "%~1" "%~2"
set "string_value=%~2"
set "check=!string_value:%~3%~3=%~3!"
if not "!check!" == "!string_value!" (
set "%~1=!check!"
call :undouble "%~1" "!check!" "%~3"
)
goto :EOF

Expand All @@ -132,35 +131,32 @@ if /i "!use_py3!" == "FALSE" (
if not "!pypath!" == "" (
goto runscript
)

if "!pypath!" == "" (
if %tried% lss 1 (
if /i "!toask!"=="yes" (
REM Better ask permission first
goto askinstall
) else (
goto installpy
)
if !tried! lss 1 (
if /i "!toask!"=="yes" (
REM Better ask permission first
goto askinstall
) else (
cls
echo ### ###
echo # Warning #
echo ### ###
echo.
REM Couldn't install for whatever reason - give the error message
echo Python is not installed or not found in your PATH var.
echo Please install it from https://www.python.org/downloads/windows/
echo.
echo Make sure you check the box labeled:
echo.
echo "Add Python X.X to PATH"
echo.
echo Where X.X is the py version you're installing.
echo.
echo Press [enter] to quit.
pause > nul
exit /b
goto installpy
)
) else (
cls
echo ### ###
echo # Warning #
echo ### ###
echo.
REM Couldn't install for whatever reason - give the error message
echo Python is not installed or not found in your PATH var.
echo Please install it from https://www.python.org/downloads/windows/
echo.
echo Make sure you check the box labeled:
echo.
echo "Add Python X.X to PATH"
echo.
echo Where X.X is the py version you're installing.
echo.
echo Press [enter] to quit.
pause > nul
exit /b
)
goto runscript

Expand Down Expand Up @@ -240,7 +236,7 @@ if /i "!menu!"=="y" (
goto installpy
) else if "!menu!"=="n" (
REM No OK here...
set /a tried=%tried%+1
set /a tried=!tried!+1
goto checkpy
)
REM Incorrect answer - go back
Expand All @@ -249,7 +245,7 @@ goto askinstall
:installpy
REM This will attempt to download and install python
REM First we get the html for the python downloads page for Windows
set /a tried=%tried%+1
set /a tried=!tried!+1
cls
echo ### ###
echo # Installing Python #
Expand Down

0 comments on commit 2e7608d

Please sign in to comment.