Advertisement
Urik_Kane

open_in_avidemux_win64_add

Dec 2nd, 2019 (edited)
1,023
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 4.70 KB | None | 0 0
  1. @echo off
  2. setlocal enabledelayedexpansion
  3. title Add Avidemux context menu entry
  4.  
  5. set default_extensions=mp4,mov,mts,m2ts,mkv
  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. set executables=avidemux.exe,avidemux_portable.exe
  12. set foundcount=0
  13.  
  14. :: search in C:\Program Files
  15. cd /d %programfiles%
  16. for /d %%F in (*avidemux*) do ( for %%X in (%executables%) do ( if exist "%%~F\%%~X" ( CALL :LogFoundFolder "%programfiles%\%%~F\%%~X")))
  17.  
  18. :: search in the same folder the script is located in
  19. cd /d "%~dp0"
  20. for %%X in (%executables%) do ( if exist "%~dp0%%~X" ( cd..\.. & CALL :LogFoundFolder "%~dp0%%~X"))
  21.  
  22.  
  23. if !foundcount!==0 echo Could not auto-find any installations. & goto :hintcustomfolder
  24. if !foundcount!==1 goto :ConfirmFolder
  25. FOR /L %%F IN (1,1,%foundcount%) DO ( if ""!folderidlist!=="" ( set folderidlist=%%F) else ( set folderidlist=!folderidlist!,%%F))
  26.  
  27.  
  28. :SelectFoundFolder
  29. echo.
  30. echo please choose folder ^( !folderidlist! or custom^)
  31. FOR /L %%F IN (1,1,%foundcount%) DO ( echo  %%F     !foundpath%%F!)
  32. echo.
  33. set folderid=
  34. set /p folderid="enter number !folderidlist! or word ^"custom^"   = "
  35. if not "!folderid!"=="" (
  36.     set "folderid=!folderid: =!"
  37.     for %%A in (!folderid!) do ( if /i "%%~A"=="custom" goto :hintcustomfolder)
  38.     for /f "delims=1234567890" %%A in ('echo !folderid!') do echo ERROR: !folderid! - only numbers are allowed^^! & goto :SelectFoundFolder
  39.     for %%A in (%folderidlist%) do if "!folderid!"=="%%A" (
  40.         set "installpath=!foundpath%%A!"
  41.         echo. & echo Selected folder: !installpath!
  42.         goto :hintextensions
  43.     )
  44.     echo ERROR: !folderid! is NOT a valid option^^!
  45. )
  46. goto :SelectFoundFolder
  47.  
  48. :hintcustomfolder
  49. echo.
  50. echo Please enter Avidemux folder
  51. echo.
  52. :AskCustomFolder
  53. set installpath=
  54. set /p installpath="Enter Avidemux folder "
  55. for %%P in (%installpath%) do goto :next
  56. goto :AskCustomFolder
  57. :next
  58. set installpath=%installpath:"=%
  59. if "%installpath:~-1%"=="\" set "installpath=%installpath:~0,-1%"
  60. if "%installpath:~-1%"=="/" set "installpath=%installpath:~0,-1%"
  61. for %%P in (%installpath%) do (
  62.     if exist "%installpath%" (
  63.         if not "%%~xP"=="" ( for %%X in (%executables%) do ( if /i "%%~nxP"=="%%~X" CALL :SetCustomFolder "%installpath%" & goto :ConfirmFolder))
  64.         for %%X in (%executables%) do ( if exist "%installpath%\%%~X" ( CALL :SetCustomFolder "%installpath%\%%~X" & goto :ConfirmFolder))
  65.     )
  66. )
  67. echo  & echo Error^: Could not find installation in provided folder. & echo. & goto :AskCustomFolder
  68.  
  69. :hintextensions
  70. echo.
  71. echo Please enter file extensions to remove, divided by comma, lowercase, no dots or just press enter for default list
  72. echo.
  73. :askextensions
  74. set /p extensions="What extensions to add for (default %default_extensions%): "
  75. if not "!extensions!"=="" (
  76.     set "extensions=!extensions: =!"
  77.     for /f "tokens=1 delims=abcdefghijklmnopqrstuvwxyz1234567890," %%A in ('echo !extensions!') do (
  78.         set "extensions=%default_extensions%"
  79.         echo Warning: input incorrect, will use default setting ^(%default_extensions%^)
  80.         pause
  81.     )
  82. ) else ( set "extensions=%default_extensions%" )
  83.  
  84. :: exec for all extensions
  85. for %%E in (%extensions%) do CALL :SetKeys %%E
  86.  
  87. :: results
  88. echo.
  89. echo -------------------------------------------------------
  90. if "!processedcount!"=="" ( echo  No entries added ) else ( echo  !processedcount! entries added: !processed! )
  91. echo -------------------------------------------------------
  92. echo.
  93. pause & goto :eof
  94.  
  95.  
  96. :SetKeys
  97. reg add "HKCR\SystemFileAssociations\.%1\shell\AviDemux.open" /f /v "" /t REG_SZ /d "Open in Avidemux">nul 2>&1
  98. reg add "HKCR\SystemFileAssociations\.%1\shell\AviDemux.open" /f /v "Icon" /t REG_SZ /d "\"%installpath%\",0">nul 2>&1
  99. reg add "HKCR\SystemFileAssociations\.%1\shell\AviDemux.open\command" /f /v "" /t REG_SZ /d "\"%installpath%\" \"%%1\"">nul 2>&1
  100. if !errorlevel!==0 CALL :LogFileType %1
  101. goto :eof
  102.  
  103. :LogFileType
  104. if "!processedcount!"=="" ( set "processedcount=1" ) else ( set /a "processedcount=!processedcount!+1" )
  105. if "!processed!"=="" ( set "processed=%1" ) else ( set "processed=!processed!,%1" )
  106. goto :eof
  107.  
  108. :LogFoundFolder
  109. set /a foundcount=!foundcount!+1
  110. echo.
  111. echo Avidemux installation found: "%~1"
  112. set "foundpath!foundcount!=%~1"
  113. goto :eof
  114.  
  115. :SetCustomFolder
  116. echo.
  117. echo Avidemux custom installation: "%~1" & echo.
  118. set "foundpath1=%~1"
  119. goto :eof
  120.  
  121. :ConfirmFolder
  122. set proceed=
  123. set /p "proceed=Use this installation (Y/N)?"
  124. if not "!proceed!"=="" (
  125.     set "proceed=!proceed: =!"
  126.     for /f "delims=yYnN" %%A in ('echo !proceed!') do goto :ConfirmFolder
  127. )
  128. if /i !proceed!==y ( set "installpath=%foundpath1%" & goto :hintextensions)
  129. if /i !proceed!==n ( echo. & goto :hintcustomfolder)
  130. goto :ConfirmFolder
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement