control-freak-ide/OpenWithSublime.bat
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

68 lines
3.0 KiB
Batchfile

@echo off
:: Path to Sublime Text installation dir.
SET stPath=%~dp0sublime_text.exe
:: Key name for the registry entries.
SET UserEntry=Sublime Text
SET AdminEntry=Sublime Text As Admin
:: Context menu texts.
SET "UserMenuText=Open with Sublime(&-)"
SET "AdminMenuText=Open with Sublime As Admin(&+)"
SET GIST_WORKSPACE=https://gist.github.com/jcppkkk/8330314/raw
SET F_ELEVATE_CMD=OpenWithSublime_elevate.cmd
SET F_ELEVATE_VBS=OpenWithSublime_elevate.vbs
SET F_UNINSTALL=OpenWithSublime_uninstall.bat
call :download %GIST_WORKSPACE%/%F_ELEVATE_CMD% %F_ELEVATE_CMD%
call :download %GIST_WORKSPACE%/%F_ELEVATE_VBS% %F_ELEVATE_VBS%
call :download %GIST_WORKSPACE%/%F_UNINSTALL% %F_UNINSTALL%
call :check_Permissions
echo ===================================
echo Add context menu entry for all file types
SET REG_BASE=HKEY_CLASSES_ROOT\*\shell\%UserEntry%
reg add "%REG_BASE%" /t REG_SZ /v "" /d "%UserMenuText%" /f
reg add "%REG_BASE%" /t REG_EXPAND_SZ /v "Icon" /d "\"%stPath%\",0" /f
reg add "%REG_BASE%\command" /t REG_SZ /v "" /d "\"%stPath%\" \"%%1\"" /f
echo Add context menu entry for all file types, open as admin
SET REG_BASE=HKEY_CLASSES_ROOT\*\shell\%AdminEntry%
reg add "%REG_BASE%" /t REG_SZ /v "" /d "%AdminMenuText%" /f
reg add "%REG_BASE%" /t REG_EXPAND_SZ /v "Icon" /d "\"%stPath%\",0" /f
reg add "%REG_BASE%\command" /t REG_SZ /v "" /d "\"%F_ELEVATE_CMD%\" \"%stPath%\" \"%%1\"" /f
echo ===================================
echo Add context menu entry for folders
SET REG_BASE=HKEY_CLASSES_ROOT\Folder\shell\%UserEntry%
reg add "%REG_BASE%" /t REG_SZ /v "" /d "%UserMenuText%" /f
reg add "%REG_BASE%" /t REG_EXPAND_SZ /v "Icon" /d "\"%stPath%\",0" /f
reg add "%REG_BASE%\command" /t REG_SZ /v "" /d "\"%stPath%\" \"%%1\"" /f
echo Add context menu entry for directories background
SET REG_BASE=HKEY_CLASSES_ROOT\Directory\Background\shell\%UserEntry%
@reg add "%REG_BASE%" /t REG_SZ /v "" /d "%UserMenuText%" /f
@reg add "%REG_BASE%" /t REG_EXPAND_SZ /v "Icon" /d "\"%stPath%\",0" /f
@reg add "%REG_BASE%\command" /t REG_SZ /v "" /d "\"%stPath%\" \"%%V\"" /f
echo ===================================
echo All done! press any key to leave.
echo ===================================
pause
goto :EOF
:check_Permissions
echo # Administrative permissions required. Detecting permissions...
net session >nul 2>&1
if %errorLevel% == 0 (
echo Administrative permissions confirmed.
goto :EOF
) else (
echo Failure: Current permissions inadequate. Try to get elevation...
SET openwithsublime_elevation=1
call "%F_ELEVATE_CMD%" "%~fs0"
exit
)
:download
if not exist "%CD%\%2" (
C:\Windows\System32\WindowsPowerShell\v1.0\powershell "$wc = New-Object System.Net.WebClient;$wc.DownloadFile(\"%1\", \"%2\")"
echo Download %2
)
goto :EOF