Advertisement
Urik_Kane

open_in_crowbar_add

Oct 14th, 2020 (edited)
605
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.30 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. title Add Crowbar context menu entries (manual)
  4.  
  5. set default_extensions=mdl,qc
  6.  
  7. :check_elevation
  8. net session >nul 2>&1
  9. if not %errorlevel%==0 echo   & echo Error: Must run as administrator. & pause>nul & goto :eof
  10.  
  11. cd /d "%~dp0"
  12.  
  13. set foundcount=0
  14.  
  15. :check nearby
  16. if exist "%~dp0crowbar.exe" ( CALL :LogFoundFolder "%~dp0Crowbar.exe" & goto :ConfirmFolder)
  17.  
  18. :hintcustomfolder
  19. echo.
  20. echo Please enter Crowbar folder
  21. echo.
  22. :AskCustomFolder
  23. set installpath=
  24. set /p installpath="Enter Crowbar.exe folder "
  25. for %%P in (%installpath%) do goto :next
  26. goto :AskCustomFolder
  27. :next
  28. set installpath=%installpath:"=%
  29. if "%installpath:~-1%"=="\" set "installpath=%installpath:~0,-1%"
  30. if "%installpath:~-1%"=="/" set "installpath=%installpath:~0,-1%"
  31. for %%P in (%installpath%) do (
  32.     if exist "%installpath%" (
  33.     if not "%%~xP"=="" if /i "%%~nxP"=="Crowbar.exe" ( CALL :SetCustomFolder "%installpath%" & goto :ConfirmFolder)
  34.     if exist "%installpath%\Crowbar.exe" ( CALL :SetCustomFolder "%installpath%\Crowbar.exe" & goto :ConfirmFolder)
  35.     )
  36. )
  37. echo  & echo Error^: Could not find installation in provided folder. & echo. & goto :AskCustomFolder
  38.  
  39. :hintextensions
  40. echo.
  41. echo Please enter file extensions to add, divided by comma, lowercase, no dots or just press enter for default list
  42. echo.
  43. :askextensions
  44. set /p extensions="What extensions to add for (default %default_extensions%): "
  45. if not "!extensions!"=="" (
  46.     set "extensions=!extensions: =!"
  47.     for /f "tokens=1 delims=abcdefghijklmnopqrstuvwxyz1234567890," %%A in ('echo !extensions!') do (
  48.         set "extensions=%default_extensions%"
  49.         echo Warning: input incorrect, will use default setting ^(%default_extensions%^)
  50.         pause
  51.     )
  52. ) else ( set "extensions=%default_extensions%" )
  53.  
  54. :: exec for all extensions
  55. for %%E in (%extensions%) do CALL :SetKeys %%E
  56.  
  57. :: results
  58. echo.
  59. echo -------------------------------------------------------
  60. if "!processedcount!"=="" ( echo  No entries added ) else ( echo  !processedcount! entries added: !processed! )
  61. echo -------------------------------------------------------
  62. echo.
  63. pause & goto :eof
  64.  
  65.  
  66. :SetKeys
  67. reg add "HKCR\SystemFileAssociations\.%1\shell\Crowbar.open" /f /v "" /t REG_SZ /d "Open in Crowbar">nul 2>&1
  68. reg add "HKCR\SystemFileAssociations\.%1\shell\Crowbar.open" /f /v "Icon" /t REG_SZ /d "\"%installpath%\",0">nul 2>&1
  69. reg add "HKCR\SystemFileAssociations\.%1\shell\Crowbar.open\command" /f /v "" /t REG_SZ /d "\"%installpath%\" \"%%1\"">nul 2>&1
  70. if !errorlevel!==0 CALL :LogFileType %1
  71. goto :eof
  72.  
  73. :LogFileType
  74. if "!processedcount!"=="" ( set "processedcount=1" ) else ( set /a "processedcount=!processedcount!+1" )
  75. if "!processed!"=="" ( set "processed=%1" ) else ( set "processed=!processed!,%1" )
  76. goto :eof
  77.  
  78. :LogFoundFolder
  79. echo.
  80. echo Crowbar installation found: "%~1"
  81. set "foundpath1=%~1"
  82. goto :eof
  83.  
  84. :SetCustomFolder
  85. echo.
  86. echo Crowbar custom installation: "%~1" & echo.
  87. set "foundpath1=%~1"
  88. goto :eof
  89.  
  90. :ConfirmFolder
  91. set proceed=
  92. set /p "proceed=Use this installation (Y/N)?"
  93. if not "!proceed!"=="" (
  94.     set "proceed=!proceed: =!"
  95.     for /f "delims=yYnN" %%A in ('echo !proceed!') do goto :ConfirmFolder
  96. )
  97. if /i !proceed!==y ( set "installpath=%foundpath1%" & goto :hintextensions)
  98. if /i !proceed!==n ( echo. & goto :hintcustomfolder)
  99. goto :ConfirmFolder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement