Advertisement
Guest User

Package builder

a guest
Oct 8th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.26 KB | None | 0 0
  1. @echo off
  2.  
  3.  
  4. :: ----------------- USER CONFIGURATION ---------------------
  5.  
  6. set WINRAR_PATH="C:\Program Files\WinRAR\WinRAR.exe"
  7. set PACKAGE_EXT=.xpi
  8.  
  9. :: ----------------------------------------------------------
  10.  
  11.  
  12.  
  13.  
  14.  
  15. :: PROGRAM CONFIGURATION
  16. title Package builder
  17.  
  18. set package_name=package%PACKAGE_EXT%
  19. set package_file="%CD%\%package_name%"
  20. set package_path=%~1
  21. set package_content=
  22.  
  23. :: INITIALIZE COLORS
  24. for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")
  25.  
  26.  
  27. :: CHECK IF PATH TO WINRAR IS SET
  28. :check_winrar_path
  29. if defined WINRAR_PATH goto check_package_ext
  30.  
  31. :: GET PATH TO WINRAR FROM USER INPUT
  32. :get_winrar_path
  33. set /p WINRAR_PATH=Path to WinRAR (WinRAR.exe):
  34.  
  35. :: IF NOTHING IS GIVEN, ASK AGAIN
  36. if not defined WINRAR_PATH (
  37.     call :colorText 04 "Path not defined!"
  38.     goto get_winrar_path
  39. )
  40.  
  41. :: IF PATH DOESN'T EXIST, ASK AGAIN
  42. if not exist WINRAR_PATH (
  43.     call :colorText 04 "Path not found!"
  44.     goto get_winrar_path
  45. )
  46.  
  47.  
  48. :: CHECK IF EXTENSION IS SET
  49. :check_package_ext
  50. if defined PACKAGE_EXT goto check_package_path
  51.  
  52. :: GET EXTENSION FROM USER INPUT
  53. :get_package_ext
  54. set /p PACKAGE_EXT=Package extension (.zip, .jar, .xpi etc.):
  55.  
  56. :: IF NOTHING IS GIVEN, ASK AGAIN
  57. if not defined PACKAGE_EXT (
  58.     call :colorText 04 "Extension not defined!"
  59.     goto get_package_ext
  60. )
  61.  
  62.  
  63. :: CHECK IF PATH TO PACKAGE IS SET
  64. :check_package_path
  65. if defined package_path goto get_package_name
  66.  
  67. :: GET PATH TO PACKAGE FROM USER INPUT
  68. :get_package_path
  69. set /p package_path=Build a package from path:
  70.  
  71. :: IF NOTHING IS GIVEN, ASK AGAIN
  72. if not defined package_path (
  73.     call :colorText 04 "Path not defined!"
  74.     goto get_package_path
  75. )
  76.  
  77. :: IF PATH DOESN'T EXIST, ASK AGAIN
  78. if not exist %package_path% (
  79.     call :colorText 04 "Path not found!"
  80.     goto get_package_path
  81. )
  82.  
  83. set package_path=%package_path:"=%
  84.  
  85.  
  86. :: GET PACKAGE NAME
  87. :get_package_name
  88. set tmp=%package_path%
  89.  
  90. :: LOOP PATH TO GET NAME
  91. :_loop
  92. for /f "tokens=1* delims=\" %%A in ( "%tmp%" ) do (
  93.     set package_name=%%A
  94.     set tmp=%%B
  95.     goto _loop
  96. )
  97.  
  98. :: IF PACKAGE NAME IS SET, UPDATE FILE PATH
  99. if defined package_name if not "%package_name:"=%"=="" (
  100.     set package_file="%CD%\%package_name%%PACKAGE_EXT%"
  101. )
  102.  
  103. echo Building package "%package_name%%PACKAGE_EXT%" ...
  104.  
  105. :: LOOP FOR EVERY FILE AND FOLDER
  106. for /f "tokens=*" %%f in ('dir "%package_path%" /A:D /B 2^> nul') do call set "package_content=%%package_content%%"%package_path%\%%f" "
  107. for /f "tokens=*" %%f in ('dir "%package_path%" /A:-D /B 2^> nul') do call set "package_content=%%package_content%%"%package_path%\%%f" "
  108.  
  109. :: DELETE EXISTING FILE
  110. if not defined package_content goto fail
  111. if exist %package_file% del %package_file%
  112.  
  113. :: BUILD PACKAGE
  114. %WINRAR_PATH% a -r -ep1 -ibck -inul -afzip -m5 %package_file% %package_content% > nul || goto fail
  115.  
  116. call :colorText 02 "Building done!"
  117. timeout 1 > nul
  118. goto end
  119.  
  120. :: FAIL LABEL
  121. :fail
  122. if %ERRORLEVEL% EQU 0 (
  123.     call :colorText 04 "Building failed for unknown reason!"
  124. ) else (
  125.     call :colorText 04 "Building failed with error code %ERRORLEVEL%!"
  126. )
  127. echo.
  128. pause
  129.  
  130. goto end
  131.  
  132. :: LABEL FOR COLORS
  133. :colorText
  134. <nul set /p ".=%DEL%" > "%~2"
  135. findstr /v /a:%1 /R "^$" "%~2" nul
  136. del "%~2" > nul 2>&1i
  137. echo.
  138. goto :eof
  139.  
  140. :: PROGRAM END
  141. :end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement